Skip to content

Commit bc7ade0

Browse files
authored
Merge pull request #1019 from sveltejs/gh-1012
deconflict computed properties with arguments to _recompute
2 parents b252e33 + 47b4162 commit bc7ade0

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/generators/Generator.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,18 @@ export default class Generator {
485485
`);
486486
};
487487

488-
const addDeclaration = (key: string, node: Node, disambiguator?: string) => {
488+
const addDeclaration = (key: string, node: Node, disambiguator?: string, conflicts?: Record<string, boolean>) => {
489489
const qualified = disambiguator ? `${disambiguator}-${key}` : key;
490490

491491
if (node.type === 'Identifier' && node.name === key) {
492492
this.templateVars.set(qualified, key);
493493
return;
494494
}
495495

496-
let name = this.getUniqueName(key);
496+
let deconflicted = key;
497+
if (conflicts) while (deconflicted in conflicts) deconflicted += '_'
498+
499+
let name = this.getUniqueName(deconflicted);
497500
this.templateVars.set(qualified, name);
498501

499502
// deindent
@@ -548,7 +551,11 @@ export default class Generator {
548551
computations.push({ key, deps });
549552

550553
const prop = templateProperties.computed.value.properties.find((prop: Node) => getName(prop.key) === key);
551-
addDeclaration(key, prop.value, 'computed');
554+
555+
addDeclaration(key, prop.value, 'computed', {
556+
state: true,
557+
changed: true
558+
});
552559
};
553560

554561
templateProperties.computed.value.properties.forEach((prop: Node) =>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
html: '<span>waiting</span>',
3+
4+
test(assert, component, target) {
5+
component.set({ x: 'ready' });
6+
assert.htmlEqual(target.innerHTML, `
7+
<span>ready</span>
8+
`);
9+
}
10+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<span>{{state}}</span>
2+
3+
<script>
4+
export default {
5+
data() {
6+
return {
7+
x: 'waiting'
8+
};
9+
},
10+
computed: {
11+
state: x => x
12+
}
13+
};
14+
</script>

0 commit comments

Comments
 (0)