content: `_ctx.ok`,
})
})
+
+ test('v-if + :key shorthand', () => {
+ const { node } = parseWithIfTransform(`<div v-if="ok" :key></div>`)
+ expect(node.type).toBe(NodeTypes.IF)
+ expect(node.branches[0].userKey).toMatchObject({
+ arg: { content: 'key' },
+ exp: { content: 'key' },
+ })
+ })
})
describe('errors', () => {
import { CREATE_COMMENT, FRAGMENT } from '../runtimeHelpers'
import { findDir, findProp, getMemoedVNodeCall, injectProp } from '../utils'
import { PatchFlags } from '@vue/shared'
+import { transformBindShorthand } from './vBind'
export const transformIf: NodeTransform = createStructuralDirectiveTransform(
/^(if|else|else-if)$/,
}
if (dir.name === 'if') {
- const branch = createIfBranch(node, dir)
+ const branch = createIfBranch(node, dir, context)
const ifNode: IfNode = {
type: NodeTypes.IF,
loc: cloneLoc(node.loc),
// move the node to the if node's branches
context.removeNode()
- const branch = createIfBranch(node, dir)
+ const branch = createIfBranch(node, dir, context)
if (
__DEV__ &&
comments.length &&
}
}
-function createIfBranch(node: ElementNode, dir: DirectiveNode): IfBranchNode {
+function createIfBranch(
+ node: ElementNode,
+ dir: DirectiveNode,
+ context: TransformContext,
+): IfBranchNode {
const isTemplateIf = node.tagType === ElementTypes.TEMPLATE
+ const keyProp = findProp(node, `key`, false, true)
+ // resolve :key shorthand #11321
+ if (keyProp && keyProp.type === NodeTypes.DIRECTIVE && !keyProp.exp) {
+ transformBindShorthand(keyProp, context)
+ }
return {
type: NodeTypes.IF_BRANCH,
loc: node.loc,