From ee6195f6f699e37ee681d425ef21a2efa5572a4e Mon Sep 17 00:00:00 2001 From: "Chris West (Faux)" Date: Mon, 20 May 2019 16:12:34 +0100 Subject: [PATCH] feat: alias export default -> module.exports --- lib/ast.js | 3 +++ test/method-detection.test.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/ast.js b/lib/ast.js index 02ac28b..1fb7c09 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -88,6 +88,9 @@ function inspectNode(node, path, cb, expectingAnonymousDeclaration) { case 'ExportNamedDeclaration': inspectNode(node.declaration, path, cb); break; + case 'ExportDefaultDeclaration': + inspectNode(node.declaration, path.concat('module.exports'), cb, true); + break; case 'AssignmentExpression': { inspectNode(node.left, path, cb); inspectNode(node.right, path.concat(unpackName(node.left)), cb, true); diff --git a/test/method-detection.test.js b/test/method-detection.test.js index f6dbc29..39bc8f8 100644 --- a/test/method-detection.test.js +++ b/test/method-detection.test.js @@ -177,6 +177,20 @@ module.exports = { t.end(); }); +test('test export default method detection', function (t) { + const contents = ` +export default function() {} +`; + const methods = ['module.exports']; + const found = ast.findAllVulnerableFunctionsInScript( + contents, methods, + ); + t.same(sorted(Object.keys(found)), sorted(methods)); + t.equal(found[methods[0]].start.line, 2, + 'export default aliased to module.exports'); + t.end(); +}); + test('test class member detection', function (t) { const contents = ` class Moog {