Skip to content
This repository was archived by the owner on Jun 2, 2022. It is now read-only.

Commit ee6195f

Browse files
committed
feat: alias export default -> module.exports
1 parent 5fb5c8f commit ee6195f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/ast.js

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ function inspectNode(node, path, cb, expectingAnonymousDeclaration) {
8888
case 'ExportNamedDeclaration':
8989
inspectNode(node.declaration, path, cb);
9090
break;
91+
case 'ExportDefaultDeclaration':
92+
inspectNode(node.declaration, path.concat('module.exports'), cb, true);
93+
break;
9194
case 'AssignmentExpression': {
9295
inspectNode(node.left, path, cb);
9396
inspectNode(node.right, path.concat(unpackName(node.left)), cb, true);

test/method-detection.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@ module.exports = {
177177
t.end();
178178
});
179179

180+
test('test export default method detection', function (t) {
181+
const contents = `
182+
export default function() {}
183+
`;
184+
const methods = ['module.exports'];
185+
const found = ast.findAllVulnerableFunctionsInScript(
186+
contents, methods,
187+
);
188+
t.same(sorted(Object.keys(found)), sorted(methods));
189+
t.equal(found[methods[0]].start.line, 2,
190+
'export default aliased to module.exports');
191+
t.end();
192+
});
193+
180194
test('test class member detection', function (t) {
181195
const contents = `
182196
class Moog {

0 commit comments

Comments
 (0)