File tree Expand file tree Collapse file tree 4 files changed +40
-35
lines changed Expand file tree Collapse file tree 4 files changed +40
-35
lines changed Original file line number Diff line number Diff line change @@ -124,13 +124,8 @@ export function warnDeprecation(
124
124
typeof message === 'function' ? message ( ...args ) : message
125
125
} ${ link ? `\n Details: ${ link } ` : `` } `
126
126
127
- if ( loc ) {
128
- const err = new SyntaxError ( msg ) as CompilerError
129
- err . code = key
130
- err . loc = loc
131
- context . onWarn ( err )
132
- return
133
- }
134
-
135
- context . onWarn ( msg )
127
+ const err = new SyntaxError ( msg ) as CompilerError
128
+ err . code = key
129
+ if ( loc ) err . loc = loc
130
+ context . onWarn ( err )
136
131
}
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import { CompilerCompatOptions } from './compat/compatConfig'
10
10
import { ParserPlugin } from '@babel/parser'
11
11
12
12
export interface ErrorHandlingOptions {
13
- onWarn ?: ( msg : string | CompilerError ) => void
13
+ onWarn ?: ( warning : CompilerError ) => void
14
14
onError ?: ( error : CompilerError ) => void
15
15
}
16
16
Original file line number Diff line number Diff line change 1
1
// This entry is the "full-build" that includes both the runtime
2
2
// and the compiler, and supports on-the-fly compilation of the template option.
3
3
import { initDev } from './dev'
4
- import { compile , CompilerOptions , CompilerError } from '@vue/compiler-dom'
4
+ import { compile , CompilerError , CompilerOptions } from '@vue/compiler-dom'
5
5
import {
6
6
registerRuntimeCompiler ,
7
7
RenderFunction ,
@@ -55,27 +55,32 @@ function compileToFunction(
55
55
extend (
56
56
{
57
57
hoistStatic : true ,
58
- onError ( err : CompilerError ) {
58
+ onError ( err ) {
59
59
if ( __DEV__ ) {
60
- const message = `Template compilation error: ${ err . message } `
61
- const codeFrame =
62
- err . loc &&
63
- generateCodeFrame (
64
- template as string ,
65
- err . loc . start . offset ,
66
- err . loc . end . offset
67
- )
68
- warn ( codeFrame ? `${ message } \n${ codeFrame } ` : message )
60
+ onError ( err )
69
61
} else {
70
62
/* istanbul ignore next */
71
63
throw err
72
64
}
73
- }
74
- } ,
65
+ } ,
66
+ onWarn : __DEV__ ? onError : NOOP
67
+ } as CompilerOptions ,
75
68
options
76
69
)
77
70
)
78
71
72
+ function onError ( err : CompilerError ) {
73
+ const message = `Template compilation error: ${ err . message } `
74
+ const codeFrame =
75
+ err . loc &&
76
+ generateCodeFrame (
77
+ template as string ,
78
+ err . loc . start . offset ,
79
+ err . loc . end . offset
80
+ )
81
+ warn ( codeFrame ? `${ message } \n${ codeFrame } ` : message )
82
+ }
83
+
79
84
// The wildcard import results in a huge object with every export
80
85
// with keys that cannot be mangled, and can be quite heavy size-wise.
81
86
// In the global build we know `Vue` is available globally so we can avoid
Original file line number Diff line number Diff line change @@ -49,27 +49,32 @@ function compileToFunction(
49
49
extend (
50
50
{
51
51
hoistStatic : true ,
52
- onError ( err : CompilerError ) {
52
+ onError ( err ) {
53
53
if ( __DEV__ ) {
54
- const message = `Template compilation error: ${ err . message } `
55
- const codeFrame =
56
- err . loc &&
57
- generateCodeFrame (
58
- template as string ,
59
- err . loc . start . offset ,
60
- err . loc . end . offset
61
- )
62
- warn ( codeFrame ? `${ message } \n${ codeFrame } ` : message )
54
+ onError ( err )
63
55
} else {
64
56
/* istanbul ignore next */
65
57
throw err
66
58
}
67
- }
68
- } ,
59
+ } ,
60
+ onWarn : __DEV__ ? onError : NOOP
61
+ } as CompilerOptions ,
69
62
options
70
63
)
71
64
)
72
65
66
+ function onError ( err : CompilerError ) {
67
+ const message = `Template compilation error: ${ err . message } `
68
+ const codeFrame =
69
+ err . loc &&
70
+ generateCodeFrame (
71
+ template as string ,
72
+ err . loc . start . offset ,
73
+ err . loc . end . offset
74
+ )
75
+ warn ( codeFrame ? `${ message } \n${ codeFrame } ` : message )
76
+ }
77
+
73
78
// The wildcard import results in a huge object with every export
74
79
// with keys that cannot be mangled, and can be quite heavy size-wise.
75
80
// In the global build we know `Vue` is available globally so we can avoid
You can’t perform that action at this time.
0 commit comments