Skip to content

fix(scope-manager): support static class blocks #4211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/scope-manager/src/ScopeManager.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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