wip: warn key usage of v-if branches

This commit is contained in:
Evan You
2021-04-17 15:35:44 -04:00
parent ab21468982
commit 3528ced0b4
2 changed files with 27 additions and 7 deletions

View File

@@ -110,7 +110,7 @@ export function processIf(
}
if (dir.name === 'if') {
const branch = createIfBranch(node, dir)
const branch = createIfBranch(node, dir, context)
const ifNode: IfNode = {
type: NodeTypes.IF,
loc: node.loc,
@@ -145,7 +145,7 @@ export function processIf(
if (sibling && sibling.type === NodeTypes.IF) {
// 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) {
branch.children = [...comments, ...branch.children]
}
@@ -187,7 +187,16 @@ export function processIf(
}
}
function createIfBranch(node: ElementNode, dir: DirectiveNode): IfBranchNode {
function createIfBranch(
node: ElementNode,
dir: DirectiveNode,
context: TransformContext
): IfBranchNode {
const userKey = findProp(node, `key`)
if (__DEV__ && userKey) {
context.onWarn(createCompilerError(ErrorCodes.X_V_IF_KEY, userKey.loc))
}
return {
type: NodeTypes.IF_BRANCH,
loc: node.loc,
@@ -196,7 +205,7 @@ function createIfBranch(node: ElementNode, dir: DirectiveNode): IfBranchNode {
node.tagType === ElementTypes.TEMPLATE && !findDir(node, 'for')
? node.children
: [node],
userKey: findProp(node, `key`)
userKey
}
}