JS: Remove a dependency on getImportedPath()

To avoid negative recursion in some upcoming changes, we want to make sure the modeling of createRequire does not depend on getImportedPath().
This commit is contained in:
Asger F
2025-04-28 13:41:01 +02:00
parent a195d074c9
commit c293f03b9e
2 changed files with 7 additions and 2 deletions

View File

@@ -94,6 +94,11 @@ class ImportDeclaration extends Stmt, Import, @import_declaration {
override PathExpr getImportedPath() { result = this.getChildExpr(-1) }
/**
* INTERNAL USE ONLY. DO NOT USE.
*/
string getRawImportPath() { result = this.getChildExpr(-1).getStringValue() }
/**
* Gets the object literal passed as part of the `with` (or `assert`) clause in this import declaration.
*

View File

@@ -242,7 +242,7 @@ private class RequireVariable extends Variable {
private predicate moduleInFile(Module m, File f) { m.getFile() = f }
private predicate isModuleModule(EarlyStageNode nd) {
exists(ImportDeclaration imp | imp.getImportedPath().getValue() = "module" |
exists(ImportDeclaration imp | imp.getRawImportPath() = "module" |
nd = TDestructuredModuleImportNode(imp)
or
nd = TValueNode(imp.getASpecifier().(ImportNamespaceSpecifier))
@@ -268,7 +268,7 @@ private predicate isCreateRequire(EarlyStageNode nd) {
)
or
exists(ImportDeclaration decl, NamedImportSpecifier spec |
decl.getImportedPath().getValue() = "module" and
decl.getRawImportPath() = "module" and
spec = decl.getASpecifier() and
spec.getImportedName() = "createRequire" and
nd = TValueNode(spec)