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/src/generators/nodes/Text.ts b/src/generators/nodes/Text.ts index 2a6865683609..f3f0c3968c15 100644 --- a/src/generators/nodes/Text.ts +++ b/src/generators/nodes/Text.ts @@ -1,7 +1,6 @@ import { stringify } from '../../utils/stringify'; import Node from './shared/Node'; import Block from '../dom/Block'; -import { State } from '../dom/interfaces'; // Whitespace inside one of these elements will not result in // a whitespace node being created in any circumstances. (This 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..180aad8fe1f5 --- /dev/null +++ b/test/runtime/samples/computed-values-deconflicted/_config.js @@ -0,0 +1,10 @@ +export default { + 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