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

Commit f58306c

Browse files
committed
feat: allow lazy || wrapper classes
1 parent 626c3b7 commit f58306c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/ast.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ function inspectNode(node, path, cb, expectingAnonymousDeclaration) {
9696
inspectNode(node.right, path.concat(unpackName(node.left)), cb, true);
9797
break;
9898
}
99+
case 'LogicalExpression':
100+
inspectNode(node.left, path, cb);
101+
inspectNode(node.right, path, cb);
102+
break;
99103
case 'UnaryExpression':
100104
inspectNode(node.argument, path, cb);
101105
break;

test/method-detection.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ if (console.both) {
107107
t.end();
108108
});
109109

110+
test('test lazy class declaration', function (t) {
111+
const contents = `
112+
var Class = Class || (function (Object) {
113+
function foo() {}
114+
});
115+
`;
116+
const methods = ['Class.foo'];
117+
const found = ast.findAllVulnerableFunctionsInScript(
118+
contents, methods,
119+
);
120+
t.same(sorted(Object.keys(found)), sorted(methods));
121+
t.equal(found[methods[0]].start.line, 3, 'foo');
122+
t.end();
123+
});
124+
110125
test('test st method detection', function (t) {
111126
const content = fs.readFileSync(__dirname + '/fixtures/st/node_modules/st.js');
112127
const methods = ['Mount.prototype.getPath'];

0 commit comments

Comments
 (0)