File tree Expand file tree Collapse file tree
javascript/ql/src/semmle/javascript/dataflow/internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -160,18 +160,26 @@ private class IIFEWithAnalyzedReturnFlow extends CallWithAnalyzedReturnFlow {
160160
161161}
162162
163+ /**
164+ * Gets the only access to `v`, which is the variable declared by `fn`.
165+ *
166+ * This predicate is not defined for global functions `fn`, or for
167+ * local variables `v` that do not have exactly one access.
168+ */
169+ private VarAccess getOnlyAccess ( FunctionDeclStmt fn , LocalVariable v ) {
170+ v = fn .getVariable ( ) and
171+ result = v .getAnAccess ( ) and
172+ strictcount ( v .getAnAccess ( ) ) = 1
173+ }
174+
163175/** A function that only is used locally, making it amenable to type inference. */
164176class LocalFunction extends Function {
165177
166178 DataFlow:: Impl:: ExplicitInvokeNode invk ;
167179
168180 LocalFunction ( ) {
169- this instanceof FunctionDeclStmt and
170- exists ( LocalVariable v , Expr callee |
171- callee = invk .getCalleeNode ( ) .asExpr ( ) and
172- v = getVariable ( ) and
173- v .getAnAccess ( ) = callee and
174- forall ( VarAccess o | o = v .getAnAccess ( ) | o = callee ) and
181+ exists ( LocalVariable v |
182+ getOnlyAccess ( this , v ) = invk .getCalleeNode ( ) .asExpr ( ) and
175183 not exists ( v .getAnAssignedExpr ( ) ) and
176184 not exists ( ExportDeclaration export | export .exportsAs ( v , _) )
177185 ) and
You can’t perform that action at this time.
0 commit comments