Skip to content

Commit aab1785

Browse files
author
Esben Sparre Andreasen
committed
JS: eliminate redundant ConstantString casts
1 parent 16c95d8 commit aab1785

File tree

13 files changed

+18
-18
lines changed

13 files changed

+18
-18
lines changed

javascript/ql/src/Declarations/DeadStore.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ predicate isDefaultInit(Expr e) {
1212
// primitive default values: zero, false, empty string, and (integer) -1
1313
e.(NumberLiteral).getValue().toFloat() = 0.0 or
1414
e.(NegExpr).getOperand().(NumberLiteral).getValue() = "1" or
15-
e.(ConstantString).getStringValue() = "" or
15+
e.getStringValue() = "" or
1616
e.(BooleanLiteral).getValue() = "false" or
1717
// initialising to an empty array or object literal, even if unnecessary,
1818
// can convey useful type information to the reader

javascript/ql/src/Expressions/HapaxLegomenon.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int countOccurrences(string name) {
2323
id.(Identifier).getName() = name
2424
or
2525
// count string literals as well to capture meta-programming
26-
id.(ConstantString).getStringValue() = name
26+
id.getStringValue() = name
2727
)
2828
}
2929

javascript/ql/src/Security/CWE-798/HardcodedCredentials.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ where
2222
// use source value in message if it's available
2323
if source.getNode().asExpr() instanceof ConstantString
2424
then
25-
value = "The hard-coded value \"" + source.getNode().asExpr().(ConstantString).getStringValue() +
25+
value = "The hard-coded value \"" + source.getNode().asExpr().getStringValue() +
2626
"\""
2727
else value = "This hard-coded value"
2828
select source.getNode(), source, sink, value + " is used as $@.", sink.getNode(),

javascript/ql/src/semmle/javascript/AMD.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private class AmdDependencyPath extends PathExprCandidate {
189189
private class ConstantAmdDependencyPathElement extends PathExprInModule, ConstantString {
190190
ConstantAmdDependencyPathElement() { this = any(AmdDependencyPath amd).getAPart() }
191191

192-
override string getValue() { result = this.(ConstantString).getStringValue() }
192+
override string getValue() { result = this.getStringValue() }
193193
}
194194

195195
/**

javascript/ql/src/semmle/javascript/ES2015Modules.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class ImportDeclaration extends Stmt, Import, @importdeclaration {
8282
private class LiteralImportPath extends PathExprInModule, ConstantString {
8383
LiteralImportPath() { exists(ImportDeclaration req | this = req.getChildExpr(-1)) }
8484

85-
override string getValue() { result = this.(ConstantString).getStringValue() }
85+
override string getValue() { result = this.getStringValue() }
8686
}
8787

8888
/**
@@ -596,7 +596,7 @@ abstract class ReExportDeclaration extends ExportDeclaration {
596596
private class LiteralReExportPath extends PathExprInModule, ConstantString {
597597
LiteralReExportPath() { exists(ReExportDeclaration bred | this = bred.getImportedPath()) }
598598

599-
override string getValue() { result = this.(ConstantString).getStringValue() }
599+
override string getValue() { result = this.getStringValue() }
600600
}
601601

602602
/**

javascript/ql/src/semmle/javascript/Expr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,7 @@ private class LiteralDynamicImportPath extends PathExprInModule, ConstantString
26002600
exists(DynamicImportExpr di | this.getParentExpr*() = di.getSource())
26012601
}
26022602

2603-
override string getValue() { result = this.(ConstantString).getStringValue() }
2603+
override string getValue() { result = this.getStringValue() }
26042604
}
26052605

26062606
/**

javascript/ql/src/semmle/javascript/StandardLibrary.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CallToObjectDefineProperty extends DataFlow::MethodCallNode {
1717
DataFlow::Node getBaseObject() { result = getArgument(0) }
1818

1919
/** Gets the name of the property being defined, if it can be determined. */
20-
string getPropertyName() { result = getArgument(1).asExpr().(ConstantString).getStringValue() }
20+
string getPropertyName() { result = getArgument(1).asExpr().getStringValue() }
2121

2222
/** Gets the data flow node denoting the descriptor of the property being defined. */
2323
DataFlow::Node getPropertyDescriptor() { result = getArgument(2) }

javascript/ql/src/semmle/javascript/TypeScript.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ private class LiteralExternalModulePath extends PathExprInModule, ConstantString
222222
exists(ExternalModuleReference emr | this.getParentExpr*() = emr.getExpression())
223223
}
224224

225-
override string getValue() { result = this.(ConstantString).getStringValue() }
225+
override string getValue() { result = this.getStringValue() }
226226
}
227227

228228
/** A TypeScript "export-assign" declaration. */

javascript/ql/src/semmle/javascript/dataflow/Nodes.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ module ModuleImportNode {
476476
exists(AmdModuleDefinition amd, CallExpr req |
477477
req = amd.getARequireCall() and
478478
this = DataFlow::valueNode(req) and
479-
path = req.getArgument(0).(ConstantString).getStringValue()
479+
path = req.getArgument(0).getStringValue()
480480
)
481481
}
482482

javascript/ql/src/semmle/javascript/dependencies/FrameworkLibraries.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ private predicate mooToolsObject(ObjectExpr oe, TopLevel tl, string version) {
390390
|
391391
d.getBase() instanceof ThisExpr and
392392
d.getPropertyName() = "MooTools" and
393-
version = oe.getPropertyByName("version").getInit().(ConstantString).getStringValue()
393+
version = oe.getPropertyByName("version").getInit().getStringValue()
394394
)
395395
}
396396

@@ -429,7 +429,7 @@ private class Prototype extends FrameworkLibraryWithGenericURL {
429429
private predicate prototypeObject(ObjectExpr oe, TopLevel tl, string version) {
430430
exists(VariableDeclarator vd | tl = vd.getTopLevel() and oe = vd.getInit() |
431431
vd.getBindingPattern().(Identifier).getName() = "Prototype" and
432-
version = oe.getPropertyByName("Version").getInit().(ConstantString).getStringValue()
432+
version = oe.getPropertyByName("Version").getInit().getStringValue()
433433
)
434434
}
435435

@@ -468,7 +468,7 @@ private class Scriptaculous extends FrameworkLibraryWithGenericURL {
468468
private predicate scriptaculousObject(ObjectExpr oe, TopLevel tl, string version) {
469469
exists(VariableDeclarator vd | tl = vd.getTopLevel() and oe = vd.getInit() |
470470
vd.getBindingPattern().(Identifier).getName() = "Scriptaculous" and
471-
version = oe.getPropertyByName("Version").getInit().(ConstantString).getStringValue()
471+
version = oe.getPropertyByName("Version").getInit().getStringValue()
472472
)
473473
}
474474

0 commit comments

Comments
 (0)