Skip to content

Commit 7aa0ea0

Browse files
fix(compiler-core): should treat attribute key as expression (#4658)
1 parent 901e18b commit 7aa0ea0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

packages/compiler-core/__tests__/transforms/vFor.spec.ts

+20
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,26 @@ describe('compiler: v-for', () => {
638638
})
639639
})
640640
})
641+
642+
test('template v-for key no prefixing on attribute key', () => {
643+
const {
644+
node: { codegenNode }
645+
} = parseWithForTransform(
646+
'<template v-for="item in items" key="key">test</template>',
647+
{ prefixIdentifiers: true }
648+
)
649+
const innerBlock = codegenNode.children.arguments[1].returns
650+
expect(innerBlock).toMatchObject({
651+
type: NodeTypes.VNODE_CALL,
652+
tag: FRAGMENT,
653+
props: createObjectMatcher({
654+
key: {
655+
type: NodeTypes.SIMPLE_EXPRESSION,
656+
content: 'key'
657+
}
658+
})
659+
})
660+
})
641661
})
642662

643663
describe('codegen', () => {

packages/compiler-core/src/transforms/vFor.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ export const transformFor = createStructuralDirectiveTransform(
6868
: keyProp.exp!)
6969
const keyProperty = keyProp ? createObjectProperty(`key`, keyExp!) : null
7070

71-
if (!__BROWSER__ && context.prefixIdentifiers && keyProperty) {
71+
if (
72+
!__BROWSER__ &&
73+
context.prefixIdentifiers &&
74+
keyProperty &&
75+
keyProp!.type !== NodeTypes.ATTRIBUTE
76+
) {
7277
// #2085 process :key expression needs to be processed in order for it
7378
// to behave consistently for <template v-for> and <div v-for>.
7479
// In the case of `<template v-for>`, the node is discarded and never

0 commit comments

Comments
 (0)