findScope method
Scope
findScope(
- Name nameNode
Implementation
Scope findScope(Name nameNode) {
String name = nameNode.value;
Node parent = nameNode.parent!;
Node node = nameNode;
if (parent is FunctionNode && parent.name == node && !parent.isExpression) {
node = parent.parent!;
}
Scope scope = enclosingScope(node);
while (scope is! Program) {
if (scope.environment == null)
throw JSException(scope.line ?? 1,
'Scope does not have an environment. Scope:${getCode(scope)}');
if (scope.environment!.contains(name)) return scope;
scope = enclosingScope(scope.parent!);
}
return scope;
}