(path: NodePath<Identifier>)
| 181 | // If true, add the identifer name to the usedVariablesFromParentScope |
| 182 | // of the containing scope |
| 183 | const fillInVarInfo = function (path: NodePath<Identifier>) { |
| 184 | // if the identifier is a function name of a function definition |
| 185 | if (isFunctionType(path.parentPath.node.type)) { |
| 186 | return; |
| 187 | } |
| 188 | const name = path.node.name; |
| 189 | let parentPath = self.findParentFunctionPath(path); |
| 190 | let parentClosureScope = parentPath |
| 191 | ? locToClosureScopeMap.get(self.locToStr(parentPath.node.loc)) |
| 192 | : null; |
| 193 | // eslint-disable-next-line no-constant-condition |
| 194 | while (true) { |
| 195 | if (!parentPath || !parentClosureScope) { |
| 196 | break; |
| 197 | } |
| 198 | const grandparentPath = self.findParentFunctionPath( |
| 199 | parentPath as NodePath<FunctionClass>, |
| 200 | ); |
| 201 | if (!grandparentPath) { |
| 202 | break; |
| 203 | } |
| 204 | const grandparentClosureScope = locToClosureScopeMap.get( |
| 205 | self.locToStr(grandparentPath.node.loc), |
| 206 | ); |
| 207 | if (!grandparentClosureScope) { |
| 208 | break; |
| 209 | } |
| 210 | if ( |
| 211 | grandparentClosureScope.variablesDefined.includes(name) && |
| 212 | !parentClosureScope.usedVariablesFromParentScope.includes(name) |
| 213 | ) { |
| 214 | parentClosureScope.usedVariablesFromParentScope.push(name); |
| 215 | break; |
| 216 | } |
| 217 | parentPath = grandparentPath; |
| 218 | parentClosureScope = grandparentClosureScope; |
| 219 | } |
| 220 | }; |
| 221 | traverse(ast, { |
| 222 | FunctionDeclaration: buildClosureScopeFromFunction, |
| 223 | FunctionExpression: buildClosureScopeFromFunction, |
nothing calls this directly
no test coverage detected