Package com.google.javascript.jscomp
Class Scope
java.lang.Object
com.google.javascript.jscomp.Scope
- All Implemented Interfaces:
StaticScope<JSType>,StaticSymbolTable<Scope.Var,Scope.Var>
public class Scope
extends Object
implements StaticScope<JSType>, StaticSymbolTable<Scope.Var,Scope.Var>
Scope contains information about a variable scope in JavaScript.
Scopes can be nested, a scope points back to its parent scope.
A Scope contains information about variables defined in that scope.
A Scope 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.
- See Also:
-
NodeTraversalDataFlowAnalysis
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA special subclass of Var used to distinguish "arguments" in the current scope.static classStores info about a variable -
Method Summary
Modifier and TypeMethodDescriptionReturns all variables in this symbol table.Get a unique VAR object to represents "arguments" within this scopeGets all variables declared with "var" but without declared types attached.getOwnSlot(String name) LikegetSlotbut does not recurse into parent scopes.Returns the scope enclosing this one or null if none.getReferences(Scope.Var var) Returns the references that point to the given symbol.Gets the container node of the scope.Returns the scope for a given symbol.Returns any defined slot within this scope for this name.Gets the type ofthisin the current scope.Returns the variable, may be nullintReturns number of variables in this scopegetVars()Return an iterator over all of the variables declared in this scope.booleanisDeclared(String name, boolean recurse) Returns true if a variable is declared.booleanisGlobal()Returns whether this is the global scope.booleanisLocal()Returns whether this is a local scope (i.e.
-
Method Details
-
getRootNode
Gets the container node of the scope. This is typically the FUNCTION node or the global BLOCK/SCRIPT node.- Specified by:
getRootNodein interfaceStaticScope<JSType>
-
getParent
-
getParentScope
Description copied from interface:StaticScopeReturns the scope enclosing this one or null if none.- Specified by:
getParentScopein interfaceStaticScope<JSType>
-
getTypeOfThis
Gets the type ofthisin the current scope.- Specified by:
getTypeOfThisin interfaceStaticScope<JSType>
-
getSlot
Description copied from interface:StaticScopeReturns any defined slot within this scope for this name. This call continues searching through parent scopes if a slot with this name is not found in the current scope.- Specified by:
getSlotin interfaceStaticScope<JSType>- Parameters:
name- The name of the variable slot to look up.- Returns:
- The defined slot for the variable, or
nullif no definition exists.
-
getOwnSlot
Description copied from interface:StaticScopeLikegetSlotbut does not recurse into parent scopes.- Specified by:
getOwnSlotin interfaceStaticScope<JSType>
-
getVar
Returns the variable, may be null -
getArgumentsVar
Get a unique VAR object to represents "arguments" within this scope -
isDeclared
Returns true if a variable is declared. -
getVars
Return an iterator over all of the variables declared in this scope. -
getReferences
Description copied from interface:StaticSymbolTableReturns the references that point to the given symbol.- Specified by:
getReferencesin interfaceStaticSymbolTable<Scope.Var,Scope.Var>
-
getScope
Description copied from interface:StaticSymbolTableReturns the scope for a given symbol.- Specified by:
getScopein interfaceStaticSymbolTable<Scope.Var,Scope.Var>
-
getAllSymbols
Description copied from interface:StaticSymbolTableReturns all variables in this symbol table.- Specified by:
getAllSymbolsin interfaceStaticSymbolTable<Scope.Var,Scope.Var>
-
getVarCount
public int getVarCount()Returns number of variables in this scope -
isGlobal
public boolean isGlobal()Returns whether this is the global scope. -
isLocal
public boolean isLocal()Returns whether this is a local scope (i.e. not the global scope). -
getDeclarativelyUnboundVarsWithoutTypes
Gets all variables declared with "var" but without declared types attached.
-