mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
JS: Avoid materializing JSONValue.getFile()
This commit is contained in:
@@ -32,6 +32,14 @@ class JSONValue extends @json_value, Locatable {
|
||||
predicate isTopLevel() { not exists(getParent()) }
|
||||
|
||||
override string toString() { json(this, _, _, _, result) }
|
||||
|
||||
/** Gets the JSON file containing this value. */
|
||||
File getJsonFile() {
|
||||
exists(Location loc |
|
||||
json_locations(this, loc) and
|
||||
result = loc.getFile()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,7 +8,7 @@ private import NodeModuleResolutionImpl
|
||||
/** A `package.json` configuration object. */
|
||||
class PackageJSON extends JSONObject {
|
||||
PackageJSON() {
|
||||
getFile().getBaseName() = "package.json" and
|
||||
getJsonFile().getBaseName() = "package.json" and
|
||||
isTopLevel()
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ class NPMPackage extends @folder {
|
||||
/** The `package.json` file of this package. */
|
||||
PackageJSON pkg;
|
||||
|
||||
NPMPackage() { pkg.getFile().getParentContainer() = this }
|
||||
NPMPackage() { pkg.getJsonFile().getParentContainer() = this }
|
||||
|
||||
/** Gets a textual representation of this package. */
|
||||
string toString() { result = this.(Folder).toString() }
|
||||
|
||||
@@ -11,7 +11,7 @@ module Babel {
|
||||
*/
|
||||
class Config extends JSONObject {
|
||||
Config() {
|
||||
isTopLevel() and getFile().getBaseName().matches(".babelrc%")
|
||||
isTopLevel() and getJsonFile().getBaseName().matches(".babelrc%")
|
||||
or
|
||||
this = any(PackageJSON pkg).getPropValue("babel")
|
||||
}
|
||||
@@ -34,12 +34,12 @@ module Babel {
|
||||
* Gets a file affected by this Babel configuration.
|
||||
*/
|
||||
Container getAContainerInScope() {
|
||||
result = getFile().getParentContainer()
|
||||
result = getJsonFile().getParentContainer()
|
||||
or
|
||||
result = getAContainerInScope().getAChildContainer() and
|
||||
// File-relative .babelrc search stops at any package.json or .babelrc file.
|
||||
not result.getAChildContainer() = any(PackageJSON pkg).getFile() and
|
||||
not result.getAChildContainer() = any(Config pkg).getFile()
|
||||
not result.getAChildContainer() = any(PackageJSON pkg).getJsonFile() and
|
||||
not result.getAChildContainer() = any(Config pkg).getJsonFile()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +133,7 @@ module Babel {
|
||||
/**
|
||||
* Gets the folder in which this configuration is located.
|
||||
*/
|
||||
Folder getFolder() { result = getFile().getParentContainer() }
|
||||
Folder getFolder() { result = getJsonFile().getParentContainer() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user