Skip to content

Commit c5c304a

Browse files
committed
wip: compiler should default to v3 behavior
1 parent 3528ced commit c5c304a

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

packages/compiler-core/__tests__/transforms/vIf.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ describe('compiler: v-if', () => {
306306
code: ErrorCodes.X_V_IF_SAME_KEY
307307
}
308308
])
309+
expect('unnecessary key usage on v-if').toHaveBeenWarned()
309310
})
310311
})
311312

packages/compiler-core/src/compat/compatConfig.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,18 @@ const deprecationData: Record<CompilerDeprecationTypes, DeprecationData> = {
9696
}
9797

9898
function getCompatValue(
99-
key: CompilerDeprecationTypes,
99+
key: CompilerDeprecationTypes | 'MODE',
100100
context: ParserContext | TransformContext
101101
) {
102102
const config = (context as ParserContext).options
103103
? (context as ParserContext).options.compatConfig
104104
: (context as TransformContext).compatConfig
105-
return config && config[key]
105+
const value = config && config[key]
106+
if (key === 'MODE') {
107+
return value || 3 // compiler defaults to v3 behavior
108+
} else {
109+
return value
110+
}
106111
}
107112

108113
export function checkCompatEnabled(
@@ -111,9 +116,11 @@ export function checkCompatEnabled(
111116
loc: SourceLocation | null,
112117
...args: any[]
113118
): boolean {
119+
const mode = getCompatValue('MODE', context)
114120
const value = getCompatValue(key, context)
115-
// during tests, only enable when value is explicitly true
116-
const enabled = __TEST__ ? value === true : value !== false
121+
// in v3 mode, only enable if explicitly set to true
122+
// otherwise enable for any non-false value
123+
const enabled = mode === 3 ? value === true : value !== false
117124
if (__DEV__ && enabled) {
118125
warnDeprecation(key, context, loc, ...args)
119126
}

packages/compiler-core/src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function defaultOnError(error: CompilerError) {
1414
}
1515

1616
export function defaultOnWarn(msg: CompilerError) {
17-
__DEV__ && console.warn(`[Vue warn]`, msg.message)
17+
__DEV__ && console.warn(`[Vue warn] ${msg.message}`)
1818
}
1919

2020
export function createCompilerError<T extends number>(

0 commit comments

Comments
 (0)