Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fix(scope-manager): correct handling for class static blocks (#5580)
- Loading branch information
1 parent
863694c
commit 35bb8dd
Showing
6 changed files
with
297 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/scope-manager/tests/fixtures/class/declaration/static-external-ref.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function f() {} | ||
|
||
class A { | ||
static { | ||
f(); | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
packages/scope-manager/tests/fixtures/class/declaration/static-external-ref.ts.shot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`class declaration static-external-ref 1`] = ` | ||
ScopeManager { | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2 { | ||
defs: Array [ | ||
FunctionNameDefinition$1 { | ||
name: Identifier<"f">, | ||
node: FunctionDeclaration$1, | ||
}, | ||
], | ||
name: "f", | ||
references: Array [ | ||
Reference$1 { | ||
identifier: Identifier<"f">, | ||
isRead: true, | ||
isTypeReference: false, | ||
isValueReference: true, | ||
isWrite: false, | ||
resolved: Variable$2, | ||
}, | ||
], | ||
isValueVariable: true, | ||
isTypeVariable: false, | ||
}, | ||
Variable$3 { | ||
defs: Array [], | ||
name: "arguments", | ||
references: Array [], | ||
isValueVariable: true, | ||
isTypeVariable: true, | ||
}, | ||
Variable$4 { | ||
defs: Array [ | ||
ClassNameDefinition$2 { | ||
name: Identifier<"A">, | ||
node: ClassDeclaration$2, | ||
}, | ||
], | ||
name: "A", | ||
references: Array [], | ||
isValueVariable: true, | ||
isTypeVariable: true, | ||
}, | ||
Variable$5 { | ||
defs: Array [ | ||
ClassNameDefinition$3 { | ||
name: Identifier<"A">, | ||
node: ClassDeclaration$2, | ||
}, | ||
], | ||
name: "A", | ||
references: Array [], | ||
isValueVariable: true, | ||
isTypeVariable: true, | ||
}, | ||
], | ||
scopes: Array [ | ||
GlobalScope$1 { | ||
block: Program$3, | ||
isStrict: false, | ||
references: Array [], | ||
set: Map { | ||
"const" => ImplicitGlobalConstTypeVariable, | ||
"f" => Variable$2, | ||
"A" => Variable$4, | ||
}, | ||
type: "global", | ||
upper: null, | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2, | ||
Variable$4, | ||
], | ||
}, | ||
FunctionScope$2 { | ||
block: FunctionDeclaration$1, | ||
isStrict: false, | ||
references: Array [], | ||
set: Map { | ||
"arguments" => Variable$3, | ||
}, | ||
type: "function", | ||
upper: GlobalScope$1, | ||
variables: Array [ | ||
Variable$3, | ||
], | ||
}, | ||
ClassScope$3 { | ||
block: ClassDeclaration$2, | ||
isStrict: true, | ||
references: Array [], | ||
set: Map { | ||
"A" => Variable$5, | ||
}, | ||
type: "class", | ||
upper: GlobalScope$1, | ||
variables: Array [ | ||
Variable$5, | ||
], | ||
}, | ||
ClassStaticBlockScope$4 { | ||
block: StaticBlock$4, | ||
isStrict: true, | ||
references: Array [ | ||
Reference$1, | ||
], | ||
set: Map {}, | ||
type: "class-static-block", | ||
upper: ClassScope$3, | ||
variables: Array [], | ||
}, | ||
], | ||
} | ||
`; |
10 changes: 10 additions & 0 deletions
10
packages/scope-manager/tests/fixtures/class/declaration/static-with-constructor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// https://github.com/typescript-eslint/typescript-eslint/issues/5577 | ||
function f() {} | ||
|
||
class A { | ||
static {} | ||
|
||
constructor() { | ||
f(); | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
packages/scope-manager/tests/fixtures/class/declaration/static-with-constructor.ts.shot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`class declaration static-with-constructor 1`] = ` | ||
ScopeManager { | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2 { | ||
defs: Array [ | ||
FunctionNameDefinition$1 { | ||
name: Identifier<"f">, | ||
node: FunctionDeclaration$1, | ||
}, | ||
], | ||
name: "f", | ||
references: Array [ | ||
Reference$1 { | ||
identifier: Identifier<"f">, | ||
isRead: true, | ||
isTypeReference: false, | ||
isValueReference: true, | ||
isWrite: false, | ||
resolved: Variable$2, | ||
}, | ||
], | ||
isValueVariable: true, | ||
isTypeVariable: false, | ||
}, | ||
Variable$3 { | ||
defs: Array [], | ||
name: "arguments", | ||
references: Array [], | ||
isValueVariable: true, | ||
isTypeVariable: true, | ||
}, | ||
Variable$4 { | ||
defs: Array [ | ||
ClassNameDefinition$2 { | ||
name: Identifier<"A">, | ||
node: ClassDeclaration$2, | ||
}, | ||
], | ||
name: "A", | ||
references: Array [], | ||
isValueVariable: true, | ||
isTypeVariable: true, | ||
}, | ||
Variable$5 { | ||
defs: Array [ | ||
ClassNameDefinition$3 { | ||
name: Identifier<"A">, | ||
node: ClassDeclaration$2, | ||
}, | ||
], | ||
name: "A", | ||
references: Array [], | ||
isValueVariable: true, | ||
isTypeVariable: true, | ||
}, | ||
Variable$6 { | ||
defs: Array [], | ||
name: "arguments", | ||
references: Array [], | ||
isValueVariable: true, | ||
isTypeVariable: true, | ||
}, | ||
], | ||
scopes: Array [ | ||
GlobalScope$1 { | ||
block: Program$3, | ||
isStrict: false, | ||
references: Array [], | ||
set: Map { | ||
"const" => ImplicitGlobalConstTypeVariable, | ||
"f" => Variable$2, | ||
"A" => Variable$4, | ||
}, | ||
type: "global", | ||
upper: null, | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2, | ||
Variable$4, | ||
], | ||
}, | ||
FunctionScope$2 { | ||
block: FunctionDeclaration$1, | ||
isStrict: false, | ||
references: Array [], | ||
set: Map { | ||
"arguments" => Variable$3, | ||
}, | ||
type: "function", | ||
upper: GlobalScope$1, | ||
variables: Array [ | ||
Variable$3, | ||
], | ||
}, | ||
ClassScope$3 { | ||
block: ClassDeclaration$2, | ||
isStrict: true, | ||
references: Array [], | ||
set: Map { | ||
"A" => Variable$5, | ||
}, | ||
type: "class", | ||
upper: GlobalScope$1, | ||
variables: Array [ | ||
Variable$5, | ||
], | ||
}, | ||
ClassStaticBlockScope$4 { | ||
block: StaticBlock$4, | ||
isStrict: true, | ||
references: Array [], | ||
set: Map {}, | ||
type: "class-static-block", | ||
upper: ClassScope$3, | ||
variables: Array [], | ||
}, | ||
FunctionScope$5 { | ||
block: FunctionExpression$5, | ||
isStrict: true, | ||
references: Array [ | ||
Reference$1, | ||
], | ||
set: Map { | ||
"arguments" => Variable$6, | ||
}, | ||
type: "function", | ||
upper: ClassScope$3, | ||
variables: Array [ | ||
Variable$6, | ||
], | ||
}, | ||
], | ||
} | ||
`; |