Skip to content

Commit 929d9da

Browse files
committed
JS: Migrate to new JSON API
1 parent 7c13163 commit 929d9da

File tree

5 files changed

+21
-27
lines changed

5 files changed

+21
-27
lines changed

javascript/ql/src/Declarations/UnusedVariable.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ predicate isReactForJSX(UnusedLocal v) {
6565
v.getName() =
6666
tsconfig
6767
.getPropValue("compilerOptions")
68-
.(JSONObject)
69-
.getPropStringValue(["jsxFactory", "jsxFragmentFactory"])
68+
.getPropValue(["jsxFactory", "jsxFragmentFactory"])
69+
.getStringValue()
7070
)
7171
)
7272
}

javascript/ql/src/semmle/javascript/NPM.qll

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class PackageJSON extends JSONObject {
4141

4242
/** Gets information for a contributor to this package. */
4343
ContributorInfo getAContributor() {
44-
result = getPropValue("contributors").(JSONArray).getElementValue(_)
44+
result = getPropValue("contributors").getElementValue(_)
4545
}
4646

4747
/** Gets the array of files for this package. */
@@ -57,13 +57,13 @@ class PackageJSON extends JSONObject {
5757
string getBin(string cmd) {
5858
cmd = getPackageName() and result = getPropStringValue("bin")
5959
or
60-
result = getPropValue("bin").(JSONObject).getPropStringValue(cmd)
60+
result = getPropValue("bin").getPropValue(cmd).getStringValue()
6161
}
6262

6363
/** Gets a manual page for this package. */
6464
string getAManFile() {
6565
result = getPropStringValue("man") or
66-
result = getPropValue("man").(JSONArray).getElementStringValue(_)
66+
result = getPropValue("man").getElementValue(_).getStringValue()
6767
}
6868

6969
/** Gets information about the directories of this package. */
@@ -191,12 +191,12 @@ class BugTrackerInfo extends JSONValue {
191191

192192
/** Gets the bug tracker URL. */
193193
string getUrl() {
194-
result = this.(JSONObject).getPropStringValue("url") or
195-
result = this.(JSONString).getValue()
194+
result = this.getPropValue("url").getStringValue() or
195+
result = this.getStringValue()
196196
}
197197

198198
/** Gets the bug reporting email address. */
199-
string getEmail() { result = this.(JSONObject).getPropStringValue("email") }
199+
string getEmail() { result = this.getPropValue("email").getStringValue() }
200200
}
201201

202202
/**
@@ -206,7 +206,7 @@ class ContributorInfo extends JSONValue {
206206
ContributorInfo() {
207207
exists(PackageJSON pkg |
208208
this = pkg.getPropValue("author") or
209-
this = pkg.getPropValue("contributors").(JSONArray).getElementValue(_)
209+
this = pkg.getPropValue("contributors").getElementValue(_)
210210
) and
211211
(this instanceof JSONObject or this instanceof JSONString)
212212
}
@@ -217,24 +217,24 @@ class ContributorInfo extends JSONValue {
217217
* homepage URL.
218218
*/
219219
private string parseInfo(int group) {
220-
result = this.(JSONString).getValue().regexpCapture("(.*?)(?: <(.*?)>)?(?: \\((.*)?\\))", group)
220+
result = this.getStringValue().regexpCapture("(.*?)(?: <(.*?)>)?(?: \\((.*)?\\))", group)
221221
}
222222

223223
/** Gets the contributor's name. */
224224
string getName() {
225-
result = this.(JSONObject).getPropStringValue("name") or
225+
result = this.getPropValue("name").getStringValue() or
226226
result = parseInfo(1)
227227
}
228228

229229
/** Gets the contributor's email address. */
230230
string getEmail() {
231-
result = this.(JSONObject).getPropStringValue("email") or
231+
result = this.getPropValue("email").getStringValue() or
232232
result = parseInfo(2)
233233
}
234234

235235
/** Gets the contributor's homepage URL. */
236236
string getUrl() {
237-
result = this.(JSONObject).getPropStringValue("url") or
237+
result = this.getPropValue("url").getStringValue() or
238238
result = parseInfo(3)
239239
}
240240
}

javascript/ql/src/semmle/javascript/Paths.qll

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,8 @@ private module TypeScriptOutDir {
236236
result =
237237
tsconfig
238238
.getPropValue("compilerOptions")
239-
.(JSONObject)
240239
.getPropValue("outDir")
241-
.(JSONString)
242-
.getValue()
240+
.getStringValue()
243241
}
244242

245243
/**
@@ -283,10 +281,8 @@ private module TypeScriptOutDir {
283281
result =
284282
getRootFolderFromPath(tsconfig
285283
.getPropValue("include")
286-
.(JSONArray)
287284
.getElementValue(_)
288-
.(JSONString)
289-
.getValue())
285+
.getStringValue())
290286
}
291287

292288
/**
@@ -297,10 +293,8 @@ private module TypeScriptOutDir {
297293
result =
298294
tsconfig
299295
.getPropValue("compilerOptions")
300-
.(JSONObject)
301296
.getPropValue("rootDir")
302-
.(JSONString)
303-
.getValue()
297+
.getStringValue()
304298
}
305299
}
306300

javascript/ql/src/semmle/javascript/frameworks/Babel.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ module Babel {
2424
plugins = getPropValue("plugins") and
2525
result = plugins.getElementValue(_)
2626
|
27-
result.(JSONString).getValue() = pluginName
27+
result.getStringValue() = pluginName
2828
or
29-
result.(JSONArray).getElementStringValue(0) = pluginName
29+
result.getElementValue(0).getStringValue() = pluginName
3030
)
3131
}
3232

@@ -67,7 +67,7 @@ module Babel {
6767
JSONValue getOptions() { result = this.(JSONArray).getElementValue(1) }
6868

6969
/** Gets a named option from the option object, if present. */
70-
JSONValue getOption(string name) { result = getOptions().(JSONObject).getPropValue(name) }
70+
JSONValue getOption(string name) { result = getOptions().getPropValue(name) }
7171

7272
/** Holds if this plugin applies to `tl`. */
7373
predicate appliesTo(TopLevel tl) { cfg.appliesTo(tl) }
@@ -186,7 +186,7 @@ module Babel {
186186
TransformReactJsxConfig() { pluginName = "transform-react-jsx" }
187187

188188
/** Gets the name of the variable used to create JSX elements. */
189-
string getJsxFactoryVariableName() { result = getOption("pragma").(JSONString).getValue() }
189+
string getJsxFactoryVariableName() { result = getOption("pragma").getStringValue() }
190190
}
191191

192192
/**

javascript/ql/src/semmle/javascript/security/dataflow/RemoteFlowSources.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private class RemoteFlowSourceAccessPath extends JSONString {
108108
exists(JSONObject specs |
109109
specs.isTopLevel() and
110110
this.getFile().getBaseName() = "codeql-javascript-remote-flow-sources.json" and
111-
this = specs.getPropValue(sourceType).(JSONArray).getElementValue(_) and
111+
this = specs.getPropValue(sourceType).getElementValue(_) and
112112
this.getValue().regexpMatch("window(\\.\\w+)+")
113113
)
114114
}

0 commit comments

Comments
 (0)