From 4eb9f2fe8489eacbbb302dcbb39d8364799a7e1b Mon Sep 17 00:00:00 2001 From: ZhongNing Date: Thu, 29 May 2025 15:18:56 +0800 Subject: [PATCH] Fix for TsOverload Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICBAS8 Test scenarios:new tests update to the linter Signed-off-by: ZhongNing --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 17 +++--- ets2panda/linter/test/main/ts_overload.ets | 52 ++++++++++++++----- .../test/main/ts_overload.ets.arkts2.json | 52 ++++++++++++++++++- 3 files changed, 101 insertions(+), 20 deletions(-) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index c6c80448bc..85cdbe5313 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -6080,12 +6080,17 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (isInternalFunction && filterDecl.length > 2 || !isInternalFunction && filterDecl.length > 1) { this.incrementCounters(decl, FaultID.TsOverload); } - } else if (ts.isConstructorDeclaration(decl)) { - const parent = decl.parent; - const constructors = parent.members.filter(ts.isConstructorDeclaration); - if (constructors.length > 1) { - this.incrementCounters(decl, FaultID.TsOverload); - } + } else if (ts.isConstructorDeclaration(decl) && decl.getText()) { + this.handleTSOverloadUnderConstructorDeclaration(decl); + } + } + + private handleTSOverloadUnderConstructorDeclaration(decl: ts.ConstructorDeclaration): void { + const parent = decl.parent; + const constructors = parent.members.filter(ts.isConstructorDeclaration); + const isStruct = decl.getText() && ts.isStructDeclaration(parent); + if ((isStruct ? --constructors.length : constructors.length) > 1) { + this.incrementCounters(decl, FaultID.TsOverload); } } diff --git a/ets2panda/linter/test/main/ts_overload.ets b/ets2panda/linter/test/main/ts_overload.ets index 40fc4f8024..d6a903fb5b 100644 --- a/ets2panda/linter/test/main/ts_overload.ets +++ b/ets2panda/linter/test/main/ts_overload.ets @@ -13,9 +13,9 @@ * limitations under the License. */ -function makeDate(timestamp: number): Date; -function makeDate(m: number, d: number, y: number): Date; -function makeDate(mOrTimestamp: number, d?: number, y?: number): Date { +function makeDate(timestamp: number): Date; //error +function makeDate(m: number, d: number, y: number): Date; //error +function makeDate(mOrTimestamp: number, d?: number, y?: number): Date { //error if (d !== undefined && y !== undefined) { return new Date(y, mOrTimestamp, d); } else { @@ -27,15 +27,15 @@ const d2 = makeDate(5, 5, 5); const d3 = makeDate(1, 3); class Vector { - abstract foo(): void - abstract foo(x: string): void - abstract foo(x?: string): void { + abstract foo(): void //error + abstract foo(x: string): void //error + abstract foo(x?: string): void { //error /body/ } - public fun(): void - public fun(x: string): void - public fun(x?: string): void { + public fun(): void //error + public fun(x: string): void //error + public fun(x?: string): void { //error /body/ } } @@ -47,11 +47,11 @@ abstract class absClass { /body/ } - constructor(x: number, y: number); + constructor(x: number, y: number); //error - constructor(magnitude: number); + constructor(magnitude: number); //error - constructor(...args: number[]) { + constructor(...args: number[]) { //error /* ... */ } } @@ -59,4 +59,30 @@ function func(){ console.log("ArkTs foo4") } -func.val = "0xff"; \ No newline at end of file +func.val = "0xff"; + +@Component +struct B{ + constructor() { + super() + } + build() { + } +} + +struct C{ + constructor() { //error + super() + } + constructor(x:number) //error +} + +class A{ + constructor() { + } +} +class D{ + constructor() { //error + } + constructor(x:number) //error +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/ts_overload.ets.arkts2.json b/ets2panda/linter/test/main/ts_overload.ets.arkts2.json index cd9bd6a42c..013ef916fe 100644 --- a/ets2panda/linter/test/main/ts_overload.ets.arkts2.json +++ b/ets2panda/linter/test/main/ts_overload.ets.arkts2.json @@ -13,7 +13,7 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "result": [ + "result": [ { "line": 16, "column": 1, @@ -233,6 +233,56 @@ "suggest": "", "rule": "Declaring properties on functions is not supported (arkts-no-func-props)", "severity": "ERROR" + }, + { + "line": 74, + "column": 3, + "endLine": 76, + "endColumn": 4, + "problem": "TsOverload", + "suggest": "", + "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", + "severity": "ERROR" + }, + { + "line": 77, + "column": 3, + "endLine": 77, + "endColumn": 24, + "problem": "TsOverload", + "suggest": "", + "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", + "severity": "ERROR" + }, + { + "line": 85, + "column": 3, + "endLine": 86, + "endColumn": 4, + "problem": "TsOverload", + "suggest": "", + "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", + "severity": "ERROR" + }, + { + "line": 87, + "column": 3, + "endLine": 87, + "endColumn": 24, + "problem": "TsOverload", + "suggest": "", + "rule": "Class TS overloading is not supported(arkts-no-ts-overload)", + "severity": "ERROR" + }, + { + "line": 64, + "column": 2, + "endLine": 64, + "endColumn": 11, + "problem": "UIInterfaceImport", + "suggest": "", + "rule": "ArkUI interface should be imported before using (arkui-modular-interface)", + "severity": "ERROR" } ] } \ No newline at end of file -- Gitee