From 5b77b744ce2c24ee135717fcbeb46559e3579ff5 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 8 Aug 2019 12:14:15 -0400 Subject: [PATCH 1/3] generate valid code when spreading literal into props (#3185) --- .../compile/render_dom/wrappers/InlineComponent/index.ts | 4 ++-- .../runtime/samples/spread-component-literal/Widget.svelte | 5 +++++ test/runtime/samples/spread-component-literal/_config.js | 5 +++++ test/runtime/samples/spread-component-literal/main.svelte | 7 +++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/runtime/samples/spread-component-literal/Widget.svelte create mode 100644 test/runtime/samples/spread-component-literal/_config.js create mode 100644 test/runtime/samples/spread-component-literal/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts index c63879c06f..fb3a4186db 100644 --- a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts +++ b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts @@ -220,9 +220,9 @@ export default class InlineComponentWrapper extends Wrapper { const conditions = Array.from(all_dependencies).map(dep => `changed.${dep}`).join(' || '); updates.push(deindent` - var ${name_changes} = ${all_dependencies.size === 1 ? `${conditions}` : `(${conditions})`} ? @get_spread_update(${levels}, [ + var ${name_changes} = ${conditions ? `(${conditions}) ? @get_spread_update(${levels}, [ ${changes.join(',\n')} - ]) : {}; + ]) : {}` : '{}'}; `); } else { this.node.attributes diff --git a/test/runtime/samples/spread-component-literal/Widget.svelte b/test/runtime/samples/spread-component-literal/Widget.svelte new file mode 100644 index 0000000000..e00796baf3 --- /dev/null +++ b/test/runtime/samples/spread-component-literal/Widget.svelte @@ -0,0 +1,5 @@ + + +

foo: {foo}

diff --git a/test/runtime/samples/spread-component-literal/_config.js b/test/runtime/samples/spread-component-literal/_config.js new file mode 100644 index 0000000000..d1613218d5 --- /dev/null +++ b/test/runtime/samples/spread-component-literal/_config.js @@ -0,0 +1,5 @@ +export default { + html: ` +

foo: bar

+ ` +}; diff --git a/test/runtime/samples/spread-component-literal/main.svelte b/test/runtime/samples/spread-component-literal/main.svelte new file mode 100644 index 0000000000..13fdf99b69 --- /dev/null +++ b/test/runtime/samples/spread-component-literal/main.svelte @@ -0,0 +1,7 @@ + + +
+ +
From 73a21b855afb688becfcee95202f53f064d73eda Mon Sep 17 00:00:00 2001 From: vages Date: Sat, 10 Aug 2019 16:18:03 +0000 Subject: [PATCH 2/3] Document $$props This was explained in the tutorial, but I could not find any documentation on it in the docs. --- site/content/docs/02-template-syntax.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/site/content/docs/02-template-syntax.md b/site/content/docs/02-template-syntax.md index ae07c90993..aaa052df3b 100644 --- a/site/content/docs/02-template-syntax.md +++ b/site/content/docs/02-template-syntax.md @@ -94,6 +94,12 @@ An element or component can have multiple spread attributes, interspersed with r ``` +*`$$props`* references all props that are passed to a component – including ones that are not declared with `export`. It is useful in rare cases, but not generally recommended, as it is difficult for Svelte to optimise. + +```html + +``` + ### Text expressions From ad790d36b4ac1714fe161d8fa51364f6399a8d94 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 11 Aug 2019 10:24:20 -0400 Subject: [PATCH 3/3] add separator --- site/content/docs/02-template-syntax.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/site/content/docs/02-template-syntax.md b/site/content/docs/02-template-syntax.md index aaa052df3b..600634ab11 100644 --- a/site/content/docs/02-template-syntax.md +++ b/site/content/docs/02-template-syntax.md @@ -94,6 +94,8 @@ An element or component can have multiple spread attributes, interspersed with r ``` +--- + *`$$props`* references all props that are passed to a component – including ones that are not declared with `export`. It is useful in rare cases, but not generally recommended, as it is difficult for Svelte to optimise. ```html