Skip to content

Commit

Permalink
fix(compiler-core): fix for :key shorthand patchflag
Browse files Browse the repository at this point in the history
  • Loading branch information
Doctor-wu committed May 14, 2024
1 parent 107e614 commit 8e64765
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/compiler-core/__tests__/transforms/vFor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { ErrorCodes } from '../../src/errors'
import { type CompilerOptions, generate } from '../../src'
import { FRAGMENT, RENDER_LIST, RENDER_SLOT } from '../../src/runtimeHelpers'
import { PatchFlags } from '@vue/shared'
import { PatchFlagNames, PatchFlags } from '@vue/shared'
import { createObjectMatcher, genFlagText } from '../testUtils'

export function parseWithForTransform(
Expand Down Expand Up @@ -658,6 +658,15 @@ describe('compiler: v-for', () => {
}),
})
})

test('template v-for key w/ :key shorthand', () => {
const {
node: { codegenNode },
} = parseWithForTransform('<div v-for="key in keys" :key>test</div>')
expect(codegenNode.patchFlag).toBe(
`${PatchFlags.KEYED_FRAGMENT} /* ${PatchFlagNames[PatchFlags.KEYED_FRAGMENT]} */`,
)
})
})

describe('codegen', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler-core/src/transforms/vFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export const transformFor = createStructuralDirectiveTransform(
]) as ForRenderListExpression
const isTemplate = isTemplateNode(node)
const memo = findDir(node, 'memo')
const keyProp = findProp(node, `key`)
// allowEmpty for check shorthand
const keyProp = findProp(node, `key`, false, true)
const keyExp =
keyProp &&
(keyProp.type === NodeTypes.ATTRIBUTE
Expand Down

0 comments on commit 8e64765

Please sign in to comment.