@@ -215,38 +215,37 @@ function processAst(ast, cb) {
215
215
if ( left . object . type === 'MemberExpression' &&
216
216
left . object . object . name === 'module' &&
217
217
left . object . property . name === 'exports' ) {
218
- // When module.exports.funcName = func1
219
218
if ( expression . right . type === 'Identifier' ) {
219
+ // module.exports.func1 = func1
220
220
return cb ( left . property . name , null , 'exportObj' ) ;
221
221
} else if ( expression . right . type === 'FunctionExpression' ) {
222
+ // module.exports.funcName = function() { ... }
223
+ // module.exports = function() { ... }
222
224
const loc = path . node . loc . start ;
223
225
let funcName = ( left . property . name ) || `anon_func_${ loc . line } _${ loc . column } ` ;
224
226
return cb ( funcName , path , 'exportObj' ) ;
225
227
}
226
228
} else if ( left . type === 'MemberExpression' &&
227
229
left . object . name === 'module' &&
228
230
left . property . name === 'exports' ) {
229
- // When module.exports is set to a single function
230
231
if ( expression . right . type === 'Identifier' ) {
232
+ // module.exports = func1
231
233
return cb ( expression . right . name , null , 'exportFn' ) ;
232
- }
233
- // When module.exports is set to an anonymous function
234
- else if ( expression . right . type === 'FunctionExpression' ) {
234
+ } else if ( expression . right . type === 'FunctionExpression' ) {
235
235
let funcName ;
236
236
if ( expression . right . id ) {
237
+ // module.exports = function func1() { ... }
237
238
funcName = expression . right . id . name ;
238
239
} else {
239
- // If function is anonymous, we will generate a name
240
- // based on the file name, line and column number
240
+ // module.exports = function() { ... }
241
241
const loc = path . node . loc . start ;
242
242
funcName = `anon_func_${ loc . line } _${ loc . column } ` ;
243
243
}
244
244
return cb ( funcName , path , 'exportFnDef' ) ;
245
- }
246
- // When module.exports is set to an object containing multiple functions
247
- else if ( expression . right . type === 'ObjectExpression' ) {
245
+ } else if ( expression . right . type === 'ObjectExpression' ) {
248
246
expression . right . properties . forEach ( prop => {
249
247
if ( prop . type === 'ObjectProperty' ) {
248
+ // module.exports = { func1 };
250
249
return cb ( prop . key . name , null , 'exportObj' ) ;
251
250
}
252
251
} ) ;
@@ -266,29 +265,39 @@ function processAst(ast, cb) {
266
265
if ( path . isExportDefaultDeclaration ( ) ) {
267
266
const declaration = path . node . declaration ;
268
267
if ( declaration . type === 'FunctionDeclaration' || declaration . type === 'Identifier' ) {
268
+ // export default func1;
269
+ // TODO export default function() { ... }
270
+ // TODO cover anonimous functions - add "anon_" name
269
271
return cb ( declaration . id ? declaration . id . name : declaration . name , null , 'exportFn' ) ;
270
272
} else if ( declaration . type === 'ObjectExpression' ) {
271
273
declaration . properties . forEach ( prop => {
272
274
if ( prop . type === 'ObjectProperty' ) {
275
+ // export default { func1: func }
276
+ // export default { func1 }
273
277
return cb ( prop . key . name , null , 'exportObj' ) ;
274
278
}
275
279
} ) ;
276
280
} else if ( declaration . type === 'ClassDeclaration' ) {
281
+ // export default class Class1 { ... }
277
282
return cb ( declaration . id ? declaration . id . name : declaration . name , null , 'exportFnDef' ) ;
278
283
}
279
284
} else if ( path . isExportNamedDeclaration ( ) ) {
280
285
if ( path . node . declaration ) {
281
286
if ( path . node . declaration . type === 'FunctionDeclaration' ) {
287
+ // export function func1 () { ... }
288
+ // export class Class1 () { ... }
282
289
return cb ( path . node . declaration . id . name , null , 'exportFnDef' ) ;
283
290
} else if ( path . node . declaration . type === 'VariableDeclaration' ) {
284
291
path . node . declaration . declarations . forEach ( declaration => {
285
292
return cb ( declaration . id . name , null , 'exportFn' ) ;
286
293
} ) ;
287
294
} else if ( path . node . declaration . type === 'ClassDeclaration' ) {
295
+ // export class Class1 { ... }
288
296
return cb ( path . node . declaration . id . name , null , 'exportFnDef' ) ;
289
297
}
290
298
} else if ( path . node . specifiers . length > 0 ) {
291
299
path . node . specifiers . forEach ( spec => {
300
+ // export { func as func1 }
292
301
return cb ( spec . exported . name , null , 'exportObj' ) ;
293
302
} ) ;
294
303
}
0 commit comments