public class TypedScope extends AbstractScope<TypedScope,TypedVar> implements StaticTypedScope
TypedScope is also used as a lattice element for flow-sensitive type inference. As a lattice
element, a scope is viewed as a map from names to types. A name not in the map is considered to
have the bottom type. The join of two maps m1 and m2 is the map of the union of names with JSType.getLeastSupertype(com.google.javascript.rhino.jstype.JSType) to meet the m1 type and m2 type.
TypedScopes also have a concept of a set of 'reserved' names. These are names that will be declared as actual TypedVars later in the compilation. Looking up any of these reserved names will always return null, even if the name is available in a parent scope.
| Modifier and Type | Method and Description |
|---|---|
java.lang.Iterable<TypedVar> |
getDeclarativelyUnboundVarsWithoutTypes()
Returns the variables in this scope that have been declared with 'var' and not declared with a
known type.
|
int |
getDepth()
The depth of the scope.
|
JSDocInfo |
getJsdocOfTypeDeclaration(java.lang.String typeName) |
JSType |
getNamespaceOrTypedefType(java.lang.String typeName) |
TypedScope |
getParent()
Returns the parent scope, or null if this is the global scope.
|
StaticScope |
getTopmostScopeOfEventualDeclaration(java.lang.String name)
Returns the topmost slot containing this name, or null if no slots do.
|
JSType |
getTypeOfThis()
Gets the type of
this in the current scope. |
TypedVar |
getVar(java.lang.String name)
Returns the slot for
name, considering shadowing of qualified names. |
protected boolean |
hasOwnImplicitSlot(com.google.javascript.jscomp.AbstractScope.ImplicitVar name)
Returns true iff this scope implies a slot with the given name.
|
TypedScope |
typed() |
getAllAccessibleVariables, getAllSymbols, getArgumentsVar, getClosestContainerScope, getClosestHoistScope, getGlobalScope, getOwnSlot, getParentScope, getRootNode, getSlot, getVarCount, getVarIterable, hasOwnSlot, hasSlot, isBlockScope, isCatchScope, isFunctionBlockScope, isFunctionScope, isGlobal, isLocal, isModuleScope, toString, untypedclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetOwnSlot, getParentScope, getSlot, lookupQualifiedNamegetRootNodepublic TypedScope typed()
typed in class AbstractScope<TypedScope,TypedVar>public int getDepth()
AbstractScopegetDepth in class AbstractScope<TypedScope,TypedVar>public TypedScope getParent()
AbstractScopegetParent in class AbstractScope<TypedScope,TypedVar>public JSType getTypeOfThis()
this in the current scope.getTypeOfThis in interface StaticTypedScopeprotected boolean hasOwnImplicitSlot(@Nullable
com.google.javascript.jscomp.AbstractScope.ImplicitVar name)
AbstractScopehasOwnImplicitSlot in class AbstractScope<TypedScope,TypedVar>public java.lang.Iterable<TypedVar> getDeclarativelyUnboundVarsWithoutTypes()
public JSType getNamespaceOrTypedefType(java.lang.String typeName)
public JSDocInfo getJsdocOfTypeDeclaration(java.lang.String typeName)
public TypedVar getVar(java.lang.String name)
name, considering shadowing of qualified names.
The superclass method does not handle shadowing.
Lookup of qualified names (i.e. names with dots) executes against scopes in the following precedence:
Scope.
Scope, if any, that declares the root of the qualified name.
Scope.
An example of where this is necessary: say the global scope contains "a" and "a.b" and a function scope contains "a". When looking up "a.b" in the function scope, AbstractScope::getVar returns "a.b". This method returns null because the global "a" is shadowed.
getVar in class AbstractScope<TypedScope,TypedVar>public StaticScope getTopmostScopeOfEventualDeclaration(java.lang.String name)
StaticScopeStaticScope.getSlot(java.lang.String) returns null, though. Do not rely on this method if you need an actual
slot.
This method is intended for use while scopes are still being built, hence the name 'eventual' declaration. Once scope building is complete, the scope returned from this method must be equivalent to "getSlot(name).getScope()" or null
getTopmostScopeOfEventualDeclaration in interface StaticScopeCopyright © 2009-2019 Google. All Rights Reserved.