From ee7f6769c48f955fbc894e89af3adec21aa96fb0 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 3 Apr 2018 16:46:27 -0400 Subject: [PATCH] spread on dynamic component - fixes #1307 --- src/generators/nodes/Component.ts | 4 +++- .../samples/spread-component-dynamic/Foo.html | 1 + .../spread-component-dynamic/_config.js | 21 +++++++++++++++++++ .../spread-component-dynamic/main.html | 13 ++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/spread-component-dynamic/Foo.html create mode 100644 test/runtime/samples/spread-component-dynamic/_config.js create mode 100644 test/runtime/samples/spread-component-dynamic/main.html diff --git a/src/generators/nodes/Component.ts b/src/generators/nodes/Component.ts index b80175250b81..79ece3310ef1 100644 --- a/src/generators/nodes/Component.ts +++ b/src/generators/nodes/Component.ts @@ -145,8 +145,10 @@ export default class Component extends Node { } }); + block.addVariable(levels); + statements.push(deindent` - var ${levels} = [ + ${levels} = [ ${initialProps.join(',\n')} ]; diff --git a/test/runtime/samples/spread-component-dynamic/Foo.html b/test/runtime/samples/spread-component-dynamic/Foo.html new file mode 100644 index 000000000000..5d65e4f61484 --- /dev/null +++ b/test/runtime/samples/spread-component-dynamic/Foo.html @@ -0,0 +1 @@ +

a: {{a}}

\ No newline at end of file diff --git a/test/runtime/samples/spread-component-dynamic/_config.js b/test/runtime/samples/spread-component-dynamic/_config.js new file mode 100644 index 000000000000..9637d2257817 --- /dev/null +++ b/test/runtime/samples/spread-component-dynamic/_config.js @@ -0,0 +1,21 @@ +export default { + data: { + props: { + a: 1, + }, + }, + + html: ` +

a: 1

+ `, + + test(assert, component, target) { + component.set({ + props: { + a: 2, + }, + }); + + assert.htmlEqual(target.innerHTML, `

a: 2

`); + }, +}; diff --git a/test/runtime/samples/spread-component-dynamic/main.html b/test/runtime/samples/spread-component-dynamic/main.html new file mode 100644 index 000000000000..687e54db79a4 --- /dev/null +++ b/test/runtime/samples/spread-component-dynamic/main.html @@ -0,0 +1,13 @@ +<:Component {Foo} {{...props}} /> + + \ No newline at end of file