diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index 668f3a61c7..458561d25c 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -290,7 +290,7 @@ export default class Generator { return alias; } - getUniqueNameMaker(names: string[]) { + getUniqueNameMaker() { const localUsedNames = new Set(); function add(name: string) { @@ -299,7 +299,6 @@ export default class Generator { reservedNames.forEach(add); this.userVars.forEach(add); - names.forEach(add); return (name: string) => { if (test) name = `${name}$`; diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index f13973a4c7..596c59e1ef 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -93,7 +93,7 @@ export default class Block { this.hasOutroMethod = false; this.outros = 0; - this.getUniqueName = this.generator.getUniqueNameMaker([...this.contexts.values()]); + this.getUniqueName = this.generator.getUniqueNameMaker(); this.variables = new Map(); this.aliases = new Map() diff --git a/src/generators/nodes/Attribute.ts b/src/generators/nodes/Attribute.ts index e1301fcfc8..943076208f 100644 --- a/src/generators/nodes/Attribute.ts +++ b/src/generators/nodes/Attribute.ts @@ -140,28 +140,20 @@ export default class Attribute extends Node { if (this.isDynamic) { let value; - const allDependencies = new Set(); let shouldCache; - let hasChangeableIndex; // TODO some of this code is repeated in Tag.ts — would be good to // DRY it out if that's possible without introducing crazy indirection if (this.chunks.length === 1) { // single {tag} — may be a non-string const expression = this.chunks[0]; - const { dependencies, snippet, indexes } = expression; + const { snippet, indexes } = expression; value = snippet; - dependencies.forEach(d => { - allDependencies.add(d); - }); - - hasChangeableIndex = Array.from(indexes).some(index => block.changeableIndexes.get(index)); shouldCache = ( expression.node.type !== 'Identifier' || - block.contexts.has(expression.node.name) || - hasChangeableIndex + block.contexts.has(expression.node.name) ); } else { // '{foo} {bar}' — treat as string concatenation @@ -174,14 +166,6 @@ export default class Attribute extends Node { } else { const { dependencies, snippet, indexes } = chunk; - if (Array.from(indexes).some(index => block.changeableIndexes.get(index))) { - hasChangeableIndex = true; - } - - dependencies.forEach(d => { - allDependencies.add(d); - }); - return chunk.getPrecedence() <= 13 ? `(${snippet})` : snippet; } }) @@ -253,8 +237,8 @@ export default class Attribute extends Node { updater = `${method}(${node.var}, "${name}", ${shouldCache ? last : value});`; } - if (allDependencies.size || hasChangeableIndex || isSelectValueAttribute) { - const dependencies = Array.from(allDependencies); + if (this.dependencies.size || isSelectValueAttribute) { + const dependencies = Array.from(this.dependencies); const changedCheck = ( ( block.hasOutroMethod ? `#outroing || ` : '' ) + dependencies.map(dependency => `changed.${dependency}`).join(' || ') @@ -310,9 +294,8 @@ export default class Attribute extends Node { let value; if (isDynamic(prop.value)) { - const allDependencies = new Set(); + const propDependencies = new Set(); let shouldCache; - let hasChangeableIndex; value = ((prop.value.length === 1 || prop.value[0].type === 'Text') ? '' : `"" + `) + @@ -321,14 +304,10 @@ export default class Attribute extends Node { if (chunk.type === 'Text') { return stringify(chunk.data); } else { - const { dependencies, snippet, indexes } = chunk; - - if (Array.from(indexes).some(index => block.changeableIndexes.get(index))) { - hasChangeableIndex = true; - } + const { dependencies, snippet } = chunk; dependencies.forEach(d => { - allDependencies.add(d); + propDependencies.add(d); }); return chunk.getPrecedence() <= 13 ? `(${snippet})` : snippet; @@ -336,8 +315,8 @@ export default class Attribute extends Node { }) .join(' + '); - if (allDependencies.size || hasChangeableIndex) { - const dependencies = Array.from(allDependencies); + if (propDependencies.size) { + const dependencies = Array.from(propDependencies); const condition = ( (block.hasOutroMethod ? `#outroing || ` : '') + dependencies.map(dependency => `changed.${dependency}`).join(' || ')