From 5d9f768f1ee82267173467a1bb47900d3cc6e042 Mon Sep 17 00:00:00 2001 From: yutent Date: Mon, 15 May 2023 10:54:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A8=A1=E6=9D=BF=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/compile-vue.js | 44 +++++++++++++++++++++++++++++++++++--------- package.json | 2 +- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/lib/compile-vue.js b/lib/compile-vue.js index 04069cb..fc0fb42 100644 --- a/lib/compile-vue.js +++ b/lib/compile-vue.js @@ -298,15 +298,41 @@ export function compileVue(file, imports, options = {}) { js = js ? js[1] : '' - html = compile(html[1], { - mode: 'module', - prefixIdentifiers: true, - hoistStatic: true, - cacheHandlers: true, - scopeId: scoped ? scopeId : void 0, - sourceMap: false, - isCustomElement: tag => tag.startsWith('wc-') - }).code.replace('export function render', 'function render') + try { + html = compile(html[1], { + mode: 'module', + prefixIdentifiers: true, + hoistStatic: true, + cacheHandlers: true, + scopeId: scoped ? scopeId : void 0, + sourceMap: false, + isCustomElement: tag => tag.startsWith('wc-') + }).code.replace('export function render', 'function render') + } catch (err) { + let tmp = html[1].split('\n') + let line = tmp[err.loc.start.line - 1] + + console.log('%s: %s', red('SyntaxError'), red(err.message)) + console.log( + ' @ %s%s%s', + line.slice(0, err.loc.start.column - 1), + red(err.loc.source), + line.slice(err.loc.end.column - 1) + ) + console.log( + ' @ (%s:%d:%d)\n', + file, + err.loc.start.line, + err.loc.start.column + ) + html = ` +import { openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue" + +function render(_ctx, _cache) { + return (_openBlock(), _createElementBlock("div", null, "SyntaxError: ${err.message}")) +} + ` + } html = html .replace(/import .* from "vue"/, str => { diff --git a/package.json b/package.json index d98f165..13687c3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fite", "type": "module", - "version": "0.9.3", + "version": "0.9.4", "bin": { "fite": "index.js" },