@@ -46,7 +46,7 @@ async function getAstFromFilePath(filePath) {
46
46
const ast = babelParser . parse ( data , {
47
47
sourceType : "module" , // Consider input as ECMAScript module
48
48
locations : true ,
49
- plugins : [ "jsx" , "objectRestSpread" ] // Enable JSX and object rest/spread syntax
49
+ plugins : [ "jsx" , "objectRestSpread" , "typescript" ] // Enable JSX, typescript and object rest/spread syntax
50
50
} ) ;
51
51
52
52
return ast ;
@@ -217,7 +217,7 @@ function processAst(ast, cb) {
217
217
left . object . property . name === 'exports' ) {
218
218
if ( expression . right . type === 'Identifier' ) {
219
219
// module.exports.func1 = func1
220
- return cb ( left . property . name , null , 'exportObj' ) ;
220
+ return cb ( left . property . name , path , 'exportObj' ) ;
221
221
} else if ( expression . right . type === 'FunctionExpression' ) {
222
222
// module.exports.funcName = function() { ... }
223
223
// module.exports = function() { ... }
@@ -230,7 +230,7 @@ function processAst(ast, cb) {
230
230
left . property . name === 'exports' ) {
231
231
if ( expression . right . type === 'Identifier' ) {
232
232
// module.exports = func1
233
- return cb ( expression . right . name , null , 'exportFn' ) ;
233
+ return cb ( expression . right . name , path , 'exportFn' ) ;
234
234
} else if ( expression . right . type === 'FunctionExpression' ) {
235
235
let funcName ;
236
236
if ( expression . right . id ) {
@@ -246,7 +246,7 @@ function processAst(ast, cb) {
246
246
expression . right . properties . forEach ( prop => {
247
247
if ( prop . type === 'ObjectProperty' ) {
248
248
// module.exports = { func1 };
249
- return cb ( prop . key . name , null , 'exportObj' ) ;
249
+ return cb ( prop . key . name , path , 'exportObj' ) ;
250
250
}
251
251
} ) ;
252
252
}
@@ -256,7 +256,7 @@ function processAst(ast, cb) {
256
256
left . object . name === 'exports' ) {
257
257
// exports.func1 = function() { ... }
258
258
// exports.func1 = func1
259
- return cb ( left . property . name , null , 'exportObj' ) ;
259
+ return cb ( left . property . name , path , 'exportObj' ) ;
260
260
}
261
261
}
262
262
}
@@ -268,37 +268,37 @@ function processAst(ast, cb) {
268
268
// export default func1;
269
269
// TODO export default function() { ... }
270
270
// TODO cover anonimous functions - add "anon_" name
271
- return cb ( declaration . id ? declaration . id . name : declaration . name , null , 'exportFn' ) ;
271
+ return cb ( declaration . id ? declaration . id . name : declaration . name , path , 'exportFn' ) ;
272
272
} else if ( declaration . type === 'ObjectExpression' ) {
273
273
declaration . properties . forEach ( prop => {
274
274
if ( prop . type === 'ObjectProperty' ) {
275
275
// export default { func1: func }
276
276
// export default { func1 }
277
- return cb ( prop . key . name , null , 'exportObj' ) ;
277
+ return cb ( prop . key . name , path , 'exportObj' ) ;
278
278
}
279
279
} ) ;
280
280
} else if ( declaration . type === 'ClassDeclaration' ) {
281
281
// export default class Class1 { ... }
282
- return cb ( declaration . id ? declaration . id . name : declaration . name , null , 'exportFnDef' ) ;
282
+ return cb ( declaration . id ? declaration . id . name : declaration . name , path , 'exportFnDef' ) ;
283
283
}
284
284
} else if ( path . isExportNamedDeclaration ( ) ) {
285
285
if ( path . node . declaration ) {
286
286
if ( path . node . declaration . type === 'FunctionDeclaration' ) {
287
287
// export function func1 () { ... }
288
288
// export class Class1 () { ... }
289
- return cb ( path . node . declaration . id . name , null , 'exportFnDef ' ) ;
289
+ return cb ( path . node . declaration . id . name , path , 'exportObj ' ) ;
290
290
} else if ( path . node . declaration . type === 'VariableDeclaration' ) {
291
291
path . node . declaration . declarations . forEach ( declaration => {
292
- return cb ( declaration . id . name , null , 'exportFn' ) ;
292
+ return cb ( declaration . id . name , path , 'exportFn' ) ;
293
293
} ) ;
294
294
} else if ( path . node . declaration . type === 'ClassDeclaration' ) {
295
295
// export class Class1 { ... }
296
- return cb ( path . node . declaration . id . name , null , 'exportFnDef' ) ;
296
+ return cb ( path . node . declaration . id . name , path , 'exportFnDef' ) ;
297
297
}
298
298
} else if ( path . node . specifiers . length > 0 ) {
299
299
path . node . specifiers . forEach ( spec => {
300
300
// export { func as func1 }
301
- return cb ( spec . exported . name , null , 'exportObj' ) ;
301
+ return cb ( spec . exported . name , path , 'exportObj' ) ;
302
302
} ) ;
303
303
}
304
304
}
0 commit comments