wip: generate codeframe for compiler deprecations

This commit is contained in:
Evan You
2021-04-16 11:51:47 -04:00
parent d974adb327
commit 79cbf21c3e
4 changed files with 40 additions and 35 deletions

View File

@@ -49,27 +49,32 @@ function compileToFunction(
extend(
{
hoistStatic: true,
onError(err: CompilerError) {
onError(err) {
if (__DEV__) {
const message = `Template compilation error: ${err.message}`
const codeFrame =
err.loc &&
generateCodeFrame(
template as string,
err.loc.start.offset,
err.loc.end.offset
)
warn(codeFrame ? `${message}\n${codeFrame}` : message)
onError(err)
} else {
/* istanbul ignore next */
throw err
}
}
},
},
onWarn: __DEV__ ? onError : NOOP
} as CompilerOptions,
options
)
)
function onError(err: CompilerError) {
const message = `Template compilation error: ${err.message}`
const codeFrame =
err.loc &&
generateCodeFrame(
template as string,
err.loc.start.offset,
err.loc.end.offset
)
warn(codeFrame ? `${message}\n${codeFrame}` : message)
}
// The wildcard import results in a huge object with every export
// with keys that cannot be mangled, and can be quite heavy size-wise.
// In the global build we know `Vue` is available globally so we can avoid