google / google/closure-compiler

Class scopes should be created by CLASS_MEMBERS node, not CLASS node

Open
#2,962 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Class nodes have three children: the (optional) name, the (optional) extends clause, and the CLASS_MEMBERS body.

Currently we create a new scope rooted at the CLASS node, but this means that the extends clause is naturally traversed inside this child scope. But it should always be evaluated in the outer scope, and in TypedScopeCreator it needs to be fully traversed in that outer scope, since the class scope may not be traversed until much later, but we need to assign some type to the constructor in the outer scope. This does in fact need to be a full post-order traversal, since the extends clause may contain arbitrarily complex structure.

I'm not aware of any fundamental reason why the scope was chosen to be rooted at the CLASS node, but I'm looking into making this change to see how hard it will be to land.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.