diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index a15641503fd7aa6af889b0b1b95a5af54dd1809e..afc77dd6483aa09d94d3786bc4d891c51599774f 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 5fc45d2e960b875ace2b3e42b94de233b7d33b66..d6534a16117f98426ee7f89c4ea96628b80da9ec 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 0000000000000000000000000000000000000000..a0e9c55367f1546d3e120937ca8372b2473fef37 --- /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 0000000000000000000000000000000000000000..3318ebbbcfd0ce90dc5f69df69452a3201e4204d --- /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 0000000000000000000000000000000000000000..ccc21ad852817e879704bf730636157c56c9016e --- /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 0000000000000000000000000000000000000000..bb890b9c3b90f345391be21fda2a5eb236ee6799 --- /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 0000000000000000000000000000000000000000..fae7c2a3fe332707886d01e70ea981341f927c59 --- /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 0000000000000000000000000000000000000000..9854ff55652fd3b6e96c5b6d2fa75d9eead0aa8a --- /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 0000000000000000000000000000000000000000..95e6d40d6a3afa83ed578df1b91fe6ad710455e3 --- /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 0000000000000000000000000000000000000000..cc5c84462f2a1a18a5f3644c13742d25b878daa7 --- /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; +