mirror of
https://github.com/github/codeql.git
synced 2026-04-27 09:45:15 +02:00
JS: Rename getTargetFile to getImportedFile and remove its deprecated name clash
'getTargetFile' was originally named to avoid the clash with 'getImportedFile' from a subclass. But we now just merge the two predicates.
This commit is contained in:
@@ -145,12 +145,12 @@ abstract class Import extends AstNode {
|
||||
/**
|
||||
* Gets the module the path of this import resolves to.
|
||||
*/
|
||||
Module resolveImportedPath() { result.getFile() = this.getTargetFile() }
|
||||
Module resolveImportedPath() { result.getFile() = this.getImportedFile() }
|
||||
|
||||
/**
|
||||
* Gets the module the path of this import resolves to.
|
||||
*/
|
||||
File getTargetFile() { result = ImportPathResolver::resolveExpr(this.getImportedPathExpr()) }
|
||||
File getImportedFile() { result = ImportPathResolver::resolveExpr(this.getImportedPathExpr()) }
|
||||
|
||||
/**
|
||||
* DEPRECATED. Use `getImportedModule()` instead.
|
||||
|
||||
@@ -327,78 +327,6 @@ class Require extends CallExpr, Import {
|
||||
|
||||
override Module getEnclosingModule() { this = result.getAnImport() }
|
||||
|
||||
/**
|
||||
* Gets the file that is imported by this `require`.
|
||||
*
|
||||
* The result can be a JavaScript file, a JSON file or a `.node` file.
|
||||
* Externs files are not treated differently from other files by this predicate.
|
||||
*/
|
||||
deprecated File getImportedFile() { result = this.load(min(int prio | exists(this.load(prio)))) }
|
||||
|
||||
/**
|
||||
* Gets the file that this `require` refers to (which may not be a JavaScript file),
|
||||
* using the root folder of priority `priority`.
|
||||
*
|
||||
* This predicate implements the specification of
|
||||
* [`require.resolve`](https://nodejs.org/api/modules.html#modules_all_together),
|
||||
* modified to allow additional JavaScript file extensions, such as `ts` and `jsx`.
|
||||
*
|
||||
* Module resolution order is modeled using the `priority` parameter as follows.
|
||||
*
|
||||
* Each candidate folder in which the path may be resolved is assigned
|
||||
* a priority (this is actually done by `Module.searchRoot`, but we explain it
|
||||
* here for completeness):
|
||||
*
|
||||
* - if the path starts with `'./'`, `'../'`, or `/`, it has a single candidate
|
||||
* folder (the enclosing folder of the module for the former two, the file
|
||||
* system root for the latter) of priority 0
|
||||
* - otherwise, candidate folders are folders of the form `<prefix>/node_modules`
|
||||
* such that `<prefix>` is a (not necessarily proper) ancestor of the enclosing
|
||||
* folder of the module which is not itself named `node_modules`; the priority
|
||||
* of a candidate folder is the number of steps from the enclosing folder of
|
||||
* the module to `<prefix>`.
|
||||
*
|
||||
* To resolve an import of a path `p`, we consider each candidate folder `c` with
|
||||
* priority `r` and resolve the import to the following files if they exist
|
||||
* (in order of priority):
|
||||
*
|
||||
* <ul>
|
||||
* <li> the file `c/p`;
|
||||
* <li> the file `c/p.{tsx,ts,jsx,es6,es,mjs,cjs}`;
|
||||
* <li> the file `c/p.js`;
|
||||
* <li> the file `c/p.json`;
|
||||
* <li> the file `c/p.node`;
|
||||
* <li> if `c/p` is a folder:
|
||||
* <ul>
|
||||
* <li> if `c/p/package.json` exists and specifies a `main` module `m`:
|
||||
* <ul>
|
||||
* <li> the file `c/p/m`;
|
||||
* <li> the file `c/p/m.{tsx,ts,jsx,es6,es,mjs,cjs}`;
|
||||
* <li> the file `c/p/m.js`;
|
||||
* <li> the file `c/p/m.json`;
|
||||
* <li> the file `c/p/m.node`;
|
||||
* </ul>
|
||||
* <li> the file `c/p/index.{tsx,ts,jsx,es6,es,mjs,cjs}`;
|
||||
* <li> the file `c/p/index.js`;
|
||||
* <li> the file `c/p/index.json`;
|
||||
* <li> the file `c/p/index.node`.
|
||||
* </ul>
|
||||
* </ul>
|
||||
*
|
||||
* The first four steps are factored out into predicate `loadAsFile`,
|
||||
* the remainder into `loadAsDirectory`; both make use of an auxiliary
|
||||
* predicate `tryExtensions` that handles the repeated distinction between
|
||||
* `.js`, `.json` and `.node`.
|
||||
*/
|
||||
deprecated private File load(int priority) {
|
||||
exists(int r | this.getEnclosingModule().searchRoot(this.getImportedPathExpr(), _, r) |
|
||||
result = loadAsFile(this, r, priority - prioritiesPerCandidate() * r) or
|
||||
result =
|
||||
loadAsDirectory(this, r,
|
||||
priority - (prioritiesPerCandidate() * r + numberOfExtensions() + 1))
|
||||
)
|
||||
}
|
||||
|
||||
override DataFlow::Node getImportedModuleNode() { result = DataFlow::valueNode(this) }
|
||||
}
|
||||
|
||||
|
||||
@@ -442,7 +442,7 @@ module Vue {
|
||||
|
||||
override DataFlow::SourceNode getASource() {
|
||||
exists(Import imprt |
|
||||
imprt.getTargetFile() instanceof VueFile and
|
||||
imprt.getImportedFile() instanceof VueFile and
|
||||
result = imprt.getImportedModuleNode()
|
||||
)
|
||||
}
|
||||
@@ -494,7 +494,7 @@ module Vue {
|
||||
// There is no explicit `new Vue()` call in .vue files, so instead get all the imports
|
||||
// of the .vue file.
|
||||
exists(Import imprt |
|
||||
imprt.getTargetFile() = file and
|
||||
imprt.getImportedFile() = file and
|
||||
result.asSource() = imprt.getImportedModuleNode()
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user