From d18810a85101204b02ca7d18ea979a3f61da3cc2 Mon Sep 17 00:00:00 2001 From: yanpeng51 Date: Mon, 4 Aug 2025 16:09:36 +0800 Subject: [PATCH] "Fix compilation test failure" Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICSHCK Signed-off-by: yanpeng51 --- .../lowering/ets/exportAnonymousConst.cpp | 7 +++++ .../ets/default_test/export_default.ets | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/default_test/export_default.ets diff --git a/ets2panda/compiler/lowering/ets/exportAnonymousConst.cpp b/ets2panda/compiler/lowering/ets/exportAnonymousConst.cpp index 26a2f43910..5677874aea 100644 --- a/ets2panda/compiler/lowering/ets/exportAnonymousConst.cpp +++ b/ets2panda/compiler/lowering/ets/exportAnonymousConst.cpp @@ -65,6 +65,13 @@ static void HandleAnonymousConst(public_lib::Context *const ctx, parser::Program auto &stmt = module->StatementsForUpdates(); auto iterator = std::find_if(stmt.begin(), stmt.end(), isExportAnonymousConst); + [[maybe_unused]] const size_t exportDefaultMaxSize = 1; + if ((*iterator)->AsExportNamedDeclaration()->Specifiers().size() != exportDefaultMaxSize) { + ctx->GetChecker()->AsETSChecker()->LogError(diagnostic::MULTIPLE_DEFAULT_EXPORTS, + (*iterator)->AsExportNamedDeclaration()->Start()); + return; + } + auto *anonymousVariableDecl = CreateAnonymousVariableDecl(ctx, (*iterator)->AsExportNamedDeclaration())->AsStatement(); stmt.insert(iterator, anonymousVariableDecl); diff --git a/ets2panda/test/ast/compiler/ets/default_test/export_default.ets b/ets2panda/test/ast/compiler/ets/default_test/export_default.ets new file mode 100644 index 0000000000..6bc32fae02 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/default_test/export_default.ets @@ -0,0 +1,26 @@ +/* + * 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. + */ + +const val = 100; +export { val as default }; + +export { default } from '.'; + +/* @@? 19:8 Error TypeError: Only one default export is allowed in a module */ +/* @@? 19:18 Error SyntaxError: Unexpected token, expected 'as'. */ +/* @@? 19:18 Error SyntaxError: Unexpected token '}'. */ +/* @@? 19:20 Error SyntaxError: Cannot find name 'from' to export. */ +/* @@? 19:20 Error SyntaxError: Cannot find name 'gensym%%_anonymous_const' to export. */ +/* @@? 19:25 Error SyntaxError: Unexpected token, expected ',' or '}'. */ -- Gitee