Skip to content

Commit

Permalink
feat: log on the fly template compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Oct 11, 2019
1 parent 68f4e5e commit 95d7e1f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,12 @@ function finishComponentSetup(
if (Component.template && !Component.render) {
if (compile) {
Component.render = compile(Component.template, {
onError(err) {}
onError(err) {
if (__DEV__) {
// TODO use err.loc to provide codeframe like Vue 2
warn(`Template compilation error: ${err.message}`)
}
}
})
} else if (__DEV__) {
warn(
Expand Down
3 changes: 2 additions & 1 deletion packages/vue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// This package is the "full-build" that includes both the runtime
// and the compiler, and supports on-the-fly compilation of the template option.
import { compile, CompilerOptions } from '@vue/compiler-dom'
import * as runtimeDom from '@vue/runtime-dom'
import { registerRuntimeCompiler, RenderFunction } from '@vue/runtime-dom'
import * as runtimeDom from '@vue/runtime-dom'

function compileToFunction(
template: string,
Expand All @@ -12,6 +12,7 @@ function compileToFunction(
hoistStatic: true,
...options
})

return new Function('Vue', code)(runtimeDom) as RenderFunction
}

Expand Down

0 comments on commit 95d7e1f

Please sign in to comment.