Skip to content

Commit 15865d0

Browse files
author
Zvonimir Sabljic
committed
Fixes to cover parsing the exported function defined with 'module.exports = function () { ... };' and 'module.exports.func1 = function () { ... };'
1 parent 27e23be commit 15865d0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/utils/code.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ function processAst(ast, cb) {
218218
// When module.exports.funcName = func1
219219
if (expression.right.type === 'Identifier') {
220220
return cb(left.property.name, null, 'exportObj');
221+
} else if (expression.right.type === 'FunctionExpression') {
222+
const loc = path.node.loc.start;
223+
let funcName = (left.property.name) || `anon_func_${loc.line}_${loc.column}`;
224+
return cb(funcName, path, 'exportObj');
221225
}
222226
} else if (left.type === 'MemberExpression' &&
223227
left.object.name === 'module' &&
@@ -251,7 +255,9 @@ function processAst(ast, cb) {
251255
// Handle TypeScript transpiled exports
252256
else if (left.type === 'MemberExpression' &&
253257
left.object.name === 'exports') {
254-
return cb(left.property.name, null, 'exportFn');
258+
// exports.func1 = function() { ... }
259+
// exports.func1 = func1
260+
return cb(left.property.name, null, 'exportObj');
255261
}
256262
}
257263
}

0 commit comments

Comments
 (0)