diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 3aa4109c2eb8eb2d86c89482000a32026599fdd0..a23c731a180bb2a7a358e561418bb5d2f6e70870 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -3664,4 +3664,9 @@ checker::Type *ETSAnalyzer::ReturnTypeForStatement([[maybe_unused]] const ir::St return nullptr; } +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSModuleDeclaration *st) const +{ + return nullptr; +} + } // namespace ark::es2panda::checker diff --git a/ets2panda/checker/ETSAnalyzerUnreachable.cpp b/ets2panda/checker/ETSAnalyzerUnreachable.cpp index f0c54c5924a652d64c423ffd410dab66ffa7ed0d..bfa1194764df68ab3ebb2602df104442c82c88e7 100644 --- a/ets2panda/checker/ETSAnalyzerUnreachable.cpp +++ b/ets2panda/checker/ETSAnalyzerUnreachable.cpp @@ -296,11 +296,6 @@ checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSModuleBlock *st) const ES2PANDA_UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSModuleDeclaration *st) const -{ - ES2PANDA_UNREACHABLE(); -} - checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSNamedTupleMember *node) const { ES2PANDA_UNREACHABLE(); diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp index 49e83d88f12ae77fafa5fa761d5eac740cb7f648..6a2c4c2bc9cbf371250230f7d9aba1ce18f179e9 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -377,7 +377,9 @@ void ScopesInitPhase::VisitExportNamedDeclaration(ir::ExportNamedDeclaration *ex auto *decl = AddOrGetDecl(VarBinder(), spec->Local()->Name(), spec, exportDecl->Start(), spec->Exported()->Name(), spec->Local()->Name(), spec); - exportDecls.push_back(decl); + if (decl != nullptr) { + exportDecls.push_back(decl); + } } VarBinder()->GetScope()->AsModuleScope()->AddExportDecl(exportDecl, std::move(exportDecls)); } @@ -570,7 +572,9 @@ void ScopeInitTyped::VisitTSModuleDeclaration(ir::TSModuleDeclaration *moduleDec if (!moduleDecl->IsExternalOrAmbient()) { auto name = moduleDecl->Name()->AsIdentifier()->Name(); auto *decl = AddOrGetDecl(VarBinder(), name, moduleDecl, moduleDecl->Name()->Start(), name); - decl->BindNode(moduleDecl); + if (decl != nullptr) { + decl->BindNode(moduleDecl); + } } auto localCtx = LexicalScopeCreateOrEnter(VarBinder(), moduleDecl); BindScopeNode(localCtx.GetScope(), moduleDecl); @@ -631,7 +635,9 @@ void ScopeInitTyped::VisitTSInterfaceDeclaration(ir::TSInterfaceDeclaration *int auto localScope = LexicalScopeCreateOrEnter(VarBinder(), interfDecl); auto *identDecl = AddOrGetDecl(VarBinder(), ident->Name(), interfDecl, ident->Start(), ident->Name()); - identDecl->BindNode(interfDecl); + if (identDecl != nullptr) { + identDecl->BindNode(interfDecl); + } BindScopeNode(localScope.GetScope(), interfDecl); CallNode(interfDecl->Body()); diff --git a/ets2panda/test/ast/compiler/ets/declare_tsmodule.ets b/ets2panda/test/ast/compiler/ets/declare_tsmodule.ets new file mode 100644 index 0000000000000000000000000000000000000000..cd3f7e49a246db776512d3ea8d5116d82ecccf32 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/declare_tsmodule.ets @@ -0,0 +1,24 @@ +/* + * 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. + */ + +declare namespace "Foo" { + +} + +function main(): void { + +} + +/* @@? 16:19 Error SyntaxError: Unexpected token, expected an identifier. */