JS: eliminate redundant ConstantString casts

This commit is contained in:
Esben Sparre Andreasen
2019-09-11 10:51:25 +02:00
parent 16c95d8c5e
commit aab17850d1
13 changed files with 18 additions and 18 deletions

View File

@@ -12,7 +12,7 @@ predicate isDefaultInit(Expr e) {
// primitive default values: zero, false, empty string, and (integer) -1
e.(NumberLiteral).getValue().toFloat() = 0.0 or
e.(NegExpr).getOperand().(NumberLiteral).getValue() = "1" or
e.(ConstantString).getStringValue() = "" or
e.getStringValue() = "" or
e.(BooleanLiteral).getValue() = "false" or
// initialising to an empty array or object literal, even if unnecessary,
// can convey useful type information to the reader

View File

@@ -23,7 +23,7 @@ int countOccurrences(string name) {
id.(Identifier).getName() = name
or
// count string literals as well to capture meta-programming
id.(ConstantString).getStringValue() = name
id.getStringValue() = name
)
}

View File

@@ -22,7 +22,7 @@ where
// use source value in message if it's available
if source.getNode().asExpr() instanceof ConstantString
then
value = "The hard-coded value \"" + source.getNode().asExpr().(ConstantString).getStringValue() +
value = "The hard-coded value \"" + source.getNode().asExpr().getStringValue() +
"\""
else value = "This hard-coded value"
select source.getNode(), source, sink, value + " is used as $@.", sink.getNode(),

View File

@@ -189,7 +189,7 @@ private class AmdDependencyPath extends PathExprCandidate {
private class ConstantAmdDependencyPathElement extends PathExprInModule, ConstantString {
ConstantAmdDependencyPathElement() { this = any(AmdDependencyPath amd).getAPart() }
override string getValue() { result = this.(ConstantString).getStringValue() }
override string getValue() { result = this.getStringValue() }
}
/**

View File

@@ -82,7 +82,7 @@ class ImportDeclaration extends Stmt, Import, @importdeclaration {
private class LiteralImportPath extends PathExprInModule, ConstantString {
LiteralImportPath() { exists(ImportDeclaration req | this = req.getChildExpr(-1)) }
override string getValue() { result = this.(ConstantString).getStringValue() }
override string getValue() { result = this.getStringValue() }
}
/**
@@ -596,7 +596,7 @@ abstract class ReExportDeclaration extends ExportDeclaration {
private class LiteralReExportPath extends PathExprInModule, ConstantString {
LiteralReExportPath() { exists(ReExportDeclaration bred | this = bred.getImportedPath()) }
override string getValue() { result = this.(ConstantString).getStringValue() }
override string getValue() { result = this.getStringValue() }
}
/**

View File

@@ -2600,7 +2600,7 @@ private class LiteralDynamicImportPath extends PathExprInModule, ConstantString
exists(DynamicImportExpr di | this.getParentExpr*() = di.getSource())
}
override string getValue() { result = this.(ConstantString).getStringValue() }
override string getValue() { result = this.getStringValue() }
}
/**

View File

@@ -17,7 +17,7 @@ class CallToObjectDefineProperty extends DataFlow::MethodCallNode {
DataFlow::Node getBaseObject() { result = getArgument(0) }
/** Gets the name of the property being defined, if it can be determined. */
string getPropertyName() { result = getArgument(1).asExpr().(ConstantString).getStringValue() }
string getPropertyName() { result = getArgument(1).asExpr().getStringValue() }
/** Gets the data flow node denoting the descriptor of the property being defined. */
DataFlow::Node getPropertyDescriptor() { result = getArgument(2) }

View File

@@ -222,7 +222,7 @@ private class LiteralExternalModulePath extends PathExprInModule, ConstantString
exists(ExternalModuleReference emr | this.getParentExpr*() = emr.getExpression())
}
override string getValue() { result = this.(ConstantString).getStringValue() }
override string getValue() { result = this.getStringValue() }
}
/** A TypeScript "export-assign" declaration. */

View File

@@ -476,7 +476,7 @@ module ModuleImportNode {
exists(AmdModuleDefinition amd, CallExpr req |
req = amd.getARequireCall() and
this = DataFlow::valueNode(req) and
path = req.getArgument(0).(ConstantString).getStringValue()
path = req.getArgument(0).getStringValue()
)
}

View File

@@ -390,7 +390,7 @@ private predicate mooToolsObject(ObjectExpr oe, TopLevel tl, string version) {
|
d.getBase() instanceof ThisExpr and
d.getPropertyName() = "MooTools" and
version = oe.getPropertyByName("version").getInit().(ConstantString).getStringValue()
version = oe.getPropertyByName("version").getInit().getStringValue()
)
}
@@ -429,7 +429,7 @@ private class Prototype extends FrameworkLibraryWithGenericURL {
private predicate prototypeObject(ObjectExpr oe, TopLevel tl, string version) {
exists(VariableDeclarator vd | tl = vd.getTopLevel() and oe = vd.getInit() |
vd.getBindingPattern().(Identifier).getName() = "Prototype" and
version = oe.getPropertyByName("Version").getInit().(ConstantString).getStringValue()
version = oe.getPropertyByName("Version").getInit().getStringValue()
)
}
@@ -468,7 +468,7 @@ private class Scriptaculous extends FrameworkLibraryWithGenericURL {
private predicate scriptaculousObject(ObjectExpr oe, TopLevel tl, string version) {
exists(VariableDeclarator vd | tl = vd.getTopLevel() and oe = vd.getInit() |
vd.getBindingPattern().(Identifier).getName() = "Scriptaculous" and
version = oe.getPropertyByName("Version").getInit().(ConstantString).getStringValue()
version = oe.getPropertyByName("Version").getInit().getStringValue()
)
}

View File

@@ -11,7 +11,7 @@ private predicate xUnitDetected() {
mc.getParent() instanceof ExprStmt and
mc = DataFlow::globalVarRef("Function").getAMemberCall("RegisterNamespace").asExpr() and
mc.getNumArgument() = 1 and
mc.getArgument(0).(ConstantString).getStringValue() = "xUnit.js"
mc.getArgument(0).getStringValue() = "xUnit.js"
)
}

View File

@@ -5,10 +5,10 @@ class ResolveCall extends CallExpr {
Variable getVariable() { result = this.getArgument(0).(VarUse).getVariable() }
string getExpectation() { result = this.getArgument(1).(ConstantString).getStringValue() }
string getExpectation() { result = this.getArgument(1).getStringValue() }
string getDeclaredValue() {
result = getVariable().getAnAssignedExpr().(ConstantString).getStringValue()
result = getVariable().getAnAssignedExpr().getStringValue()
or
exists(NamespaceDeclaration decl | decl.getId() = getVariable().getADeclaration() |
result = getNamespaceName(decl)
@@ -17,7 +17,7 @@ class ResolveCall extends CallExpr {
}
string getNamespaceName(NamespaceDeclaration decl) {
result = decl.getStmt(0).(ExprStmt).getExpr().(ConstantString).getStringValue()
result = decl.getStmt(0).(ExprStmt).getExpr().getStringValue()
or
not decl.getStmt(0).(ExprStmt).getExpr() instanceof ConstantString and
result = "Namespace " + decl.getId() + " on line " +

View File

@@ -50,7 +50,7 @@ class OspreyMethodDefinition extends MethodCallExpr {
string getVerb() { result = getMethodName() }
/** Get the resource path to which this method belongs. */
string getResourcePath() { result = getArgument(0).(ConstantString).getStringValue() }
string getResourcePath() { result = getArgument(0).getStringValue() }
}
/** A callback function bound to a REST method. */