Skip to content
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

fix(scope-manager): visit static blocks #5489

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/scope-manager/src/referencer/ClassVisitor.ts
Expand Up @@ -322,6 +322,10 @@ class ClassVisitor extends Visitor {
this.visitType(node);
}

protected visitStaticBlock(node: TSESTree.StaticBlock): void {
this.#referencer.scopeManager.nestClassStaticBlockScope(node);
}

/////////////////////
// Visit selectors //
/////////////////////
Expand Down Expand Up @@ -359,6 +363,10 @@ class ClassVisitor extends Visitor {
protected PrivateIdentifier(): void {
// intentionally skip
}

protected StaticBlock(node: TSESTree.StaticBlock): void {
this.visitStaticBlock(node);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/scope-manager/src/scope/ClassStaticBlockScope.ts
Expand Up @@ -6,7 +6,7 @@ import { ScopeManager } from '../ScopeManager';

class ClassStaticBlockScope extends ScopeBase<
ScopeType.classStaticBlock,
TSESTree.Expression,
TSESTree.StaticBlock,
Scope
> {
constructor(
Expand Down
@@ -0,0 +1,3 @@
class A {
static {}
}
@@ -0,0 +1,72 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`class declaration static-block 1`] = `
ScopeManager {
variables: Array [
ImplicitGlobalConstTypeVariable,
Variable$2 {
defs: Array [
ClassNameDefinition$1 {
name: Identifier<"A">,
node: ClassDeclaration$1,
},
],
name: "A",
references: Array [],
isValueVariable: true,
isTypeVariable: true,
},
Variable$3 {
defs: Array [
ClassNameDefinition$2 {
name: Identifier<"A">,
node: ClassDeclaration$1,
},
],
name: "A",
references: Array [],
isValueVariable: true,
isTypeVariable: true,
},
],
scopes: Array [
GlobalScope$1 {
block: Program$2,
isStrict: false,
references: Array [],
set: Map {
"const" => ImplicitGlobalConstTypeVariable,
"A" => Variable$2,
},
type: "global",
upper: null,
variables: Array [
ImplicitGlobalConstTypeVariable,
Variable$2,
],
},
ClassScope$2 {
block: ClassDeclaration$1,
isStrict: true,
references: Array [],
set: Map {
"A" => Variable$3,
},
type: "class",
upper: GlobalScope$1,
variables: Array [
Variable$3,
],
},
ClassStaticBlockScope$3 {
block: StaticBlock$3,
isStrict: true,
references: Array [],
set: Map {},
type: "class-static-block",
upper: ClassScope$2,
variables: Array [],
},
],
}
`;