From c5c304af144be505a3adb42088c86804eb861ad7 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 17 Apr 2021 15:55:14 -0400 Subject: [PATCH] wip: compiler should default to v3 behavior --- .../__tests__/transforms/vIf.spec.ts | 1 + packages/compiler-core/src/compat/compatConfig.ts | 15 +++++++++++---- packages/compiler-core/src/errors.ts | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/compiler-core/__tests__/transforms/vIf.spec.ts b/packages/compiler-core/__tests__/transforms/vIf.spec.ts index f1b91cc4..2024cdd3 100644 --- a/packages/compiler-core/__tests__/transforms/vIf.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vIf.spec.ts @@ -306,6 +306,7 @@ describe('compiler: v-if', () => { code: ErrorCodes.X_V_IF_SAME_KEY } ]) + expect('unnecessary key usage on v-if').toHaveBeenWarned() }) }) diff --git a/packages/compiler-core/src/compat/compatConfig.ts b/packages/compiler-core/src/compat/compatConfig.ts index 6c54111c..c9fde5de 100644 --- a/packages/compiler-core/src/compat/compatConfig.ts +++ b/packages/compiler-core/src/compat/compatConfig.ts @@ -96,13 +96,18 @@ const deprecationData: Record = { } 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) } diff --git a/packages/compiler-core/src/errors.ts b/packages/compiler-core/src/errors.ts index bccc54f8..6dfa62cb 100644 --- a/packages/compiler-core/src/errors.ts +++ b/packages/compiler-core/src/errors.ts @@ -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(