Skip to content

Commit ba72875

Browse files
committed
🐛 fix to resolve references in dynamic arguments
1 parent fb08ee1 commit ba72875

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/html/parser.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,16 @@ export class Parser {
475475

476476
// Resolve references.
477477
for (const attribute of element.startTag.attributes) {
478-
if (attribute.directive && attribute.value != null) {
479-
resolveReferences(attribute.value)
478+
if (attribute.directive) {
479+
if (
480+
attribute.key.argument != null &&
481+
attribute.key.argument.type === "VExpressionContainer"
482+
) {
483+
resolveReferences(attribute.key.argument)
484+
}
485+
if (attribute.value != null) {
486+
resolveReferences(attribute.value)
487+
}
480488
}
481489
}
482490

test/variables-references.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,33 @@ describe("Variables of template-scope and references", () => {
328328
}
329329
})
330330
})
331+
332+
describe("Variables of v-for and references of dynamic arguments", () => {
333+
const code = '<template><div v-for="x of xs" :[x]="1" /></template>'
334+
let variables = null
335+
let vForReferences = null
336+
let vBindKeyReferences = null
337+
338+
before(() => {
339+
const ast = parse(
340+
code,
341+
Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS)
342+
).ast
343+
variables = ast.templateBody.children[0].variables
344+
vForReferences =
345+
ast.templateBody.children[0].startTag.attributes[0].value.references
346+
vBindKeyReferences =
347+
ast.templateBody.children[0].startTag.attributes[1].key.argument
348+
.references
349+
})
350+
351+
it("should have relationship each other", () => {
352+
assert(variables.length === 1)
353+
assert(vForReferences.length === 1)
354+
assert(vBindKeyReferences.length === 1)
355+
assert(variables[0].references.length === 1)
356+
assert(variables[0].references[0] === vBindKeyReferences[0])
357+
assert(vForReferences[0].variable === null)
358+
assert(vBindKeyReferences[0].variable === variables[0])
359+
})
360+
})

0 commit comments

Comments
 (0)