From 04d0466b2c2d4107461647d5d05bcfab06d5b058 Mon Sep 17 00:00:00 2001 From: Sergey Ignatov Date: Mon, 16 Jun 2025 14:35:36 +0300 Subject: [PATCH] Fix for self import test Signed-off-by: Sergey Ignatov --- ets2panda/compiler/core/compilerImpl.cpp | 3 ++- ets2panda/test/tsconfig/CMakeLists.txt | 5 ++--- .../test/tsconfig/test-build/CMakeLists.txt | 1 + .../test-build/selfimport/expected.txt | 2 ++ .../tsconfig/test-build/selfimport/main.ets | 18 ++++++++++++++++++ .../tsconfig/test-build/selfimport/test.ets | 16 ++++++++++++++++ .../test-build/selfimport/tsconfig.json | 9 +++++++++ ets2panda/util/options.yaml | 2 +- ets2panda/varbinder/scope.cpp | 15 +++++++++++++++ ets2panda/varbinder/scope.h | 3 +++ 10 files changed, 69 insertions(+), 5 deletions(-) create mode 100755 ets2panda/test/tsconfig/test-build/selfimport/expected.txt create mode 100644 ets2panda/test/tsconfig/test-build/selfimport/main.ets create mode 100644 ets2panda/test/tsconfig/test-build/selfimport/test.ets create mode 100644 ets2panda/test/tsconfig/test-build/selfimport/tsconfig.json diff --git a/ets2panda/compiler/core/compilerImpl.cpp b/ets2panda/compiler/core/compilerImpl.cpp index 74f75da500..de5dc96a95 100644 --- a/ets2panda/compiler/core/compilerImpl.cpp +++ b/ets2panda/compiler/core/compilerImpl.cpp @@ -332,7 +332,8 @@ static void SavePermanents(public_lib::Context *ctx, parser::Program *program) } } for (auto &&key : declaredKeys) { - topScope->EraseBinding(key); + topScope->ForceEraseBinding(key); + topScope->ForceEraseForeignBinding(key); } auto *varbinder = static_cast(program->VarBinder()); diff --git a/ets2panda/test/tsconfig/CMakeLists.txt b/ets2panda/test/tsconfig/CMakeLists.txt index 182e3aaa09..6765b38bfe 100644 --- a/ets2panda/test/tsconfig/CMakeLists.txt +++ b/ets2panda/test/tsconfig/CMakeLists.txt @@ -16,6 +16,5 @@ if(NOT PANDA_REGRESSION_TESTS) endif() add_subdirectory(test-config) -# 25872 -# add_subdirectory(test-build) -# add_subdirectory(test-decl) +add_subdirectory(test-build) +add_subdirectory(test-decl) diff --git a/ets2panda/test/tsconfig/test-build/CMakeLists.txt b/ets2panda/test/tsconfig/test-build/CMakeLists.txt index 8980d26a49..ecf63af123 100644 --- a/ets2panda/test/tsconfig/test-build/CMakeLists.txt +++ b/ets2panda/test/tsconfig/test-build/CMakeLists.txt @@ -28,3 +28,4 @@ add_es2panda_tsconfig_test(extends) add_es2panda_tsconfig_test(include) add_es2panda_tsconfig_test(paths) add_es2panda_tsconfig_test(glob-include) +add_es2panda_tsconfig_test(selfimport) diff --git a/ets2panda/test/tsconfig/test-build/selfimport/expected.txt b/ets2panda/test/tsconfig/test-build/selfimport/expected.txt new file mode 100755 index 0000000000..3b317edbee --- /dev/null +++ b/ets2panda/test/tsconfig/test-build/selfimport/expected.txt @@ -0,0 +1,2 @@ +./build/main.abc +./build/test.abc diff --git a/ets2panda/test/tsconfig/test-build/selfimport/main.ets b/ets2panda/test/tsconfig/test-build/selfimport/main.ets new file mode 100644 index 0000000000..de443aabb2 --- /dev/null +++ b/ets2panda/test/tsconfig/test-build/selfimport/main.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. + */ + +import * as __main from "./main" +import * as __test from "./test" +function main(){console.log("in main")} diff --git a/ets2panda/test/tsconfig/test-build/selfimport/test.ets b/ets2panda/test/tsconfig/test-build/selfimport/test.ets new file mode 100644 index 0000000000..3f255a0344 --- /dev/null +++ b/ets2panda/test/tsconfig/test-build/selfimport/test.ets @@ -0,0 +1,16 @@ +/* + * 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 * as __test from "./test" diff --git a/ets2panda/test/tsconfig/test-build/selfimport/tsconfig.json b/ets2panda/test/tsconfig/test-build/selfimport/tsconfig.json new file mode 100644 index 0000000000..de56ccc5bd --- /dev/null +++ b/ets2panda/test/tsconfig/test-build/selfimport/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "outDir": "build" + }, + "files": [ + "test.ets", + "main.ets" + ] +} diff --git a/ets2panda/util/options.yaml b/ets2panda/util/options.yaml index 22bf3b6f48..5cf3fc0cae 100644 --- a/ets2panda/util/options.yaml +++ b/ets2panda/util/options.yaml @@ -372,5 +372,5 @@ options: - name: perm-arena type: bool - default: false + default: true description: Place AST trees in permanent arena diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index 4625e5f011..09cbee9aef 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -120,6 +120,11 @@ Scope::VariableMap::size_type Scope::EraseBinding(const util::StringView &name) return bindings_.erase(name); } +void Scope::ForceEraseBinding(const util::StringView &name) +{ + bindings_.erase(name); +} + ConstScopeFindResult Scope::FindInGlobal(const util::StringView &name, const ResolveBindingOptions options) const { const auto *scopeIter = this; @@ -623,6 +628,16 @@ Scope::VariableMap::size_type GlobalScope::EraseBinding(const util::StringView & return erased; } +void GlobalScope::ForceEraseBinding(const util::StringView &name) +{ + Scope::ForceEraseBinding(name); +} + +void GlobalScope::ForceEraseForeignBinding(const util::StringView &name) +{ + foreignBindings_.erase(name); +} + Scope::InsertResult GlobalScope::InsertForeignBinding(const util::StringView &name, Variable *const var) { return GlobalScope::InsertImpl(name, var, InsertBindingFlags::FOREIGN); diff --git a/ets2panda/varbinder/scope.h b/ets2panda/varbinder/scope.h index d8701598bd..43875f6d22 100644 --- a/ets2panda/varbinder/scope.h +++ b/ets2panda/varbinder/scope.h @@ -249,6 +249,7 @@ public: virtual InsertResult TryInsertBinding(const util::StringView &name, Variable *var); virtual void MergeBindings(VariableMap const &bindings); virtual VariableMap::size_type EraseBinding(const util::StringView &name); + void ForceEraseBinding(const util::StringView &name); [[nodiscard]] const VariableMap &Bindings() const noexcept { @@ -894,6 +895,8 @@ public: [[nodiscard]] bool IsForeignBinding(const util::StringView &name) const; InsertResult InsertDynamicBinding(const util::StringView &name, Variable *var); + void ForceEraseBinding(const util::StringView &name); + void ForceEraseForeignBinding(const util::StringView &name); private: enum class InsertBindingFlags : uint8_t { NONE = 0, FOREIGN = 1U << 0U, DYNAMIC = 1U << 1U, ASSIGN = 1U << 2U }; -- Gitee