diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 9e2059c27df99093f40076b6b1ea5a46dc84feab..2462dc583591648f7feb93aaffeabfd436740fc5 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -1103,6 +1103,20 @@ void ETSParser::ReportIfVarDeclaration(VariableParsingFlags flags) } } +ir::Statement *ETSParser::CreateReExportDeclarationNode(ir::ETSImportDeclaration *reExportDeclaration, + const lexer::SourcePosition &startLoc, + const ir::ModifierFlags &modifiers) +{ + if (GetProgram()->AbsoluteName().Is(reExportDeclaration->ResolvedSource())) { + LogError(diagnostic::RE_EXPORTING_LOCAL_BINDINGS_IS_NOT_ALLOWED, {}, startLoc); + return AllocBrokenStatement(startLoc); + } + auto reExport = AllocNode(reExportDeclaration, std::vector(), + GetProgram()->AbsoluteName(), Allocator()); + reExport->AddModifier(modifiers); + return reExport; +} + ir::Statement *ETSParser::ParseExport(lexer::SourcePosition startLoc, ir::ModifierFlags modifiers) { const size_t exportDefaultMaxSize = 1; @@ -1154,10 +1168,7 @@ ir::Statement *ETSParser::ParseExport(lexer::SourcePosition startLoc, ir::Modifi } // re-export directive auto *reExportDeclaration = ParseImportPathBuildImport(std::move(specifiers), true, startLoc, ir::ImportKinds::ALL); - auto reExport = AllocNode(reExportDeclaration, std::vector(), - GetProgram()->AbsoluteName(), Allocator()); - reExport->AddModifier(modifiers); - return reExport; + return CreateReExportDeclarationNode(reExportDeclaration, startLoc, modifiers); } ir::ETSPackageDeclaration *ETSParser::ParsePackageDeclaration() diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index b9be64d56c89daa7a37c2ad3e9a7951555c77af3..a2b40abbd9f1b1db810d7a0647aa15fe018cb12a 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -188,6 +188,9 @@ private: #endif ir::ETSImportDeclaration *ParseImportPathBuildImport(ArenaVector &&specifiers, bool requireFrom, lexer::SourcePosition startLoc, ir::ImportKinds importKind); + ir::Statement *CreateReExportDeclarationNode(ir::ETSImportDeclaration *reExportDeclaration, + const lexer::SourcePosition &startLoc, + const ir::ModifierFlags &modifiers); void ParseNamedExportSpecifiers(ArenaVector *specifiers, bool defaultExport); void ParseUserSources(std::vector userParths); ArenaVector ParseTopLevelDeclaration(); diff --git a/ets2panda/test/ast/parser/ets/re_export/re_export_circular.ets b/ets2panda/test/ast/parser/ets/re_export/re_export_circular.ets new file mode 100644 index 0000000000000000000000000000000000000000..bfc5c191e694bbc02f5ecd1d56f2b6f74f475c7c --- /dev/null +++ b/ets2panda/test/ast/parser/ets/re_export/re_export_circular.ets @@ -0,0 +1,18 @@ +/* + * 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 {foo} from "./re_export_circular.ets" + +/* @@? 16:8 Error SyntaxError: Re-exporting local bindings is not allowed */ diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index 47d782ae5720fba482574599edd9b88bb7ba0c80..fbff3a25f190e17286c181e991a1d66363bff538 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -1053,6 +1053,10 @@ syntax: id: 287 message: "Unexpected return value." +- name: RE_EXPORTING_LOCAL_BINDINGS_IS_NOT_ALLOWED + id: 138237 + message: "Re-exporting local bindings is not allowed" + - name: SETTER_FORMAL_PARAMS id: 63 message: "Setter must have exactly one formal parameter."