@@ -61,7 +61,13 @@ class AmdModuleDefinition extends CallExpr instanceof AmdModuleDefinition::Range
6161 }
6262
6363 /** Gets the `i`th dependency of this module definition. */
64- PathExpr getDependency ( int i ) { result = this .getDependencies ( ) .getElement ( i ) }
64+ PathExpr getDependency ( int i ) {
65+ exists ( Expr expr |
66+ expr = this .getDependencies ( ) .getElement ( i ) and
67+ not isPseudoDependency ( expr .getStringValue ( ) ) and
68+ result = expr
69+ )
70+ }
6571
6672 /** Gets a dependency of this module definition. */
6773 PathExpr getADependency ( ) {
@@ -102,9 +108,10 @@ class AmdModuleDefinition extends CallExpr instanceof AmdModuleDefinition::Range
102108 /**
103109 * Holds if `p` is the parameter corresponding to dependency `dep`.
104110 */
105- predicate dependencyParameter ( PathExpr dep , Parameter p ) {
111+ predicate dependencyParameter ( Expr dep , Parameter p ) {
106112 exists ( int i |
107- dep = this .getDependency ( i ) and
113+ // Note: to avoid spurious recursion, do not depend on PathExpr here
114+ dep = this .getDependencies ( ) .getElement ( i ) and
108115 p = this .getFactoryParameter ( i )
109116 )
110117 }
@@ -122,9 +129,9 @@ class AmdModuleDefinition extends CallExpr instanceof AmdModuleDefinition::Range
122129 * `dep1` and `dep2`.
123130 */
124131 Parameter getDependencyParameter ( string name ) {
125- exists ( PathExpr dep |
132+ exists ( Expr dep |
126133 this .dependencyParameter ( dep , result ) and
127- dep .getValue ( ) = name
134+ name = dep .getStringValue ( )
128135 )
129136 }
130137
@@ -202,11 +209,15 @@ class AmdModuleDefinition extends CallExpr instanceof AmdModuleDefinition::Range
202209 }
203210}
204211
212+ private predicate isPseudoDependency ( string s ) { s = [ "exports" , "require" , "module" ] }
213+
205214/** An AMD dependency, considered as a path expression. */
206215private class AmdDependencyPath extends PathExprCandidate {
207216 AmdDependencyPath ( ) {
208217 exists ( AmdModuleDefinition amd |
209- this = amd .getDependencies ( ) .getAnElement ( ) or
218+ this = amd .getDependencies ( ) .getAnElement ( ) and
219+ not isPseudoDependency ( this .getStringValue ( ) )
220+ or
210221 this = amd .getARequireCall ( ) .getAnArgument ( )
211222 )
212223 }
0 commit comments