From 5b77b744ce2c24ee135717fcbeb46559e3579ff5 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 8 Aug 2019 12:14:15 -0400 Subject: [PATCH] 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 @@ + + +
+ +