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

Commit

Permalink
Merge pull request #90 from snyk/feat/alias-export-default
Browse files Browse the repository at this point in the history
feat: alias export default -> module.exports
  • Loading branch information
FauxFaux authored May 21, 2019
2 parents 5fb5c8f + ee6195f commit 6ab9cae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions test/method-detection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6ab9cae

Please sign in to comment.