Skip to content

Commit

Permalink
Consolidate TypedScopeCreator's ScopeBuilders
Browse files Browse the repository at this point in the history
LocalScopeBuilder and GlobalScopeBuilder were basically doing the same thing, with the only difference being how function scopes were handled.  With ES6 block scoping, function scopes are much more limited: they never include any statements and therefore don't have any declarations.  This change combines the existing two concrete ScopeBuilder subclasses into a NormalScopeBuilder, but pulls out the separate behavior for FunctionScopeBuilder into its own place, differentiated by completely different shouldTraverse() and visit() logic.

It turns out that much of the complex type creation logic is actually still needed in both, since blockless arrow functions and default parameter initializers still allow object literals to exist directly in function scopes - so parsing JSDoc function declarations (etc) is still required.  But we can get by with less branching and special casing in shouldTraverse, and this opens the door to a separate ClassScopeBuilder in the near future with its own separate logic.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=198965310
  • Loading branch information
shicks authored and tjgq committed Jun 5, 2018
1 parent 35a972d commit 7bf1adc
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 272 deletions.
7 changes: 3 additions & 4 deletions src/com/google/javascript/jscomp/SymbolTable.java
Expand Up @@ -1158,13 +1158,12 @@ private void inlineEs6ExportProperty(
* node. Creates one if it doesn't exist yet. * node. Creates one if it doesn't exist yet.
*/ */
private SymbolScope createScopeFrom(StaticScope otherScope) { private SymbolScope createScopeFrom(StaticScope otherScope) {
Node otherScopeRoot = otherScope.getRootNode();

// NOTE: Kythe is not set up to handle block scopes yet, so only create // NOTE: Kythe is not set up to handle block scopes yet, so only create
// SymbolScopes for container scope roots, giving a pre-ES6 view of the world. // SymbolScopes for container scope roots, giving a pre-ES6 view of the world.
while (NodeUtil.createsBlockScope(otherScopeRoot)) { while (NodeUtil.createsBlockScope(otherScope.getRootNode())) {
otherScopeRoot = otherScopeRoot.getParent(); otherScope = otherScope.getParentScope();
} }
Node otherScopeRoot = otherScope.getRootNode();


SymbolScope myScope = scopes.get(otherScopeRoot); SymbolScope myScope = scopes.get(otherScopeRoot);
if (myScope == null) { if (myScope == null) {
Expand Down

0 comments on commit 7bf1adc

Please sign in to comment.