]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: remove v-if key warning as there are legit use cases
authorEvan You <yyx990803@gmail.com>
Wed, 5 May 2021 20:25:33 +0000 (16:25 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 5 May 2021 20:35:44 +0000 (16:35 -0400)
packages/compiler-core/__tests__/transforms/vIf.spec.ts
packages/compiler-core/src/errors.ts
packages/compiler-core/src/transforms/vIf.ts

index 2024cdd3d12f65b8d76fe7ff00e0fb87f06b87b4..f1b91cc4567dbdfdbc4f9dfe3d1d35c424047527 100644 (file)
@@ -306,7 +306,6 @@ describe('compiler: v-if', () => {
           code: ErrorCodes.X_V_IF_SAME_KEY
         }
       ])
-      expect('unnecessary key usage on v-if').toHaveBeenWarned()
     })
   })
 
index 6dfa62cbcd6ecfdcd1768f6650e1347568fa3d20..3cae36da6c14535a8b12c6fe039186ea0d410016 100644 (file)
@@ -91,9 +91,6 @@ export const enum ErrorCodes {
   X_CACHE_HANDLER_NOT_SUPPORTED,
   X_SCOPE_ID_NOT_SUPPORTED,
 
-  // warnings
-  X_V_IF_KEY,
-
   // Special value for higher-order compilers to pick up the last code
   // to avoid collision of error codes. This should always be kept as the last
   // item.
@@ -174,11 +171,6 @@ export const errorMessages: Record<ErrorCodes, string> = {
   [ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
   [ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED]: `"scopeId" option is only supported in module mode.`,
 
-  // warnings
-  [ErrorCodes.X_V_IF_KEY]:
-    `unnecessary key usage on v-if/else branches. ` +
-    `Vue will automatically generate unique keys for each branch.`,
-
   // just to fullfill types
   [ErrorCodes.__EXTEND_POINT__]: ``
 }
index 9ba84f8b75c4bbc820eab482e4e9f17c0c7f0b52..384b6612a31128a0e8d9a82e043862ddcad8a6ec 100644 (file)
@@ -110,7 +110,7 @@ export function processIf(
   }
 
   if (dir.name === 'if') {
-    const branch = createIfBranch(node, dir, context)
+    const branch = createIfBranch(node, dir)
     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, context)
+        const branch = createIfBranch(node, dir)
         if (__DEV__ && comments.length) {
           branch.children = [...comments, ...branch.children]
         }
@@ -187,16 +187,7 @@ export function processIf(
   }
 }
 
-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))
-  }
-
+function createIfBranch(node: ElementNode, dir: DirectiveNode): IfBranchNode {
   return {
     type: NodeTypes.IF_BRANCH,
     loc: node.loc,
@@ -205,7 +196,7 @@ function createIfBranch(
       node.tagType === ElementTypes.TEMPLATE && !findDir(node, 'for')
         ? node.children
         : [node],
-    userKey
+    userKey: findProp(node, `key`)
   }
 }