From da4d90004ecfb2450d1f76347a6793b3e0b65e7b Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Wed, 9 Oct 2019 22:20:54 -0400 Subject: [PATCH] update code-red, update some tests etc --- package-lock.json | 35 ++++++++++-------- package.json | 2 +- src/compiler/compile/render_dom/index.ts | 2 +- .../render_dom/wrappers/shared/add_actions.ts | 4 +- .../action-custom-event-handler/expected.js | 33 ++++++----------- test/js/samples/action/expected.js | 37 ++++++++----------- test/js/samples/bind-online/expected.js | 1 - 7 files changed, 52 insertions(+), 62 deletions(-) diff --git a/package-lock.json b/package-lock.json index 88c3353c22..26b2b8b627 100644 --- a/package-lock.json +++ b/package-lock.json @@ -318,11 +318,6 @@ "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "dev": true }, - "astring": { - "version": "github:Rich-Harris/astring#9f675d470d1c758de5ec42724aa5dd2e1dabf919", - "from": "github:Rich-Harris/astring#generic-handler", - "dev": true - }, "async-limiter": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", @@ -495,16 +490,15 @@ "dev": true }, "code-red": { - "version": "0.0.15", - "resolved": "https://registry.npmjs.org/code-red/-/code-red-0.0.15.tgz", - "integrity": "sha512-r3c5r7IFsgKw3IE+F1wkTOezvwZ1N6xXKAJ0Dfyrs+JxHVEWbPU+goKwbo6XCCc8ykO5IU5Pofq1BvuxiXMQHQ==", + "version": "0.0.16", + "resolved": "https://registry.npmjs.org/code-red/-/code-red-0.0.16.tgz", + "integrity": "sha512-40SV6oWnBVVfUP+i8NYeTo9EQWtTnlZ17LIv91dKhLa6R/iZKqxOAV/5HEkj86EhLmNiRB7O6hEnga2jy0hoBA==", "dev": true, "requires": { "acorn": "^7.0.0", - "astring": "github:Rich-Harris/astring#9f675d470d1c758de5ec42724aa5dd2e1dabf919", "is-reference": "^1.1.3", - "periscopic": "^1.0.0", - "source-map": "^0.7.3" + "periscopic": "^1.0.1", + "sourcemap-codec": "^1.4.6" } }, "codecov": { @@ -2727,12 +2721,23 @@ "dev": true }, "periscopic": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/periscopic/-/periscopic-1.0.0.tgz", - "integrity": "sha512-ftydZZH2Ca4FdWJXDwQ1Uuz4VEBhh4jXuT1bprR4qg/zM2+FhulluBUxnQXI0olDqADmsQRE1eHLs42iIhNjtA==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/periscopic/-/periscopic-1.0.1.tgz", + "integrity": "sha512-JcSQ6sufVNGT04lPr2f2qGuJ2FCkZcbWBw0gQ8mzSVf9+6bEX9ea6l48+PdAekjJIHlEwSrqJND1TR2cC1FbtQ==", "dev": true, "requires": { - "is-reference": "^1.1.3" + "is-reference": "^1.1.4" + }, + "dependencies": { + "is-reference": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.1.4.tgz", + "integrity": "sha512-uJA/CDPO3Tao3GTrxYn6AwkM4nUPJiGGYu5+cB8qbC7WGFlrKZbiRo7SFKxUAEpFUfiHofWCXBUNhvYJMh+6zw==", + "dev": true, + "requires": { + "@types/estree": "0.0.39" + } + } } }, "pify": { diff --git a/package.json b/package.json index c103604e4a..44c4cda6d1 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "acorn": "^7.0.0", "agadoo": "^1.1.0", "c8": "^5.0.1", - "code-red": "0.0.15", + "code-red": "0.0.16", "codecov": "^3.5.0", "css-tree": "1.0.0-alpha22", "eslint": "^6.3.0", diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index 4269a929b9..ea2ccb422e 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -283,7 +283,7 @@ export default function dom( const instance_javascript = component.extract_javascript(component.ast.instance); const has_definition = ( - instance_javascript || + instance_javascript.length > 0 || filtered_props.length > 0 || uses_props || component.partly_hoisted.length > 0 || diff --git a/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts b/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts index 6eb25fcc36..331a71708e 100644 --- a/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts +++ b/src/compiler/compile/render_dom/wrappers/shared/add_actions.ts @@ -33,7 +33,7 @@ export default function add_actions( ); if (dependencies && dependencies.length > 0) { - let condition = x`typeof ${id}.update === 'function'`; + let condition = x`@is_function(${id}.update)`; // TODO can this case be handled more elegantly? if (dependencies.length > 0) { @@ -51,7 +51,7 @@ export default function add_actions( } block.chunks.destroy.push( - b`if (${id} && typeof ${id}.destroy === 'function') ${id}.destroy();` + b`if (${id} && @is_function(${id}.destroy)) ${id}.destroy();` ); }); } diff --git a/test/js/samples/action-custom-event-handler/expected.js b/test/js/samples/action-custom-event-handler/expected.js index 34d5ca10aa..ec65b83cd2 100644 --- a/test/js/samples/action-custom-event-handler/expected.js +++ b/test/js/samples/action-custom-event-handler/expected.js @@ -1,62 +1,53 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, detach, element, init, insert, + is_function, noop, safe_not_equal } from "svelte/internal"; function create_fragment(ctx) { - var button, foo_action; + let button; + let foo_action; return { c() { button = element("button"); button.textContent = "foo"; }, - m(target, anchor) { insert(target, button, anchor); - foo_action = foo.call(null, button, ctx.foo_function) || {}; + foo_action = foo.call(null, button, ctx.foo_function) || ({}); }, - p(changed, ctx) { - if (typeof foo_action.update === 'function' && changed.bar) { - foo_action.update.call(null, ctx.foo_function); - } + if (is_function(foo_action.update) && changed.bar) foo_action.update.call(null, ctx.foo_function); }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(button); - } - - if (foo_action && typeof foo_action.destroy === 'function') foo_action.destroy(); + if (detaching) detach(button); + if (foo_action && is_function(foo_action.destroy)) foo_action.destroy(); } }; } -function handleFoo(bar) { - console.log(bar); +function foo(node, callback) { + } -function foo(node, callback) { - // code goes here +function handleFoo(bar) { + console.log(bar); } function instance($$self, $$props, $$invalidate) { let { bar } = $$props; - const foo_function = () => handleFoo(bar); $$self.$set = $$props => { - if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar); + if ("bar" in $$props) $$invalidate("bar", bar = $$props.bar); }; return { bar, foo_function }; diff --git a/test/js/samples/action/expected.js b/test/js/samples/action/expected.js index ed0a0a7430..04882f88f5 100644 --- a/test/js/samples/action/expected.js +++ b/test/js/samples/action/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, attr, @@ -6,12 +5,14 @@ import { element, init, insert, + is_function, noop, safe_not_equal } from "svelte/internal"; function create_fragment(ctx) { - var a, link_action; + let a; + let link_action; return { c() { @@ -19,39 +20,33 @@ function create_fragment(ctx) { a.textContent = "Test"; attr(a, "href", "#"); }, - m(target, anchor) { insert(target, a, anchor); - link_action = link.call(null, a) || {}; + link_action = link.call(null, a) || ({}); }, - p: noop, i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(a); - } - - if (link_action && typeof link_action.destroy === 'function') link_action.destroy(); + if (detaching) detach(a); + if (link_action && is_function(link_action.destroy)) link_action.destroy(); } }; } function link(node) { - function onClick(event) { - event.preventDefault(); - history.pushState(null, null, event.target.href); - } + function onClick(event) { + event.preventDefault(); + history.pushState(null, null, event.target.href); + } - node.addEventListener('click', onClick); + node.addEventListener("click", onClick); - return { - destroy() { - node.removeEventListener('click', onClick); - } - } + return { + destroy() { + node.removeEventListener("click", onClick); + } + }; } class Component extends SvelteComponent { diff --git a/test/js/samples/bind-online/expected.js b/test/js/samples/bind-online/expected.js index d42f804325..30087ca615 100644 --- a/test/js/samples/bind-online/expected.js +++ b/test/js/samples/bind-online/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, add_render_callback,