Skip to content

Commit

Permalink
feat(alita-core): 支持形如 <A x /> x这类无指的属性
Browse files Browse the repository at this point in the history
affects: @areslabs/alita-core
  • Loading branch information
ykforerlang committed Feb 14, 2020
1 parent f06465f commit ffbe802
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/alita-core/src/precheck/checkJSX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ export default function checkJSX(ast, filepath, rawCode) {
return
}

if (path.node.value.type === 'JSXExpressionContainer'
if (path.node.value
&& path.node.value.type === 'JSXExpressionContainer'
&& path.node.value.expression
&& path.node.value.expression.type === 'MemberExpression'
&& path.node.value.expression.object.type === 'ThisExpression'
Expand All @@ -284,7 +285,8 @@ export default function checkJSX(ast, filepath, rawCode) {


// this.xx.bind(this)
if (path.node.value.type === 'JSXExpressionContainer'
if (path.node.value
&& path.node.value.type === 'JSXExpressionContainer'
&& path.node.value.expression
&& path.node.value.expression.type === 'CallExpression'
&& path.node.value.expression.callee.type === 'MemberExpression'
Expand Down
8 changes: 8 additions & 0 deletions packages/alita-core/src/tran/compPreHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import * as t from "@babel/types"
*
* 3. 移除JSX里面的注释
*
* 4. <A x/> ==> <A x="true"/>
*
* ...
*
* @param ast
Expand Down Expand Up @@ -78,6 +80,12 @@ export default function compPreHandle(ast, info) {
path.parentPath.remove()
return
}

if (path.type === 'JSXAttribute'
&& !path.node.value
) {
path.node.value = t.stringLiteral('true')
}
}
})

Expand Down

0 comments on commit ffbe802

Please sign in to comment.