Skip to content

Commit f4635dc

Browse files
committed
fix(alita): 2个组件 + defaut导出 判断错误的bug
1 parent 6668145 commit f4635dc

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"weixin",
1717
"redux"
1818
],
19-
"version": "2.1.0-beta.2",
19+
"version": "2.1.1",
2020
"description": "alita-core",
2121
"main": "./lib/index.js",
2222
"scripts": {

src/tran/funcCompToClassComp.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export default function funcCompToClassComp(ast, info) {
4242

4343
let comps = new Set([])
4444

45+
let totalComps = 0
46+
4547
errorLogTraverse(ast, {
4648
enter: path => {
4749

@@ -151,6 +153,9 @@ export default function funcCompToClassComp(ast, info) {
151153

152154
// @ts-ignore
153155
if (isReactComponent(path.node.superClass)) {
156+
157+
totalComps ++
158+
154159
if (path.parentPath.type === 'ExportDefaultDeclaration') {
155160
comps.add('default')
156161
// @ts-ignore
@@ -203,8 +208,8 @@ export default function funcCompToClassComp(ast, info) {
203208
// 有默认导出的情况
204209
if (path.type === 'Program') {
205210

206-
if (comps.has('default') && comps.size === 2) {
207-
// 有一个组件且有默认导出,特殊处理
211+
if (totalComps === 1 && comps.has('default')) {
212+
// 只有一个组件且有默认导出,特殊处理
208213
info.outComp = ['default']
209214
} else {
210215
info.outComp = Array.from(comps)

0 commit comments

Comments
 (0)