diff --git a/es2panda/test/BUILD.gn b/es2panda/test/BUILD.gn index dcd5afa0e2fb4ee0912207617e226c26458fca3e..56a3aaa6f792e914b980805c340ded1f8fc3ea10 100644 --- a/es2panda/test/BUILD.gn +++ b/es2panda/test/BUILD.gn @@ -82,3 +82,16 @@ action("es2abc_compiler_tests") { outputs = [ "${es2abc_build_path}/keep_es2abc_compiler_tests_run" ] } + +action("es2abc_hotfix_tests") { + script = "${es2abc_root}/test/runner.py" + + deps = es2abc_build_deps + + args = [ + "--hotfix", + rebase_path("${es2abc_build_path}"), + ] + + outputs = [ "${es2abc_build_path}/keep_es2abc_hotfix_tests_run" ] +} diff --git a/es2panda/test/hotfix/hotfix-throwerror/add-anon-function/base.js b/es2panda/test/hotfix/hotfix-throwerror/add-anon-function/base.js new file mode 100644 index 0000000000000000000000000000000000000000..b607d2358b4490bc036878f45f9e6e534e1c8c76 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/add-anon-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/hotfix/hotfix-throwerror/add-anon-function/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/add-anon-function/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..be8c47ddf5d2b13c3b6fc80fb326981eee4edfd5 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/add-anon-function/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: 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/hotfix/hotfix-throwerror/add-anon-function/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/add-anon-function/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..a035149a69f98cb0fa1c759e524734ebfbeb4a3e --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/add-anon-function/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 new anonymous or duplicate name function .#2# 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/hotfix/hotfix-throwerror/add-dup-name-function/base.js b/es2panda/test/hotfix/hotfix-throwerror/add-dup-name-function/base.js new file mode 100644 index 0000000000000000000000000000000000000000..4e806c169f2468909d2b162e9cb15739582f954f --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/add-dup-name-function/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/add-dup-name-function/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..3e85e23106bd94895e3519e0fa60f193e399d623 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/add-dup-name-function/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/add-dup-name-function/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..da1e8c6ab7d6123155f1d00e06bf9040ea3f455d --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/add-dup-name-function/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 new anonymous or duplicate name function .#1#B 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/hotfix/hotfix-throwerror/add-lexenv-1/base.js b/es2panda/test/hotfix/hotfix-throwerror/add-lexenv-1/base.js new file mode 100644 index 0000000000000000000000000000000000000000..5aa8e624fb64d73ba4b2b4ea70a012722e30b242 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/add-lexenv-1/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/add-lexenv-1/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..ce1145f4ed6f1ea404544429f951f423f3dc511d --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/add-lexenv-1/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/add-lexenv-1/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..48879050e5a348ae048aa8b23122ff3a30932d76 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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 lexenv size 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/hotfix/hotfix-throwerror/modify-class-1/base.js b/es2panda/test/hotfix/hotfix-throwerror/modify-class-1/base.js new file mode 100644 index 0000000000000000000000000000000000000000..d8ea343e9216cc1e108c839baad7d2e6f91861a4 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-class-1/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/modify-class-1/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..96876d2892f699735f3b9861e41904d7c7a0591a --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-class-1/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/modify-class-1/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..c2769ab6dc4abb2adc0d0ccfb9875a422c6de285 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-export-1/base.js b/es2panda/test/hotfix/hotfix-throwerror/modify-export-1/base.js new file mode 100644 index 0000000000000000000000000000000000000000..150707fb054819247df195559ffe19f1cbee0e49 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-export-1/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/modify-export-1/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..070b50ffab9720931ba5f4487b7edb1f43660aa2 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-export-1/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/modify-export-1/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e574e0591d712df221689c96ba8f2ee630f439d --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-export-2/base.js b/es2panda/test/hotfix/hotfix-throwerror/modify-export-2/base.js new file mode 100644 index 0000000000000000000000000000000000000000..150707fb054819247df195559ffe19f1cbee0e49 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-export-2/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/modify-export-2/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..7b98e796d62bfe3ec8668bf7e7eecddbbf5d80a6 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-export-2/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/modify-export-2/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e574e0591d712df221689c96ba8f2ee630f439d --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-export-3/base.js b/es2panda/test/hotfix/hotfix-throwerror/modify-export-3/base.js new file mode 100644 index 0000000000000000000000000000000000000000..e5000a893bac4ef0b3936efd14ec7873ffab29ea --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-export-3/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/modify-export-3/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..3879ad1f98912a92ed4f7f4a6b0438a973005c0a --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-export-3/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/modify-export-3/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e574e0591d712df221689c96ba8f2ee630f439d --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-import/base.js b/es2panda/test/hotfix/hotfix-throwerror/modify-import/base.js new file mode 100644 index 0000000000000000000000000000000000000000..ae16c316925168b4a6ce80b28b56d59e06116a7d --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-import/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/modify-import/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..b692407433d59c3c3d38be9290baf960e91e8a01 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-import/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/modify-import/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e574e0591d712df221689c96ba8f2ee630f439d --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-lexenv-1/base.js b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-1/base.js new file mode 100644 index 0000000000000000000000000000000000000000..2dd34836caf1504140ee5e32d5cc5d1d29226d2c --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-lexenv-1/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-1/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..15d3324fe16461181c7c471bf873241bce2ad404 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-lexenv-1/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-1/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0729488a2a0faca244406e723bdea0c5d38f183f --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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 new lex env added 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/hotfix/hotfix-throwerror/modify-lexenv-2/base.js b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-2/base.js new file mode 100644 index 0000000000000000000000000000000000000000..53c0fb49853945a2c8f73dffca56b436d0a36406 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-lexenv-2/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-2/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..2fc81d26a6c6de7e5c344ca1f5c505f0faed5873 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-lexenv-2/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-2/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0729488a2a0faca244406e723bdea0c5d38f183f --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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 new lex env added 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/hotfix/hotfix-throwerror/modify-lexenv-3/base.js b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-3/base.js new file mode 100644 index 0000000000000000000000000000000000000000..53c0fb49853945a2c8f73dffca56b436d0a36406 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-lexenv-3/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-3/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..c31eafd2f69ac9bdcb10cdeac0ce1f0a4ecde6fb --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-lexenv-3/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-3/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..eb704505c4782ae8b9f905b672f3585450c400c7 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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 new lex env changed(slot or type) 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/hotfix/hotfix-throwerror/modify-lexenv-4/base.js b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-4/base.js new file mode 100644 index 0000000000000000000000000000000000000000..744471c316a996ec00b86a68d9d854868159c12c --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-lexenv-4/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-4/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..e06ed7ff5c6270a94606649d3ec892dbc7282feb --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-lexenv-4/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-4/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..48879050e5a348ae048aa8b23122ff3a30932d76 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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 lexenv size 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/hotfix/hotfix-throwerror/modify-lexenv-5/base.js b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-5/base.js new file mode 100644 index 0000000000000000000000000000000000000000..90551f2ed50eb63e4ef41152d5296587d72508bc --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-lexenv-5/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-5/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..2315d1ec5d43fdf5d53fae3c270ef2ee783c2159 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-lexenv-5/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-5/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..48879050e5a348ae048aa8b23122ff3a30932d76 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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 lexenv size 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/hotfix/hotfix-throwerror/modify-lexenv-6/base.js b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-6/base.js new file mode 100644 index 0000000000000000000000000000000000000000..90551f2ed50eb63e4ef41152d5296587d72508bc --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-lexenv-6/base_mod.js b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-6/base_mod.js new file mode 100644 index 0000000000000000000000000000000000000000..473150a7068807c16698018b4a64a9f0fd473a6e --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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/hotfix/hotfix-throwerror/modify-lexenv-6/expected.txt b/es2panda/test/hotfix/hotfix-throwerror/modify-lexenv-6/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..48879050e5a348ae048aa8b23122ff3a30932d76 --- /dev/null +++ b/es2panda/test/hotfix/hotfix-throwerror/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 lexenv size 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/runner.py b/es2panda/test/runner.py index d02b38c33918a6908915706649755d6da0c6d1c9..6ced45f13c9340efb7934b52202c72281d8f3bd6 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -130,6 +130,8 @@ def get_args(): parser.add_argument( '--tsc-path', dest='tsc_path', default=None, type=lambda arg: is_directory(parser, arg), help='the path of tsc') + parser.add_argument('--hotfix', dest='hotfix', action='store_true', default=False, + help='run hotfix tests') return parser.parse_args() @@ -443,7 +445,7 @@ class Runner: path_str = test.path err_col = {} if test.error: - err_str = test.error.split('[')[0] + err_str = test.error.split('[')[0] if "hotfix" not in test.path else " hotfix throw error failed" err_col = {"path" : [path_str], "status": ["fail"], "error" : [test.error], "type" : [err_str]} else: err_col = {"path" : [path_str], "status": ["fail"], "error" : ["Segmentation fault"], @@ -833,6 +835,87 @@ class CompilerTest(Test): return self +class HotfixTest(Test): + def __init__(self, test_path): + Test.__init__(self, test_path, "") + + def run(self, runner): + symbol_table_file = 'base.map' + origin_input_file = 'base.js' + origin_output_abc = 'base.abc' + modified_input_file = 'base_mod.js' + modified_output_abc = 'patch.abc' + + gen_base_cmd = runner.cmd_prefix + [runner.es2panda, '--module'] + gen_base_cmd.extend(['--dump-symbol-table', os.path.join(self.path, symbol_table_file)]) + gen_base_cmd.extend(['--output', os.path.join(self.path, origin_output_abc)]) + 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) + + process_base = subprocess.Popen(gen_base_cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout_base, stderr_base = process_base.communicate(timeout=runner.args.es2panda_timeout) + if stderr_base: + self.passed = False + self.error = stderr_base.decode("utf-8", errors="ignore") + return self + + process_patch = subprocess.Popen(gen_patch_cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout_patch, stderr_patch = process_patch.communicate(timeout=runner.args.es2panda_timeout) + if stderr_patch: + self.passed = False + self.error = stderr_patch.decode("utf-8", errors="ignore") + + self.output = stdout_patch.decode("utf-8", errors="ignore") + stderr_patch.decode("utf-8", errors="ignore") + 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 + self.passed = expected == self.output + except Exception: + self.passed = False + + if not self.passed: + self.error = "expected output:" + os.linesep + expected + os.linesep + "actual output:" + os.linesep +\ + self.output + + return self + + +class HotfixRunner(Runner): + def __init__(self, args): + Runner.__init__(self, args, "Hotfix") + 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: + self.clear_directory() + + 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: + files_in_dir = os.listdir(test) + filtered_files = [file for file in files_in_dir if file.endswith(".map") or file.endswith(".abc")] + for file in filtered_files: + os.remove(os.path.join(test, file)) + + def test_path(self, src): + return os.path.basename(src) + + def main(): args = get_args() @@ -864,6 +947,9 @@ def main(): runners.append(runner) + if args.hotfix: + runners.append(HotfixRunner(args)) + failed_tests = 0 for runner in runners: