From 865ec227f878f9945e2dad0f496d4d97aa305ede Mon Sep 17 00:00:00 2001 From: Konstantin Baladurin Date: Wed, 23 Aug 2023 18:22:26 +0300 Subject: [PATCH] Linter: fix arkts-no-multiple-static-blocks diagnostic Signed-off-by: Konstantin Baladurin --- linter-4.2/src/TypeScriptLinter.ts | 3 +++ linter/src/TypeScriptLinter.ts | 1 + linter/test/class_static_block.ts | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index dafd72b8f..8865b78c1 100644 --- a/linter-4.2/src/TypeScriptLinter.ts +++ b/linter-4.2/src/TypeScriptLinter.ts @@ -1040,6 +1040,9 @@ export class TypeScriptLinter { private handleClassDeclaration(node: ts.Node) { let tsClassDecl = node as ts.ClassDeclaration; + + this.staticBlocks.clear(); + if (tsClassDecl.name) this.countDeclarationsWithDuplicateName( this.tsTypeChecker.getSymbolAtLocation(tsClassDecl.name), diff --git a/linter/src/TypeScriptLinter.ts b/linter/src/TypeScriptLinter.ts index 0c9ef14d4..63b0c6779 100644 --- a/linter/src/TypeScriptLinter.ts +++ b/linter/src/TypeScriptLinter.ts @@ -1014,6 +1014,7 @@ export class TypeScriptLinter { private handleClassDeclaration(node: ts.Node) { let tsClassDecl = node as ts.ClassDeclaration; + this.staticBlocks.clear(); if (tsClassDecl.name) { this.countDeclarationsWithDuplicateName( this.tsTypeChecker.getSymbolAtLocation(tsClassDecl.name), diff --git a/linter/test/class_static_block.ts b/linter/test/class_static_block.ts index 82371491a..69a140371 100644 --- a/linter/test/class_static_block.ts +++ b/linter/test/class_static_block.ts @@ -33,3 +33,23 @@ class B { static n: number; } + +{ + class C { + static t: string + static { + C.t = "aa" + C.t = C.t + "bb" + } + } +} + +{ + class C { + static s: string + static { + C.s = "aa" + C.s = C.s + "bb" + } + } +} \ No newline at end of file -- Gitee