findScope method
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 "$scope does not have an environment";
}
if (scope.environment!.contains(name)) return scope;
scope = enclosingScope(scope.parent);
}
return scope;
}