mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
JS: Migrate to new JSON API
This commit is contained in:
@@ -65,8 +65,8 @@ predicate isReactForJSX(UnusedLocal v) {
|
||||
v.getName() =
|
||||
tsconfig
|
||||
.getPropValue("compilerOptions")
|
||||
.(JSONObject)
|
||||
.getPropStringValue(["jsxFactory", "jsxFragmentFactory"])
|
||||
.getPropValue(["jsxFactory", "jsxFragmentFactory"])
|
||||
.getStringValue()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class PackageJSON extends JSONObject {
|
||||
|
||||
/** Gets information for a contributor to this package. */
|
||||
ContributorInfo getAContributor() {
|
||||
result = getPropValue("contributors").(JSONArray).getElementValue(_)
|
||||
result = getPropValue("contributors").getElementValue(_)
|
||||
}
|
||||
|
||||
/** Gets the array of files for this package. */
|
||||
@@ -57,13 +57,13 @@ class PackageJSON extends JSONObject {
|
||||
string getBin(string cmd) {
|
||||
cmd = getPackageName() and result = getPropStringValue("bin")
|
||||
or
|
||||
result = getPropValue("bin").(JSONObject).getPropStringValue(cmd)
|
||||
result = getPropValue("bin").getPropValue(cmd).getStringValue()
|
||||
}
|
||||
|
||||
/** Gets a manual page for this package. */
|
||||
string getAManFile() {
|
||||
result = getPropStringValue("man") or
|
||||
result = getPropValue("man").(JSONArray).getElementStringValue(_)
|
||||
result = getPropValue("man").getElementValue(_).getStringValue()
|
||||
}
|
||||
|
||||
/** Gets information about the directories of this package. */
|
||||
@@ -191,12 +191,12 @@ class BugTrackerInfo extends JSONValue {
|
||||
|
||||
/** Gets the bug tracker URL. */
|
||||
string getUrl() {
|
||||
result = this.(JSONObject).getPropStringValue("url") or
|
||||
result = this.(JSONString).getValue()
|
||||
result = this.getPropValue("url").getStringValue() or
|
||||
result = this.getStringValue()
|
||||
}
|
||||
|
||||
/** Gets the bug reporting email address. */
|
||||
string getEmail() { result = this.(JSONObject).getPropStringValue("email") }
|
||||
string getEmail() { result = this.getPropValue("email").getStringValue() }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,7 +206,7 @@ class ContributorInfo extends JSONValue {
|
||||
ContributorInfo() {
|
||||
exists(PackageJSON pkg |
|
||||
this = pkg.getPropValue("author") or
|
||||
this = pkg.getPropValue("contributors").(JSONArray).getElementValue(_)
|
||||
this = pkg.getPropValue("contributors").getElementValue(_)
|
||||
) and
|
||||
(this instanceof JSONObject or this instanceof JSONString)
|
||||
}
|
||||
@@ -217,24 +217,24 @@ class ContributorInfo extends JSONValue {
|
||||
* homepage URL.
|
||||
*/
|
||||
private string parseInfo(int group) {
|
||||
result = this.(JSONString).getValue().regexpCapture("(.*?)(?: <(.*?)>)?(?: \\((.*)?\\))", group)
|
||||
result = this.getStringValue().regexpCapture("(.*?)(?: <(.*?)>)?(?: \\((.*)?\\))", group)
|
||||
}
|
||||
|
||||
/** Gets the contributor's name. */
|
||||
string getName() {
|
||||
result = this.(JSONObject).getPropStringValue("name") or
|
||||
result = this.getPropValue("name").getStringValue() or
|
||||
result = parseInfo(1)
|
||||
}
|
||||
|
||||
/** Gets the contributor's email address. */
|
||||
string getEmail() {
|
||||
result = this.(JSONObject).getPropStringValue("email") or
|
||||
result = this.getPropValue("email").getStringValue() or
|
||||
result = parseInfo(2)
|
||||
}
|
||||
|
||||
/** Gets the contributor's homepage URL. */
|
||||
string getUrl() {
|
||||
result = this.(JSONObject).getPropStringValue("url") or
|
||||
result = this.getPropValue("url").getStringValue() or
|
||||
result = parseInfo(3)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,10 +236,8 @@ private module TypeScriptOutDir {
|
||||
result =
|
||||
tsconfig
|
||||
.getPropValue("compilerOptions")
|
||||
.(JSONObject)
|
||||
.getPropValue("outDir")
|
||||
.(JSONString)
|
||||
.getValue()
|
||||
.getStringValue()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,10 +281,8 @@ private module TypeScriptOutDir {
|
||||
result =
|
||||
getRootFolderFromPath(tsconfig
|
||||
.getPropValue("include")
|
||||
.(JSONArray)
|
||||
.getElementValue(_)
|
||||
.(JSONString)
|
||||
.getValue())
|
||||
.getStringValue())
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -297,10 +293,8 @@ private module TypeScriptOutDir {
|
||||
result =
|
||||
tsconfig
|
||||
.getPropValue("compilerOptions")
|
||||
.(JSONObject)
|
||||
.getPropValue("rootDir")
|
||||
.(JSONString)
|
||||
.getValue()
|
||||
.getStringValue()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ module Babel {
|
||||
plugins = getPropValue("plugins") and
|
||||
result = plugins.getElementValue(_)
|
||||
|
|
||||
result.(JSONString).getValue() = pluginName
|
||||
result.getStringValue() = pluginName
|
||||
or
|
||||
result.(JSONArray).getElementStringValue(0) = pluginName
|
||||
result.getElementValue(0).getStringValue() = pluginName
|
||||
)
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ module Babel {
|
||||
JSONValue getOptions() { result = this.(JSONArray).getElementValue(1) }
|
||||
|
||||
/** Gets a named option from the option object, if present. */
|
||||
JSONValue getOption(string name) { result = getOptions().(JSONObject).getPropValue(name) }
|
||||
JSONValue getOption(string name) { result = getOptions().getPropValue(name) }
|
||||
|
||||
/** Holds if this plugin applies to `tl`. */
|
||||
predicate appliesTo(TopLevel tl) { cfg.appliesTo(tl) }
|
||||
@@ -186,7 +186,7 @@ module Babel {
|
||||
TransformReactJsxConfig() { pluginName = "transform-react-jsx" }
|
||||
|
||||
/** Gets the name of the variable used to create JSX elements. */
|
||||
string getJsxFactoryVariableName() { result = getOption("pragma").(JSONString).getValue() }
|
||||
string getJsxFactoryVariableName() { result = getOption("pragma").getStringValue() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -108,7 +108,7 @@ private class RemoteFlowSourceAccessPath extends JSONString {
|
||||
exists(JSONObject specs |
|
||||
specs.isTopLevel() and
|
||||
this.getFile().getBaseName() = "codeql-javascript-remote-flow-sources.json" and
|
||||
this = specs.getPropValue(sourceType).(JSONArray).getElementValue(_) and
|
||||
this = specs.getPropValue(sourceType).getElementValue(_) and
|
||||
this.getValue().regexpMatch("window(\\.\\w+)+")
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user