diff --git a/es2panda/binder/variable.cpp b/es2panda/binder/variable.cpp index 2d5536c11207a7b6b4afbb4ddab8f27e24d7ffe4..14ee1f3ee99c44556368fb9cd21b428d7f510296 100644 --- a/es2panda/binder/variable.cpp +++ b/es2panda/binder/variable.cpp @@ -50,11 +50,11 @@ void LocalVariable::SetLexical(Scope *scope, util::PatchFix *patchFixHelper) uint32_t slot = 0; auto name = Declaration()->Name(); - if (patchFixHelper && patchFixHelper->IsScopeValidToPatchLexical(varScope)) { + if (patchFixHelper && !patchFixHelper->IsHotReload() && patchFixHelper->IsScopeValidToPatchLexical(varScope)) { slot = patchFixHelper->GetSlotIdFromSymbolTable(std::string(name)); if (patchFixHelper->IsPatchVar(slot)) { patchFixHelper->AllocSlotfromPatchEnv(std::string(name)); - } + } } else { slot = varScope->NextSlot(); } diff --git a/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/base.js b/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/base.js new file mode 100644 index 0000000000000000000000000000000000000000..2d829a51e7452ed852b889246712b1f464763eef --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/base.js @@ -0,0 +1,8 @@ +let a = 1; +let b = 1; +let c = 1; +function A() { + a = 2; + b = 2; + c = 2; +} \ No newline at end of file diff --git a/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/base_mod.js b/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..5761bc6f08c4e1cf529aa90f5216ac014f4e7949 --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/base_mod.js @@ -0,0 +1,8 @@ +let a = 1; +let b = 2; +let c = 1; +function A() { + a = 4; + b = 2; + c = 3; +} diff --git a/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/expected.txt b/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..f79be095e6f9f04da8406bce072d4e7c18b340a0 --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/exist-lexenv-3/expected.txt @@ -0,0 +1,53 @@ +# Copyright (c) 2023 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. +.language ECMAScript + +.function any .A(any a0, any a1, any a2) { +label_1: +label_0: + ldlexvar 0x0, 0x0 + throw.undefinedifholewithname a + ldai 0x4 + stlexvar 0x0, 0x0 + ldlexvar 0x0, 0x1 + throw.undefinedifholewithname b + ldai 0x2 + stlexvar 0x0, 0x1 + ldlexvar 0x0, 0x2 + throw.undefinedifholewithname c + ldai 0x3 + stlexvar 0x0, 0x2 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + newlexenv 0x3 + definefunc 0x0, .A, 0x0 + ldai 0x1 + sta v0 + lda v0 + stlexvar 0x0, 0x0 + ldai 0x2 + stlexvar 0x0, 0x1 + lda v0 + stlexvar 0x0, 0x2 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/base.js b/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/base.js new file mode 100644 index 0000000000000000000000000000000000000000..b377a08164dffb24d314854e1fa897e8fda03946 --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/base.js @@ -0,0 +1,9 @@ +let a = 1; +let b = 1; +let c = 1; +function A() { + let d = a + b; + let e = 3; + let m = d + e; + return m; +} diff --git a/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/base_mod.js b/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..f9fecd7991c6d52296e178c72975aa6440afa875 --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/base_mod.js @@ -0,0 +1,10 @@ +let a = 1; +let b = 1; +let c = 1; +let n = 2; +function A() { + let d = a + b + c; + let e = 3; + let m = d + e + n; + return m; +} diff --git a/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/expected.txt b/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..5d8ca0489d4fbff9566e8e36432536b3d4e81082 --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/lexenv-increase/expected.txt @@ -0,0 +1,65 @@ +# Copyright (c) 2023 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. +.language ECMAScript + +.function any .A(any a0, any a1, any a2) { +label_1: +label_0: + ldlexvar 0x0, 0x0 + sta v0 + throw.undefinedifholewithname a + ldlexvar 0x0, 0x1 + sta v1 + throw.undefinedifholewithname b + lda v1 + add2 0x0, v0 + sta v0 + ldlexvar 0x0, 0x2 + sta v1 + throw.undefinedifholewithname c + lda v1 + add2 0x1, v0 + sta v0 + ldai 0x3 + add2 0x2, v0 + sta v0 + ldlexvar 0x0, 0x3 + sta v1 + throw.undefinedifholewithname n + lda v1 + add2 0x3, v0 + return +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + newlexenv 0x4 + definefunc 0x0, .A, 0x0 + ldai 0x1 + sta v0 + lda v0 + stlexvar 0x0, 0x0 + lda v0 + stlexvar 0x0, 0x1 + lda v0 + stlexvar 0x0, 0x2 + ldai 0x2 + stlexvar 0x0, 0x3 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base.js b/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base.js new file mode 100644 index 0000000000000000000000000000000000000000..b377a08164dffb24d314854e1fa897e8fda03946 --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base.js @@ -0,0 +1,9 @@ +let a = 1; +let b = 1; +let c = 1; +function A() { + let d = a + b; + let e = 3; + let m = d + e; + return m; +} diff --git a/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base_mod.js b/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..3f9da8bb7be1c5ff93229a5efd319cdac53be17c --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/base_mod.js @@ -0,0 +1,9 @@ +let a = 1; +let b = 1; +let c = 1; +function A() { + let d = a; + let e = 3; + let m = d + e; + return m; +} diff --git a/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/expected.txt b/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d94e48e6757495807626b83e50b6b984325a56ae --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/lexenv-reduce/expected.txt @@ -0,0 +1,39 @@ +# Copyright (c) 2023 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. +.language ECMAScript + +.function any .A(any a0, any a1, any a2) { +label_1: +label_0: + ldlexvar 0x0, 0x0 + sta v0 + throw.undefinedifholewithname a + ldai 0x3 + add2 0x0, v0 + return +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + newlexenv 0x1 + definefunc 0x0, .A, 0x0 + ldai 0x1 + stlexvar 0x0, 0x0 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 91b2bab2096af640e2cc686720ca9088bd901e21..9d86b1d2023c9e8d0ae598d9f71ac690cec690c6 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -1083,9 +1083,10 @@ class PatchTest(Test): patch_test_cmd.extend([os.path.join(self.path, modified_input_file)]) if 'record-name-with-dots' in os.path.basename(self.path): patch_test_cmd.extend(['--merge-abc', '--record-name=record.name.with.dots']) - if ('modify-anon-content-keep-origin-name' in os.path.basename(self.path) or - 'modify-class-memeber-function' in os.path.basename(self.path)): - patch_test_cmd.extend(['--dump-assembly']) + dump_assembly_testname = ['modify-anon-content-keep-origin-name', 'modify-class-memeber-function', 'exist-lexenv-3', 'lexenv-reduce', 'lexenv-increase'] + for name in dump_assembly_testname: + if name in os.path.basename(self.path): + patch_test_cmd.extend(['--dump-assembly']) self.log_cmd(patch_test_cmd) process_base = subprocess.Popen(gen_base_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)