remove some unnecessary code

pull/1367/head
Rich Harris 7 years ago
parent deca8882ac
commit 3aca6a6c63

@ -290,7 +290,7 @@ export default class Generator {
return alias; return alias;
} }
getUniqueNameMaker(names: string[]) { getUniqueNameMaker() {
const localUsedNames = new Set(); const localUsedNames = new Set();
function add(name: string) { function add(name: string) {
@ -299,7 +299,6 @@ export default class Generator {
reservedNames.forEach(add); reservedNames.forEach(add);
this.userVars.forEach(add); this.userVars.forEach(add);
names.forEach(add);
return (name: string) => { return (name: string) => {
if (test) name = `${name}$`; if (test) name = `${name}$`;

@ -93,7 +93,7 @@ export default class Block {
this.hasOutroMethod = false; this.hasOutroMethod = false;
this.outros = 0; this.outros = 0;
this.getUniqueName = this.generator.getUniqueNameMaker([...this.contexts.values()]); this.getUniqueName = this.generator.getUniqueNameMaker();
this.variables = new Map(); this.variables = new Map();
this.aliases = new Map() this.aliases = new Map()

@ -140,28 +140,20 @@ export default class Attribute extends Node {
if (this.isDynamic) { if (this.isDynamic) {
let value; let value;
const allDependencies = new Set();
let shouldCache; let shouldCache;
let hasChangeableIndex;
// TODO some of this code is repeated in Tag.ts — would be good to // 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 // DRY it out if that's possible without introducing crazy indirection
if (this.chunks.length === 1) { if (this.chunks.length === 1) {
// single {tag} — may be a non-string // single {tag} — may be a non-string
const expression = this.chunks[0]; const expression = this.chunks[0];
const { dependencies, snippet, indexes } = expression; const { snippet, indexes } = expression;
value = snippet; value = snippet;
dependencies.forEach(d => {
allDependencies.add(d);
});
hasChangeableIndex = Array.from(indexes).some(index => block.changeableIndexes.get(index));
shouldCache = ( shouldCache = (
expression.node.type !== 'Identifier' || expression.node.type !== 'Identifier' ||
block.contexts.has(expression.node.name) || block.contexts.has(expression.node.name)
hasChangeableIndex
); );
} else { } else {
// '{foo} {bar}' — treat as string concatenation // '{foo} {bar}' — treat as string concatenation
@ -174,14 +166,6 @@ export default class Attribute extends Node {
} else { } else {
const { dependencies, snippet, indexes } = chunk; 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; return chunk.getPrecedence() <= 13 ? `(${snippet})` : snippet;
} }
}) })
@ -253,8 +237,8 @@ export default class Attribute extends Node {
updater = `${method}(${node.var}, "${name}", ${shouldCache ? last : value});`; updater = `${method}(${node.var}, "${name}", ${shouldCache ? last : value});`;
} }
if (allDependencies.size || hasChangeableIndex || isSelectValueAttribute) { if (this.dependencies.size || isSelectValueAttribute) {
const dependencies = Array.from(allDependencies); const dependencies = Array.from(this.dependencies);
const changedCheck = ( const changedCheck = (
( block.hasOutroMethod ? `#outroing || ` : '' ) + ( block.hasOutroMethod ? `#outroing || ` : '' ) +
dependencies.map(dependency => `changed.${dependency}`).join(' || ') dependencies.map(dependency => `changed.${dependency}`).join(' || ')
@ -310,9 +294,8 @@ export default class Attribute extends Node {
let value; let value;
if (isDynamic(prop.value)) { if (isDynamic(prop.value)) {
const allDependencies = new Set(); const propDependencies = new Set();
let shouldCache; let shouldCache;
let hasChangeableIndex;
value = value =
((prop.value.length === 1 || prop.value[0].type === 'Text') ? '' : `"" + `) + ((prop.value.length === 1 || prop.value[0].type === 'Text') ? '' : `"" + `) +
@ -321,14 +304,10 @@ export default class Attribute extends Node {
if (chunk.type === 'Text') { if (chunk.type === 'Text') {
return stringify(chunk.data); return stringify(chunk.data);
} else { } else {
const { dependencies, snippet, indexes } = chunk; const { dependencies, snippet } = chunk;
if (Array.from(indexes).some(index => block.changeableIndexes.get(index))) {
hasChangeableIndex = true;
}
dependencies.forEach(d => { dependencies.forEach(d => {
allDependencies.add(d); propDependencies.add(d);
}); });
return chunk.getPrecedence() <= 13 ? `(${snippet})` : snippet; return chunk.getPrecedence() <= 13 ? `(${snippet})` : snippet;
@ -336,8 +315,8 @@ export default class Attribute extends Node {
}) })
.join(' + '); .join(' + ');
if (allDependencies.size || hasChangeableIndex) { if (propDependencies.size) {
const dependencies = Array.from(allDependencies); const dependencies = Array.from(propDependencies);
const condition = ( const condition = (
(block.hasOutroMethod ? `#outroing || ` : '') + (block.hasOutroMethod ? `#outroing || ` : '') +
dependencies.map(dependency => `changed.${dependency}`).join(' || ') dependencies.map(dependency => `changed.${dependency}`).join(' || ')

Loading…
Cancel
Save