Skip to content

Commit

Permalink
Merge branch 'master-wmj-fix' into 'master-bugfix'
Browse files Browse the repository at this point in the history
bug-fix c-show component-is {{}}

See merge request !12
  • Loading branch information
yangyiliang committed Feb 1, 2019
2 parents f1b236d + 569779f commit 4c2c750
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ exports.analyzeTemplate = function(source, options) {
exports._operationMustache = function (content) {
let mustacheReg = /{{([\s\S]*?)}}/g
return content.replace(mustacheReg, function (match, key) {
key = exports._deOperationGtLt(key);
return `_cml{${key}}lmc_`
})
}
Expand Down
14 changes: 12 additions & 2 deletions packages/chameleon-template-parse/src/parser/parse-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ parseDirective.tap('web-weex-cml', (args) => {
let elementShow = utils.trimCurly(showDirectiveNode.value.value);

let styleNodeValue = `display:{{${elementShow}?'':'none'}};{{${elementShow}?'':'height:0px;width:0px;overflow:hidden'}}`
attributes.push(t.jsxAttribute(t.jsxIdentifier(`style`), t.stringLiteral(styleNodeValue)))
if (type === 'weex') {
attributes.push(t.jsxAttribute(t.jsxIdentifier(`style`), t.stringLiteral(styleNodeValue)))
} else if (type === 'web') {
attributes.push(t.jsxAttribute(t.jsxIdentifier(`v-show`), t.stringLiteral(elementShow)))
}

}
}
});
Expand Down Expand Up @@ -139,7 +144,12 @@ parseDirective.tap('web-weex-vue', (args) => {
if (type === 'weex' && styleNodeValue.indexOf('_cmlStyleProxy') === -1) {
styleNodeValue = `${weexMixins.styleProxyName}(${utils.getReactiveValue(styleNodeValue)})`
}
attributes.push(t.jsxAttribute(t.jsxIdentifier(`:style`), t.stringLiteral(styleNodeValue)))
if (type === 'weex') {
attributes.push(t.jsxAttribute(t.jsxIdentifier(`:style`), t.stringLiteral(styleNodeValue)))
} else if (type === 'web') {
attributes.push(t.jsxAttribute(t.jsxIdentifier(`v-show`), t.stringLiteral(elementShow)))
}

}
}
})
Expand Down
4 changes: 2 additions & 2 deletions packages/chameleon-template-parse/src/parser/parse-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ parseStyle.tap('web-cml', (args) => {
if (styleNode && styleNode.value && utils.isMustacheReactive(styleNode.value.value)) {
styleNode.value.value = utils.getReactiveValue(styleNode.value.value);

styleNode.value.value = `${webMixins.styleProxyName}(${styleNode.value.value},${cmssString})`
styleNode.value.value = `${webMixins.styleProxyName}((${styleNode.value.value}),${cmssString})`
styleNode.name.name = `:${styleNode.name.name}`;
} else { // 静态的
styleNode.value.value = webStaticStyleHandle(styleNode.value.value, cmssString);
Expand All @@ -39,7 +39,7 @@ parseStyle.tap('weex-cml', (args) => {
if (styleNode && styleNode.value && utils.isMustacheReactive(styleNode.value.value)) {
// weex动态style
styleNode.value.value = utils.getReactiveValue(styleNode.value.value);
styleNode.value.value = `${weexMixins.styleProxyName}(${styleNode.value.value})`
styleNode.value.value = `${weexMixins.styleProxyName}((${styleNode.value.value}))`
styleNode.name.name = `:${styleNode.name.name}`;
} else { // weex静态style

Expand Down
10 changes: 8 additions & 2 deletions packages/chameleon-template-parse/src/parser/parse-vue2wx.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ parseVue2Wx.tap('vue2wx-v-for', (args) => {
});
parseVue2Wx.tap('component-is', (args) => {
let {path, node, type, options} = args;
let lang = options.lang;
let usingComponents = (options.usingComponents || []).map(item => item.tagName)
if (type === 'wx' && t.isJSXElement(node)) {
let currentTag = node.openingElement.name.name;
Expand All @@ -102,13 +103,18 @@ parseVue2Wx.tap('component-is', (args) => {
let currentComp;
(path.node.openingElement.attributes || []).forEach((attr) => {
let attrName = attr.name
if (t.isJSXNamespacedName(attrName) && attrName.name.name === 'is') {
if (lang === 'vue' && t.isJSXNamespacedName(attrName) && attrName.name.name === 'is') {
currentComp = attr.value.value;
}
if (lang === 'cml' && t.isJSXIdentifier(attrName) && attrName.name === 'is') {
currentComp = utils.trimCurly(attr.value.value);
}

})
if (currentComp && usingComponents) {
let elementAttributes = path.node.openingElement.attributes || []
usingComponents.forEach((comp) => {
let openTag = t.jsxOpeningElement(t.jsxIdentifier(comp), [t.jsxAttribute(t.jsxIdentifier('wx:if'), t.stringLiteral(`{{${currentComp} === '${comp}'}}`))]);
let openTag = t.jsxOpeningElement(t.jsxIdentifier(comp), [t.jsxAttribute(t.jsxIdentifier('wx:if'), t.stringLiteral(`{{${currentComp} === '${comp}'}}`))].concat(elementAttributes));
let closeTag = t.jsxClosingElement(t.jsxIdentifier(comp))
let insertNode = t.jsxElement(openTag, closeTag, jsxElementChildren, false);

Expand Down

0 comments on commit 4c2c750

Please sign in to comment.