@@ -20,11 +20,17 @@ DataFlow::ParameterNode getALibraryInputParameter() {
20
20
* Gets a value exported by the main module from a named `package.json` file.
21
21
*/
22
22
private DataFlow:: Node getAValueExportedByPackage ( ) {
23
+ // The base case, an export from a named `package.json` file.
23
24
result =
24
25
getAnExportFromModule ( any ( PackageJSON pack | exists ( pack .getPackageName ( ) ) ) .getMainModule ( ) )
25
26
or
27
+ // module.exports.bar.baz = result;
26
28
result = getAValueExportedByPackage ( ) .( DataFlow:: PropWrite ) .getRhs ( )
27
29
or
30
+ // class Foo {
31
+ // bar() {} // <- result
32
+ // };
33
+ // module.exports = new Foo();
28
34
exists ( DataFlow:: SourceNode callee |
29
35
callee = getAValueExportedByPackage ( ) .( DataFlow:: NewNode ) .getCalleeNode ( ) .getALocalSource ( )
30
36
|
@@ -35,14 +41,21 @@ private DataFlow::Node getAValueExportedByPackage() {
35
41
or
36
42
result = getAValueExportedByPackage ( ) .getALocalSource ( )
37
43
or
44
+ // Nested property reads.
38
45
result = getAValueExportedByPackage ( ) .( DataFlow:: SourceNode ) .getAPropertyReference ( )
39
46
or
47
+ // module.exports.foo = require("./other-module.js");
40
48
exists ( Module mod |
41
49
mod = getAValueExportedByPackage ( ) .getEnclosingExpr ( ) .( Import ) .getImportedModule ( )
42
50
|
43
51
result = getAnExportFromModule ( mod )
44
52
)
45
53
or
54
+ // module.exports = class Foo {
55
+ // bar() {} // <- result
56
+ // static baz() {} // <- result
57
+ // constructor() {} // <- result
58
+ // };
46
59
exists ( DataFlow:: ClassNode cla | cla = getAValueExportedByPackage ( ) |
47
60
result = cla .getAnInstanceMethod ( ) or
48
61
result = cla .getAStaticMethod ( ) or
@@ -72,6 +85,12 @@ private DataFlow::Node getAValueExportedByPackage() {
72
85
)
73
86
or
74
87
// the exported value is a call to a unique callee
88
+ // ```JavaScript
89
+ // module.exports = foo();
90
+ // function foo() {
91
+ // return result;
92
+ // }
93
+ // ```
75
94
exists ( DataFlow:: CallNode call | call = getAValueExportedByPackage ( ) |
76
95
result = unique( | | call .getCalleeNode ( ) .getAFunctionValue ( ) ) .getAReturn ( )
77
96
)
0 commit comments