Skip to content

Commit

Permalink
Merge pull request #1357 from sveltejs/gh-1337
Browse files Browse the repository at this point in the history
Update spread props in each blocks
  • Loading branch information
Rich-Harris authored Apr 20, 2018
2 parents d215279 + a0404f7 commit 350d1ed
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/generators/nodes/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/generators/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/flattenReference.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 1 addition & 0 deletions test/runtime/samples/spread-each-component/Nested.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div data-a={a} data-b={b}></div>
26 changes: 26 additions & 0 deletions test/runtime/samples/spread-each-component/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default {
html: `
<div data-a="1" data-b="2"></div>
<div data-a="3" data-b="4"></div>
`,

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, `
<div data-a="3" data-b="4"></div>
<div data-a="1" data-b="2"></div>
`);
},
};
11 changes: 11 additions & 0 deletions test/runtime/samples/spread-each-component/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{#each things as thing}
<Nested {...thing}/>
{/each}

<script>
import Nested from './Nested.html';

export default {
components: { Nested }
};
</script>
26 changes: 26 additions & 0 deletions test/runtime/samples/spread-each-element/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default {
html: `
<div data-a="1" data-b="2"></div>
<div data-c="3" data-d="4"></div>
`,

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, `
<div data-c="3" data-d="4"></div>
<div data-a="1" data-b="2"></div>
`);
},
};
3 changes: 3 additions & 0 deletions test/runtime/samples/spread-each-element/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{#each things as thing}
<div {...thing}></div>
{/each}

0 comments on commit 350d1ed

Please sign in to comment.