remove some unnecessary code

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

@ -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}$`;

@ -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()

@ -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(' || ')

Loading…
Cancel
Save