|
|
@ -213,12 +213,11 @@ export default class Generator {
|
|
|
|
context: string,
|
|
|
|
context: string,
|
|
|
|
isEventHandler: boolean
|
|
|
|
isEventHandler: boolean
|
|
|
|
): {
|
|
|
|
): {
|
|
|
|
dependencies: string[],
|
|
|
|
|
|
|
|
contexts: Set<string>,
|
|
|
|
contexts: Set<string>,
|
|
|
|
indexes: Set<string>,
|
|
|
|
indexes: Set<string>,
|
|
|
|
snippet: string
|
|
|
|
snippet: string
|
|
|
|
} {
|
|
|
|
} {
|
|
|
|
this.addSourcemapLocations(expression);
|
|
|
|
// this.addSourcemapLocations(expression);
|
|
|
|
|
|
|
|
|
|
|
|
const usedContexts: Set<string> = new Set();
|
|
|
|
const usedContexts: Set<string> = new Set();
|
|
|
|
const usedIndexes: Set<string> = new Set();
|
|
|
|
const usedIndexes: Set<string> = new Set();
|
|
|
@ -298,10 +297,7 @@ export default class Generator {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const dependencies: Set<string> = new Set(expression._dependencies || []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
dependencies: Array.from(dependencies),
|
|
|
|
|
|
|
|
contexts: usedContexts,
|
|
|
|
contexts: usedContexts,
|
|
|
|
indexes: usedIndexes,
|
|
|
|
indexes: usedIndexes,
|
|
|
|
snippet: `[✂${expression.start}-${expression.end}✂]`,
|
|
|
|
snippet: `[✂${expression.start}-${expression.end}✂]`,
|
|
|
@ -650,18 +646,23 @@ export default class Generator {
|
|
|
|
|
|
|
|
|
|
|
|
walkTemplate() {
|
|
|
|
walkTemplate() {
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
|
|
|
|
code,
|
|
|
|
expectedProperties,
|
|
|
|
expectedProperties,
|
|
|
|
helpers
|
|
|
|
helpers
|
|
|
|
} = this;
|
|
|
|
} = this;
|
|
|
|
const { html } = this.parsed;
|
|
|
|
const { html } = this.parsed;
|
|
|
|
|
|
|
|
|
|
|
|
function findDependencies(node: Node, contextDependencies: Map<string, string[]>, indexes: Set<string>) {
|
|
|
|
const contextualise = (node: Node, contextDependencies: Map<string, string[]>, indexes: Set<string>) => {
|
|
|
|
const dependencies: Set<string> = new Set();
|
|
|
|
this.addSourcemapLocations(node); // TODO this involves an additional walk — can we roll it in somewhere else?
|
|
|
|
|
|
|
|
|
|
|
|
let scope = annotateWithScopes(node);
|
|
|
|
let scope = annotateWithScopes(node);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dependencies: Set<string> = new Set();
|
|
|
|
|
|
|
|
|
|
|
|
walk(node, {
|
|
|
|
walk(node, {
|
|
|
|
enter(node: Node, parent: Node) {
|
|
|
|
enter(node: Node, parent: Node) {
|
|
|
|
|
|
|
|
code.addSourcemapLocation(node.start);
|
|
|
|
|
|
|
|
code.addSourcemapLocation(node.end);
|
|
|
|
|
|
|
|
|
|
|
|
if (node._scope) {
|
|
|
|
if (node._scope) {
|
|
|
|
scope = node._scope;
|
|
|
|
scope = node._scope;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -692,7 +693,9 @@ export default class Generator {
|
|
|
|
expectedProperties.add(dependency);
|
|
|
|
expectedProperties.add(dependency);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return Array.from(dependencies);
|
|
|
|
return {
|
|
|
|
|
|
|
|
dependencies: Array.from(dependencies)
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const contextStack = [];
|
|
|
|
const contextStack = [];
|
|
|
@ -708,10 +711,10 @@ export default class Generator {
|
|
|
|
walk(html, {
|
|
|
|
walk(html, {
|
|
|
|
enter(node: Node, parent: Node) {
|
|
|
|
enter(node: Node, parent: Node) {
|
|
|
|
if (node.type === 'EachBlock') {
|
|
|
|
if (node.type === 'EachBlock') {
|
|
|
|
node.dependencies = findDependencies(node.expression, contextDependencies, indexes);
|
|
|
|
node.metadata = contextualise(node.expression, contextDependencies, indexes);
|
|
|
|
|
|
|
|
|
|
|
|
contextDependencies = new Map(contextDependencies);
|
|
|
|
contextDependencies = new Map(contextDependencies);
|
|
|
|
contextDependencies.set(node.context, node.dependencies);
|
|
|
|
contextDependencies.set(node.context, node.metadata.dependencies);
|
|
|
|
|
|
|
|
|
|
|
|
if (node.destructuredContexts) {
|
|
|
|
if (node.destructuredContexts) {
|
|
|
|
for (let i = 0; i < node.destructuredContexts.length; i += 1) {
|
|
|
|
for (let i = 0; i < node.destructuredContexts.length; i += 1) {
|
|
|
@ -719,7 +722,7 @@ export default class Generator {
|
|
|
|
const value = `${node.context}[${i}]`;
|
|
|
|
const value = `${node.context}[${i}]`;
|
|
|
|
|
|
|
|
|
|
|
|
// contexts.set(node.destructuredContexts[i], `${context}[${i}]`);
|
|
|
|
// contexts.set(node.destructuredContexts[i], `${context}[${i}]`);
|
|
|
|
contextDependencies.set(name, node.dependencies);
|
|
|
|
contextDependencies.set(name, node.metadata.dependencies);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -733,22 +736,22 @@ export default class Generator {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (node.type === 'IfBlock') {
|
|
|
|
if (node.type === 'IfBlock') {
|
|
|
|
node.dependencies = findDependencies(node.expression, contextDependencies, indexes);
|
|
|
|
node.metadata = contextualise(node.expression, contextDependencies, indexes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (node.type === 'MustacheTag' || node.type === 'RawMustacheTag' || node.type === 'AttributeShorthand') {
|
|
|
|
if (node.type === 'MustacheTag' || node.type === 'RawMustacheTag' || node.type === 'AttributeShorthand') {
|
|
|
|
node.dependencies = findDependencies(node.expression, contextDependencies, indexes);
|
|
|
|
node.metadata = contextualise(node.expression, contextDependencies, indexes);
|
|
|
|
this.skip();
|
|
|
|
this.skip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (node.type === 'Binding') {
|
|
|
|
if (node.type === 'Binding') {
|
|
|
|
node.dependencies = findDependencies(node.value, contextDependencies, indexes);
|
|
|
|
node.metadata = contextualise(node.value, contextDependencies, indexes);
|
|
|
|
this.skip();
|
|
|
|
this.skip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (node.type === 'EventHandler' && node.expression) {
|
|
|
|
if (node.type === 'EventHandler' && node.expression) {
|
|
|
|
node.expression.arguments.forEach((arg: Node) => {
|
|
|
|
node.expression.arguments.forEach((arg: Node) => {
|
|
|
|
arg.dependencies = findDependencies(arg, contextDependencies, indexes);
|
|
|
|
arg.metadata = contextualise(arg, contextDependencies, indexes);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.skip();
|
|
|
|
this.skip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|