wip: warn v-bind object ordering

This commit is contained in:
Evan You
2021-04-17 16:26:13 -04:00
parent bf41354abd
commit 2c31227e7c
2 changed files with 70 additions and 16 deletions

View File

@@ -54,10 +54,10 @@ const deprecationData: Record<CompilerDeprecationTypes, DeprecationData> = {
[CompilerDeprecationTypes.COMPILER_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.`,
`object spread: it will now overwrite an existing non-mergeable attribute ` +
`that appears before v-bind in the case of conflict. ` +
`To retain 2.x behavior, move v-bind to make it the first attribute. ` +
`You can also suppress this warning if the usage is intended.`,
link: `https://v3.vuejs.org/guide/migration/v-bind.html`
},
@@ -98,17 +98,24 @@ function getCompatValue(
}
}
export function isCompatEnabled(
key: CompilerDeprecationTypes,
context: ParserContext | TransformContext
) {
const mode = getCompatValue('MODE', context)
const value = getCompatValue(key, context)
// in v3 mode, only enable if explicitly set to true
// otherwise enable for any non-false value
return mode === 3 ? value === true : value !== false
}
export function checkCompatEnabled(
key: CompilerDeprecationTypes,
context: ParserContext | TransformContext,
loc: SourceLocation | null,
...args: any[]
): boolean {
const mode = getCompatValue('MODE', context)
const value = getCompatValue(key, context)
// 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
const enabled = isCompatEnabled(key, context)
if (__DEV__ && enabled) {
warnDeprecation(key, context, loc, ...args)
}