Skip to content

Commit

Permalink
feat(alita): 去除无用属性,减少小程序包体积
Browse files Browse the repository at this point in the history
  • Loading branch information
ykforerlang committed Jul 23, 2019
1 parent fefb3a6 commit 274957f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/misc/transformJSX.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ const transformJSX = (api, options) => {
if (t.isJSXElement(path.node.value)) {
path.node.value = t.jsxExpressionContainer(path.node.value);
}

if (path.type === 'JSXAttribute' && path.node.name.type === 'JSXNamespacedName') {
path.remove()
}
};

visitor.JSXOpeningElement = function (path) {
if (path.node.name.name === 'template') {
path.node.attributes = path.node.attributes.filter(attr => {
return attr.type === 'JSXAttribute'
&& (attr.name.name === 'datakey'
|| attr.name.name === 'tempVnode'
)
})
}
};

return {
Expand Down
6 changes: 5 additions & 1 deletion src/tran/geneAllTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ export default function(ast, info) {
) {
const jsxOp = path.node.openingElement
let tempName = ''
jsxOp.attributes.forEach(attr => {
jsxOp.attributes = jsxOp.attributes.filter(attr => {
if (attr.name && attr.name.name === 'tempName') {
tempName = attr.value.value
return false
}

return true
})

info.templates.push(decTemlate(tempName, path.node))
Expand All @@ -108,6 +111,7 @@ export default function(ast, info) {
if (name === 'tempVnode'
|| name === 'CPTVnode'
|| name === 'key'
|| name === 'datakey'
) {
path.remove()
return
Expand Down

0 comments on commit 274957f

Please sign in to comment.