mirror of
https://github.com/github/codeql.git
synced 2026-05-02 04:05:14 +02:00
JS: eliminate redundant ConstantString casts
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) }
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 " +
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user