From ffbe8025414b112b022b3cd4f54e5f35cf207c3b Mon Sep 17 00:00:00 2001
From: ykforerlang <1527997464@qq.com>
Date: Fri, 14 Feb 2020 18:06:51 +0800
Subject: [PATCH] =?UTF-8?q?feat(alita-core):=20=E6=94=AF=E6=8C=81=E5=BD=A2?=
=?UTF-8?q?=E5=A6=82=20=20x=E8=BF=99=E7=B1=BB=E6=97=A0=E6=8C=87?=
=?UTF-8?q?=E7=9A=84=E5=B1=9E=E6=80=A7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
affects: @areslabs/alita-core
---
packages/alita-core/src/precheck/checkJSX.ts | 6 ++++--
packages/alita-core/src/tran/compPreHandle.js | 8 ++++++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/packages/alita-core/src/precheck/checkJSX.ts b/packages/alita-core/src/precheck/checkJSX.ts
index c14af57..fb67248 100644
--- a/packages/alita-core/src/precheck/checkJSX.ts
+++ b/packages/alita-core/src/precheck/checkJSX.ts
@@ -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'
@@ -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'
diff --git a/packages/alita-core/src/tran/compPreHandle.js b/packages/alita-core/src/tran/compPreHandle.js
index c4a3e4b..c242721 100644
--- a/packages/alita-core/src/tran/compPreHandle.js
+++ b/packages/alita-core/src/tran/compPreHandle.js
@@ -19,6 +19,8 @@ import * as t from "@babel/types"
*
* 3. 移除JSX里面的注释
*
+ * 4. ==>
+ *
* ...
*
* @param ast
@@ -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')
+ }
}
})