Skip to content

Commit

Permalink
🐛 fix to resolve references in dynamic arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Feb 10, 2019
1 parent fb08ee1 commit ba72875
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/html/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions test/variables-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,33 @@ describe("Variables of template-scope and references", () => {
}
})
})

describe("Variables of v-for and references of dynamic arguments", () => {
const code = '<template><div v-for="x of xs" :[x]="1" /></template>'
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])
})
})

0 comments on commit ba72875

Please sign in to comment.