Skip to content

Commit dd076c6

Browse files
committed
Update UnusedDependency.ql
1 parent 1f58564 commit dd076c6

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

javascript/ql/src/NodeJS/UnusedDependency.ql

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,17 @@ predicate declaresDependency(NpmPackage pkg, string name, JsonValue dep) {
2323
/**
2424
* Gets a path expression in a module belonging to `pkg`.
2525
*/
26-
PathExpr getAPathExpr(NpmPackage pkg) { result.getEnclosingModule() = pkg.getAModule() }
26+
Expr getAPathExpr(NpmPackage pkg) {
27+
exists(Import imprt |
28+
result = imprt.getImportedPathExpr() and
29+
pkg.getAModule() = imprt.getEnclosingModule()
30+
)
31+
or
32+
exists(ReExportDeclaration decl |
33+
result = decl.getImportedPath() and
34+
pkg.getAModule() = decl.getEnclosingModule()
35+
)
36+
}
2737

2838
/**
2939
* Gets a URL-valued attribute in a module or HTML file belonging to `pkg`.
@@ -56,9 +66,8 @@ predicate usesDependency(NpmPackage pkg, string name) {
5666
(
5767
// there is a path expression (e.g., in a `require` or `import`) that
5868
// references `pkg`
59-
exists(PathExpr path | path = getAPathExpr(pkg) |
60-
// check whether the path is `name` or starts with `name/`, ignoring a prefix that ends with '!' (example: "scriptloader!moment")
61-
path.getValue().regexpMatch("(.*!)?\\Q" + name + "\\E(/.*)?")
69+
exists(Expr path | path = getAPathExpr(pkg) |
70+
path.getStringValue().(FilePath).getPackagePrefix() = name
6271
)
6372
or
6473
// there is an HTML URL attribute that may reference `pkg`

0 commit comments

Comments
 (0)