diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index 10029782aa46d400f94caa0587a961ca39e3787d..24b44044b9001bbded19889c168be1122fcddf69 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -548,7 +548,8 @@ group("es2panda_build_win") { } group("es2abc_tests") { - deps = [ "./test:es2abc_parser_tests" ] + deps = [ "./test:es2abc_compiler_tests" ] + deps += [ "./test:es2abc_parser_tests" ] deps += [ "./test:es2abc_parser_tsc_tests" ] - deps += [ "./test:es2abc_compiler_tests" ] + deps += [ "./test:es2abc_patch_tests" ] } diff --git a/es2panda/test/BUILD.gn b/es2panda/test/BUILD.gn index 56a3aaa6f792e914b980805c340ded1f8fc3ea10..c310f5130401840e0d83b628cd2910517fe7b503 100644 --- a/es2panda/test/BUILD.gn +++ b/es2panda/test/BUILD.gn @@ -83,15 +83,17 @@ action("es2abc_compiler_tests") { outputs = [ "${es2abc_build_path}/keep_es2abc_compiler_tests_run" ] } -action("es2abc_hotfix_tests") { +action("es2abc_patch_tests") { script = "${es2abc_root}/test/runner.py" deps = es2abc_build_deps args = [ + "--no-progress", "--hotfix", + "--hotreload", rebase_path("${es2abc_build_path}"), ] - outputs = [ "${es2abc_build_path}/keep_es2abc_hotfix_tests_run" ] + outputs = [ "${es2abc_build_path}/keep_es2abc_patch_tests_run" ] } diff --git a/es2panda/test/hotreload/add-anonymous-function/base.js b/es2panda/test/hotreload/add-anonymous-function/base.js new file mode 100644 index 0000000000000000000000000000000000000000..b607d2358b4490bc036878f45f9e6e534e1c8c76 --- /dev/null +++ b/es2panda/test/hotreload/add-anonymous-function/base.js @@ -0,0 +1,18 @@ +/* + * 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. + */ + +(()=>{ + print("anonymous: 1"); +})() diff --git a/es2panda/test/hotreload/add-anonymous-function/base_mod.js b/es2panda/test/hotreload/add-anonymous-function/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..69b38f6fc18ae4e5035aa4d2a5b7259d2d42e111 --- /dev/null +++ b/es2panda/test/hotreload/add-anonymous-function/base_mod.js @@ -0,0 +1,23 @@ +/* + * 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. + */ +// Test scenario: add anonymous function, es2abc can specify and throw error. + +(()=>{ + print("anonymous: 1"); +})() + +(()=>{ + print("anonymous: 2"); // add anonymous function +})() \ No newline at end of file diff --git a/es2panda/test/hotreload/add-anonymous-function/expected.txt b/es2panda/test/hotreload/add-anonymous-function/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..4d0f814fda98c789dedae02afbeb4f129ab83674 --- /dev/null +++ b/es2panda/test/hotreload/add-anonymous-function/expected.txt @@ -0,0 +1,12 @@ +# 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. diff --git a/es2panda/test/hotreload/add-dup-name-function/base.js b/es2panda/test/hotreload/add-dup-name-function/base.js new file mode 100644 index 0000000000000000000000000000000000000000..4e806c169f2468909d2b162e9cb15739582f954f --- /dev/null +++ b/es2panda/test/hotreload/add-dup-name-function/base.js @@ -0,0 +1,22 @@ +/* + * 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. + */ + +function A() { + print("A"); +} + +function B() { + print("B"); +} \ No newline at end of file diff --git a/es2panda/test/hotreload/add-dup-name-function/base_mod.js b/es2panda/test/hotreload/add-dup-name-function/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..3e85e23106bd94895e3519e0fa60f193e399d623 --- /dev/null +++ b/es2panda/test/hotreload/add-dup-name-function/base_mod.js @@ -0,0 +1,27 @@ +/* + * 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. + */ + +// Test scenario: add function which has same name as exits functions, es2abc can specify and throw error. + +function A() { + print("A"); + function B() { // add function B, which has a duplicate name + print("A::B"); + } +} + +function B() { + print("B"); +} \ No newline at end of file diff --git a/es2panda/test/hotreload/add-dup-name-function/expected.txt b/es2panda/test/hotreload/add-dup-name-function/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..4d0f814fda98c789dedae02afbeb4f129ab83674 --- /dev/null +++ b/es2panda/test/hotreload/add-dup-name-function/expected.txt @@ -0,0 +1,12 @@ +# 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. diff --git a/es2panda/test/hotreload/add-lexenv-1/base.js b/es2panda/test/hotreload/add-lexenv-1/base.js new file mode 100644 index 0000000000000000000000000000000000000000..5aa8e624fb64d73ba4b2b4ea70a012722e30b242 --- /dev/null +++ b/es2panda/test/hotreload/add-lexenv-1/base.js @@ -0,0 +1,18 @@ +/* + * 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. + */ + +function A() { + print("base A()"); +} diff --git a/es2panda/test/hotreload/add-lexenv-1/base_mod.js b/es2panda/test/hotreload/add-lexenv-1/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..ce1145f4ed6f1ea404544429f951f423f3dc511d --- /dev/null +++ b/es2panda/test/hotreload/add-lexenv-1/base_mod.js @@ -0,0 +1,29 @@ +/* + * 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. + */ + +// Test scenario: add new lexenv function, function is not in top scope, es2abc can specify and throw error + +function A() { + print("base A()"); + function B() { + print("patch B()"); + } + + function C() { + B(); // make B become a lexenv, and B is not in top scope + } + + C(); +} diff --git a/es2panda/test/hotreload/add-lexenv-1/expected.txt b/es2panda/test/hotreload/add-lexenv-1/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..15b6dd42582ac855ea8676bbc77acdbab5b72aed --- /dev/null +++ b/es2panda/test/hotreload/add-lexenv-1/expected.txt @@ -0,0 +1,17 @@ +# 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. + +[Patch] Found lexical variable added or removed in .A, not supported! +[Patch] Found unsupported change in file, will not generate patch! +Error: [base_mod.js:0:0] +the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/modify-class-1/base.js b/es2panda/test/hotreload/modify-class-1/base.js new file mode 100644 index 0000000000000000000000000000000000000000..d8ea343e9216cc1e108c839baad7d2e6f91861a4 --- /dev/null +++ b/es2panda/test/hotreload/modify-class-1/base.js @@ -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. + */ + +class Car { + constructor(brand) { + this.carname = brand; + } + present() { + return 'I have a ' + this.carname; + } +} + +class Model extends Car { + constructor(brand, mod) { + super(brand); + this.model = mod; + } + show() { + return this.present() + ', it is a ' + this.model; + } + + ["123"]() { // computed properties + return 0; + } +} + +let myCar = new Model("Ford", "Mustang"); \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-class-1/base_mod.js b/es2panda/test/hotreload/modify-class-1/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..96876d2892f699735f3b9861e41904d7c7a0591a --- /dev/null +++ b/es2panda/test/hotreload/modify-class-1/base_mod.js @@ -0,0 +1,46 @@ +/* + * 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. + */ + +// Test scenario: add class attributes, which is before computed properties, es2abc can specify and throw error + +class Car { + constructor(brand) { + this.carname = brand; + } + present() { + return 'I have a ' + this.carname; + } +} + +class Model extends Car { + constructor(brand, mod) { + super(brand); + this.model = mod; + } + + show() { + return this.present() + ', it is a ' + this.model; + } + + a() { // an attribute added before computed properties + + } + + ["123"]() { // computed properties + return 0; + } +} + +let myCar = new Model("Ford", "Mustang"); \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-class-1/expected.txt b/es2panda/test/hotreload/modify-class-1/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..c2769ab6dc4abb2adc0d0ccfb9875a422c6de285 --- /dev/null +++ b/es2panda/test/hotreload/modify-class-1/expected.txt @@ -0,0 +1,17 @@ +# 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. + +[Patch] Found class .Model changed, not supported! +[Patch] Found unsupported change in file, will not generate patch! +Error: [base_mod.js:0:0] +the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/modify-export-1/base.js b/es2panda/test/hotreload/modify-export-1/base.js new file mode 100644 index 0000000000000000000000000000000000000000..150707fb054819247df195559ffe19f1cbee0e49 --- /dev/null +++ b/es2panda/test/hotreload/modify-export-1/base.js @@ -0,0 +1,22 @@ +/* + * 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. + */ + +function v1() { print("v1") } +function v2() { print("v2") } + +export { + v1 as streamV1, + v2 as base, +}; \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-export-1/base_mod.js b/es2panda/test/hotreload/modify-export-1/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..070b50ffab9720931ba5f4487b7edb1f43660aa2 --- /dev/null +++ b/es2panda/test/hotreload/modify-export-1/base_mod.js @@ -0,0 +1,24 @@ +/* + * 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. + */ + +// Test scenario: modify export variable's name, es2abc can specify and throw error + +function v1() { print("v1") } +function v2() { print("v2") } + +export { + v1 as streamV1, + v2 as patch, // modify export variable's name from 'base' to 'patch' +}; \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-export-1/expected.txt b/es2panda/test/hotreload/modify-export-1/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e574e0591d712df221689c96ba8f2ee630f439d --- /dev/null +++ b/es2panda/test/hotreload/modify-export-1/expected.txt @@ -0,0 +1,17 @@ +# 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. + +[Patch] Found import/export expression changed in _ESModuleRecord, not supported! +[Patch] Found unsupported change in file, will not generate patch! +Error: [base_mod.js:0:0] +the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/modify-export-2/base.js b/es2panda/test/hotreload/modify-export-2/base.js new file mode 100644 index 0000000000000000000000000000000000000000..150707fb054819247df195559ffe19f1cbee0e49 --- /dev/null +++ b/es2panda/test/hotreload/modify-export-2/base.js @@ -0,0 +1,22 @@ +/* + * 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. + */ + +function v1() { print("v1") } +function v2() { print("v2") } + +export { + v1 as streamV1, + v2 as base, +}; \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-export-2/base_mod.js b/es2panda/test/hotreload/modify-export-2/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..7b98e796d62bfe3ec8668bf7e7eecddbbf5d80a6 --- /dev/null +++ b/es2panda/test/hotreload/modify-export-2/base_mod.js @@ -0,0 +1,23 @@ +/* + * 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. + */ + +// Test scenario: delete export variables, es2abc can specify and throw error + +function v1() { print("v1") } +function v2() { print("v2") } + +export { + v1 as streamV1, // delete an export variable +}; \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-export-2/expected.txt b/es2panda/test/hotreload/modify-export-2/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e574e0591d712df221689c96ba8f2ee630f439d --- /dev/null +++ b/es2panda/test/hotreload/modify-export-2/expected.txt @@ -0,0 +1,17 @@ +# 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. + +[Patch] Found import/export expression changed in _ESModuleRecord, not supported! +[Patch] Found unsupported change in file, will not generate patch! +Error: [base_mod.js:0:0] +the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/modify-export-3/base.js b/es2panda/test/hotreload/modify-export-3/base.js new file mode 100644 index 0000000000000000000000000000000000000000..e5000a893bac4ef0b3936efd14ec7873ffab29ea --- /dev/null +++ b/es2panda/test/hotreload/modify-export-3/base.js @@ -0,0 +1,19 @@ +/* + * 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. + */ + +function v1() { print("v1") } +function v2() { print("v2") } + +export {v1, v2}; \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-export-3/base_mod.js b/es2panda/test/hotreload/modify-export-3/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..3879ad1f98912a92ed4f7f4a6b0438a973005c0a --- /dev/null +++ b/es2panda/test/hotreload/modify-export-3/base_mod.js @@ -0,0 +1,21 @@ +/* + * 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. + */ + +// Test scenario: delete export variables, es2abc can specify and throw error + +function v1() { print("v1") } +function v2() { print("v2") } + +export {v1}; // delete export variables \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-export-3/expected.txt b/es2panda/test/hotreload/modify-export-3/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e574e0591d712df221689c96ba8f2ee630f439d --- /dev/null +++ b/es2panda/test/hotreload/modify-export-3/expected.txt @@ -0,0 +1,17 @@ +# 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. + +[Patch] Found import/export expression changed in _ESModuleRecord, not supported! +[Patch] Found unsupported change in file, will not generate patch! +Error: [base_mod.js:0:0] +the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/modify-import/base.js b/es2panda/test/hotreload/modify-import/base.js new file mode 100644 index 0000000000000000000000000000000000000000..ae16c316925168b4a6ce80b28b56d59e06116a7d --- /dev/null +++ b/es2panda/test/hotreload/modify-import/base.js @@ -0,0 +1,16 @@ +/* + * 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. + */ + +import base from '../hotfix-throwerror/modify-export-1/base.js' \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-import/base_mod.js b/es2panda/test/hotreload/modify-import/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..b692407433d59c3c3d38be9290baf960e91e8a01 --- /dev/null +++ b/es2panda/test/hotreload/modify-import/base_mod.js @@ -0,0 +1,18 @@ +/* + * 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. + */ + +// Test scenario: modify import variables, es2abc can specify and throw error + +import streamV1 from '../hotfix-throwerror/modify-export-1/base.js' \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-import/expected.txt b/es2panda/test/hotreload/modify-import/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e574e0591d712df221689c96ba8f2ee630f439d --- /dev/null +++ b/es2panda/test/hotreload/modify-import/expected.txt @@ -0,0 +1,17 @@ +# 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. + +[Patch] Found import/export expression changed in _ESModuleRecord, not supported! +[Patch] Found unsupported change in file, will not generate patch! +Error: [base_mod.js:0:0] +the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/modify-lexenv-1/base.js b/es2panda/test/hotreload/modify-lexenv-1/base.js new file mode 100644 index 0000000000000000000000000000000000000000..2dd34836caf1504140ee5e32d5cc5d1d29226d2c --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-1/base.js @@ -0,0 +1,25 @@ +/* + * 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. + */ + +function A() { + var a1 = 1; + var a2 = 2; + function B() { + print(a1); + } + B(); + } + +A() \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-lexenv-1/base_mod.js b/es2panda/test/hotreload/modify-lexenv-1/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..15d3324fe16461181c7c471bf873241bce2ad404 --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-1/base_mod.js @@ -0,0 +1,27 @@ +/* + * 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. + */ + +// Test scenario: modify lexenvs, es2abc can specify and throw error + +function A() { + var a1 = 1; + var a2 = 2; + function B() { + print(a2); // modify lexenv that used by function B(from a1 to a2) + } + B(); + } + +A() \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-lexenv-1/expected.txt b/es2panda/test/hotreload/modify-lexenv-1/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..939e788db79cbff903c04e69bc01ef672f94eb52 --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-1/expected.txt @@ -0,0 +1,17 @@ +# 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. + +[Patch] Found lexical variable changed in function .A, not supported! +[Patch] Found unsupported change in file, will not generate patch! +Error: [base_mod.js:0:0] +the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/modify-lexenv-2/base.js b/es2panda/test/hotreload/modify-lexenv-2/base.js new file mode 100644 index 0000000000000000000000000000000000000000..53c0fb49853945a2c8f73dffca56b436d0a36406 --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-2/base.js @@ -0,0 +1,25 @@ +/* + * 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. + */ + +function A() { + var a1 = 1; + var a2 = 2; + function B() { + print(a1 + a2); + } + B(); + } + +A() \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-lexenv-2/base_mod.js b/es2panda/test/hotreload/modify-lexenv-2/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..2fc81d26a6c6de7e5c344ca1f5c505f0faed5873 --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-2/base_mod.js @@ -0,0 +1,27 @@ +/* + * 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. + */ + +// Test scenario: modify lexenv, es2abc can specify and throw error + +function A() { + var a1 = 1; + var a3 = 2; // modify lexenv (from a2 to a3) + function B() { + print(a1 + a3); + } + B(); + } + +A() \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-lexenv-2/expected.txt b/es2panda/test/hotreload/modify-lexenv-2/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..939e788db79cbff903c04e69bc01ef672f94eb52 --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-2/expected.txt @@ -0,0 +1,17 @@ +# 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. + +[Patch] Found lexical variable changed in function .A, not supported! +[Patch] Found unsupported change in file, will not generate patch! +Error: [base_mod.js:0:0] +the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/modify-lexenv-3/base.js b/es2panda/test/hotreload/modify-lexenv-3/base.js new file mode 100644 index 0000000000000000000000000000000000000000..53c0fb49853945a2c8f73dffca56b436d0a36406 --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-3/base.js @@ -0,0 +1,25 @@ +/* + * 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. + */ + +function A() { + var a1 = 1; + var a2 = 2; + function B() { + print(a1 + a2); + } + B(); + } + +A() \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-lexenv-3/base_mod.js b/es2panda/test/hotreload/modify-lexenv-3/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..c31eafd2f69ac9bdcb10cdeac0ce1f0a4ecde6fb --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-3/base_mod.js @@ -0,0 +1,29 @@ +/* + * 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. + */ + +// Test scenario: modify lexenv type, es2abc can specify and throw error + +function A() { + var a1 = 1; + function a2() { // modify lexenv a2's type(from var to function) + return 2; + } + function B() { + print(a1 + a2()); + } + B(); + } + +A() \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-lexenv-3/expected.txt b/es2panda/test/hotreload/modify-lexenv-3/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..939e788db79cbff903c04e69bc01ef672f94eb52 --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-3/expected.txt @@ -0,0 +1,17 @@ +# 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. + +[Patch] Found lexical variable changed in function .A, not supported! +[Patch] Found unsupported change in file, will not generate patch! +Error: [base_mod.js:0:0] +the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/modify-lexenv-4/base.js b/es2panda/test/hotreload/modify-lexenv-4/base.js new file mode 100644 index 0000000000000000000000000000000000000000..744471c316a996ec00b86a68d9d854868159c12c --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-4/base.js @@ -0,0 +1,26 @@ +/* + * 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. + */ + +function makeAdder(x) { + return function(y) { + return x + y; + }; + } + + var add5 = makeAdder(5); + var add10 = makeAdder(10); + + console.log(add5(2)); // 7 + console.log(add10(2)); // 12 \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-lexenv-4/base_mod.js b/es2panda/test/hotreload/modify-lexenv-4/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..e06ed7ff5c6270a94606649d3ec892dbc7282feb --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-4/base_mod.js @@ -0,0 +1,28 @@ +/* + * 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. + */ + +// Test scenario: modify lexenv, es2abc can specify and throw error + +function makeAdder() { // In base, use function parameter as lexenv, in patch, lexenv deleted + return function(y) { + return y; + }; + } + +var add5 = makeAdder(5); +var add10 = makeAdder(10); + +print(add5(2)); // 2 +print(add10(2)); // 10 \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-lexenv-4/expected.txt b/es2panda/test/hotreload/modify-lexenv-4/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..f2be1c8b3187fb892e03ce00b08dc9524d5880f0 --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-4/expected.txt @@ -0,0 +1,17 @@ +# 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. + +[Patch] Found lexical variable added or removed in .makeAdder, not supported! +[Patch] Found unsupported change in file, will not generate patch! +Error: [base_mod.js:0:0] +the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/modify-lexenv-5/base.js b/es2panda/test/hotreload/modify-lexenv-5/base.js new file mode 100644 index 0000000000000000000000000000000000000000..90551f2ed50eb63e4ef41152d5296587d72508bc --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-5/base.js @@ -0,0 +1,23 @@ +/* + * 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. + */ + +function a() { + var c = 9; + for (let i = 1; i < 10; i++){ + function b() { + return i + c; + } + } +} \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-lexenv-5/base_mod.js b/es2panda/test/hotreload/modify-lexenv-5/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..2315d1ec5d43fdf5d53fae3c270ef2ee783c2159 --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-5/base_mod.js @@ -0,0 +1,31 @@ +/* + * 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. + */ + +// Test scenario: modify lexenv, es2abc can specify and throw error + +function a() { + var c = 9; + for (let i = 1; i < 10; i++){ + function b() { + return i + c; + } + } + + for (let j = 1; j < 10; j++){ // add a for loop that use 'j' as lexenv, function a's lexenv changed + function d() { + return j + c; + } + } +} \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-lexenv-5/expected.txt b/es2panda/test/hotreload/modify-lexenv-5/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..5d87e24565a8a06e7b4bb68be28108551e2cad5b --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-5/expected.txt @@ -0,0 +1,17 @@ +# 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. + +[Patch] Found lexical variable added or removed in .a, not supported! +[Patch] Found unsupported change in file, will not generate patch! +Error: [base_mod.js:0:0] +the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/modify-lexenv-6/base.js b/es2panda/test/hotreload/modify-lexenv-6/base.js new file mode 100644 index 0000000000000000000000000000000000000000..90551f2ed50eb63e4ef41152d5296587d72508bc --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-6/base.js @@ -0,0 +1,23 @@ +/* + * 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. + */ + +function a() { + var c = 9; + for (let i = 1; i < 10; i++){ + function b() { + return i + c; + } + } +} \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-lexenv-6/base_mod.js b/es2panda/test/hotreload/modify-lexenv-6/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..473150a7068807c16698018b4a64a9f0fd473a6e --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-6/base_mod.js @@ -0,0 +1,25 @@ +/* + * 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. + */ + +// Test scenario: modify lexenv, es2abc can specify and throw error + +function a() { + var c = 9; // 'c' is lexenv in base, but not a lexenv in patch + for (let i = 1; i < 10; i++){ + function b() { + return i; + } + } +} \ No newline at end of file diff --git a/es2panda/test/hotreload/modify-lexenv-6/expected.txt b/es2panda/test/hotreload/modify-lexenv-6/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..5d87e24565a8a06e7b4bb68be28108551e2cad5b --- /dev/null +++ b/es2panda/test/hotreload/modify-lexenv-6/expected.txt @@ -0,0 +1,17 @@ +# 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. + +[Patch] Found lexical variable added or removed in .a, not supported! +[Patch] Found unsupported change in file, will not generate patch! +Error: [base_mod.js:0:0] +the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/multi-lexenv-with-same-name/base.js b/es2panda/test/hotreload/multi-lexenv-with-same-name/base.js new file mode 100644 index 0000000000000000000000000000000000000000..8a2d6f621fba30627ce461cae330141b0d0300d0 --- /dev/null +++ b/es2panda/test/hotreload/multi-lexenv-with-same-name/base.js @@ -0,0 +1,28 @@ +/* + * 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. + */ + +function A() { + let a = 1; + { + let a = 2; + function b() { + a = 3; + } + } + + function c() { + a = 4; + } +} \ No newline at end of file diff --git a/es2panda/test/hotreload/multi-lexenv-with-same-name/base_mod.js b/es2panda/test/hotreload/multi-lexenv-with-same-name/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..8a2d6f621fba30627ce461cae330141b0d0300d0 --- /dev/null +++ b/es2panda/test/hotreload/multi-lexenv-with-same-name/base_mod.js @@ -0,0 +1,28 @@ +/* + * 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. + */ + +function A() { + let a = 1; + { + let a = 2; + function b() { + a = 3; + } + } + + function c() { + a = 4; + } +} \ No newline at end of file diff --git a/es2panda/test/hotreload/multi-lexenv-with-same-name/expected.txt b/es2panda/test/hotreload/multi-lexenv-with-same-name/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..4d0f814fda98c789dedae02afbeb4f129ab83674 --- /dev/null +++ b/es2panda/test/hotreload/multi-lexenv-with-same-name/expected.txt @@ -0,0 +1,12 @@ +# 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. diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index b7e6903b514a0dac6a4b629c996a1eb9bf72c6a1..2f88db88986f1c033b2977baba4049e7ec4e2bf7 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -133,6 +133,8 @@ def get_args(): help='the path of tsc') parser.add_argument('--hotfix', dest='hotfix', action='store_true', default=False, help='run hotfix tests') + parser.add_argument('--hotreload', dest='hotreload', action='store_true', default=False, + help='run hotreload tests') return parser.parse_args() @@ -982,9 +984,10 @@ class TransformerTest(Test): return self -class HotfixTest(Test): - def __init__(self, test_path): +class PatchTest(Test): + def __init__(self, test_path, mode_arg): Test.__init__(self, test_path, "") + self.mode = mode_arg def run(self, runner): symbol_table_file = 'base.map' @@ -999,11 +1002,16 @@ class HotfixTest(Test): gen_base_cmd.extend([os.path.join(self.path, origin_input_file)]) self.log_cmd(gen_base_cmd) - gen_patch_cmd = runner.cmd_prefix + [runner.es2panda, '--module', '--generate-patch'] - gen_patch_cmd.extend(['--input-symbol-table', os.path.join(self.path, symbol_table_file)]) - gen_patch_cmd.extend(['--output', os.path.join(self.path, modified_output_abc)]) - gen_patch_cmd.extend([os.path.join(self.path, modified_input_file)]) - self.log_cmd(gen_patch_cmd) + if self.mode == 'hotfix': + mode_arg = "--generate-patch" + elif self.mode == 'hotreload': + mode_arg = "--hot-reload" + + patch_test_cmd = runner.cmd_prefix + [runner.es2panda, '--module', mode_arg] + patch_test_cmd.extend(['--input-symbol-table', os.path.join(self.path, symbol_table_file)]) + patch_test_cmd.extend(['--output', os.path.join(self.path, modified_output_abc)]) + patch_test_cmd.extend([os.path.join(self.path, modified_input_file)]) + self.log_cmd(patch_test_cmd) process_base = subprocess.Popen(gen_base_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -1013,7 +1021,7 @@ class HotfixTest(Test): self.error = stderr_base.decode("utf-8", errors="ignore") return self - process_patch = subprocess.Popen(gen_patch_cmd, stdout=subprocess.PIPE, + process_patch = subprocess.Popen(patch_test_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout_patch, stderr_patch = process_patch.communicate(timeout=runner.args.es2panda_timeout) if stderr_patch: @@ -1024,7 +1032,7 @@ class HotfixTest(Test): expected_path = os.path.join(self.path, 'expected.txt') try: with open(expected_path, 'r') as fp: - expected = ''.join(fp.readlines()[13:]) # ignore license description lines + expected = (''.join((fp.readlines()[12:]))).lstrip() # ignore license description lines and skip leading blank lines self.passed = expected == self.output except Exception: self.passed = False @@ -1036,12 +1044,10 @@ class HotfixTest(Test): return self -class HotfixRunner(Runner): - def __init__(self, args): - Runner.__init__(self, args, "Hotfix") +class PatchRunner(Runner): + def __init__(self, args, name): + Runner.__init__(self, args, name) self.preserve_files = args.error - self.test_directory = path.join(self.test_root, "hotfix", "hotfix-throwerror") - self.add_directory() def __del__(self): if not self.preserve_files: @@ -1050,7 +1056,6 @@ class HotfixRunner(Runner): def add_directory(self): glob_expression = path.join(self.test_directory, "*") self.tests_in_dirs = glob(glob_expression, recursive=False) - self.tests += list(map(lambda t: HotfixTest(t), self.tests_in_dirs)) def clear_directory(self): for test in self.tests_in_dirs: @@ -1063,6 +1068,22 @@ class HotfixRunner(Runner): return os.path.basename(src) +class HotfixRunner(PatchRunner): + def __init__(self, args): + PatchRunner.__init__(self, args, "Hotfix") + self.test_directory = path.join(self.test_root, "hotfix", "hotfix-throwerror") + self.add_directory() + self.tests += list(map(lambda t: PatchTest(t, "hotfix"), self.tests_in_dirs)) + + +class HotreloadRunner(PatchRunner): + def __init__(self, args): + PatchRunner.__init__(self, args, "Hotreload") + self.test_directory = path.join(self.test_root, "hotreload") + self.add_directory() + self.tests += list(map(lambda t: PatchTest(t, "hotreload"), self.tests_in_dirs)) + + def main(): args = get_args() @@ -1108,6 +1129,9 @@ def main(): if args.hotfix: runners.append(HotfixRunner(args)) + if args.hotreload: + runners.append(HotreloadRunner(args)) + failed_tests = 0 for runner in runners: diff --git a/es2panda/util/hotfix.cpp b/es2panda/util/hotfix.cpp index fc889412496bd69a8fabc46245fc3563a0d65b22..92eb7071fa20769c4a1ed6c6b17a16b3add979a4 100644 --- a/es2panda/util/hotfix.cpp +++ b/es2panda/util/hotfix.cpp @@ -481,6 +481,10 @@ void Hotfix::HandleFunction(const compiler::PandaGen *pg, panda::pandasm::Functi std::string funcName = func->name; auto originFunction = originFunctionInfo_->find(funcName); if (originFunction == originFunctionInfo_->end()) { + // Support adding anonymous funtion in hotreload mode. + if (hotReload_) { + return; + } if (IsAnonymousOrDuplicateNameFunction(funcName)) { std::cerr << "[Patch] Found new anonymous or duplicate name function " << funcName << " not supported!" << std::endl;