Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(scope-manager): correct handling for class static blocks#5580

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bradzacher merged 1 commit intomainfrom5577-static-blocks
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1018,6 +1018,27 @@ export class TestClass {
`,
parserOptions: withMetaParserOptions,
},
// https://github.com/typescript-eslint/typescript-eslint/issues/5577
`
function foo() {}

export class Foo {
constructor() {
foo();
}
}
`,
`
function foo() {}

export class Foo {
static {}

constructor() {
foo();
}
}
`,
],

invalid: [
Expand Down
10 changes: 5 additions & 5 deletionspackages/scope-manager/src/referencer/ClassVisitor.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -322,10 +322,6 @@ class ClassVisitor extends Visitor {
this.visitType(node);
}

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

/////////////////////
// Visit selectors //
/////////////////////
Expand DownExpand Up@@ -365,7 +361,11 @@ class ClassVisitor extends Visitor {
}

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

node.body.forEach(b => this.visit(b));

this.#referencer.close(node);
}
}

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
function f() {}

class A {
static {
f();
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff 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 [],
},
],
}
`;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
// https://github.com/typescript-eslint/typescript-eslint/issues/5577
function f() {}

class A {
static {}

constructor() {
f();
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff 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,
],
},
],
}
`;

[8]ページ先頭

©2009-2025 Movatter.jp