Skip to content

Commit

Permalink
Modify IncrementalScopeCreator to partially invalidate and refresh th…
Browse files Browse the repository at this point in the history
…e global scope vars as SCRIPT contents change.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=159175960
  • Loading branch information
concavelenz authored and Tyler Breisacher committed Jun 16, 2017
1 parent cbf8e33 commit 5af3444
Show file tree
Hide file tree
Showing 5 changed files with 376 additions and 53 deletions.
18 changes: 14 additions & 4 deletions src/com/google/javascript/jscomp/Es6SyntacticScopeCreator.java
Expand Up @@ -21,6 +21,7 @@
import com.google.common.base.Preconditions;
import com.google.javascript.rhino.InputId;
import com.google.javascript.rhino.Node;
import java.util.Set;

/**
* <p>The syntactic scope creator scans the parse tree to create a Scope object
Expand All @@ -40,7 +41,6 @@ public class Es6SyntacticScopeCreator implements ScopeCreator {
// but not explicitly declared.
private static final String ARGUMENTS = "arguments";


public static final RedeclarationHandler DEFAULT_REDECLARATION_HANDLER =
new DefaultRedeclarationHandler();

Expand Down Expand Up @@ -88,7 +88,7 @@ public Scope create(Scope parent, Node n) {
@Override
public Scope createScope(Node n, Scope parent) {
Scope scope = scopeFactory.create(parent, n);
new ScopeScanner(compiler, redeclarationHandler, scope).populate();
new ScopeScanner(compiler, redeclarationHandler, scope, null).populate();
return scope;
}

Expand All @@ -97,16 +97,20 @@ static class ScopeScanner {
private final AbstractCompiler compiler;
private final RedeclarationHandler redeclarationHandler;
private InputId inputId;
private final Set<Node> changeRootSet;

ScopeScanner(AbstractCompiler compiler, Scope scope) {
this(compiler, DEFAULT_REDECLARATION_HANDLER, scope);
this(compiler, DEFAULT_REDECLARATION_HANDLER, scope, null);
}

ScopeScanner(
AbstractCompiler compiler, RedeclarationHandler redeclarationHandler, Scope scope) {
AbstractCompiler compiler, RedeclarationHandler redeclarationHandler, Scope scope,
Set<Node> changeRootSet) {
this.compiler = compiler;
this.redeclarationHandler = redeclarationHandler;
this.scope = scope;
this.changeRootSet = changeRootSet;
checkState(changeRootSet == null || scope.isGlobal());
}

void populate() {
Expand Down Expand Up @@ -227,6 +231,12 @@ private void scanVars(Node n, boolean scanInnerBlockScopes, boolean firstScan) {
return; // only one child to scan

case SCRIPT:
if (changeRootSet != null && !changeRootSet.contains(n)) {
// If there is a changeRootSet configured, that means
// a partial update is being done and we should skip
// any SCRIPT that aren't being asked for.
return;
}
inputId = n.getInputId();
Preconditions.checkNotNull(inputId);
break;
Expand Down

0 comments on commit 5af3444

Please sign in to comment.