From f8e91256e0a721aaa906a5c40a92784da9433b53 Mon Sep 17 00:00:00 2001 From: juank1809 <82288753+juank1809@users.noreply.github.com> Date: Tue, 23 Nov 2021 18:47:58 -0500 Subject: [PATCH] fix(scope-manager): support static class blocks (#4211) --- packages/scope-manager/src/ScopeManager.ts | 10 +++++++++ .../src/scope/ClassStaticBlockScope.ts | 21 +++++++++++++++++++ packages/scope-manager/src/scope/Scope.ts | 2 ++ packages/scope-manager/src/scope/ScopeBase.ts | 1 + packages/scope-manager/src/scope/ScopeType.ts | 1 + 5 files changed, 35 insertions(+) create mode 100644 packages/scope-manager/src/scope/ClassStaticBlockScope.ts diff --git a/packages/scope-manager/src/ScopeManager.ts b/packages/scope-manager/src/ScopeManager.ts index 3f360710cb0..5a53fe6fbf8 100644 --- a/packages/scope-manager/src/ScopeManager.ts +++ b/packages/scope-manager/src/ScopeManager.ts @@ -20,6 +20,7 @@ import { WithScope, } from './scope'; import { ClassFieldInitializerScope } from './scope/ClassFieldInitializerScope'; +import { ClassStaticBlockScope } from './scope/ClassStaticBlockScope'; import { Variable } from './variable'; @@ -178,6 +179,15 @@ class ScopeManager { ); } + public nestClassStaticBlockScope( + node: ClassStaticBlockScope['block'], + ): ClassStaticBlockScope { + assert(this.currentScope); + return this.nestScope( + new ClassStaticBlockScope(this, this.currentScope, node), + ); + } + public nestConditionalTypeScope( node: ConditionalTypeScope['block'], ): ConditionalTypeScope { diff --git a/packages/scope-manager/src/scope/ClassStaticBlockScope.ts b/packages/scope-manager/src/scope/ClassStaticBlockScope.ts new file mode 100644 index 00000000000..40a5d54b37c --- /dev/null +++ b/packages/scope-manager/src/scope/ClassStaticBlockScope.ts @@ -0,0 +1,21 @@ +import { TSESTree } from '@typescript-eslint/types'; +import { Scope } from './Scope'; +import { ScopeBase } from './ScopeBase'; +import { ScopeType } from './ScopeType'; +import { ScopeManager } from '../ScopeManager'; + +class ClassStaticBlockScope extends ScopeBase< + ScopeType.classStaticBlock, + TSESTree.Expression, + Scope +> { + constructor( + scopeManager: ScopeManager, + upperScope: ClassStaticBlockScope['upper'], + block: ClassStaticBlockScope['block'], + ) { + super(scopeManager, ScopeType.classStaticBlock, upperScope, block, false); + } +} + +export { ClassStaticBlockScope }; diff --git a/packages/scope-manager/src/scope/Scope.ts b/packages/scope-manager/src/scope/Scope.ts index 966e52a9456..e6237a09119 100644 --- a/packages/scope-manager/src/scope/Scope.ts +++ b/packages/scope-manager/src/scope/Scope.ts @@ -1,6 +1,7 @@ import { BlockScope } from './BlockScope'; import { CatchScope } from './CatchScope'; import { ClassFieldInitializerScope } from './ClassFieldInitializerScope'; +import { ClassStaticBlockScope } from './ClassStaticBlockScope'; import { ClassScope } from './ClassScope'; import { ConditionalTypeScope } from './ConditionalTypeScope'; import { ForScope } from './ForScope'; @@ -21,6 +22,7 @@ type Scope = | CatchScope | ClassScope | ClassFieldInitializerScope + | ClassStaticBlockScope | ConditionalTypeScope | ForScope | FunctionExpressionNameScope diff --git a/packages/scope-manager/src/scope/ScopeBase.ts b/packages/scope-manager/src/scope/ScopeBase.ts index 34c9a338b5b..18196d9cce9 100644 --- a/packages/scope-manager/src/scope/ScopeBase.ts +++ b/packages/scope-manager/src/scope/ScopeBase.ts @@ -126,6 +126,7 @@ const generator = createIdGenerator(); type VariableScope = GlobalScope | FunctionScope | ModuleScope | TSModuleScope; const VARIABLE_SCOPE_TYPES = new Set([ ScopeType.classFieldInitializer, + ScopeType.classStaticBlock, ScopeType.function, ScopeType.global, ScopeType.module, diff --git a/packages/scope-manager/src/scope/ScopeType.ts b/packages/scope-manager/src/scope/ScopeType.ts index 8a63ffbdea7..cd8bb1a61bd 100644 --- a/packages/scope-manager/src/scope/ScopeType.ts +++ b/packages/scope-manager/src/scope/ScopeType.ts @@ -3,6 +3,7 @@ enum ScopeType { catch = 'catch', class = 'class', classFieldInitializer = 'class-field-initializer', + classStaticBlock = 'class-static-block', conditionalType = 'conditionalType', for = 'for', function = 'function',