Skip to content

Commit

Permalink
Make GlobalNamespace implement StaticScope, not StaticTypedScope
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=251300456
  • Loading branch information
lauraharker authored and EatingW committed Jun 4, 2019
1 parent 2e3dd48 commit ed8e37c
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions src/com/google/javascript/jscomp/GlobalNamespace.java
Expand Up @@ -19,7 +19,6 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Streams.stream;
import static com.google.javascript.rhino.jstype.JSTypeNative.GLOBAL_THIS;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
Expand All @@ -29,12 +28,11 @@
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship;
import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.StaticRef;
import com.google.javascript.rhino.StaticScope;
import com.google.javascript.rhino.StaticSlot;
import com.google.javascript.rhino.StaticSourceFile;
import com.google.javascript.rhino.StaticSymbolTable;
import com.google.javascript.rhino.jstype.JSType;
import com.google.javascript.rhino.jstype.StaticTypedRef;
import com.google.javascript.rhino.jstype.StaticTypedScope;
import com.google.javascript.rhino.jstype.StaticTypedSlot;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -47,13 +45,16 @@
import javax.annotation.Nullable;

/**
* Builds a global namespace of all the objects and their properties in the global scope. Also
* builds an index of all the references to those names.
* Builds a namespace of all qualified names whose root is in the global scope, plus an index of all
* references to those global names.
*
* <p>The namespace can be updated as the AST is changed. Removing names or references should be
* done by the methods on Name. Adding new names should be done with {@link #scanNewNodes}.
*
* @author nicksantos@google.com (Nick Santos)
*/
class GlobalNamespace
implements StaticTypedScope, StaticSymbolTable<GlobalNamespace.Name, GlobalNamespace.Ref> {
implements StaticScope, StaticSymbolTable<GlobalNamespace.Name, GlobalNamespace.Ref> {

private final AbstractCompiler compiler;
private final Node root;
Expand Down Expand Up @@ -126,7 +127,7 @@ public Node getRootNode() {
}

@Override
public StaticTypedScope getParentScope() {
public StaticScope getParentScope() {
return null;
}

Expand All @@ -141,19 +142,14 @@ public Name getOwnSlot(String name) {
return nameMap.get(name);
}

@Override
public JSType getTypeOfThis() {
return compiler.getTypeRegistry().getNativeObjectType(GLOBAL_THIS);
}

@Override
public Iterable<Ref> getReferences(Name slot) {
ensureGenerated();
return Collections.unmodifiableCollection(slot.getRefs());
}

@Override
public StaticTypedScope getScope(Name slot) {
public StaticScope getScope(Name slot) {
return this;
}

Expand Down Expand Up @@ -1022,7 +1018,7 @@ Name getOrCreateName(String name) {
* traversal proceeds, we'll discover that some names correspond to JavaScript objects whose
* properties we should consider collapsing.
*/
static final class Name implements StaticTypedSlot {
static final class Name implements StaticSlot {
private enum Type {
CLASS, // class C {}
OBJECTLIT, // var x = {};
Expand Down Expand Up @@ -1125,16 +1121,6 @@ public Ref getDeclaration() {
return declaration;
}

@Override
public boolean isTypeInferred() {
return false;
}

@Override
public JSType getType() {
return null;
}

boolean isFunction() {
return this.type == Type.FUNCTION;
}
Expand Down Expand Up @@ -1180,7 +1166,7 @@ Name getParent() {
}

@Override
public StaticTypedScope getScope() {
public StaticScope getScope() {
throw new UnsupportedOperationException();
}

Expand Down Expand Up @@ -1991,7 +1977,7 @@ private static boolean isQnameDeclarationWithoutAssignment(@Nullable Node node)
* A global name reference. Contains references to the relevant parse tree node and its ancestors
* that may be affected.
*/
static class Ref implements StaticTypedRef {
static class Ref implements StaticRef {

// Note: we are more aggressive about collapsing @enum and @constructor
// declarations than implied here, see Name#canCollapse
Expand Down Expand Up @@ -2075,7 +2061,7 @@ public StaticSourceFile getSourceFile() {
}

@Override
public StaticTypedSlot getSymbol() {
public StaticSlot getSymbol() {
return name;
}

Expand Down

0 comments on commit ed8e37c

Please sign in to comment.