From e130c7db23f77f1be7202292c1f58eb15324fa7d Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 12 Apr 2021 19:42:09 -0400 Subject: [PATCH] wip: compiler deprecation config --- .../compiler-core/src/compat/compatConfig.ts | 133 ++++++++++++++++++ packages/compiler-core/src/errors.ts | 7 +- packages/compiler-core/src/index.ts | 7 + packages/compiler-core/src/options.ts | 17 ++- packages/compiler-core/src/parse.ts | 20 ++- packages/compiler-core/src/transform.ts | 14 +- packages/compiler-dom/src/errors.ts | 4 +- packages/compiler-dom/src/transforms/vOn.ts | 10 +- packages/compiler-ssr/src/errors.ts | 4 +- 9 files changed, 198 insertions(+), 18 deletions(-) create mode 100644 packages/compiler-core/src/compat/compatConfig.ts diff --git a/packages/compiler-core/src/compat/compatConfig.ts b/packages/compiler-core/src/compat/compatConfig.ts new file mode 100644 index 00000000..3abb77fa --- /dev/null +++ b/packages/compiler-core/src/compat/compatConfig.ts @@ -0,0 +1,133 @@ +import { SourceLocation } from '../ast' +import { CompilerError } from '../errors' +import { ParserContext } from '../parse' +import { TransformContext } from '../transform' + +export type CompilerCompatConfig = Partial< + Record +> & { + MODE?: 2 | 3 +} + +export interface CompilerCompatOptions { + compatConfig?: CompilerCompatConfig +} + +export const enum CompilerDeprecationTypes { + IS_ON_ELEMENT = 'IS_ON_ELEMENT', + V_BIND_SYNC = 'V_BIND_SYNC', + V_BIND_OBJECT_ORDER = 'V_BIND_OBJECT_ORDER', + V_ON_NATIVE_MODIFIER = 'V_ON_NATIVE_MODIFIER', + KEY_V_IF = 'KEY_V_IF', + KEY_V_FOR_TEMPLATE = 'KEY_V_FOR_TEMPLATE', + V_IF_V_FOR_PRECEDENCE = 'V_IF_V_FOR_PRECEDENCE', + NATIVE_TEMPLATE = 'NATIVE_TEMPLATE' +} + +type DeprecationData = { + message: string | ((...args: any[]) => string) + link?: string +} + +const deprecationData: Record = { + [CompilerDeprecationTypes.IS_ON_ELEMENT]: { + message: ``, + link: `https://v3.vuejs.org/guide/migration/custom-elements-interop.html` + }, + + [CompilerDeprecationTypes.V_BIND_SYNC]: { + message: key => + `.sync modifier for v-bind has been removed. Use v-model with ` + + `argument instead. \`v-bind:${key}.sync\` should be changed to ` + + `\`v-model:${key}\`.`, + link: `https://v3.vuejs.org/guide/migration/v-model.html` + }, + + [CompilerDeprecationTypes.V_BIND_OBJECT_ORDER]: { + message: + `v-bind="obj" usage is now order sensitive and behaves like JavaScript ` + + `object spread: it will now overwrite an existing attribute that appears ` + + `before v-bind in the case of conflicting keys. To retain 2.x behavior, ` + + `move v-bind to and make it the first attribute. If all occurences ` + + `of this warning are working as intended, you can suppress it.`, + link: `https://v3.vuejs.org/guide/migration/v-bind.html` + }, + + [CompilerDeprecationTypes.V_ON_NATIVE_MODIFIER]: { + message: `.native modifier for v-on has been removed as is no longer necessary.`, + link: `https://v3.vuejs.org/guide/migration/v-on-native-modifier-removed.html` + }, + + [CompilerDeprecationTypes.KEY_V_IF]: { + message: ``, + link: `https://v3.vuejs.org/guide/migration/key-attribute.html#on-conditional-branches` + }, + + [CompilerDeprecationTypes.KEY_V_FOR_TEMPLATE]: { + message: ``, + link: `https://v3.vuejs.org/guide/migration/key-attribute.html#with-template-v-for` + }, + + [CompilerDeprecationTypes.V_IF_V_FOR_PRECEDENCE]: { + message: + `v-if / v-for precedence when used on the same element has changed ` + + `in Vue 3. It is best to avoid the ambiguity with either