Skip to content

Commit

Permalink
fix(scope-manager): visit static blocks (#5489)
Browse files Browse the repository at this point in the history
  • Loading branch information
DMartens committed Aug 17, 2022
1 parent 3ced62f commit 78745c2
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
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 [],
},
],
}
`;

0 comments on commit 78745c2

Please sign in to comment.