From 3911148e46fc642159d11e3210e3a951d4577196 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 26 Nov 2019 17:15:33 +0800 Subject: [PATCH] fix(v3): parseKey error (https://ask.dcloud.net.cn/question/83806) --- .../uni-template-compiler/lib/app/service.js | 2 +- packages/uni-template-compiler/lib/index.js | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/uni-template-compiler/lib/app/service.js b/packages/uni-template-compiler/lib/app/service.js index df156cc34..ee9add480 100644 --- a/packages/uni-template-compiler/lib/app/service.js +++ b/packages/uni-template-compiler/lib/app/service.js @@ -50,7 +50,7 @@ function parseKey (el) { } const forEl = getForEl(el) if (!forEl) { - isVar(el.key) && (el.key = createGenVar(el.attrsMap[ID])('a-key', el.key)) + return isVar(el.key) && (el.key = createGenVar(el.attrsMap[ID])('a-key', el.key)) } if (!isVar(forEl.for)) { return diff --git a/packages/uni-template-compiler/lib/index.js b/packages/uni-template-compiler/lib/index.js index 2ff6ad5b7..cacdda93a 100644 --- a/packages/uni-template-compiler/lib/index.js +++ b/packages/uni-template-compiler/lib/index.js @@ -36,15 +36,22 @@ module.exports = { options.isReservedTag = (tagName) => !isComponent(tagName) // 非组件均为内置 options.getTagNamespace = () => false - // clear staticRenderFns - const compiled = compile(source, options) - - return compiled + try { + return compile(source, options) + } catch (e) { + console.error(`'错误:${options.resourcePath}'`) + throw new Error(e.message) + } } else if (options.view) { (options.modules || (options.modules = [])).push(require('./app/view')) options.optimize = false // 暂不启用 staticRenderFns options.isReservedTag = (tagName) => false // 均为组件 - return compile(source, options) + try { + return compile(source, options) + } catch (e) { + console.error(`'错误:${options.resourcePath}'`) + throw new Error(e.message) + } } if (!options.mp) { // h5 -- GitLab