diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index 5ecb021d730a..a11a8d962a31 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -485,7 +485,7 @@ export default class Generator { `); }; - const addDeclaration = (key: string, node: Node, disambiguator?: string) => { + const addDeclaration = (key: string, node: Node, disambiguator?: string, conflicts?: Record) => { const qualified = disambiguator ? `${disambiguator}-${key}` : key; if (node.type === 'Identifier' && node.name === key) { @@ -493,7 +493,10 @@ export default class Generator { 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 @@ -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) => diff --git a/test/runtime/samples/computed-values-deconflicted/_config.js b/test/runtime/samples/computed-values-deconflicted/_config.js new file mode 100644 index 000000000000..549325488005 --- /dev/null +++ b/test/runtime/samples/computed-values-deconflicted/_config.js @@ -0,0 +1,12 @@ +export default { + solo: true, + + html: 'waiting', + + test(assert, component, target) { + component.set({ x: 'ready' }); + assert.htmlEqual(target.innerHTML, ` + ready + `); + } +}; diff --git a/test/runtime/samples/computed-values-deconflicted/main.html b/test/runtime/samples/computed-values-deconflicted/main.html new file mode 100644 index 000000000000..d32fde6167a6 --- /dev/null +++ b/test/runtime/samples/computed-values-deconflicted/main.html @@ -0,0 +1,14 @@ +{{state}} + + \ No newline at end of file