From c84bd8516792ca327cf348d166b574c7f253471f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 19 Apr 2018 12:44:48 -0400 Subject: [PATCH 1/2] rename function to make it easier to find --- src/utils/flattenReference.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/flattenReference.ts b/src/utils/flattenReference.ts index b44fb6e27f68..a2303bca3463 100644 --- a/src/utils/flattenReference.ts +++ b/src/utils/flattenReference.ts @@ -1,6 +1,6 @@ import { Node } from '../interfaces'; -export default function flatten(node: Node) { +export default function flattenReference(node: Node) { const parts = []; const propEnd = node.end; From a0404f7331e8ec9b6a266e36e4e4bb309aac4f61 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 20 Apr 2018 15:13:01 -0400 Subject: [PATCH 2/2] update spread props in each blocks without other dynamic attributes - fixes #1337 --- src/generators/nodes/Component.ts | 2 +- src/generators/nodes/Element.ts | 2 ++ .../samples/spread-each-component/Nested.html | 1 + .../samples/spread-each-component/_config.js | 26 +++++++++++++++++++ .../samples/spread-each-component/main.html | 11 ++++++++ .../samples/spread-each-element/_config.js | 26 +++++++++++++++++++ .../samples/spread-each-element/main.html | 3 +++ 7 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/spread-each-component/Nested.html create mode 100644 test/runtime/samples/spread-each-component/_config.js create mode 100644 test/runtime/samples/spread-each-component/main.html create mode 100644 test/runtime/samples/spread-each-element/_config.js create mode 100644 test/runtime/samples/spread-each-element/main.html diff --git a/src/generators/nodes/Component.ts b/src/generators/nodes/Component.ts index d7bd3d442f94..cc829819288f 100644 --- a/src/generators/nodes/Component.ts +++ b/src/generators/nodes/Component.ts @@ -37,7 +37,7 @@ export default class Component extends Node { attribute.expression.arguments.forEach((arg: Node) => { block.addDependencies(arg.metadata.dependencies); }); - } else if (attribute.type === 'Binding') { + } else if (attribute.type === 'Binding' || attribute.type === 'Spread') { block.addDependencies(attribute.metadata.dependencies); } } diff --git a/src/generators/nodes/Element.ts b/src/generators/nodes/Element.ts index 0bc180e8d1f2..a44c94981621 100644 --- a/src/generators/nodes/Element.ts +++ b/src/generators/nodes/Element.ts @@ -89,6 +89,8 @@ export default class Element extends Node { } } else if (attribute.type === 'Action' && attribute.expression) { block.addDependencies(attribute.metadata.dependencies); + } else if (attribute.type === 'Spread') { + block.addDependencies(attribute.metadata.dependencies); } } }); diff --git a/test/runtime/samples/spread-each-component/Nested.html b/test/runtime/samples/spread-each-component/Nested.html new file mode 100644 index 000000000000..fb0f25d2e70a --- /dev/null +++ b/test/runtime/samples/spread-each-component/Nested.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/runtime/samples/spread-each-component/_config.js b/test/runtime/samples/spread-each-component/_config.js new file mode 100644 index 000000000000..c5fcfb06b775 --- /dev/null +++ b/test/runtime/samples/spread-each-component/_config.js @@ -0,0 +1,26 @@ +export default { + html: ` +
+
+ `, + + data: { + things: [ + { a: 1, b: 2 }, + { a: 3, b: 4 } + ] + }, + + test(assert, component, target) { + const { things } = component.get(); + + component.set({ + things: things.reverse() + }); + + assert.htmlEqual(target.innerHTML, ` +
+
+ `); + }, +}; diff --git a/test/runtime/samples/spread-each-component/main.html b/test/runtime/samples/spread-each-component/main.html new file mode 100644 index 000000000000..0e1e9ce1d6a9 --- /dev/null +++ b/test/runtime/samples/spread-each-component/main.html @@ -0,0 +1,11 @@ +{#each things as thing} + +{/each} + + \ No newline at end of file diff --git a/test/runtime/samples/spread-each-element/_config.js b/test/runtime/samples/spread-each-element/_config.js new file mode 100644 index 000000000000..913a7cc8657f --- /dev/null +++ b/test/runtime/samples/spread-each-element/_config.js @@ -0,0 +1,26 @@ +export default { + html: ` +
+
+ `, + + data: { + things: [ + { 'data-a': 1, 'data-b': 2 }, + { 'data-c': 3, 'data-d': 4 } + ] + }, + + test(assert, component, target) { + const { things } = component.get(); + + component.set({ + things: things.reverse() + }); + + assert.htmlEqual(target.innerHTML, ` +
+
+ `); + }, +}; diff --git a/test/runtime/samples/spread-each-element/main.html b/test/runtime/samples/spread-each-element/main.html new file mode 100644 index 000000000000..99ae4eeecec9 --- /dev/null +++ b/test/runtime/samples/spread-each-element/main.html @@ -0,0 +1,3 @@ +{#each things as thing} +
+{/each} \ No newline at end of file