Skip to content

Commit 2e4ce75

Browse files
authored
Merge pull request #1516 from sveltejs/gh-1515
fix spread when an attribute or prop has multiple dependencies
2 parents 7032ec7 + 755f085 commit 2e4ce75

File tree

7 files changed

+48
-2
lines changed

7 files changed

+48
-2
lines changed

src/compile/nodes/Component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export default class Component extends Node {
176176
const { name, dependencies } = attr;
177177

178178
const condition = dependencies.size > 0 && (dependencies.size !== allDependencies.size)
179-
? [...dependencies].map(d => `changed.${d}`).join(' || ')
179+
? `(${[...dependencies].map(d => `changed.${d}`).join(' || ')})`
180180
: null;
181181

182182
if (attr.isSpread) {

src/compile/nodes/Element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ export default class Element extends Node {
559559
.filter(attr => attr.type === 'Attribute' || attr.type === 'Spread')
560560
.forEach(attr => {
561561
const condition = attr.dependencies.size > 0
562-
? [...attr.dependencies].map(d => `changed.${d}`).join(' || ')
562+
? `(${[...attr.dependencies].map(d => `changed.${d}`).join(' || ')})`
563563
: null;
564564

565565
if (attr.isSpread) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{foo} {baz}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
html: `b baz`,
3+
test(assert, component, target) {
4+
component.set({ foo: true });
5+
assert.htmlEqual(
6+
target.innerHTML,
7+
`a baz`
8+
);
9+
},
10+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Widget foo={foo ? a : b} {...bar}/>
2+
3+
<script>
4+
export default {
5+
components: { Widget: './Widget.html' },
6+
data: () => ({
7+
foo: false,
8+
a: 'a',
9+
b: 'b',
10+
bar: { baz: 'baz' },
11+
}),
12+
};
13+
</script>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
html: `<div class='b' title='baz'></div>`,
3+
test(assert, component, target) {
4+
component.set({ foo: true });
5+
assert.htmlEqual(
6+
target.innerHTML,
7+
`<div class='a' title='baz'></div>`
8+
);
9+
},
10+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class={foo ? a : b} {...bar}></div>
2+
3+
<script>
4+
export default {
5+
data: () => ({
6+
foo: false,
7+
a: 'a',
8+
b: 'b',
9+
bar: { title: 'baz' },
10+
}),
11+
};
12+
</script>

0 commit comments

Comments
 (0)