Scopes nest like boxes, and a name resolves to the nearest enclosing scope that declares it — never an inner one, never a sibling. Write whereDeclared(tree, path, name).
tree is the outermost scope: { name, declares, children }, where declares is an array of names and children is an array of scopes shaped the same waypath lists scope names from the outermost down to the scope where the name is used, e.g. ["global", "outer", "inner"]- return the
name of the scope the identifier resolves to, or null if none declares it