Skip to content

Commit d017f21

Browse files
committed
feat(alita): support export from json组件路径查找
1 parent 065605c commit d017f21

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

src/packByWebpack/gatherInfo-loader.ts

+34-10
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,7 @@ function getFileInfo(ast, filepath) {
9292
) {
9393
isRNEntry = true
9494
}
95-
},
96-
97-
ExportNamedDeclaration: path => {
98-
path.node.specifiers.forEach(spe => {
99-
const name = spe.exported.name
100-
ex[name] = {
101-
102-
}
103-
})
104-
},
95+
}
10596
})
10697

10798

@@ -115,6 +106,13 @@ function getFileInfo(ast, filepath) {
115106
return
116107
}
117108

109+
// export {A} from './A'
110+
if (path.type === 'ExportNamedDeclaration' && (path.node as t.ExportNamedDeclaration).source) {
111+
// TODO
112+
handleExportSource(path, filepath, JSXElements, im)
113+
return
114+
}
115+
118116
// @ts-ignore
119117
if (path.type === 'CallExpression' && path.node.callee.name === 'require' && path.key === 'init') {
120118
handleRequire(path, filepath, JSXElements, im)
@@ -204,3 +202,29 @@ function handleImport(path, filepath, JSXElements, im) {
204202
}
205203

206204

205+
function handleExportSource(path, filepath, JSXElements, im) {
206+
const relativePath = path.node.source.value
207+
208+
const idens = []
209+
path.node.specifiers.forEach(spe => {
210+
//spe = spe as t.ImportSpecifier
211+
const name = spe.exported.name
212+
im[name] = {
213+
source: relativePath,
214+
defaultSpecifier: spe.type === 'ImportDefaultSpecifier',
215+
// @ts-ignore
216+
imported: spe.type === 'ImportSpecifier' ? spe.imported.name : null,
217+
}
218+
219+
idens.push(name)
220+
})
221+
222+
const isLibPath = judgeLibPath(relativePath)
223+
if (!isLibPath) return
224+
225+
const isCompPack = idens.some(iden => JSXElements.has(iden))
226+
if (!isCompPack) return
227+
228+
getLibCompInfos(idens, JSXElements, filepath, relativePath)
229+
}
230+

0 commit comments

Comments
 (0)