@@ -20,7 +20,10 @@ module.exports = function (source) {
20
20
21
21
// allow using custom compiler via options
22
22
const compiler = options . compiler || require ( 'vue-template-compiler' )
23
- const compilerOptions = Object . assign ( { } , options . compilerOptions , {
23
+
24
+ const compilerOptions = Object . assign ( {
25
+ outputSourceRange : true
26
+ } , options . compilerOptions , {
24
27
scopeId : query . scoped ? `data-v-${ id } ` : null ,
25
28
comments : query . comments
26
29
} )
@@ -45,17 +48,29 @@ module.exports = function (source) {
45
48
// tips
46
49
if ( compiled . tips && compiled . tips . length ) {
47
50
compiled . tips . forEach ( tip => {
48
- loaderContext . emitWarning ( tip )
51
+ loaderContext . emitWarning ( typeof tip === 'object' ? tip . msg : tip )
49
52
} )
50
53
}
51
54
52
55
// errors
53
56
if ( compiled . errors && compiled . errors . length ) {
54
- loaderContext . emitError (
55
- `\n Error compiling template:\n${ pad ( compiled . source ) } \n` +
56
- compiled . errors . map ( e => ` - ${ e } ` ) . join ( '\n' ) +
57
+ // 2.6 compiler outputs errors as objects with range
58
+ if ( compiler . generateCodeFrame && finalOptions . outputSourceRange ) {
59
+ loaderContext . emitError (
60
+ `\n\n Errors compiling template:\n\n` +
61
+ compiled . errors . map ( ( { msg, start, end } ) => {
62
+ const frame = compiler . generateCodeFrame ( source , start , end )
63
+ return ` ${ msg } \n\n${ pad ( frame ) } `
64
+ } ) . join ( `\n\n` ) +
57
65
'\n'
58
- )
66
+ )
67
+ } else {
68
+ loaderContext . emitError (
69
+ `\n Error compiling template:\n${ pad ( compiled . source ) } \n` +
70
+ compiled . errors . map ( e => ` - ${ e } ` ) . join ( '\n' ) +
71
+ '\n'
72
+ )
73
+ }
59
74
}
60
75
61
76
const { code } = compiled
0 commit comments