Skip to content

Commit 46cdb17

Browse files
committed
JS: Use PackageJsonEx instead of resolveMainModule
1 parent d39d431 commit 46cdb17

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

javascript/ql/lib/semmle/javascript/PackageExports.qll

+3-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import javascript
88
private import semmle.javascript.internal.CachedStages
9+
private import semmle.javascript.internal.paths.PackageJsonEx
910

1011
/**
1112
* Gets a parameter that is a library input to a top-level package.
@@ -126,19 +127,12 @@ private DataFlow::Node getAValueExportedByPackage() {
126127
// ....
127128
// }));
128129
// ```
129-
// Such files are not recognized as modules, so we manually use `NodeModule::resolveMainModule` to resolve the file against a `package.json` file.
130+
// Such files are not recognized as modules, so we manually use `PackageJsonEx` to resolve the file against a `package.json` file.
130131
exists(ImmediatelyInvokedFunctionExpr func, DataFlow::ParameterNode factory, int i |
131132
factory.getName() = "factory" and
132133
func.getParameter(i) = factory.getParameter() and
133134
DataFlow::globalVarRef("define").getACall().getAnArgument() = factory.getALocalUse() and
134-
func.getFile() =
135-
min(int j, File f |
136-
f =
137-
NodeModule::resolveMainModule(any(PackageJson pack | exists(pack.getPackageName())), j,
138-
".")
139-
|
140-
f order by j
141-
)
135+
func.getFile() = any(PackageJsonEx pack).getMainFileOrBestGuess()
142136
|
143137
result = func.getInvocation().getArgument(i).flow().getAFunctionValue().getAReturn()
144138
or

0 commit comments

Comments
 (0)