From adb90f4f92eac348eb8d864c647cdb4d4045f64a Mon Sep 17 00:00:00 2001 From: JiM-W <550116990@qq.com> Date: Tue, 16 Apr 2019 18:25:41 +0800 Subject: [PATCH] =?UTF-8?q?origin-=E5=92=8C=E5=8E=9F=E7=94=9F=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E7=9A=84=E5=B1=9E=E6=80=A7=E4=B8=8D=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mvvm-template-parser/common/index.js | 4 ++-- .../common/process-template.js | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/mvvm-template-parser/common/index.js b/packages/mvvm-template-parser/common/index.js index 19344565..f4eb6d3a 100644 --- a/packages/mvvm-template-parser/common/index.js +++ b/packages/mvvm-template-parser/common/index.js @@ -22,8 +22,8 @@ let source = `` let options = {lang: 'cml', diff --git a/packages/mvvm-template-parser/common/process-template.js b/packages/mvvm-template-parser/common/process-template.js index d51a97fe..531f89b5 100644 --- a/packages/mvvm-template-parser/common/process-template.js +++ b/packages/mvvm-template-parser/common/process-template.js @@ -68,7 +68,8 @@ _.compileTemplate = function(source,options) { }); traverse(ast, { enter(path) { - _.parseAllAttributes(path); + //所有的入口都以JSXElement为入口解析; + _.parseAllAttributes(path,options); _.parseBuildTag(path,options); } }); @@ -76,7 +77,15 @@ _.compileTemplate = function(source,options) { return generate(ast).code; } - +_.isOriginTagOrNativeComp = function(tagName,options){ + let usedComponentInfo = (options.usingComponents || []).find((item) => item.tagName === tagName) + let isNative = usedComponentInfo && usedComponentInfo.isNative; + let isOrigin = (tagName && typeof tagName === 'string' && tagName.indexOf('origin-') === 0); + if (isOrigin || isNative) { + return true + } + return false; +} /* 以标签为基础,解析attruibutes即可 1 v-bind:id="value" ==> id="{{value}}" @@ -86,9 +95,13 @@ _.compileTemplate = function(source,options) { */ -_.parseAllAttributes = function(path) { +_.parseAllAttributes = function(path,options) { let node = path.node; if (t.isJSXElement(node)) { + let tagName = node.openingElement.name.name + if(_.isOriginTagOrNativeComp(tagName,options)){ + return //原生标签和原生组件直接不解析 + } let attributes = node.openingElement.attributes; let directives = ['v-if', 'v-else-if', 'v-else', 'v-model', 'v-show', 'v-text', 'v-for']; let specialJSXNameSapce = ['c-bind', 'c-catch']; -- GitLab