Class TypedScope
- All Implemented Interfaces:
StaticTypedScope,StaticScope,Serializable
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.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturns the variables in this scope that have been declared with 'var' and not yet declared with a known type.intgetDepth()The depth of the scope.Returns the parent scope, or null if this is the global scope.@Nullable StaticScopeReturns the topmost slot containing this name, or null if no slots do.@Nullable JSTypeGets the type ofthisin the current scope.final @Nullable TypedVarReturns the slot forname, considering shadowing of qualified names.protected booleanhasOwnImplicitSlot(@Nullable com.google.javascript.jscomp.AbstractScope.ImplicitVar name) Returns true iff this scope implies a slot with the given name.typed()Methods inherited from class com.google.javascript.jscomp.AbstractScope
getAllAccessibleVariables, getAllSymbols, getArgumentsVar, getClosestCfgRootScope, getClosestContainerScope, getClosestHoistScope, getGlobalScope, getOwnSlot, getParentScope, getRootNode, getSlot, getVarCount, getVarIterable, hasOwnSlot, hasSlot, isBlockScope, isCatchScope, isCfgRootScope, isComputedFieldDefRhsScope, isFunctionBlockScope, isFunctionScope, isGlobal, isLocal, isMemberFieldDefScope, isModuleScope, isStaticBlockScope, toString, untypedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.google.javascript.rhino.StaticScope
getRootNodeMethods inherited from interface com.google.javascript.rhino.jstype.StaticTypedScope
getOwnSlot, getParentScope, getSlot, lookupQualifiedName
-
Method Details
-
typed
- Overrides:
typedin classAbstractScope<TypedScope,TypedVar>
-
getDepth
public int getDepth()Description copied from class:AbstractScopeThe depth of the scope. The global scope has depth 0.- Specified by:
getDepthin classAbstractScope<TypedScope,TypedVar>
-
getParent
Description copied from class:AbstractScopeReturns the parent scope, or null if this is the global scope.- Specified by:
getParentin classAbstractScope<TypedScope,TypedVar>
-
getTypeOfThis
Gets the type ofthisin the current scope.- Specified by:
getTypeOfThisin interfaceStaticTypedScope
-
hasOwnImplicitSlot
protected boolean hasOwnImplicitSlot(@Nullable com.google.javascript.jscomp.AbstractScope.ImplicitVar name) Description copied from class:AbstractScopeReturns true iff this scope implies a slot with the given name.- Overrides:
hasOwnImplicitSlotin classAbstractScope<TypedScope,TypedVar>
-
getDeclarativelyUnboundVarsWithoutTypes
Returns the variables in this scope that have been declared with 'var' and not yet declared with a known type.These variables can safely be set to undefined (rather than unknown) at the start of type inference, and will be reset to the correct type when analyzing the first assignment to them. Parameters and externs are excluded because they are not initialized in the function body, and lexically-bound variables (let and const) are excluded because they are initialized when inferring the LET/CONST node, which is guaranteed to occur before any use, since they are not hoisted.
-
getVar
Returns the slot forname, 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:
- This
Scope. - The first ancestor
Scope, if any, that declares the root of the qualified name. - The global
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.
- Overrides:
getVarin classAbstractScope<TypedScope,TypedVar>
- This
-
getTopmostScopeOfEventualDeclaration
Description copied from interface:StaticScopeReturns the topmost slot containing this name, or null if no slots do. May return true in cases whereStaticScope.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
- Specified by:
getTopmostScopeOfEventualDeclarationin interfaceStaticScope
-