Skip to content

Commit 6b9c629

Browse files
committed
JS: Avoid unwanted recursion
1 parent 56c9ee3 commit 6b9c629

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

javascript/ql/lib/semmle/javascript/ES2015Modules.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ private predicate hasDefaultExport(ES2015Module mod) {
9292
class ImportDeclaration extends Stmt, Import, @import_declaration {
9393
override ES2015Module getEnclosingModule() { result = this.getTopLevel() }
9494

95+
/**
96+
* Internal use only. Use `getImportedPathExpr` instead.
97+
*/
98+
string getRawImportPath() { result = this.getChildExpr(-1).getStringValue() }
99+
95100
override Expr getImportedPathExpr() { result = this.getChildExpr(-1) }
96101

97102
/**

javascript/ql/lib/semmle/javascript/NodeJS.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private class RequireVariable extends Variable {
237237
}
238238

239239
private predicate isModuleModule(EarlyStageNode nd) {
240-
exists(ImportDeclaration imp | imp.getImportedPathString() = "module" |
240+
exists(ImportDeclaration imp | imp.getRawImportPath() = "module" |
241241
nd = TDestructuredModuleImportNode(imp)
242242
or
243243
nd = TValueNode(imp.getASpecifier().(ImportNamespaceSpecifier))
@@ -263,7 +263,7 @@ private predicate isCreateRequire(EarlyStageNode nd) {
263263
)
264264
or
265265
exists(ImportDeclaration decl, NamedImportSpecifier spec |
266-
decl.getImportedPathString() = "module" and
266+
decl.getRawImportPath() = "module" and
267267
spec = decl.getASpecifier() and
268268
spec.getImportedName() = "createRequire" and
269269
nd = TValueNode(spec)

0 commit comments

Comments
 (0)