diff --git a/ets2panda/compiler/core/compilerImpl.cpp b/ets2panda/compiler/core/compilerImpl.cpp index 74f75da500434aa44008f5aaf14ea5ee51bc9f70..de5dc96a95cff5adea109d1f7c22249b43769b69 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 182e3aaa09e3202404db294ea0ee665c630059cd..6765b38bfef232ae2a18dc32899353230bdfe883 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 8980d26a49e772f4aac9067270b5763cf993e5d5..ecf63af123b69ce0fe5f42878d9f50c54e15e10b 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 0000000000000000000000000000000000000000..3b317edbee278710ae232b74a6ba04ba674b2a22 --- /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 0000000000000000000000000000000000000000..de443aabb2878b6eceb9c5850570dfbe45bf1019 --- /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 0000000000000000000000000000000000000000..3f255a03448e33d676b10242d661e169ef971ffd --- /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 0000000000000000000000000000000000000000..de56ccc5bd84ed5950131047f736074732c58d60 --- /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 22bf3b6f48301a1117aae46e01affdc0b5769d59..5cf3fc0caefe92c227f82067ffb1ea1b8794ba76 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 4625e5f011d23cce9335194492f80587e2da3073..09cbee9aef3c73b4fc4aa121c00ec6756e748b43 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 d8701598bd2d46f1fa646fed8afaa85f2968d76a..43875f6d2281081f803bdaf528b5419ada55e79a 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 };