@@ -12,6 +12,7 @@ import {
12
12
// This is injected by the global pitcher (../pitch) for template
13
13
// selection requests initiated from vue files.
14
14
const TemplateLoader : webpack . loader . Loader = function ( source ) {
15
+ source = String ( source )
15
16
const loaderContext = this
16
17
const query = qs . parse ( this . resourceQuery . slice ( 1 ) )
17
18
@@ -25,13 +26,13 @@ const TemplateLoader: webpack.loader.Loader = function(source) {
25
26
// const isProduction = options.productionMode || loaderContext.minimize || process.env.NODE_ENV === 'production'
26
27
27
28
const compilerOptions = Object . assign ( { } , options . compilerOptions , {
28
- // TODO inMap
29
+ // TODO line offset
29
30
scopeId : query . scoped ? `data-v-${ id } ` : null
30
31
} )
31
32
32
33
// for vue-component-compiler
33
34
const finalOptions : TemplateCompileOptions = {
34
- source : String ( source ) ,
35
+ source,
35
36
filename : this . resourcePath ,
36
37
compiler : options . compiler ,
37
38
compilerOptions,
@@ -49,8 +50,21 @@ const TemplateLoader: webpack.loader.Loader = function(source) {
49
50
50
51
// errors
51
52
if ( compiled . errors && compiled . errors . length ) {
52
- // TODO generate codeframes for errors
53
- generateCodeFrame
53
+ compiled . errors . forEach ( err => {
54
+ if ( typeof err === 'string' ) {
55
+ loaderContext . emitError ( err )
56
+ } else {
57
+ if ( err . loc ) {
58
+ err . message = `\n${ err . message } \n\n${
59
+ generateCodeFrame (
60
+ source as string ,
61
+ err . loc . start . offset ,
62
+ err . loc . end . offset
63
+ ) } `
64
+ }
65
+ loaderContext . emitError ( err )
66
+ }
67
+ } )
54
68
}
55
69
56
70
const { code, map } = compiled
0 commit comments