📄 ScopeManager¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 29 |
| 🧱 Classes | 1 |
| 📦 Imports | 24 |
| 📐 Interfaces | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/scope-manager/src/ScopeManager.ts
📦 Imports¶
| Name | Source |
|---|---|
SourceType |
@typescript-eslint/types |
TSESTree |
@typescript-eslint/types |
Scope |
./scope |
Variable |
./variable |
assert |
./assert |
BlockScope |
./scope |
CatchScope |
./scope |
ClassScope |
./scope |
ConditionalTypeScope |
./scope |
ForScope |
./scope |
FunctionExpressionNameScope |
./scope |
FunctionScope |
./scope |
FunctionTypeScope |
./scope |
GlobalScope |
./scope |
MappedTypeScope |
./scope |
ModuleScope |
./scope |
ScopeType |
./scope |
SwitchScope |
./scope |
TSEnumScope |
./scope |
TSModuleScope |
./scope |
TypeScope |
./scope |
WithScope |
./scope |
ClassFieldInitializerScope |
./scope/ClassFieldInitializerScope |
ClassStaticBlockScope |
./scope/ClassStaticBlockScope |
Functions¶
ScopeManager.isES6(): boolean¶
Returns: boolean
ScopeManager.isGlobalReturn(): boolean¶
Returns: boolean
ScopeManager.isImpliedStrict(): boolean¶
Returns: boolean
ScopeManager.isModule(): boolean¶
Returns: boolean
ScopeManager.isStrictModeSupported(): boolean¶
Returns: boolean
ScopeManager.getDeclaredVariables(node: TSESTree.Node): Variable[]¶
Get the variables that a given AST node defines. The gotten variables' def[].node/def[].parent property is the node.
If the node does not define any variable, this returns an empty array.
Parameters:
nodeany: An AST node to get their variables.
Raw JSDoc
Calls:
this.declaredVariables.get
Code
ScopeManager.acquire(node: TSESTree.Node, inner: boolean): Scope | null¶
Get the scope of a given AST node. The gotten scope's block property is the node.
This method never returns function-expression-name scope. If the node does not have their scope, this returns null.
Parameters:
nodeany: An AST node to get their scope.innerany: If the node has multiple scopes, this returns the outermost scope normally. Ifinneristruethen this returns the innermost scope.
Raw JSDoc
/**
* Get the scope of a given AST node. The gotten scope's `block` property is the node.
* This method never returns `function-expression-name` scope. If the node does not have their scope, this returns `null`.
*
* @param node An AST node to get their scope.
* @param inner If the node has multiple scopes, this returns the outermost scope normally.
* If `inner` is `true` then this returns the innermost scope.
*/
Calls:
this.nodeToScope.getpredicatescopes.find
Internal Comments:
// Heuristic selection from all scopes.
// If you would like to get all scopes, please use ScopeManager#acquireAll.
Code
public acquire(node: TSESTree.Node, inner = false): Scope | null {
function predicate(testScope: Scope): boolean {
if (
testScope.type === ScopeType.function &&
testScope.functionExpressionScope
) {
return false;
}
return true;
}
const scopes = this.nodeToScope.get(node);
if (!scopes || scopes.length === 0) {
return null;
}
// Heuristic selection from all scopes.
// If you would like to get all scopes, please use ScopeManager#acquireAll.
if (scopes.length === 1) {
return scopes[0];
}
if (inner) {
for (let i = scopes.length - 1; i >= 0; --i) {
const scope = scopes[i];
if (predicate(scope)) {
return scope;
}
}
return null;
}
return scopes.find(predicate) ?? null;
}
ScopeManager.addGlobals(names: string[]): void¶
Adds dynamically created globals to the global scope and resolve their references. This method is called by ESLint.
Parameters:
namesany: Names of the globals to create
Raw JSDoc
Calls:
this.globalScope?.addVariables
ScopeManager.nestBlockScope(node: BlockScope['block']): BlockScope¶
Parameters:
nodeBlockScope['block']
Returns: BlockScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestCatchScope(node: CatchScope['block']): CatchScope¶
Parameters:
nodeCatchScope['block']
Returns: CatchScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestClassFieldInitializerScope(node: ClassFieldInitializerScope['block']): ClassFieldInitializerScope¶
Parameters:
nodeClassFieldInitializerScope['block']
Returns: ClassFieldInitializerScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestClassScope(node: ClassScope['block']): ClassScope¶
Parameters:
nodeClassScope['block']
Returns: ClassScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestClassStaticBlockScope(node: ClassStaticBlockScope['block']): ClassStaticBlockScope¶
Parameters:
nodeClassStaticBlockScope['block']
Returns: ClassStaticBlockScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestConditionalTypeScope(node: ConditionalTypeScope['block']): ConditionalTypeScope¶
Parameters:
nodeConditionalTypeScope['block']
Returns: ConditionalTypeScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestForScope(node: ForScope['block']): ForScope¶
Parameters:
nodeForScope['block']
Returns: ForScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestFunctionExpressionNameScope(node: FunctionExpressionNameScope['block']): FunctionExpressionNameScope¶
Parameters:
nodeFunctionExpressionNameScope['block']
Returns: FunctionExpressionNameScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestFunctionScope(node: FunctionScope['block'], isMethodDefinition: boolean): FunctionScope¶
Parameters:
nodeFunctionScope['block']isMethodDefinitionboolean
Returns: FunctionScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestFunctionTypeScope(node: FunctionTypeScope['block']): FunctionTypeScope¶
Parameters:
nodeFunctionTypeScope['block']
Returns: FunctionTypeScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestGlobalScope(node: GlobalScope['block']): GlobalScope¶
Parameters:
nodeGlobalScope['block']
Returns: GlobalScope
Calls:
this.nestScope
Code
ScopeManager.nestMappedTypeScope(node: MappedTypeScope['block']): MappedTypeScope¶
Parameters:
nodeMappedTypeScope['block']
Returns: MappedTypeScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestModuleScope(node: ModuleScope['block']): ModuleScope¶
Parameters:
nodeModuleScope['block']
Returns: ModuleScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestSwitchScope(node: SwitchScope['block']): SwitchScope¶
Parameters:
nodeSwitchScope['block']
Returns: SwitchScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestTSEnumScope(node: TSEnumScope['block']): TSEnumScope¶
Parameters:
nodeTSEnumScope['block']
Returns: TSEnumScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestTSModuleScope(node: TSModuleScope['block']): TSModuleScope¶
Parameters:
nodeTSModuleScope['block']
Returns: TSModuleScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestTypeScope(node: TypeScope['block']): TypeScope¶
Parameters:
nodeTypeScope['block']
Returns: TypeScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestWithScope(node: WithScope['block']): WithScope¶
Parameters:
nodeWithScope['block']
Returns: WithScope
Calls:
assert (from ./assert)this.nestScope
Code
ScopeManager.nestScope(scope: T): T¶
Parameters:
scopeT
Returns: T
Internal helpers¶
Declared inside another function in this file.
recurse(scope: Scope): void¶
Parameters:
scopeScope
Returns: void
Calls:
scope.variables.forEachvariables.addscope.childScopes.forEach
Code
predicate(testScope: Scope): boolean¶
Parameters:
testScopeScope
Returns: boolean
Code
Classes¶
ScopeManager¶
Methods (28) — full entries under Functions
| Method | Signature |
|---|---|
isES6 |
(): boolean |
isGlobalReturn |
(): boolean |
isImpliedStrict |
(): boolean |
isModule |
(): boolean |
isStrictModeSupported |
(): boolean |
getDeclaredVariables |
(node: TSESTree.Node): Variable[] |
acquire |
(node: TSESTree.Node, inner: boolean): Scope \| null |
addGlobals |
(names: string[]): void |
nestBlockScope |
(node: BlockScope['block']): BlockScope |
nestCatchScope |
(node: CatchScope['block']): CatchScope |
nestClassFieldInitializerScope |
(node: ClassFieldInitializerScope['block']): ClassFieldInitializerScope |
nestClassScope |
(node: ClassScope['block']): ClassScope |
nestClassStaticBlockScope |
(node: ClassStaticBlockScope['block']): ClassStaticBlockScope |
nestConditionalTypeScope |
(node: ConditionalTypeScope['block']): ConditionalTypeScope |
nestForScope |
(node: ForScope['block']): ForScope |
nestFunctionExpressionNameScope |
(node: FunctionExpressionNameScope['block']): FunctionExpressionNameScope |
nestFunctionScope |
(node: FunctionScope['block'], isMethodDefinition: boolean): FunctionScope |
nestFunctionTypeScope |
(node: FunctionTypeScope['block']): FunctionTypeScope |
nestGlobalScope |
(node: GlobalScope['block']): GlobalScope |
nestMappedTypeScope |
(node: MappedTypeScope['block']): MappedTypeScope |
nestModuleScope |
(node: ModuleScope['block']): ModuleScope |
nestSwitchScope |
(node: SwitchScope['block']): SwitchScope |
nestTSEnumScope |
(node: TSEnumScope['block']): TSEnumScope |
nestTSModuleScope |
(node: TSModuleScope['block']): TSModuleScope |
nestTypeScope |
(node: TypeScope['block']): TypeScope |
nestWithScope |
(node: WithScope['block']): WithScope |
nestScope |
(scope: T): T |
nestScope |
(scope: Scope): Scope |
Interfaces¶
ScopeManagerOptions¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
globalReturn |
boolean |
✓ | not shown |
impliedStrict |
boolean |
✓ | not shown |
sourceType |
SourceType |
✓ | not shown |
Generated by Syntax Scribe