diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index 084f1e7d901c..5ead00769dd7 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -32,6 +32,7 @@ export default class Generator { code: MagicString; bindingGroups: string[]; + indirectDependencies: Map>; expectedProperties: Set; cascade: boolean; css: string; @@ -61,6 +62,7 @@ export default class Generator { this.importedComponents = new Map(); this.bindingGroups = []; + this.indirectDependencies = new Map(); // track which properties are needed, so we can provide useful info // in dev mode @@ -185,8 +187,20 @@ export default class Generator { }, }); + const dependencies = new Set(expression._dependencies || []); + + if (expression._dependencies) { + expression._dependencies.forEach((prop: string) => { + if (this.indirectDependencies.has(prop)) { + this.indirectDependencies.get(prop).forEach(dependency => { + dependencies.add(dependency); + }); + } + }); + } + return { - dependencies: expression._dependencies, // TODO probably a better way to do this + dependencies: Array.from(dependencies), contexts: usedContexts, snippet: `[✂${expression.start}-${expression.end}✂]`, }; diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index c23a80977c69..7b7a19eb10a3 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -174,7 +174,7 @@ export default class Block { ); } - findDependencies(expression) { + findDependencies(expression: Node) { return this.generator.findDependencies( this.contextDependencies, this.indexes, diff --git a/src/generators/dom/interfaces.ts b/src/generators/dom/interfaces.ts index 8c460a47336f..625f919c28d9 100644 --- a/src/generators/dom/interfaces.ts +++ b/src/generators/dom/interfaces.ts @@ -8,4 +8,5 @@ export interface State { inEachBlock?: boolean; allUsedContexts?: string[]; usesComponent?: boolean; + selectBindingDependencies?: string[]; } diff --git a/src/generators/dom/preprocess.ts b/src/generators/dom/preprocess.ts index 93cbbf7e4bc4..6d68c5c3714e 100644 --- a/src/generators/dom/preprocess.ts +++ b/src/generators/dom/preprocess.ts @@ -217,6 +217,60 @@ const preprocessors = { state: State, node: Node ) => { + node.attributes.forEach((attribute: Node) => { + if (attribute.type === 'Attribute' && attribute.value !== true) { + attribute.value.forEach((chunk: Node) => { + if (chunk.type !== 'Text') { + const dependencies = block.findDependencies(chunk.expression); + block.addDependencies(dependencies); + + // special case —