remove more unnecessary stuff

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

@ -11,8 +11,6 @@ export interface BlockOptions {
comment?: string;
key?: string;
contexts?: Map<string, string>;
indexes?: Map<string, string>;
changeableIndexes?: Map<string, boolean>;
indexNames?: Map<string, string>;
listNames?: Map<string, string>;
dependencies?: Set<string>;
@ -27,8 +25,6 @@ export default class Block {
first: string;
contexts: Map<string, string>;
indexes: Map<string, string>;
changeableIndexes: Map<string, boolean>;
dependencies: Set<string>;
indexNames: Map<string, string>;
listNames: Map<string, string>;
@ -68,8 +64,6 @@ export default class Block {
this.first = null;
this.contexts = options.contexts;
this.indexes = options.indexes;
this.changeableIndexes = options.changeableIndexes;
this.dependencies = new Set();
this.indexNames = options.indexNames;

@ -1,12 +1,9 @@
export default class TemplateScope {
names: Set<string>;
indexes: Set<string>;
dependenciesForName: Map<string, string>;
constructor(parent?: TemplateScope) {
this.names = new Set(parent ? parent.names : []);
this.indexes = new Set(parent ? parent.names : []);
this.dependenciesForName = new Map(parent ? parent.dependenciesForName : []);
}

@ -147,7 +147,7 @@ export default class Attribute extends Node {
if (this.chunks.length === 1) {
// single {tag} — may be a non-string
const expression = this.chunks[0];
const { snippet, indexes } = expression;
const { snippet } = expression;
value = snippet;
@ -164,9 +164,9 @@ export default class Attribute extends Node {
if (chunk.type === 'Text') {
return stringify(chunk.data);
} else {
const { dependencies, snippet, indexes } = chunk;
return chunk.getPrecedence() <= 13 ? `(${snippet})` : snippet;
return chunk.getPrecedence() <= 13
? `(${chunk.snippet})`
: chunk.snippet;
}
})
.join(' + ');

@ -33,7 +33,6 @@ export default class EachBlock extends Node {
this.scope = scope.child();
// TODO handle indexes and destructuring
this.scope.add(this.context, this.expression.dependencies);
if (this.index) {
@ -76,8 +75,6 @@ export default class EachBlock extends Node {
key: this.key,
contexts: new Map(block.contexts),
indexes: new Map(block.indexes),
changeableIndexes: new Map(block.changeableIndexes),
indexNames: new Map(block.indexNames),
listNames: new Map(block.listNames)
@ -91,8 +88,6 @@ export default class EachBlock extends Node {
if (this.index) {
this.block.getUniqueName(this.index); // this prevents name collisions (#1254)
this.block.indexes.set(this.index, this.context);
this.block.changeableIndexes.set(this.index, this.key); // TODO is this right?
}
const context = this.block.getUniqueName(this.context);

@ -25,8 +25,6 @@ export default class Fragment extends Node {
key: null,
contexts: new Map(),
indexes: new Map(),
changeableIndexes: new Map(),
indexNames: new Map(),
listNames: new Map(),

@ -30,7 +30,7 @@ export default class Title extends Node {
if (this.children.length === 1) {
// single {{tag}} — may be a non-string
const { expression } = this.children[0];
const { dependencies, snippet, indexes } = this.children[0].expression;
const { dependencies, snippet } = this.children[0].expression;
value = snippet;
dependencies.forEach(d => {

@ -62,7 +62,6 @@ export default class Expression {
references: Set<string>;
dependencies: Set<string>;
contexts: Set<string>;
indexes: Set<string>;
thisReferences: Array<{ start: number, end: number }>;
@ -80,8 +79,6 @@ export default class Expression {
this.snippet = `[✂${info.start}-${info.end}✂]`;
this.usesContext = false;
const contextDependencies = new Map(); // TODO
const indexes = new Map();
const dependencies = new Set();
@ -137,7 +134,7 @@ export default class Expression {
scope.dependenciesForName.get(name).forEach(dependency => {
dependencies.add(dependency);
});
} else if (!indexes.has(name)) {
} else {
dependencies.add(name);
compiler.expectedProperties.add(name);
}
@ -163,7 +160,6 @@ export default class Expression {
this.dependencies = dependencies;
this.contexts = new Set(); // TODO...
this.indexes = new Set(); // TODO...
}
getPrecedence() {

@ -4,32 +4,30 @@ import Block from '../../dom/Block';
export default class Tag extends Node {
expression: Expression;
shouldCache: boolean;
constructor(compiler, parent, scope, info) {
super(compiler, parent, scope, info);
this.expression = new Expression(compiler, this, scope, info.expression);
this.shouldCache = (
info.expression.type !== 'Identifier' ||
(this.expression.dependencies.size && scope.names.has(info.expression.name))
);
}
renameThisMethod(
block: Block,
update: ((value: string) => string)
) {
const { snippet, dependencies, indexes } = this.expression;
const hasChangeableIndex = Array.from(indexes).some(index => block.changeableIndexes.get(index));
const shouldCache = (
this.expression.node.type !== 'Identifier' ||
block.contexts.has(this.expression.node.name) ||
hasChangeableIndex
);
const { snippet, dependencies } = this.expression;
const value = shouldCache && block.getUniqueName(`${this.var}_value`);
const content = shouldCache ? value : snippet;
const value = this.shouldCache && block.getUniqueName(`${this.var}_value`);
const content = this.shouldCache ? value : snippet;
if (shouldCache) block.addVariable(value, snippet);
if (this.shouldCache) block.addVariable(value, snippet);
if (dependencies.size || hasChangeableIndex) {
if (dependencies.size) {
const changedCheck = (
(block.hasOutroMethod ? `#outroing || ` : '') +
[...dependencies].map((dependency: string) => `changed.${dependency}`).join(' || ')
@ -37,7 +35,7 @@ export default class Tag extends Node {
const updateCachedValue = `${value} !== (${value} = ${snippet})`;
const condition = shouldCache ?
const condition = this.shouldCache ?
(dependencies.size ? `(${changedCheck}) && ${updateCachedValue}` : updateCachedValue) :
changedCheck;

@ -13,7 +13,6 @@ export default class Block {
conditions: string[];
contexts: Map<string, string>;
indexes: Map<string, string>;
constructor(options: BlockOptions) {
Object.assign(this, options);
@ -41,8 +40,4 @@ export default class Block {
child(options: BlockOptions) {
return new Block(Object.assign({}, this, options, { parent: this }));
}
// contextualise(expression: Node, context?: string, isEventHandler?: boolean) {
// return this.generator.contextualise(this.contexts, this.indexes, expression, context, isEventHandler);
// }
}

@ -60,7 +60,6 @@ export default function ssr(
const mainBlock = new Block({
generator,
contexts: new Map(),
indexes: new Map(),
conditions: [],
});

@ -25,9 +25,6 @@ export default function visitEachBlock(
const contexts = new Map(block.contexts);
contexts.set(node.context, node.context);
const indexes = new Map(block.indexes);
if (node.index) indexes.set(node.index, node.context);
if (node.destructuredContexts) {
for (let i = 0; i < node.destructuredContexts.length; i += 1) {
contexts.set(node.destructuredContexts[i], `${node.context}[${i}]`);
@ -35,8 +32,7 @@ export default function visitEachBlock(
}
const childBlock = block.child({
contexts,
indexes
contexts
});
node.children.forEach((child: Node) => {

Loading…
Cancel
Save