Skip to content

Commit 61c0f8c

Browse files
committed
feat: emit template compile error
1 parent 958d55a commit 61c0f8c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/templateLoader.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
// This is injected by the global pitcher (../pitch) for template
1313
// selection requests initiated from vue files.
1414
const TemplateLoader: webpack.loader.Loader = function(source) {
15+
source = String(source)
1516
const loaderContext = this
1617
const query = qs.parse(this.resourceQuery.slice(1))
1718

@@ -25,13 +26,13 @@ const TemplateLoader: webpack.loader.Loader = function(source) {
2526
// const isProduction = options.productionMode || loaderContext.minimize || process.env.NODE_ENV === 'production'
2627

2728
const compilerOptions = Object.assign({}, options.compilerOptions, {
28-
// TODO inMap
29+
// TODO line offset
2930
scopeId: query.scoped ? `data-v-${id}` : null
3031
})
3132

3233
// for vue-component-compiler
3334
const finalOptions: TemplateCompileOptions = {
34-
source: String(source),
35+
source,
3536
filename: this.resourcePath,
3637
compiler: options.compiler,
3738
compilerOptions,
@@ -49,8 +50,21 @@ const TemplateLoader: webpack.loader.Loader = function(source) {
4950

5051
// errors
5152
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+
})
5468
}
5569

5670
const { code, map } = compiled

0 commit comments

Comments
 (0)