aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-05-24 02:56:02 +0100
committerGitHub <noreply@github.com>2021-05-24 09:56:02 +0800
commiteb08fed120ad1d2dcd41a2ae03cec3d3b2885c7b (patch)
tree0d7646d9ea44be188d11fb12d34dd33b2c0aea8a /test
parent8b0c8365150c1471eef98ed37e33bb66a51c3a45 (diff)
downloadtracifyjs-eb08fed120ad1d2dcd41a2ae03cec3d3b2885c7b.tar.gz
tracifyjs-eb08fed120ad1d2dcd41a2ae03cec3d3b2885c7b.zip
fix corner case in `merge_vars` (#4957)
fixes #4956
Diffstat (limited to 'test')
-rw-r--r--test/compress/merge_vars.js77
-rw-r--r--test/sandbox.js2
2 files changed, 78 insertions, 1 deletions
diff --git a/test/compress/merge_vars.js b/test/compress/merge_vars.js
index 0494acfb..dc526c5f 100644
--- a/test/compress/merge_vars.js
+++ b/test/compress/merge_vars.js
@@ -3301,3 +3301,80 @@ issue_4761: {
}
expect_stdout: "undefined"
}
+
+issue_4956_1: {
+ options = {
+ merge_vars: true,
+ toplevel: true,
+ }
+ input: {
+ var a, b;
+ function f(c) {
+ switch (c) {
+ case 0:
+ a = { p: 42 };
+
+ case 1:
+ b = a.p;
+ console.log(b);
+ }
+ }
+ f(0);
+ f(1);
+ }
+ expect: {
+ var a, b;
+ function f(c) {
+ switch (c) {
+ case 0:
+ a = { p: 42 };
+
+ case 1:
+ b = a.p;
+ console.log(b);
+ }
+ }
+ f(0);
+ f(1);
+ }
+ expect_stdout: [
+ "42",
+ "42",
+ ]
+}
+
+issue_4956_2: {
+ options = {
+ merge_vars: true,
+ toplevel: true,
+ }
+ input: {
+ var a, b;
+ function f(c) {
+ if (0 == c) {
+ console;
+ a = { p: 42 };
+ }
+ b = a.p;
+ if (1 == c)
+ console.log(b);
+ }
+ f(0);
+ f(1);
+ }
+ expect: {
+ var a, b;
+ function f(c) {
+ if (0 == c) {
+ console;
+ a = { p: 42 };
+ }
+ b = a.p;
+ if (1 == c)
+ console.log(b);
+ }
+ f(0);
+ f(1);
+ }
+ expect_stdout: "42"
+}
diff --git a/test/sandbox.js b/test/sandbox.js
index edebcabe..c0e9e09b 100644
--- a/test/sandbox.js
+++ b/test/sandbox.js
@@ -27,7 +27,7 @@ exports.run_code = semver.satisfies(process.version, "0.8") ? function(code, top
} : semver.satisfies(process.version, "<0.12") ? run_code_vm : function(code, toplevel, timeout) {
if ([
/\basync[ \t]*\([\s\S]*?\)[ \t]*=>/,
- /\b(async[ \t]+function|setImmediate|setInterval|setTimeout)\b/,
+ /\b(async[ \t]+function|Promise|setImmediate|setInterval|setTimeout)\b/,
/\basync([ \t]+|[ \t]*#|[ \t]*\*[ \t]*)[^\s()[\]{},.&|!~=*%/+-]+(\s*\(|[ \t]*=>)/,
].some(function(pattern) {
return pattern.test(code);