typeof message === 'function' ? message(...args) : message
}${link ? `\n Details: ${link}` : ``}`
- if (loc) {
- const err = new SyntaxError(msg) as CompilerError
- err.code = key
- err.loc = loc
- context.onWarn(err)
- return
- }
-
- context.onWarn(msg)
+ const err = new SyntaxError(msg) as CompilerError
+ err.code = key
+ if (loc) err.loc = loc
+ context.onWarn(err)
}
import { ParserPlugin } from '@babel/parser'
export interface ErrorHandlingOptions {
- onWarn?: (msg: string | CompilerError) => void
+ onWarn?: (warning: CompilerError) => void
onError?: (error: CompilerError) => void
}
// This entry is the "full-build" that includes both the runtime
// and the compiler, and supports on-the-fly compilation of the template option.
import { initDev } from './dev'
-import { compile, CompilerOptions, CompilerError } from '@vue/compiler-dom'
+import { compile, CompilerError, CompilerOptions } from '@vue/compiler-dom'
import {
registerRuntimeCompiler,
RenderFunction,
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
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