Skip to content

Commit

Permalink
perf(alita): 对Text标签的子元素特殊处理
Browse files Browse the repository at this point in the history
  • Loading branch information
ykforerlang committed Aug 28, 2019
1 parent c408139 commit ec38d66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/tran/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function (ast, filepath, isFuncComp, entryFilePath, isPageComp) {

geneReactJS(ast, info)

//ast = literalTemplate(ast, info)
ast = literalTemplate(ast, info)

ast = addEventHandler(ast, info)

Expand Down
16 changes: 13 additions & 3 deletions src/tran/literalTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import * as t from "@babel/types"
* @param info
* @returns {*}
*/
export default function literalTemplate (ast,info) {
export default function literalTemplate (ast, info) {

traverse(ast, {
exit: path => {
if (path.type === 'JSXElement') {

if (path.type === 'JSXElement'
&& isTextElement(path.node.openingElement)
) {
const newChildren = []
path.node.children.forEach(item => {
if (
Expand Down Expand Up @@ -56,4 +57,13 @@ export default function literalTemplate (ast,info) {
})

return ast
}

function isTextElement(openingElement) {
if (openingElement.name.name !== 'view') return false

return openingElement.attributes.some(item =>
item.type === 'JSXAttribute'
&& item.name.name === 'original'
&& (item.value.value === 'OuterText' || item.value.value === 'InnerText'))
}

0 comments on commit ec38d66

Please sign in to comment.