From 0c7cdf06bf259de0070ab1233145c179b9cb9388 Mon Sep 17 00:00:00 2001 From: ZhongNing Date: Wed, 11 Jun 2025 13:55:42 +0800 Subject: [PATCH] fix issue for SharedArrayBufferDeprecated Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICD38W Test scenarios:new tests update to the linter Signed-off-by: ZhongNing --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 23 +++- .../src/lib/utils/consts/ConcurrentAPI.ts | 2 +- .../concurrent_sharedarraybuffer1_arkts2.ets | 29 +++++ ...nt_sharedarraybuffer1_arkts2.ets.args.json | 21 ++++ ..._sharedarraybuffer1_arkts2.ets.arkts2.json | 58 ++++++++++ ...sharedarraybuffer1_arkts2.ets.autofix.json | 102 ++++++++++++++++++ ...current_sharedarraybuffer1_arkts2.ets.json | 17 +++ ..._sharedarraybuffer1_arkts2.ets.migrate.ets | 29 +++++ ...sharedarraybuffer1_arkts2.ets.migrate.json | 3 + .../oh_modules/sharedArrayBuffer.ts | 32 ++++++ 10 files changed, 314 insertions(+), 2 deletions(-) create mode 100755 ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets create mode 100755 ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.args.json create mode 100755 ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.arkts2.json create mode 100755 ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.autofix.json create mode 100755 ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.json create mode 100755 ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.ets create mode 100755 ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.json create mode 100755 ets2panda/linter/test/concurrent/oh_modules/sharedArrayBuffer.ts diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index a15641503f..afc77dd648 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -5416,8 +5416,29 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (!ts.isIdentifier(typeNameIdentifier) || typeNameIdentifier.getText() !== ESLIB_SHAREDARRAYBUFFER) { return; } + const symbol = this.tsUtils.trueSymbolAtLocation(typeNameIdentifier); + if (!symbol) { + return; + } + + const isImported = this.sourceFile.statements.some(stmt => { + if (!ts.isImportDeclaration(stmt)) { + return false; + } + const importClause = stmt.importClause; + if (!importClause?.namedBindings || !ts.isNamedImports(importClause.namedBindings)) { + return false; + } - const decls = this.tsUtils.trueSymbolAtLocation(typeNameIdentifier)?.getDeclarations(); + const elements = importClause.namedBindings.elements.some( + element => element.name.text === ESLIB_SHAREDARRAYBUFFER + ); + return elements; + }); + if (isImported) { + return; + } + const decls = symbol.getDeclarations(); const isSharedMemoryEsLib = decls?.some((decl) => { const srcFileName = decl.getSourceFile().fileName; return srcFileName.endsWith(ESLIB_SHAREDMEMORY_FILENAME); diff --git a/ets2panda/linter/src/lib/utils/consts/ConcurrentAPI.ts b/ets2panda/linter/src/lib/utils/consts/ConcurrentAPI.ts index 5fc45d2e96..d6534a1611 100644 --- a/ets2panda/linter/src/lib/utils/consts/ConcurrentAPI.ts +++ b/ets2panda/linter/src/lib/utils/consts/ConcurrentAPI.ts @@ -17,4 +17,4 @@ export const USE_CONCURRENT = 'use concurrent'; export const USE_SHARED = 'use shared'; export const ESLIB_SHAREDARRAYBUFFER = 'SharedArrayBuffer'; export const ESLIB_SHAREDMEMORY_FILENAME = 'lib.es2017.sharedmemory.d.ts'; -export const TASKPOOL_MODULES = ['@kit.ArkTS', '@ohos.taskpool']; +export const TASKPOOL_MODULES = ['@kit.ArkTS', '@ohos.taskpool']; \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets new file mode 100755 index 0000000000..a0e9c55367 --- /dev/null +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { SharedArrayBuffer } from './oh_modules/sharedArrayBuffer' + +let s1 = new SharedArrayBuffer(1) //lib.es2017.sharedmemory.d.ts +s1.slice(0) +type sharedArray = SharedArrayBuffer +let s2: sharedArray; +type mapShare = Map +{ + let s1 = new SharedArrayBuffer(1) //lib.es2017.sharedmemory.d.ts + let s2:sharedArray; +} +function fun6(pa:sharedArray) { + let s1 = new SharedArrayBuffer(1) //lib.es2017.sharedmemory.d.ts + let s2:sharedArray; +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.args.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.args.json new file mode 100755 index 0000000000..3318ebbbcf --- /dev/null +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.args.json @@ -0,0 +1,21 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "", + "autofix": "--arkts-2", + "migrate": "--arkts-2" + } +} diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.arkts2.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.arkts2.json new file mode 100755 index 0000000000..ccc21ad852 --- /dev/null +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.arkts2.json @@ -0,0 +1,58 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 17, + "column": 32, + "endLine": 17, + "endColumn": 33, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 10, + "endLine": 18, + "endColumn": 11, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 34, + "endLine": 23, + "endColumn": 35, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 34, + "endLine": 27, + "endColumn": 35, + "problem": "NumericSemantics", + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + } + ] +} diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.autofix.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.autofix.json new file mode 100755 index 0000000000..bb890b9c3b --- /dev/null +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.autofix.json @@ -0,0 +1,102 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 17, + "column": 32, + "endLine": 17, + "endColumn": 33, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 724, + "end": 725, + "replacementText": "1.0", + "line": 17, + "column": 32, + "endLine": 17, + "endColumn": 33 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 18, + "column": 10, + "endLine": 18, + "endColumn": 11, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 769, + "end": 770, + "replacementText": "0.0", + "line": 18, + "column": 10, + "endLine": 18, + "endColumn": 11 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 34, + "endLine": 23, + "endColumn": 35, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 917, + "end": 918, + "replacementText": "1.0", + "line": 23, + "column": 34, + "endLine": 23, + "endColumn": 35 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + }, + { + "line": 27, + "column": 34, + "endLine": 27, + "endColumn": 35, + "problem": "NumericSemantics", + "autofix": [ + { + "start": 1044, + "end": 1045, + "replacementText": "1.0", + "line": 27, + "column": 34, + "endLine": 27, + "endColumn": 35 + } + ], + "suggest": "", + "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", + "severity": "ERROR" + } + ] +} diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.json new file mode 100755 index 0000000000..fae7c2a3fe --- /dev/null +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +} diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.ets b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.ets new file mode 100755 index 0000000000..9854ff5565 --- /dev/null +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { SharedArrayBuffer } from './oh_modules/sharedArrayBuffer' + +let s1 = new SharedArrayBuffer(1.0) //lib.es2017.sharedmemory.d.ts +s1.slice(0.0) +type sharedArray = SharedArrayBuffer +let s2: sharedArray; +type mapShare = Map +{ + let s1 = new SharedArrayBuffer(1.0) //lib.es2017.sharedmemory.d.ts + let s2:sharedArray; +} +function fun6(pa:sharedArray) { + let s1 = new SharedArrayBuffer(1.0) //lib.es2017.sharedmemory.d.ts + let s2:sharedArray; +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.json b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.json new file mode 100755 index 0000000000..95e6d40d6a --- /dev/null +++ b/ets2panda/linter/test/concurrent/concurrent_sharedarraybuffer1_arkts2.ets.migrate.json @@ -0,0 +1,3 @@ +{ + "result": [] +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/oh_modules/sharedArrayBuffer.ts b/ets2panda/linter/test/concurrent/oh_modules/sharedArrayBuffer.ts new file mode 100755 index 0000000000..cc5c84462f --- /dev/null +++ b/ets2panda/linter/test/concurrent/oh_modules/sharedArrayBuffer.ts @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// oh_modules/sharedArrayBuffer.ts +export interface SharedArrayBuffer { + /** + * Read-only. The length of the ArrayBuffer (in bytes). + */ + readonly byteLength: number; + +/** + * Returns a section of an SharedArrayBuffer. + */ + slice(begin: number, end?: number): SharedArrayBuffer; +} +interface SharedArrayBufferConstructor { + readonly prototype: SharedArrayBuffer; + new (byteLength: number): SharedArrayBuffer; +} +export declare var SharedArrayBuffer: SharedArrayBufferConstructor; + -- Gitee