@@ -20,7 +20,10 @@ module.exports = function (source) {
2020
2121 // allow using custom compiler via options
2222 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 , {
2427 scopeId : query . scoped ? `data-v-${ id } ` : null ,
2528 comments : query . comments
2629 } )
@@ -45,17 +48,29 @@ module.exports = function (source) {
4548 // tips
4649 if ( compiled . tips && compiled . tips . length ) {
4750 compiled . tips . forEach ( tip => {
48- loaderContext . emitWarning ( tip )
51+ loaderContext . emitWarning ( typeof tip === 'object' ? tip . msg : tip )
4952 } )
5053 }
5154
5255 // errors
5356 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` ) +
5765 '\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+ }
5974 }
6075
6176 const { code } = compiled
0 commit comments