Skip to content

Commit

Permalink
fix(scope-manager): support static class blocks (#4211)
Browse files Browse the repository at this point in the history
  • Loading branch information
juank1809 committed Nov 23, 2021
1 parent 46a9aee commit f8e9125
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/scope-manager/src/ScopeManager.ts
Expand Up @@ -20,6 +20,7 @@ import {
WithScope,
} from './scope';
import { ClassFieldInitializerScope } from './scope/ClassFieldInitializerScope';
import { ClassStaticBlockScope } from './scope/ClassStaticBlockScope';

import { Variable } from './variable';

Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions 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 };
2 changes: 2 additions & 0 deletions 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';
Expand All @@ -21,6 +22,7 @@ type Scope =
| CatchScope
| ClassScope
| ClassFieldInitializerScope
| ClassStaticBlockScope
| ConditionalTypeScope
| ForScope
| FunctionExpressionNameScope
Expand Down
1 change: 1 addition & 0 deletions packages/scope-manager/src/scope/ScopeBase.ts
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/scope-manager/src/scope/ScopeType.ts
Expand Up @@ -3,6 +3,7 @@ enum ScopeType {
catch = 'catch',
class = 'class',
classFieldInitializer = 'class-field-initializer',
classStaticBlock = 'class-static-block',
conditionalType = 'conditionalType',
for = 'for',
function = 'function',
Expand Down

0 comments on commit f8e9125

Please sign in to comment.