fix(compiler-core): fix prefixing for <template v-for> key expressions

fix #2085
This commit is contained in:
Evan You
2020-09-14 17:04:27 -04:00
parent a32870a8f6
commit be946ea549
2 changed files with 77 additions and 8 deletions

View File

@@ -582,6 +582,61 @@ describe('compiler: v-for', () => {
]
})
})
test('element v-for key expression prefixing', () => {
const {
node: { codegenNode }
} = parseWithForTransform(
'<div v-for="item in items" :key="itemKey(item)">test</div>',
{ prefixIdentifiers: true }
)
const innerBlock = codegenNode.children.arguments[1].returns
expect(innerBlock).toMatchObject({
type: NodeTypes.VNODE_CALL,
tag: `"div"`,
props: createObjectMatcher({
key: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
// should prefix outer scope references
{ content: `_ctx.itemKey` },
`(`,
// should NOT prefix in scope variables
{ content: `item` },
`)`
]
}
})
})
})
// #2085
test('template v-for key expression prefixing', () => {
const {
node: { codegenNode }
} = parseWithForTransform(
'<template v-for="item in items" :key="itemKey(item)">test</template>',
{ prefixIdentifiers: true }
)
const innerBlock = codegenNode.children.arguments[1].returns
expect(innerBlock).toMatchObject({
type: NodeTypes.VNODE_CALL,
tag: FRAGMENT,
props: createObjectMatcher({
key: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
// should prefix outer scope references
{ content: `_ctx.itemKey` },
`(`,
// should NOT prefix in scope variables
{ content: `item` },
`)`
]
}
})
})
})
})
describe('codegen', () => {