Skip to content
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
5 changes: 4 additions & 1 deletion tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2863,6 +2863,9 @@ func (c *Checker) checkClassStaticBlockDeclaration(node *ast.Node) {
// Grammar checking
c.checkGrammarModifiers(node)
node.ForEachChild(c.checkSourceElement)
if len(node.Locals()) != 0 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this if?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c.registerForUnusedIdentifiersCheck(node)
}
}

func (c *Checker) checkConstructorDeclaration(node *ast.Node) {
Expand Down Expand Up @@ -7220,7 +7223,7 @@ func (c *Checker) checkUnusedIdentifiers(potentiallyUnusedIdentifiers []*ast.Nod
c.checkUnusedClassMembers(node)
c.checkUnusedTypeParameters(node)
case ast.KindSourceFile, ast.KindModuleDeclaration, ast.KindBlock, ast.KindCaseBlock, ast.KindForStatement, ast.KindForInStatement,
ast.KindForOfStatement:
ast.KindForOfStatement, ast.KindClassStaticBlockDeclaration:
c.checkUnusedLocalsAndParameters(node)
case ast.KindConstructor, ast.KindFunctionExpression, ast.KindFunctionDeclaration, ast.KindArrowFunction, ast.KindMethodDeclaration,
ast.KindGetAccessor, ast.KindSetAccessor:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ unusedLocalsAndParameters.ts(71,11): error TS6133: 'c' is declared but its value
unusedLocalsAndParameters.ts(74,11): error TS6133: 'c' is declared but its value is never read.
unusedLocalsAndParameters.ts(79,11): error TS6133: 'N' is declared but its value is never read.
unusedLocalsAndParameters.ts(80,9): error TS6133: 'x' is declared but its value is never read.
unusedLocalsAndParameters.ts(83,13): error TS2304: Cannot find name 'y'.
unusedLocalsAndParameters.ts(83,14): error TS1005: ',' expected.
unusedLocalsAndParameters.ts(84,6): error TS1005: ',' expected.
unusedLocalsAndParameters.ts(85,1): error TS1109: Expression expected.
unusedLocalsAndParameters.ts(84,7): error TS6196: 'C1' is declared but never used.
unusedLocalsAndParameters.ts(86,13): error TS6133: 'foo' is declared but its value is never read.
unusedLocalsAndParameters.ts(90,13): error TS2304: Cannot find name 'y'.
unusedLocalsAndParameters.ts(90,14): error TS1005: ',' expected.
unusedLocalsAndParameters.ts(91,6): error TS1005: ',' expected.
unusedLocalsAndParameters.ts(92,1): error TS1109: Expression expected.


==== unusedLocalsAndParameters.ts (25 errors) ====
==== unusedLocalsAndParameters.ts (27 errors) ====
export { };

// function declaration paramter
Expand Down Expand Up @@ -150,6 +152,17 @@ unusedLocalsAndParameters.ts(85,1): error TS1109: Expression expected.
!!! error TS6133: 'x' is declared but its value is never read.
}

// in a class static block
class C1 {
~~
!!! error TS6196: 'C1' is declared but never used.
static {
let foo = 1;
~~~
!!! error TS6133: 'foo' is declared but its value is never read.
}
}

for (let x: y) {
~
!!! error TS2304: Cannot find name 'y'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ namespace N {
var x;
}

// in a class static block
class C1 {
static {
let foo = 1;
}
}

for (let x: y) {
z(x);
}
Expand Down Expand Up @@ -154,6 +161,12 @@ var N;
(function (N) {
var x;
})(N || (N = {}));
// in a class static block
class C1 {
}
(() => {
let foo = 1;
})();
for (let x, { z }; (x); )
;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,22 @@ namespace N {
>x : Symbol(x, Decl(unusedLocalsAndParameters.ts, 79, 7))
}

// in a class static block
class C1 {
>C1 : Symbol(C1, Decl(unusedLocalsAndParameters.ts, 80, 1))

static {
let foo = 1;
>foo : Symbol(foo, Decl(unusedLocalsAndParameters.ts, 85, 11))
}
}

for (let x: y) {
>x : Symbol(x, Decl(unusedLocalsAndParameters.ts, 82, 8))
>x : Symbol(x, Decl(unusedLocalsAndParameters.ts, 89, 8))
>y : Symbol(y)

z(x);
>z : Symbol(z, Decl(unusedLocalsAndParameters.ts, 82, 16))
>x : Symbol(x, Decl(unusedLocalsAndParameters.ts, 82, 8))
>z : Symbol(z, Decl(unusedLocalsAndParameters.ts, 89, 16))
>x : Symbol(x, Decl(unusedLocalsAndParameters.ts, 89, 8))
}

Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ namespace N {
>x : any
}

// in a class static block
class C1 {
>C1 : C1

static {
let foo = 1;
>foo : number
>1 : 1
}
}

for (let x: y) {
>x : y

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ namespace N {
var x;
}

// in a class static block
class C1 {
static {
let foo = 1;
}
}

for (let x: y) {
z(x);
}
Loading