From 26b94fd95af674c04909b6a2116cda22714b8935 Mon Sep 17 00:00:00 2001 From: oh_ci Date: Fri, 18 Jul 2025 02:00:46 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!6639=20?= =?UTF-8?q?:=20allow=20alias=20exports=20with=20same=20name'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../invariants/importExportAccessValid.cpp | 2 +- .../variableNameIdentifierNameSame.cpp | 4 +- ets2panda/checker/ets/etsWarningAnalyzer.cpp | 2 +- ets2panda/checker/ets/helpers.cpp | 4 +- .../topLevelStmts/globalDeclTransformer.cpp | 5 ++- .../ets/topLevelStmts/importExportDecls.cpp | 37 +++++++++++-------- .../ets/topLevelStmts/importExportDecls.h | 3 +- ets2panda/ir/ets/etsModule.cpp | 2 +- .../ir/statements/functionDeclaration.cpp | 7 +--- .../ets/export_and_export_type_class.ets | 2 + .../ets/export_and_export_type_interface.ets | 2 + ...ame_type_at_decl_and_selective_binding.ets | 3 ++ .../ets/export_type_class_multiple_times.ets | 3 +- .../export_type_interface_multiple_times.ets | 3 ++ .../ets/import_tests/export_multi_error.ets | 7 +++- .../export_type_several_times_1.ets | 24 ------------ .../export_type_several_times_2.ets | 27 -------------- .../import_same_type_form_alias_1.ets | 23 ------------ .../import_same_type_form_alias_2.ets | 23 ------------ .../import_same_type_form_alias_3.ets | 24 ------------ .../selective_export_clashing_exports_1.ets | 4 +- .../selective_export_clashing_exports_2.ets | 4 +- .../ast/compiler/ets/namespaceExport_neg.ets | 2 + .../parser/ets/import_tests/type/type_2.ets | 2 + .../parser/ets/import_tests/type/type_3.ets | 3 +- .../astchecker/astchecker-ets-ignored.txt | 7 +--- ets2panda/util/diagnostic/syntax.yaml | 4 -- ets2panda/util/diagnostic/warning.yaml | 4 -- ets2panda/varbinder/ETSBinder.cpp | 25 ++++--------- ets2panda/varbinder/ETSBinder.h | 6 +-- ets2panda/varbinder/scope.cpp | 2 +- 31 files changed, 75 insertions(+), 195 deletions(-) delete mode 100644 ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/export_type_several_times_1.ets delete mode 100644 ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/export_type_several_times_2.ets delete mode 100644 ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/import_same_type_form_alias_1.ets delete mode 100644 ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/import_same_type_form_alias_2.ets delete mode 100644 ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/import_same_type_form_alias_3.ets diff --git a/ets2panda/ast_verifier/invariants/importExportAccessValid.cpp b/ets2panda/ast_verifier/invariants/importExportAccessValid.cpp index 4832d10fb7b..d865ebe9c91 100644 --- a/ets2panda/ast_verifier/invariants/importExportAccessValid.cpp +++ b/ets2panda/ast_verifier/invariants/importExportAccessValid.cpp @@ -70,7 +70,7 @@ bool ImportExportAccessValid::ValidateExport(const varbinder::Variable *var) if (node == nullptr) { return false; } - return node->IsExported() || node->HasExportAlias(); + return node->IsExported(); } bool ImportExportAccessValid::InvariantImportExportMethod(const std::unordered_set &importedVariables, diff --git a/ets2panda/ast_verifier/invariants/variableNameIdentifierNameSame.cpp b/ets2panda/ast_verifier/invariants/variableNameIdentifierNameSame.cpp index 3b82e3e138b..f3d85ee0a0b 100644 --- a/ets2panda/ast_verifier/invariants/variableNameIdentifierNameSame.cpp +++ b/ets2panda/ast_verifier/invariants/variableNameIdentifierNameSame.cpp @@ -32,8 +32,8 @@ namespace ark::es2panda::compiler::ast_verifier { } const auto variableNode = variable->Declaration()->Node(); // NOTE(psaykerone): skip because, this exceptions need to be fixed in checker and lowering - if (variableNode->IsExported() || variableNode->IsDefaultExported() || variableNode->HasExportAlias() || - id->Name().Utf8().find("field") == 0 || variable->Name().Utf8().find("field") == 0) { + if (variableNode->IsExported() || variableNode->IsDefaultExported() || id->Name().Utf8().find("field") == 0 || + variable->Name().Utf8().find("field") == 0) { return {CheckDecision::CORRECT, CheckAction::CONTINUE}; } if (id->Name() == variable->Name()) { diff --git a/ets2panda/checker/ets/etsWarningAnalyzer.cpp b/ets2panda/checker/ets/etsWarningAnalyzer.cpp index f207387c3f3..f686ff057b0 100644 --- a/ets2panda/checker/ets/etsWarningAnalyzer.cpp +++ b/ets2panda/checker/ets/etsWarningAnalyzer.cpp @@ -42,7 +42,7 @@ void ETSWarningAnalyzer::AnalyzeClassDefForFinalModifier(const ir::ClassDefiniti ES2PANDA_ASSERT(classDef != nullptr); if (program_ == nullptr || classDef->IsFinal() || classDef->IsAbstract() || classDef->IsStatic() || - classDef->IsGlobal() || classDef->IsExported() || classDef->HasExportAlias()) { + classDef->IsGlobal() || classDef->IsExported()) { return; } diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index d7eb47097e0..b8dceccca91 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1751,9 +1751,7 @@ void ETSChecker::BindingsModuleObjectAddProperty(checker::ETSObjectType *moduleO if (!var->AsLocalVariable()->Declaration()->Node()->IsValidInCurrentPhase()) { continue; } - if ((var->AsLocalVariable()->Declaration()->Node()->IsExported() || - var->AsLocalVariable()->Declaration()->Node()->HasExportAlias()) && - found) { + if ((var->AsLocalVariable()->Declaration()->Node()->IsExported()) && found) { if (!aliasedName.Empty()) { moduleObjType->AddReExportAlias(var->Declaration()->Name(), aliasedName); } diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp index 9b66d0c0953..2ec4129350c 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp @@ -79,7 +79,7 @@ void GlobalDeclTransformer::VisitFunctionDeclaration(ir::FunctionDeclaration *fu method->SetRange(funcDecl->Range()); method->Function()->SetAnnotations(funcDecl->Annotations()); - if (funcDecl->Function()->HasExportAlias()) { + if (funcDecl->Function()->IsExported() && funcDecl->Function()->HasExportAlias()) { method->AddAstNodeFlags(ir::AstNodeFlags::HAS_EXPORT_ALIAS); } @@ -113,7 +113,8 @@ void GlobalDeclTransformer::VisitVariableDeclaration(ir::VariableDeclaration *va field->SetAnnotations(std::move(propAnnotations)); } - if (varDecl->HasExportAlias() || declarator->HasExportAlias()) { + if ((varDecl->IsExported() || declarator->IsExported()) && + (varDecl->HasExportAlias() || declarator->HasExportAlias())) { field->AddAstNodeFlags(ir::AstNodeFlags::HAS_EXPORT_ALIAS); } diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp index 4030eca9087..c7b88afa101 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.cpp @@ -15,7 +15,6 @@ #include "compiler/lowering/ets/topLevelStmts/importExportDecls.h" #include "compiler/lowering/util.h" -#include "generated/diagnostic.h" #include "utils/arena_containers.h" namespace ark::es2panda::compiler { @@ -98,33 +97,37 @@ GlobalClassHandler::ModuleDependencies ImportExportDecls::HandleGlobalStmts(Aren void ImportExportDecls::PopulateAliasMap(const ir::ExportNamedDeclaration *decl, const util::StringView &path) { for (auto spec : decl->Specifiers()) { - if (!varbinder_->AddSelectiveExportAlias(parser_, path, spec->Local()->Name(), spec->Exported()->Name(), - decl)) { - parser_->LogError(diagnostic::CANNOT_EXPORT_DIFFERENT_OBJECTS_WITH_SAME_NAME, - {spec->Local()->Name().Mutf8()}, spec->Exported()->Start()); + if (!varbinder_->AddSelectiveExportAlias(path, spec->Local()->Name(), spec->Exported()->Name(), decl)) { + parser_->LogError(diagnostic::DUPLICATE_EXPORT_NAME, {spec->Local()->Name().Mutf8()}, + spec->Exported()->Start()); lastExportErrorPos_ = lexer::SourcePosition(); } } } -void ImportExportDecls::AddExportFlags(ir::AstNode *node, util::StringView originalFieldName, bool exportedWithAlias) +void ImportExportDecls::AddExportFlags(ir::AstNode *node, util::StringView originalFieldName, + lexer::SourcePosition startLoc, bool exportedWithAlias) { - if (exportedWithAlias) { - node->AddAstNodeFlags(ir::AstNodeFlags::HAS_EXPORT_ALIAS); - return; + if ((node->Modifiers() & ir::ModifierFlags::EXPORTED) != 0) { + // Note (oeotvos) Needs to be discussed, whether we would like to allow exporting the same program + // element using its original name and also an alias, like: export {test_func, test_func as foo}. + parser_->LogError(diagnostic::ALREADY_EXPORTED, {originalFieldName.Mutf8()}, startLoc); } if (originalFieldName == exportDefaultName_) { node->AddModifier(ir::ModifierFlags::DEFAULT_EXPORT); } else { node->AddModifier(ir::ModifierFlags::EXPORT); } + if (exportedWithAlias) { + node->AddAstNodeFlags(ir::AstNodeFlags::HAS_EXPORT_ALIAS); + } } void ImportExportDecls::PopulateAliasMap(const ir::TSTypeAliasDeclaration *decl, const util::StringView &path) { - if (!varbinder_->AddSelectiveExportAlias(parser_, path, decl->Id()->AsIdentifier()->Name(), + if (!varbinder_->AddSelectiveExportAlias(path, decl->Id()->AsIdentifier()->Name(), decl->Id()->AsIdentifier()->Name(), decl)) { - parser_->LogError(diagnostic::CANNOT_EXPORT_DIFFERENT_OBJECTS_WITH_SAME_NAME, - {decl->Id()->AsIdentifier()->Name().Mutf8()}, lastExportErrorPos_); + parser_->LogError(diagnostic::DUPLICATE_EXPORT_NAME, {decl->Id()->AsIdentifier()->Name().Mutf8()}, + lastExportErrorPos_); lastExportErrorPos_ = lexer::SourcePosition(); } } @@ -144,9 +147,9 @@ void ImportExportDecls::HandleSelectiveExportWithAlias(util::StringView original } if (variableDeclarator != nullptr) { - AddExportFlags(variableDeclarator, originalFieldName, exportedWithAlias); + AddExportFlags(variableDeclarator, originalFieldName, startLoc, exportedWithAlias); } else { - AddExportFlags(field, originalFieldName, exportedWithAlias); + AddExportFlags(field, originalFieldName, startLoc, exportedWithAlias); } } @@ -231,7 +234,11 @@ void ImportExportDecls::VisitExportNamedDeclaration(ir::ExportNamedDeclaration * } exportDefaultName_ = local->Name(); } - exportNameMap_.emplace(local->Name(), local->Start()); + + if (!exportNameMap_.emplace(local->Name(), local->Start()).second) { + lastExportErrorPos_ = local->Start(); + parser_->LogError(diagnostic::DUPLICATE_EXPORT_NAME, {local->Name().Mutf8()}, lastExportErrorPos_); + } } } diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h index 4d785eb815a..c873e8ffdb4 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/importExportDecls.h @@ -64,7 +64,8 @@ public: void HandleSimpleType(std::set &exportedStatements, ir::Statement *stmt, util::StringView name); void VerifySingleExportDefault(const ArenaVector &programs); - void AddExportFlags(ir::AstNode *node, util::StringView originalFieldName, bool exportedWithAlias); + void AddExportFlags(ir::AstNode *node, util::StringView originalFieldName, lexer::SourcePosition startLoc, + bool exportedWithAlias); void HandleSelectiveExportWithAlias(util::StringView originalFieldName, util::StringView exportName, lexer::SourcePosition startLoc); void PopulateAliasMap(const ir::ExportNamedDeclaration *decl, const util::StringView &path); diff --git a/ets2panda/ir/ets/etsModule.cpp b/ets2panda/ir/ets/etsModule.cpp index 147f0769e2d..7c8faf7945b 100644 --- a/ets2panda/ir/ets/etsModule.cpp +++ b/ets2panda/ir/ets/etsModule.cpp @@ -29,7 +29,7 @@ void ETSModule::Dump(ir::SrcDumper *dumper) const dumper->Add("export default "); } - if (IsDeclare() && !(parent_ != nullptr && parent_->IsDeclare())) { + if (IsDeclare()) { dumper->Add("declare "); } diff --git a/ets2panda/ir/statements/functionDeclaration.cpp b/ets2panda/ir/statements/functionDeclaration.cpp index f4cbcad2289..be0f1341c42 100644 --- a/ets2panda/ir/statements/functionDeclaration.cpp +++ b/ets2panda/ir/statements/functionDeclaration.cpp @@ -79,12 +79,7 @@ void FunctionDeclaration::Dump(ir::SrcDumper *dumper) const if (func->IsNative()) { dumper->Add("native "); } - if (IsExported()) { - dumper->Add("export "); - } else if (IsDefaultExported()) { - dumper->Add("export default "); - } - if (func->IsDeclare() && !(parent_ != nullptr && parent_->IsDeclare())) { + if (func->IsDeclare()) { dumper->Add("declare "); } if (func->IsAsyncFunc()) { diff --git a/ets2panda/test/ast/compiler/ets/export_and_export_type_class.ets b/ets2panda/test/ast/compiler/ets/export_and_export_type_class.ets index ba28d7a7b82..57d8b40dda0 100644 --- a/ets2panda/test/ast/compiler/ets/export_and_export_type_class.ets +++ b/ets2panda/test/ast/compiler/ets/export_and_export_type_class.ets @@ -15,3 +15,5 @@ export class A {} export type {/* @@ label */A} + +/* @@@ label Error SyntaxError: Cannot export 'A', it was already exported. */ diff --git a/ets2panda/test/ast/compiler/ets/export_and_export_type_interface.ets b/ets2panda/test/ast/compiler/ets/export_and_export_type_interface.ets index 201b28a8dde..0b4bef44310 100644 --- a/ets2panda/test/ast/compiler/ets/export_and_export_type_interface.ets +++ b/ets2panda/test/ast/compiler/ets/export_and_export_type_interface.ets @@ -15,3 +15,5 @@ export interface I {} export type {/* @@ label */I} + +/* @@@ label Error SyntaxError: Cannot export 'I', it was already exported. */ diff --git a/ets2panda/test/ast/compiler/ets/export_same_type_at_decl_and_selective_binding.ets b/ets2panda/test/ast/compiler/ets/export_same_type_at_decl_and_selective_binding.ets index 206cbcabbfd..e566df5aae0 100644 --- a/ets2panda/test/ast/compiler/ets/export_same_type_at_decl_and_selective_binding.ets +++ b/ets2panda/test/ast/compiler/ets/export_same_type_at_decl_and_selective_binding.ets @@ -15,3 +15,6 @@ export type class A {} export type {/* @@ label */A} + + +/* @@@ label Error SyntaxError: Cannot export 'A', it was already exported. */ diff --git a/ets2panda/test/ast/compiler/ets/export_type_class_multiple_times.ets b/ets2panda/test/ast/compiler/ets/export_type_class_multiple_times.ets index 4a2147118c7..4609849c5dd 100644 --- a/ets2panda/test/ast/compiler/ets/export_type_class_multiple_times.ets +++ b/ets2panda/test/ast/compiler/ets/export_type_class_multiple_times.ets @@ -19,4 +19,5 @@ export type {A} export type MyA = A export type {MyA} -/* @@? 16:1 Warning Warning: Duplicated export aliases for 'MyA'. */ +/* @@? 20:14 Error SyntaxError: The given name 'MyA' is already used in another export. */ +/* @@? 20:14 Error SyntaxError: Cannot export 'MyA', it was already exported. */ diff --git a/ets2panda/test/ast/compiler/ets/export_type_interface_multiple_times.ets b/ets2panda/test/ast/compiler/ets/export_type_interface_multiple_times.ets index c714b60e24c..0a34b8a2ccc 100644 --- a/ets2panda/test/ast/compiler/ets/export_type_interface_multiple_times.ets +++ b/ets2panda/test/ast/compiler/ets/export_type_interface_multiple_times.ets @@ -18,3 +18,6 @@ interface I {} export type {I} export type MyI = I export type {MyI} + +/* @@? 20:14 Error SyntaxError: The given name 'MyI' is already used in another export. */ +/* @@? 20:14 Error SyntaxError: Cannot export 'MyI', it was already exported. */ diff --git a/ets2panda/test/ast/compiler/ets/import_tests/export_multi_error.ets b/ets2panda/test/ast/compiler/ets/import_tests/export_multi_error.ets index 1bcecf5a368..c02f3a526ae 100644 --- a/ets2panda/test/ast/compiler/ets/import_tests/export_multi_error.ets +++ b/ets2panda/test/ast/compiler/ets/import_tests/export_multi_error.ets @@ -58,6 +58,11 @@ export default function TestFuncToo(): void {} /*-----------------*/ /* @@? 16:10 Error SyntaxError: Cannot find name 'foo' to export. */ -/* @@? 27:14 Error SyntaxError: Cannot export two different names with the same export alias name 'foo2'. */ +/* @@? 27:14 Error SyntaxError: The given name 'foo2' is already used in another export. */ +/* @@? 27:27 Error SyntaxError: The given name 'foo2' is already used in another export. */ +/* @@? 33:11 Error SyntaxError: Cannot export 'foo3', it was already exported. */ +/* @@? 39:19 Error SyntaxError: Cannot export 'A', it was already exported. */ +/* @@? 46:14 Error SyntaxError: The given name 'MyI' is already used in another export. */ +/* @@? 46:14 Error SyntaxError: Cannot export 'MyI', it was already exported. */ /* @@? 56:16 Error TypeError: Only one default export is allowed in a module */ /* @@? 57:16 Error TypeError: Only one default export is allowed in a module */ diff --git a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/export_type_several_times_1.ets b/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/export_type_several_times_1.ets deleted file mode 100644 index 3262d1a8397..00000000000 --- a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/export_type_several_times_1.ets +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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. - */ - -export function foo(): void {} -export class A {} - -export { - foo as f1, - foo as f2, - A as a1, - A as a2 -} diff --git a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/export_type_several_times_2.ets b/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/export_type_several_times_2.ets deleted file mode 100644 index 54f88f12e3d..00000000000 --- a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/export_type_several_times_2.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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. - */ - -function foo(): void {} -class A {} -let a = new A() - -export { - foo as f1, - foo as f2, - A as a1, - A as a2, - a as a3, - a as a4 -} diff --git a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/import_same_type_form_alias_1.ets b/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/import_same_type_form_alias_1.ets deleted file mode 100644 index f3d2d5d4dce..00000000000 --- a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/import_same_type_form_alias_1.ets +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ - -import { foo, f1, f2, A, a1, a2 } from "./export_type_several_times_1.ets" - -foo() -f1() -f2() -let c: A = new A() -let c1: A = new a1() -let c2: A = new a2() \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/import_same_type_form_alias_2.ets b/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/import_same_type_form_alias_2.ets deleted file mode 100644 index 91be1a73dbe..00000000000 --- a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/import_same_type_form_alias_2.ets +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ - -import { f1, f2, a1, a2, a3, a4 } from "./export_type_several_times_2.ets" - -f1() -f2() -let c1: a1 = new a1() -let c2: a2 = new a2() -c1 = a3 -c2 = a4 \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/import_same_type_form_alias_3.ets b/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/import_same_type_form_alias_3.ets deleted file mode 100644 index fec071802f9..00000000000 --- a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/import_same_type_form_alias_3.ets +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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. - */ - -import { foo, f1, f2, A, a1, a2 } from "./export_type_several_times_2.ets" - -f1() -f2() -let c1: a1 = new a1() -let c2: a2 = new a2() - -/* @@? 16:10 Error TypeError: Cannot find imported element 'foo' */ -/* @@? 16:23 Error TypeError: Cannot find imported element 'A' */ diff --git a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/selective_export_clashing_exports_1.ets b/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/selective_export_clashing_exports_1.ets index bddda705c6d..453e606be33 100644 --- a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/selective_export_clashing_exports_1.ets +++ b/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/selective_export_clashing_exports_1.ets @@ -16,5 +16,7 @@ export function foo(): void {} export { - foo as bar + foo as /* @@ label */bar } + +/* @@@ label Error SyntaxError: Cannot export 'foo', it was already exported. */ diff --git a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/selective_export_clashing_exports_2.ets b/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/selective_export_clashing_exports_2.ets index a75a5dbac45..b5eeab80f63 100644 --- a/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/selective_export_clashing_exports_2.ets +++ b/ets2panda/test/ast/compiler/ets/import_tests/selective_export_tests/selective_export_clashing_exports_2.ets @@ -16,5 +16,7 @@ export default function foo(): void {} export { - foo as bar + foo as /* @@ label */bar } + +/* @@@ label Error SyntaxError: Cannot export 'foo', it was already exported. */ diff --git a/ets2panda/test/ast/compiler/ets/namespaceExport_neg.ets b/ets2panda/test/ast/compiler/ets/namespaceExport_neg.ets index fb3ea3bbd88..e742a4cdc82 100644 --- a/ets2panda/test/ast/compiler/ets/namespaceExport_neg.ets +++ b/ets2panda/test/ast/compiler/ets/namespaceExport_neg.ets @@ -30,3 +30,5 @@ declare namespace A { } export default A +/* @@? 27:20 Error SyntaxError: Cannot export 'A', it was already exported. */ + diff --git a/ets2panda/test/ast/parser/ets/import_tests/type/type_2.ets b/ets2panda/test/ast/parser/ets/import_tests/type/type_2.ets index 7cab79843aa..aa88265896a 100644 --- a/ets2panda/test/ast/parser/ets/import_tests/type/type_2.ets +++ b/ets2panda/test/ast/parser/ets/import_tests/type/type_2.ets @@ -16,3 +16,5 @@ export class A {} export type {A as AA}; + +/* @@? 18:19 Error SyntaxError: Cannot export 'A', it was already exported. */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/import_tests/type/type_3.ets b/ets2panda/test/ast/parser/ets/import_tests/type/type_3.ets index ea9cf69480b..0b9164b765f 100644 --- a/ets2panda/test/ast/parser/ets/import_tests/type/type_3.ets +++ b/ets2panda/test/ast/parser/ets/import_tests/type/type_3.ets @@ -19,4 +19,5 @@ class TestClass {} export {foo} export type {TestClass as foo} -/* @@? 20:14 Error SyntaxError: Cannot export two different names with the same export alias name 'foo'. */ +/* @@? 20:14 Error SyntaxError: The given name 'foo' is already used in another export. */ +/* @@? 20:27 Error SyntaxError: The given name 'foo' is already used in another export. */ diff --git a/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt b/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt index 39fca20a23b..f6ce7f89771 100644 --- a/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt +++ b/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt @@ -163,9 +163,4 @@ ast/parser/ets/unexpected_token_62.ets #26984 ast/parser/ets/primitive_type_method_2.ets -ast/parser/ets/staticFunctionCallOfObject.ets - -# Issue: #27365 Cannot add correct comment to astchecker to see warning with 0:0 position (duplicate export warning) -ast/compiler/ets/export_type_class_multiple_times.ets -ast/compiler/ets/export_type_interface_multiple_times.ets -ast/compiler/ets/import_tests/export_multi_error.ets \ No newline at end of file +ast/parser/ets/staticFunctionCallOfObject.ets \ No newline at end of file diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index 55c4bfe1693..be4c8ab3932 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -109,10 +109,6 @@ syntax: id: 217 message: "A binding pattern parameter cannot be optional in an implementation signature." -- name: CANNOT_EXPORT_DIFFERENT_OBJECTS_WITH_SAME_NAME - id: 344 - message: "Cannot export two different names with the same export alias name '{}'." - - name: CAN_NOT_FIND_NAME_TO_EXPORT id: 279 message: "Cannot find name '{}' to export." diff --git a/ets2panda/util/diagnostic/warning.yaml b/ets2panda/util/diagnostic/warning.yaml index 59820b70e1b..49f08b5c8e8 100644 --- a/ets2panda/util/diagnostic/warning.yaml +++ b/ets2panda/util/diagnostic/warning.yaml @@ -25,10 +25,6 @@ warning: id: 4 message: "Boost Equality Statement. Change sides of binary expression." -- name: DUPLICATE_EXPORT_ALIASES - id: 73 - message: "Duplicated export aliases for '{}'." - - name: DUPLICATE_SIGS id: 12 message: "Detect duplicate signatures, use '{}{}' to replace" diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index ff783ab4364..bc544f0631a 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -190,20 +190,11 @@ void ETSBinder::ResolveReferencesForScopeWithContext(ir::AstNode *node, Scope *s ResolveReference(node); } -// export { a as b } value => a, key => b -// value == value and key == key => Warning, value == value and key != key => Ok, value != value and key == key => CTE -bool ETSBinder::AddSelectiveExportAlias(parser::ETSParser *parser, util::StringView const &path, - util::StringView const &key, util::StringView const &value, - ir::AstNode const *decl) noexcept +bool ETSBinder::AddSelectiveExportAlias(util::StringView const &path, util::StringView const &key, + util::StringView const &value, ir::AstNode const *decl) noexcept { if (auto foundMap = selectiveExportAliasMultimap_.find(path); foundMap != selectiveExportAliasMultimap_.end()) { - auto inserted = foundMap->second.insert({key, std::make_pair(value, decl)}).second; - if (UNLIKELY(!inserted && foundMap->second.find(key)->second.first == value)) { - parser->DiagnosticEngine().Log( - {util::DiagnosticType::WARNING, diagnostic::DUPLICATE_EXPORT_ALIASES, {key}, decl->Start()}); - return true; - } - return inserted; + return foundMap->second.insert({key, std::make_pair(value, decl)}).second; } ArenaMap> map(Allocator()->Adapter()); @@ -764,8 +755,7 @@ Variable *ETSBinder::FindImportSpecifiersVariable(const util::StringView &import static bool IsExportedVariable(varbinder::Variable *const var) { return var != nullptr && - (var->Declaration()->Node()->IsExported() || var->Declaration()->Node()->IsDefaultExported() || - var->Declaration()->Node()->HasExportAlias()); + (var->Declaration()->Node()->IsExported() || var->Declaration()->Node()->IsDefaultExported()); } std::pair ETSBinder::FindImportDeclInExports( @@ -902,7 +892,7 @@ void ETSBinder::ValidateImportVariable(const ir::AstNode *node, const util::Stri { if (node->IsDefaultExported()) { ThrowError(importPath->Start(), diagnostic::DEFAULT_EXPORT_DIRECT_IMPORTED); - } else if (!node->IsExported() && !node->IsDefaultExported() && !node->HasExportAlias()) { + } else if (!node->IsExported() && !node->IsDefaultExported()) { ThrowError(importPath->Start(), diagnostic::IMPORTED_NOT_EXPORTED, {imported}); } } @@ -1022,9 +1012,8 @@ bool ETSBinder::AddImportSpecifiersToTopBindings(Span re } // The first part of the condition will be true, if something was given an alias when exported, but we try - // to import it using its original name and if original name is not exported. - if (nameToSearchFor == imported && var->Declaration()->Node()->HasExportAlias() && - !var->Declaration()->Node()->IsExported()) { + // to import it using its original name. + if (nameToSearchFor == imported && var->Declaration()->Node()->HasExportAlias()) { ThrowError(importSpecifier->Start(), diagnostic::IMPORT_NOT_FOUND, {imported}); return false; } diff --git a/ets2panda/varbinder/ETSBinder.h b/ets2panda/varbinder/ETSBinder.h index 091f30c6891..001a02cb105 100644 --- a/ets2panda/varbinder/ETSBinder.h +++ b/ets2panda/varbinder/ETSBinder.h @@ -23,7 +23,6 @@ #include "ir/expressions/identifier.h" #include "ir/module/importSpecifier.h" #include "ir/statements/annotationDeclaration.h" -#include "parser/ETSparser.h" namespace ark::es2panda::ir { class ETSImportDeclaration; @@ -251,9 +250,8 @@ public: void ResolveReferencesForScopeWithContext(ir::AstNode *node, Scope *scope); - [[nodiscard]] bool AddSelectiveExportAlias(parser::ETSParser *parser, util::StringView const &path, - util::StringView const &key, util::StringView const &value, - ir::AstNode const *decl) noexcept; + [[nodiscard]] bool AddSelectiveExportAlias(util::StringView const &path, util::StringView const &key, + util::StringView const &value, ir::AstNode const *decl) noexcept; [[nodiscard]] const ModulesToExportedNamesWithAliases &GetSelectiveExportAliasMultimap() const noexcept { diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index 1e1c3112913..010ccd2e8a7 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -674,7 +674,7 @@ Scope::InsertResult GlobalScope::InsertImpl(const util::StringView &name, Variab ES2PANDA_ASSERT(var->Declaration()->Name().Utf8().find(compiler::Signatures::ETS_GLOBAL) == std::string::npos); const auto *const node = var->Declaration()->Node(); - if (!(node->IsExported() || node->IsDefaultExported() || node->HasExportAlias())) { + if (!(node->IsExported() || node->IsDefaultExported())) { return Scope::InsertResult {Bindings().end(), false}; } } -- Gitee