diff --git a/src/html/parser.ts b/src/html/parser.ts index 61b72854..c4f38c20 100644 --- a/src/html/parser.ts +++ b/src/html/parser.ts @@ -475,8 +475,16 @@ export class Parser { // Resolve references. for (const attribute of element.startTag.attributes) { - if (attribute.directive && attribute.value != null) { - resolveReferences(attribute.value) + if (attribute.directive) { + if ( + attribute.key.argument != null && + attribute.key.argument.type === "VExpressionContainer" + ) { + resolveReferences(attribute.key.argument) + } + if (attribute.value != null) { + resolveReferences(attribute.value) + } } } diff --git a/test/variables-references.js b/test/variables-references.js index 256b6da3..1cb3ba9f 100644 --- a/test/variables-references.js +++ b/test/variables-references.js @@ -328,3 +328,33 @@ describe("Variables of template-scope and references", () => { } }) }) + +describe("Variables of v-for and references of dynamic arguments", () => { + const code = '' + let variables = null + let vForReferences = null + let vBindKeyReferences = null + + before(() => { + const ast = parse( + code, + Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS) + ).ast + variables = ast.templateBody.children[0].variables + vForReferences = + ast.templateBody.children[0].startTag.attributes[0].value.references + vBindKeyReferences = + ast.templateBody.children[0].startTag.attributes[1].key.argument + .references + }) + + it("should have relationship each other", () => { + assert(variables.length === 1) + assert(vForReferences.length === 1) + assert(vBindKeyReferences.length === 1) + assert(variables[0].references.length === 1) + assert(variables[0].references[0] === vBindKeyReferences[0]) + assert(vForReferences[0].variable === null) + assert(vBindKeyReferences[0].variable === variables[0]) + }) +})