JavaScript: Use proper camel-case for AMD-related class names.

This commit is contained in:
Max Schaefer
2019-03-25 11:58:13 +00:00
parent d541bd58fb
commit b29b3dff4d
21 changed files with 36 additions and 26 deletions

View File

@@ -17,6 +17,6 @@ where
not f.inExternsFile() and
f.getNumParameter() > 7 and
// exclude AMD modules
not exists(AMDModuleDefinition m | f = m.getFactoryNode().(DataFlow::FunctionNode).getAstNode())
not exists(AmdModuleDefinition m | f = m.getFactoryNode().(DataFlow::FunctionNode).getAstNode())
select f.(FirstLineOf),
capitalize(f.describe()) + " has too many parameters (" + f.getNumParameter() + ")."

View File

@@ -23,8 +23,8 @@ import javascript
* where the first argument is the module name, the second argument an
* array of dependencies, and the third argument a factory method or object.
*/
class AMDModuleDefinition extends CallExpr {
AMDModuleDefinition() {
class AmdModuleDefinition extends CallExpr {
AmdModuleDefinition() {
getParent() instanceof ExprStmt and
getCallee().(GlobalVarAccess).getName() = "define" and
exists(int n | n = getNumArgument() |
@@ -153,7 +153,7 @@ class AMDModuleDefinition extends CallExpr {
result = getModuleExpr().analyze().getAValue()
or
// explicit exports: anything assigned to `module.exports`
exists(AbstractProperty moduleExports, AMDModule m |
exists(AbstractProperty moduleExports, AmdModule m |
this = m.getDefine() and
moduleExports.getBase().(AbstractModuleObject).getModule() = m and
moduleExports.getPropertyName() = "exports"
@@ -170,10 +170,15 @@ class AMDModuleDefinition extends CallExpr {
}
}
/**
* DEPRECATED: Use `AmdModuleDefinition` instead.
*/
deprecated class AMDModuleDefinition = AmdModuleDefinition;
/** An AMD dependency, considered as a path expression. */
private class AmdDependencyPath extends PathExprCandidate {
AmdDependencyPath() {
exists(AMDModuleDefinition amd |
exists(AmdModuleDefinition amd |
this = amd.getDependencies().getAnElement() or
this = amd.getARequireCall().getAnArgument()
)
@@ -191,9 +196,9 @@ private class ConstantAmdDependencyPathElement extends PathExprInModule, Constan
* Holds if `def` is an AMD module definition in `tl` which is not
* nested inside another module definition.
*/
private predicate amdModuleTopLevel(AMDModuleDefinition def, TopLevel tl) {
private predicate amdModuleTopLevel(AmdModuleDefinition def, TopLevel tl) {
def.getTopLevel() = tl and
not def.getParent+() instanceof AMDModuleDefinition
not def.getParent+() instanceof AmdModuleDefinition
}
/**
@@ -201,11 +206,11 @@ private predicate amdModuleTopLevel(AMDModuleDefinition def, TopLevel tl) {
*/
private class AmdDependencyImport extends Import {
AmdDependencyImport() {
this = any(AMDModuleDefinition def).getADependency()
this = any(AmdModuleDefinition def).getADependency()
}
override Module getEnclosingModule() {
this = result.(AMDModule).getDefine().getADependency()
this = result.(AmdModule).getDefine().getADependency()
}
override PathExpr getImportedPath() {
@@ -216,11 +221,11 @@ private class AmdDependencyImport extends Import {
/**
* An AMD-style module.
*/
class AMDModule extends Module {
AMDModule() { strictcount(AMDModuleDefinition def | amdModuleTopLevel(def, this)) = 1 }
class AmdModule extends Module {
AmdModule() { strictcount(AmdModuleDefinition def | amdModuleTopLevel(def, this)) = 1 }
/** Gets the definition of this module. */
AMDModuleDefinition getDefine() { amdModuleTopLevel(result, this) }
AmdModuleDefinition getDefine() { amdModuleTopLevel(result, this) }
override predicate exports(string name, ASTNode export) {
exists(DataFlow::PropWrite pwn | export = pwn.getAstNode() |
@@ -229,3 +234,8 @@ class AMDModule extends Module {
)
}
}
/**
* DEPRECATED: Use `AmdModule` instead.
*/
deprecated class AMDModule = AmdModule;

View File

@@ -472,12 +472,12 @@ module ModuleImportNode {
)
or
// declared AMD dependency
exists(AMDModuleDefinition amd |
exists(AmdModuleDefinition amd |
this = DataFlow::parameterNode(amd.getDependencyParameter(path))
)
or
// AMD require
exists(AMDModuleDefinition amd, CallExpr req |
exists(AmdModuleDefinition amd, CallExpr req |
req = amd.getARequireCall() and
this = DataFlow::valueNode(req) and
path = req.getArgument(0).(ConstantString).getStringValue()

View File

@@ -61,7 +61,7 @@ private predicate mayDynamicallyComputeExports(Module m) {
or
// AMD modules can export arbitrary objects, so an import is essentially a property read
// and hence must be considered indefinite
m instanceof AMDModule
m instanceof AmdModule
or
// `m` re-exports all exports of some other module that dynamically computes its exports
exists(BulkReExportDeclaration rexp | rexp = m.(ES2015Module).getAnExport() |
@@ -229,7 +229,7 @@ class AnalyzedExternalModuleReference extends AnalyzedPropertyRead, DataFlow::Va
* Flow analysis for AMD exports.
*/
private class AnalyzedAmdExport extends AnalyzedPropertyWrite, DataFlow::ValueNode {
AMDModule amd;
AmdModule amd;
AnalyzedAmdExport() { astNode = amd.getDefine().getModuleExpr() }
@@ -248,7 +248,7 @@ private class AnalyzedAmdImport extends AnalyzedPropertyRead, DataFlow::Node {
Module required;
AnalyzedAmdImport() {
exists(AMDModule amd, PathExpr dep, Parameter p |
exists(AmdModule amd, PathExpr dep, Parameter p |
amd.getDefine().dependencyParameter(dep, p) and
this = DataFlow::parameterNode(p) and
required.getFile() = amd.resolve(dep)

View File

@@ -180,7 +180,7 @@ private class AnalyzedAmdParameter extends AnalyzedVarDef {
AbstractValue implicitInitVal;
AnalyzedAmdParameter() {
exists(AMDModule m, AMDModuleDefinition mdef | mdef = m.getDefine() |
exists(AmdModule m, AmdModuleDefinition mdef | mdef = m.getDefine() |
this = mdef.getModuleParameter() and
implicitInitVal = TAbstractModuleObject(m)
or

View File

@@ -57,7 +57,7 @@ module TaintedPath {
ModulePathSink() {
astNode = any(Require rq).getArgument(0) or
astNode = any(ExternalModuleReference rq).getExpression() or
astNode = any(AMDModuleDefinition amd).getDependencies()
astNode = any(AmdModuleDefinition amd).getDependencies()
}
}