Skip to content

Commit

Permalink
feat: support for compiler 2.6 outputSourceRange
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 11, 2019
1 parent 7275ae4 commit 2215585
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions lib/loaders/templateLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ module.exports = function (source) {

// allow using custom compiler via options
const compiler = options.compiler || require('vue-template-compiler')
const compilerOptions = Object.assign({}, options.compilerOptions, {

const compilerOptions = Object.assign({
outputSourceRange: true
}, options.compilerOptions, {
scopeId: query.scoped ? `data-v-${id}` : null,
comments: query.comments
})
Expand All @@ -45,17 +48,29 @@ module.exports = function (source) {
// tips
if (compiled.tips && compiled.tips.length) {
compiled.tips.forEach(tip => {
loaderContext.emitWarning(tip)
loaderContext.emitWarning(typeof tip === 'object' ? tip.msg : tip)
})
}

// errors
if (compiled.errors && compiled.errors.length) {
loaderContext.emitError(
`\n Error compiling template:\n${pad(compiled.source)}\n` +
compiled.errors.map(e => ` - ${e}`).join('\n') +
// 2.6 compiler outputs errors as objects with range
if (compiler.generateCodeFrame && finalOptions.outputSourceRange) {
loaderContext.emitError(
`\n\n Errors compiling template:\n\n` +
compiled.errors.map(({ msg, start, end }) => {
const frame = compiler.generateCodeFrame(source, start, end)
return ` ${msg}\n\n${pad(frame)}`
}).join(`\n\n`) +
'\n'
)
)
} else {
loaderContext.emitError(
`\n Error compiling template:\n${pad(compiled.source)}\n` +
compiled.errors.map(e => ` - ${e}`).join('\n') +
'\n'
)
}
}

const { code } = compiled
Expand Down

0 comments on commit 2215585

Please sign in to comment.