提交 adb90f4f 编写于 作者: J JiM-W

origin-和原生组件上的属性不解析

上级 12c4b60a
......@@ -22,8 +22,8 @@ let source = `<template>
<view class="cls1 cls2"></view>
<view :class="true ? 'cls4' : 'cls5'"></view>
<button></button>
<third-comp1 h-on:click="click1"></third-comp1>
<origin-checkbox :class="click1"></origin-checkbox>
<third-comp1 v-on:click="click1"></third-comp1>
<origin-checkbox :class="click1" class="cls1"></origin-checkbox>
</view>
</template>`
let options = {lang: 'cml',
......
......@@ -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'];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册