Skip to content

Commit 20532a6

Browse files
committed
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.
1 parent b8bb46a commit 20532a6

File tree

3 files changed

+4
-76
lines changed

3 files changed

+4
-76
lines changed

javascript/ql/lib/semmle/javascript/Modules.qll

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ abstract class Import extends AstNode {
145145
/**
146146
* Gets the module the path of this import resolves to.
147147
*/
148-
Module resolveImportedPath() { result.getFile() = this.getTargetFile() }
148+
Module resolveImportedPath() { result.getFile() = this.getImportedFile() }
149149

150150
/**
151151
* Gets the module the path of this import resolves to.
152152
*/
153-
File getTargetFile() { result = ImportPathResolver::resolveExpr(this.getImportedPathExpr()) }
153+
File getImportedFile() { result = ImportPathResolver::resolveExpr(this.getImportedPathExpr()) }
154154

155155
/**
156156
* DEPRECATED. Use `getImportedModule()` instead.

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

-72
Original file line numberDiff line numberDiff line change
@@ -327,78 +327,6 @@ class Require extends CallExpr, Import {
327327

328328
override Module getEnclosingModule() { this = result.getAnImport() }
329329

330-
/**
331-
* Gets the file that is imported by this `require`.
332-
*
333-
* The result can be a JavaScript file, a JSON file or a `.node` file.
334-
* Externs files are not treated differently from other files by this predicate.
335-
*/
336-
deprecated File getImportedFile() { result = this.load(min(int prio | exists(this.load(prio)))) }
337-
338-
/**
339-
* Gets the file that this `require` refers to (which may not be a JavaScript file),
340-
* using the root folder of priority `priority`.
341-
*
342-
* This predicate implements the specification of
343-
* [`require.resolve`](https://nodejs.org/api/modules.html#modules_all_together),
344-
* modified to allow additional JavaScript file extensions, such as `ts` and `jsx`.
345-
*
346-
* Module resolution order is modeled using the `priority` parameter as follows.
347-
*
348-
* Each candidate folder in which the path may be resolved is assigned
349-
* a priority (this is actually done by `Module.searchRoot`, but we explain it
350-
* here for completeness):
351-
*
352-
* - if the path starts with `'./'`, `'../'`, or `/`, it has a single candidate
353-
* folder (the enclosing folder of the module for the former two, the file
354-
* system root for the latter) of priority 0
355-
* - otherwise, candidate folders are folders of the form `<prefix>/node_modules`
356-
* such that `<prefix>` is a (not necessarily proper) ancestor of the enclosing
357-
* folder of the module which is not itself named `node_modules`; the priority
358-
* of a candidate folder is the number of steps from the enclosing folder of
359-
* the module to `<prefix>`.
360-
*
361-
* To resolve an import of a path `p`, we consider each candidate folder `c` with
362-
* priority `r` and resolve the import to the following files if they exist
363-
* (in order of priority):
364-
*
365-
* <ul>
366-
* <li> the file `c/p`;
367-
* <li> the file `c/p.{tsx,ts,jsx,es6,es,mjs,cjs}`;
368-
* <li> the file `c/p.js`;
369-
* <li> the file `c/p.json`;
370-
* <li> the file `c/p.node`;
371-
* <li> if `c/p` is a folder:
372-
* <ul>
373-
* <li> if `c/p/package.json` exists and specifies a `main` module `m`:
374-
* <ul>
375-
* <li> the file `c/p/m`;
376-
* <li> the file `c/p/m.{tsx,ts,jsx,es6,es,mjs,cjs}`;
377-
* <li> the file `c/p/m.js`;
378-
* <li> the file `c/p/m.json`;
379-
* <li> the file `c/p/m.node`;
380-
* </ul>
381-
* <li> the file `c/p/index.{tsx,ts,jsx,es6,es,mjs,cjs}`;
382-
* <li> the file `c/p/index.js`;
383-
* <li> the file `c/p/index.json`;
384-
* <li> the file `c/p/index.node`.
385-
* </ul>
386-
* </ul>
387-
*
388-
* The first four steps are factored out into predicate `loadAsFile`,
389-
* the remainder into `loadAsDirectory`; both make use of an auxiliary
390-
* predicate `tryExtensions` that handles the repeated distinction between
391-
* `.js`, `.json` and `.node`.
392-
*/
393-
deprecated private File load(int priority) {
394-
exists(int r | this.getEnclosingModule().searchRoot(this.getImportedPathExpr(), _, r) |
395-
result = loadAsFile(this, r, priority - prioritiesPerCandidate() * r) or
396-
result =
397-
loadAsDirectory(this, r,
398-
priority - (prioritiesPerCandidate() * r + numberOfExtensions() + 1))
399-
)
400-
}
401-
402330
override DataFlow::Node getImportedModuleNode() { result = DataFlow::valueNode(this) }
403331
}
404332

javascript/ql/lib/semmle/javascript/frameworks/Vue.qll

+2-2
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ module Vue {
442442

443443
override DataFlow::SourceNode getASource() {
444444
exists(Import imprt |
445-
imprt.getTargetFile() instanceof VueFile and
445+
imprt.getImportedFile() instanceof VueFile and
446446
result = imprt.getImportedModuleNode()
447447
)
448448
}
@@ -494,7 +494,7 @@ module Vue {
494494
// There is no explicit `new Vue()` call in .vue files, so instead get all the imports
495495
// of the .vue file.
496496
exists(Import imprt |
497-
imprt.getTargetFile() = file and
497+
imprt.getImportedFile() = file and
498498
result.asSource() = imprt.getImportedModuleNode()
499499
)
500500
}

0 commit comments

Comments
 (0)