diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index d54aab52ff..b9642abd14 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -6,6 +6,7 @@ import Renderer from './Renderer'; import { CompileOptions } from '../../interfaces'; import { walk } from 'estree-walker'; import flattenReference from '../../utils/flattenReference'; +import stringifyProps from '../../utils/stringifyProps'; export default function dom( component: Component, @@ -201,7 +202,7 @@ export default function dom( ${component.partly_hoisted.length > 0 && component.partly_hoisted.join('\n\n')} - $$self.$$.get = () => ({ ${component.declarations.join(', ')} }); + $$self.$$.get = () => (${stringifyProps(component.declarations)}); ${set && `$$self.$$.set = ${set};`} diff --git a/src/compile/render-dom/wrappers/InlineComponent/index.ts b/src/compile/render-dom/wrappers/InlineComponent/index.ts index 9506426cb8..8580b2d7a9 100644 --- a/src/compile/render-dom/wrappers/InlineComponent/index.ts +++ b/src/compile/render-dom/wrappers/InlineComponent/index.ts @@ -108,7 +108,11 @@ export default class InlineComponentWrapper extends Wrapper { ); if (this.node.attributes.length || this.node.bindings.length) { - componentInitProperties.push(`props: ${props}`); + if (!usesSpread && this.node.bindings.length === 0) { + componentInitProperties.push(`props: ${attributeObject}`); + } else { + componentInitProperties.push(`props: ${props}`); + } } if (component.options.dev) { diff --git a/src/utils/deindent.ts b/src/utils/deindent.ts index fbd794ca9f..665f9c3dc1 100644 --- a/src/utils/deindent.ts +++ b/src/utils/deindent.ts @@ -19,6 +19,11 @@ export default function deindent( expression = expression.length ? expression.join('\n') : null; } + // discard empty codebuilders + if (expression && expression.isEmpty && expression.isEmpty()) { + expression = null; + } + if (expression || expression === '') { const value = String(expression).replace( /\n/g, diff --git a/test/js/index.js b/test/js/index.js index 3ee1a1da2d..71416d8cf3 100644 --- a/test/js/index.js +++ b/test/js/index.js @@ -3,7 +3,7 @@ import * as fs from "fs"; import * as path from "path"; import { loadConfig, svelte } from "../helpers.js"; -describe("js", () => { +describe.only("js", () => { fs.readdirSync("test/js/samples").forEach(dir => { if (dir[0] === ".") return; diff --git a/test/js/samples/bind-width-height/expected.js b/test/js/samples/bind-width-height/expected.js index 15e5c4d39b..30f1bc7fe4 100644 --- a/test/js/samples/bind-width-height/expected.js +++ b/test/js/samples/bind-width-height/expected.js @@ -21,7 +21,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index 212bedabff..ffbf9e543a 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -46,7 +46,7 @@ function create_fragment(component, ctx) { }; } -function define($$self, $$props, $$make_dirty) { +function define($$self, $$props) { let { foo = 42 } = $$props; $$self.$$.get = () => ({ foo }); diff --git a/test/js/samples/component-static-array/expected.js b/test/js/samples/component-static-array/expected.js index f300a76774..a3ffce0e49 100644 --- a/test/js/samples/component-static-array/expected.js +++ b/test/js/samples/component-static-array/expected.js @@ -24,7 +24,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/component-static-immutable2/expected.js b/test/js/samples/component-static-immutable2/expected.js index 5cef972a00..27d78d6c93 100644 --- a/test/js/samples/component-static-immutable2/expected.js +++ b/test/js/samples/component-static-immutable2/expected.js @@ -24,7 +24,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/component-static/expected.js b/test/js/samples/component-static/expected.js index 5dabd36aef..cb61bdf9de 100644 --- a/test/js/samples/component-static/expected.js +++ b/test/js/samples/component-static/expected.js @@ -24,7 +24,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index 86110d6dd2..c2d076a4cf 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -2,19 +2,12 @@ import { SvelteComponent as SvelteComponent_1, flush, init, noop, run, safe_not_equal } from "svelte/internal.js"; function create_fragment(component, ctx) { - var current; - return { c: noop, - m: noop, - p: noop, - i: noop, - o: run, - d: noop }; } diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index e1f4bb40b5..6cc33f6861 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -26,7 +26,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index 37df2e768f..c53db44d8e 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -20,7 +20,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/debug-empty/expected.js b/test/js/samples/debug-empty/expected.js index 146ff56e6e..6de9094712 100644 --- a/test/js/samples/debug-empty/expected.js +++ b/test/js/samples/debug-empty/expected.js @@ -40,7 +40,6 @@ function create_fragment(component, ctx) { i: function intro(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/debug-foo-bar-baz-things/expected.js b/test/js/samples/debug-foo-bar-baz-things/expected.js index dd3f1d0827..59571d43ad 100644 --- a/test/js/samples/debug-foo-bar-baz-things/expected.js +++ b/test/js/samples/debug-foo-bar-baz-things/expected.js @@ -123,7 +123,6 @@ function create_fragment(component, ctx) { i: function intro(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/debug-foo/expected.js b/test/js/samples/debug-foo/expected.js index 5e79d5280f..70c93e59f9 100644 --- a/test/js/samples/debug-foo/expected.js +++ b/test/js/samples/debug-foo/expected.js @@ -123,7 +123,6 @@ function create_fragment(component, ctx) { i: function intro(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/deconflict-builtins/expected.js b/test/js/samples/deconflict-builtins/expected.js index 8c0cd98bf6..abe92ccd58 100644 --- a/test/js/samples/deconflict-builtins/expected.js +++ b/test/js/samples/deconflict-builtins/expected.js @@ -90,7 +90,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/dev-warning-missing-data-computed/expected.js b/test/js/samples/dev-warning-missing-data-computed/expected.js index aca9612310..788d582c29 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected.js @@ -39,7 +39,6 @@ function create_fragment(component, ctx) { i: function intro(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/do-use-dataset/expected.js b/test/js/samples/do-use-dataset/expected.js index b7708da88e..adedc9df03 100644 --- a/test/js/samples/do-use-dataset/expected.js +++ b/test/js/samples/do-use-dataset/expected.js @@ -28,7 +28,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/dont-use-dataset-in-legacy/expected.js b/test/js/samples/dont-use-dataset-in-legacy/expected.js index 817f8ff76e..05e87514a5 100644 --- a/test/js/samples/dont-use-dataset-in-legacy/expected.js +++ b/test/js/samples/dont-use-dataset-in-legacy/expected.js @@ -28,7 +28,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/dont-use-dataset-in-svg/expected.js b/test/js/samples/dont-use-dataset-in-svg/expected.js index 621cb04500..a731fc910c 100644 --- a/test/js/samples/dont-use-dataset-in-svg/expected.js +++ b/test/js/samples/dont-use-dataset-in-svg/expected.js @@ -28,7 +28,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/dynamic-import/expected.js b/test/js/samples/dynamic-import/expected.js index 16e526988d..f68300fe54 100644 --- a/test/js/samples/dynamic-import/expected.js +++ b/test/js/samples/dynamic-import/expected.js @@ -26,7 +26,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 5be82de3a2..c972d66f61 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -129,7 +129,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/each-block-keyed-animated/expected.js b/test/js/samples/each-block-keyed-animated/expected.js index 58a73a1cdc..fc71eac904 100644 --- a/test/js/samples/each-block-keyed-animated/expected.js +++ b/test/js/samples/each-block-keyed-animated/expected.js @@ -105,7 +105,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/each-block-keyed/expected.js b/test/js/samples/each-block-keyed/expected.js index 1870c983c5..e527bc7a7c 100644 --- a/test/js/samples/each-block-keyed/expected.js +++ b/test/js/samples/each-block-keyed/expected.js @@ -75,7 +75,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index 78ec56a971..d101e33880 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -24,7 +24,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/event-modifiers/expected.js b/test/js/samples/event-modifiers/expected.js index e0801e4c1a..7ff50d564a 100644 --- a/test/js/samples/event-modifiers/expected.js +++ b/test/js/samples/event-modifiers/expected.js @@ -43,7 +43,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/head-no-whitespace/expected.js b/test/js/samples/head-no-whitespace/expected.js index d179906aa2..53089f010c 100644 --- a/test/js/samples/head-no-whitespace/expected.js +++ b/test/js/samples/head-no-whitespace/expected.js @@ -24,7 +24,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index d7521ecf0d..805799045d 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -79,7 +79,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index 2614e7af04..be88a92f6d 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -55,7 +55,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index a8ae965a62..2ad7afcc82 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -28,7 +28,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index 00a626773c..1b6904addf 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -23,7 +23,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/input-range/expected.js b/test/js/samples/input-range/expected.js index 57f3126632..10d2325769 100644 --- a/test/js/samples/input-range/expected.js +++ b/test/js/samples/input-range/expected.js @@ -26,7 +26,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index 40b3e099c3..41f6896905 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -25,7 +25,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index 58e3214476..1148105155 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -19,7 +19,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index d8f4f39801..5487b2d0b2 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -36,7 +36,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index 970bda8ff5..ab1242d844 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -27,7 +27,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/select-dynamic-value/expected.js b/test/js/samples/select-dynamic-value/expected.js index 37b0b83024..028a15c434 100644 --- a/test/js/samples/select-dynamic-value/expected.js +++ b/test/js/samples/select-dynamic-value/expected.js @@ -50,7 +50,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index 6a8546bc0c..5b2b7cc78f 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,7 +1,7 @@ /* generated by Svelte vX.Y.Z-alpha1 */ import { SvelteComponent as SvelteComponent_1, init, noop, run, safe_not_equal } from "svelte/internal.js"; -export const SOME_CONSTANT = 42; +const SOME_CONSTANT = 42; function foo(bar) { console.log(bar); @@ -29,4 +29,5 @@ class SvelteComponent extends SvelteComponent_1 { } } -export default SvelteComponent; \ No newline at end of file +export default SvelteComponent; +export { SOME_CONSTANT }; \ No newline at end of file diff --git a/test/js/samples/ssr-no-oncreate-etc/expected.js b/test/js/samples/ssr-no-oncreate-etc/expected.js index 50e3e6ed23..1335ce2942 100644 --- a/test/js/samples/ssr-no-oncreate-etc/expected.js +++ b/test/js/samples/ssr-no-oncreate-etc/expected.js @@ -1,4 +1,5 @@ /* generated by Svelte vX.Y.Z-alpha1 */ +import { create_ssr_component } from "svelte/internal.js"; import { onMount, onDestroy } from "svelte"; function preload(input) { @@ -13,7 +14,7 @@ function swipe(node, callback) { // TODO implement } -function define($$props) { +const SvelteComponent = create_ssr_component(($$result, $$props, $$bindings, $$slots) => { onMount(() => { console.log('onMount'); }); @@ -22,46 +23,8 @@ function define($$props) { console.log('onDestroy'); }); - return {}; -} - -var SvelteComponent = {}; - -SvelteComponent.render = function(props = {}, options = {}) { - var components = new Set(); - - function addComponent(component) { - components.add(component); - } - - var result = { head: '', addComponent }; - var html = SvelteComponent.$$render(result, props, options); - - var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n'); - - return { - html, - head: result.head, - css: { code: cssCode, map: null }, - toString() { - return html; - } - }; -} - -SvelteComponent.$$render = function($$result, props, options) { - const ctx = define(props); - - $$result.addComponent(SvelteComponent); - return ``; -}; - -SvelteComponent.css = { - code: '', - map: null -}; +}); -var warned = false; export default SvelteComponent; export { preload }; \ No newline at end of file diff --git a/test/js/samples/ssr-preserve-comments/expected.js b/test/js/samples/ssr-preserve-comments/expected.js index 0c688b87c5..c6b05af940 100644 --- a/test/js/samples/ssr-preserve-comments/expected.js +++ b/test/js/samples/ssr-preserve-comments/expected.js @@ -1,42 +1,10 @@ /* generated by Svelte vX.Y.Z-alpha1 */ +import { create_ssr_component } from "svelte/internal.js"; -var SvelteComponent = {}; - -SvelteComponent.render = function(props = {}, options = {}) { - var components = new Set(); - - function addComponent(component) { - components.add(component); - } - - var result = { head: '', addComponent }; - var html = SvelteComponent.$$render(result, props, options); - - var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n'); - - return { - html, - head: result.head, - css: { code: cssCode, map: null }, - toString() { - return html; - } - }; -} - -SvelteComponent.$$render = function($$result, ctx, options) { - $$result.addComponent(SvelteComponent); - +const SvelteComponent = create_ssr_component(($$result, $$props, $$bindings, $$slots) => { return `
content
more content
`; -}; - -SvelteComponent.css = { - code: '', - map: null -}; - -var warned = false; +}); export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/svg-title/expected.js b/test/js/samples/svg-title/expected.js index f7f66b1009..587574b7bd 100644 --- a/test/js/samples/svg-title/expected.js +++ b/test/js/samples/svg-title/expected.js @@ -22,7 +22,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 95ac7b2c4a..0d28049386 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -223,7 +223,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); }, diff --git a/test/js/samples/window-binding-scroll/expected.js b/test/js/samples/window-binding-scroll/expected.js index ca7e920b46..5b133058dd 100644 --- a/test/js/samples/window-binding-scroll/expected.js +++ b/test/js/samples/window-binding-scroll/expected.js @@ -38,7 +38,6 @@ function create_fragment(component, ctx) { i(target, anchor) { if (current) return; - this.m(target, anchor); },