From a5be3da717da86b58eae6cbc66abb5178fe91531 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Mon, 20 Mar 2023 14:39:40 +0800 Subject: [PATCH] No exception reported for new anonymous function in hotreload Issue: I6OIOT Signed-off-by: gavin1012_hw Change-Id: Icebc92396ffeebab6c0e0d86be19b2036c0d2dfc --- es2panda/BUILD.gn | 5 +- es2panda/test/BUILD.gn | 6 ++- .../hotreload/add-anonymous-function/base.js | 18 +++++++ .../add-anonymous-function/base_mod.js | 23 ++++++++ .../add-anonymous-function/expected.txt | 12 +++++ .../hotreload/add-dup-name-function/base.js | 22 ++++++++ .../add-dup-name-function/base_mod.js | 27 ++++++++++ .../add-dup-name-function/expected.txt | 12 +++++ es2panda/test/hotreload/add-lexenv-1/base.js | 18 +++++++ .../test/hotreload/add-lexenv-1/base_mod.js | 29 ++++++++++ .../test/hotreload/add-lexenv-1/expected.txt | 17 ++++++ .../test/hotreload/modify-class-1/base.js | 39 ++++++++++++++ .../test/hotreload/modify-class-1/base_mod.js | 46 ++++++++++++++++ .../hotreload/modify-class-1/expected.txt | 17 ++++++ .../test/hotreload/modify-export-1/base.js | 22 ++++++++ .../hotreload/modify-export-1/base_mod.js | 24 +++++++++ .../hotreload/modify-export-1/expected.txt | 17 ++++++ .../test/hotreload/modify-export-2/base.js | 22 ++++++++ .../hotreload/modify-export-2/base_mod.js | 23 ++++++++ .../hotreload/modify-export-2/expected.txt | 17 ++++++ .../test/hotreload/modify-export-3/base.js | 19 +++++++ .../hotreload/modify-export-3/base_mod.js | 21 ++++++++ .../hotreload/modify-export-3/expected.txt | 17 ++++++ es2panda/test/hotreload/modify-import/base.js | 16 ++++++ .../test/hotreload/modify-import/base_mod.js | 18 +++++++ .../test/hotreload/modify-import/expected.txt | 17 ++++++ .../test/hotreload/modify-lexenv-1/base.js | 25 +++++++++ .../hotreload/modify-lexenv-1/base_mod.js | 27 ++++++++++ .../hotreload/modify-lexenv-1/expected.txt | 17 ++++++ .../test/hotreload/modify-lexenv-2/base.js | 25 +++++++++ .../hotreload/modify-lexenv-2/base_mod.js | 27 ++++++++++ .../hotreload/modify-lexenv-2/expected.txt | 17 ++++++ .../test/hotreload/modify-lexenv-3/base.js | 25 +++++++++ .../hotreload/modify-lexenv-3/base_mod.js | 29 ++++++++++ .../hotreload/modify-lexenv-3/expected.txt | 17 ++++++ .../test/hotreload/modify-lexenv-4/base.js | 26 +++++++++ .../hotreload/modify-lexenv-4/base_mod.js | 28 ++++++++++ .../hotreload/modify-lexenv-4/expected.txt | 17 ++++++ .../test/hotreload/modify-lexenv-5/base.js | 23 ++++++++ .../hotreload/modify-lexenv-5/base_mod.js | 31 +++++++++++ .../hotreload/modify-lexenv-5/expected.txt | 17 ++++++ .../test/hotreload/modify-lexenv-6/base.js | 23 ++++++++ .../hotreload/modify-lexenv-6/base_mod.js | 25 +++++++++ .../hotreload/modify-lexenv-6/expected.txt | 17 ++++++ .../multi-lexenv-with-same-name/base.js | 28 ++++++++++ .../multi-lexenv-with-same-name/base_mod.js | 28 ++++++++++ .../multi-lexenv-with-same-name/expected.txt | 12 +++++ es2panda/test/runner.py | 54 +++++++++++++------ es2panda/util/hotfix.cpp | 4 ++ 49 files changed, 1047 insertions(+), 19 deletions(-) create mode 100644 es2panda/test/hotreload/add-anonymous-function/base.js create mode 100644 es2panda/test/hotreload/add-anonymous-function/base_mod.js create mode 100644 es2panda/test/hotreload/add-anonymous-function/expected.txt create mode 100644 es2panda/test/hotreload/add-dup-name-function/base.js create mode 100644 es2panda/test/hotreload/add-dup-name-function/base_mod.js create mode 100644 es2panda/test/hotreload/add-dup-name-function/expected.txt create mode 100644 es2panda/test/hotreload/add-lexenv-1/base.js create mode 100644 es2panda/test/hotreload/add-lexenv-1/base_mod.js create mode 100644 es2panda/test/hotreload/add-lexenv-1/expected.txt create mode 100644 es2panda/test/hotreload/modify-class-1/base.js create mode 100644 es2panda/test/hotreload/modify-class-1/base_mod.js create mode 100644 es2panda/test/hotreload/modify-class-1/expected.txt create mode 100644 es2panda/test/hotreload/modify-export-1/base.js create mode 100644 es2panda/test/hotreload/modify-export-1/base_mod.js create mode 100644 es2panda/test/hotreload/modify-export-1/expected.txt create mode 100644 es2panda/test/hotreload/modify-export-2/base.js create mode 100644 es2panda/test/hotreload/modify-export-2/base_mod.js create mode 100644 es2panda/test/hotreload/modify-export-2/expected.txt create mode 100644 es2panda/test/hotreload/modify-export-3/base.js create mode 100644 es2panda/test/hotreload/modify-export-3/base_mod.js create mode 100644 es2panda/test/hotreload/modify-export-3/expected.txt create mode 100644 es2panda/test/hotreload/modify-import/base.js create mode 100644 es2panda/test/hotreload/modify-import/base_mod.js create mode 100644 es2panda/test/hotreload/modify-import/expected.txt create mode 100644 es2panda/test/hotreload/modify-lexenv-1/base.js create mode 100644 es2panda/test/hotreload/modify-lexenv-1/base_mod.js create mode 100644 es2panda/test/hotreload/modify-lexenv-1/expected.txt create mode 100644 es2panda/test/hotreload/modify-lexenv-2/base.js create mode 100644 es2panda/test/hotreload/modify-lexenv-2/base_mod.js create mode 100644 es2panda/test/hotreload/modify-lexenv-2/expected.txt create mode 100644 es2panda/test/hotreload/modify-lexenv-3/base.js create mode 100644 es2panda/test/hotreload/modify-lexenv-3/base_mod.js create mode 100644 es2panda/test/hotreload/modify-lexenv-3/expected.txt create mode 100644 es2panda/test/hotreload/modify-lexenv-4/base.js create mode 100644 es2panda/test/hotreload/modify-lexenv-4/base_mod.js create mode 100644 es2panda/test/hotreload/modify-lexenv-4/expected.txt create mode 100644 es2panda/test/hotreload/modify-lexenv-5/base.js create mode 100644 es2panda/test/hotreload/modify-lexenv-5/base_mod.js create mode 100644 es2panda/test/hotreload/modify-lexenv-5/expected.txt create mode 100644 es2panda/test/hotreload/modify-lexenv-6/base.js create mode 100644 es2panda/test/hotreload/modify-lexenv-6/base_mod.js create mode 100644 es2panda/test/hotreload/modify-lexenv-6/expected.txt create mode 100644 es2panda/test/hotreload/multi-lexenv-with-same-name/base.js create mode 100644 es2panda/test/hotreload/multi-lexenv-with-same-name/base_mod.js create mode 100644 es2panda/test/hotreload/multi-lexenv-with-same-name/expected.txt diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index 9e33605992d..c2dc8f94147 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 56a3aaa6f79..c310f513040 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 00000000000..b607d2358b4 --- /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 00000000000..69b38f6fc18 --- /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 00000000000..4d0f814fda9 --- /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 00000000000..4e806c169f2 --- /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 00000000000..3e85e23106b --- /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 00000000000..4d0f814fda9 --- /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 00000000000..5aa8e624fb6 --- /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 00000000000..ce1145f4ed6 --- /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 00000000000..15b6dd42582 --- /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 00000000000..d8ea343e921 --- /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 00000000000..96876d2892f --- /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 00000000000..c2769ab6dc4 --- /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 00000000000..150707fb054 --- /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 00000000000..070b50ffab9 --- /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 00000000000..3e574e0591d --- /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 00000000000..150707fb054 --- /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 00000000000..7b98e796d62 --- /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 00000000000..3e574e0591d --- /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 00000000000..e5000a893ba --- /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 00000000000..3879ad1f989 --- /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 00000000000..3e574e0591d --- /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 00000000000..ae16c316925 --- /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 00000000000..b692407433d --- /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 00000000000..3e574e0591d --- /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 00000000000..2dd34836caf --- /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 00000000000..15d3324fe16 --- /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 00000000000..939e788db79 --- /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 00000000000..53c0fb49853 --- /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 00000000000..2fc81d26a6c --- /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 00000000000..939e788db79 --- /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 00000000000..53c0fb49853 --- /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 00000000000..c31eafd2f69 --- /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 00000000000..939e788db79 --- /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 00000000000..744471c316a --- /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 00000000000..e06ed7ff5c6 --- /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 00000000000..f2be1c8b318 --- /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 00000000000..90551f2ed50 --- /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 00000000000..2315d1ec5d4 --- /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 00000000000..5d87e24565a --- /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 00000000000..90551f2ed50 --- /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 00000000000..473150a7068 --- /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 00000000000..5d87e24565a --- /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 00000000000..8a2d6f621fb --- /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 00000000000..8a2d6f621fb --- /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 00000000000..4d0f814fda9 --- /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 6ced45f13c9..b06fb27e992 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -132,6 +132,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() @@ -835,9 +837,10 @@ class CompilerTest(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' @@ -852,11 +855,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) @@ -866,7 +874,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: @@ -877,7 +885,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 @@ -889,12 +897,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: @@ -903,7 +909,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: @@ -916,6 +921,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() @@ -950,6 +971,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 fc889412496..92eb7071fa2 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; -- Gitee