]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: compiler should default to v3 behavior
authorEvan You <yyx990803@gmail.com>
Sat, 17 Apr 2021 19:55:14 +0000 (15:55 -0400)
committerEvan You <yyx990803@gmail.com>
Sat, 17 Apr 2021 19:55:14 +0000 (15:55 -0400)
packages/compiler-core/__tests__/transforms/vIf.spec.ts
packages/compiler-core/src/compat/compatConfig.ts
packages/compiler-core/src/errors.ts

index f1b91cc4567dbdfdbc4f9dfe3d1d35c424047527..2024cdd3d12f65b8d76fe7ff00e0fb87f06b87b4 100644 (file)
@@ -306,6 +306,7 @@ describe('compiler: v-if', () => {
           code: ErrorCodes.X_V_IF_SAME_KEY
         }
       ])
+      expect('unnecessary key usage on v-if').toHaveBeenWarned()
     })
   })
 
index 6c54111cad2d82fcc030f36ebcbef79a165ff844..c9fde5de10ff3eb0928d9000a1d2594ad310b277 100644 (file)
@@ -96,13 +96,18 @@ const deprecationData: Record<CompilerDeprecationTypes, DeprecationData> = {
 }
 
 function getCompatValue(
-  key: CompilerDeprecationTypes,
+  key: CompilerDeprecationTypes | 'MODE',
   context: ParserContext | TransformContext
 ) {
   const config = (context as ParserContext).options
     ? (context as ParserContext).options.compatConfig
     : (context as TransformContext).compatConfig
-  return config && config[key]
+  const value = config && config[key]
+  if (key === 'MODE') {
+    return value || 3 // compiler defaults to v3 behavior
+  } else {
+    return value
+  }
 }
 
 export function checkCompatEnabled(
@@ -111,9 +116,11 @@ export function checkCompatEnabled(
   loc: SourceLocation | null,
   ...args: any[]
 ): boolean {
+  const mode = getCompatValue('MODE', context)
   const value = getCompatValue(key, context)
-  // during tests, only enable when value is explicitly true
-  const enabled = __TEST__ ? value === true : value !== false
+  // in v3 mode, only enable if explicitly set to true
+  // otherwise enable for any non-false value
+  const enabled = mode === 3 ? value === true : value !== false
   if (__DEV__ && enabled) {
     warnDeprecation(key, context, loc, ...args)
   }
index bccc54f884d0fd88b0623b9d9a1fff562cdab97f..6dfa62cbcd6ecfdcd1768f6650e1347568fa3d20 100644 (file)
@@ -14,7 +14,7 @@ export function defaultOnError(error: CompilerError) {
 }
 
 export function defaultOnWarn(msg: CompilerError) {
-  __DEV__ && console.warn(`[Vue warn]`, msg.message)
+  __DEV__ && console.warn(`[Vue warn] ${msg.message}`)
 }
 
 export function createCompilerError<T extends number>(