Skip to content

Commit

Permalink
deconflict computed properties with arguments to _recompute - fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 13, 2017
1 parent 9b09758 commit e4d257d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/generators/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,15 +485,18 @@ export default class Generator {
`);
};

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

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

let name = this.getUniqueName(key);
let deconflicted = key;
if (conflicts) while (deconflicted in conflicts) deconflicted += '_'

let name = this.getUniqueName(deconflicted);
this.templateVars.set(qualified, name);

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

const prop = templateProperties.computed.value.properties.find((prop: Node) => getName(prop.key) === key);
addDeclaration(key, prop.value, 'computed');

addDeclaration(key, prop.value, 'computed', {
state: true,
changed: true
});
};

templateProperties.computed.value.properties.forEach((prop: Node) =>
Expand Down
12 changes: 12 additions & 0 deletions test/runtime/samples/computed-values-deconflicted/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
solo: true,

html: '<span>waiting</span>',

test(assert, component, target) {
component.set({ x: 'ready' });
assert.htmlEqual(target.innerHTML, `
<span>ready</span>
`);
}
};
14 changes: 14 additions & 0 deletions test/runtime/samples/computed-values-deconflicted/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<span>{{state}}</span>

<script>
export default {
data() {
return {
x: 'waiting'
};
},
computed: {
state: x => x
}
};
</script>

0 comments on commit e4d257d

Please sign in to comment.