From: Evan You Date: Fri, 11 Oct 2019 15:16:20 +0000 (-0400) Subject: feat: log on the fly template compilation error X-Git-Tag: v3.0.0-alpha.0~492 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=95d7e1f471ed098f1f3bb3fa9cb4bd27bc2e76c8;p=thirdparty%2Fvuejs%2Fcore.git feat: log on the fly template compilation error --- diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 10e0a7ef69..77ed68ab52 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -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( diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts index 3ad4bca05c..6e44e7a59b 100644 --- a/packages/vue/src/index.ts +++ b/packages/vue/src/index.ts @@ -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, @@ -12,6 +12,7 @@ function compileToFunction( hoistStatic: true, ...options }) + return new Function('Vue', code)(runtimeDom) as RenderFunction }