[Pkg-javascript-commits] [uglifyjs] 196/228: fix corner case in `switch` (#1765)
Jonas Smedegaard
dr at jones.dk
Sat Apr 15 14:25:29 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository uglifyjs.
commit 9469c03ac976b3cfc1e52abf034ce76f1d6aca59
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Sun Apr 2 17:07:20 2017 +0800
fix corner case in `switch` (#1765)
---
lib/compress.js | 7 +++----
test/compress/issue-1750.js | 28 ++++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 763490a..79e7d4d 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2557,7 +2557,7 @@ merge(Compressor.prototype, {
if (!default_branch) {
default_branch = branch;
} else {
- eliminate_branch(branch);
+ eliminate_branch(branch, body[body.length - 1]);
}
} else if (value !== self.expression) {
var exp = branch.expression.evaluate(compressor);
@@ -2570,7 +2570,7 @@ merge(Compressor.prototype, {
default_branch = null;
}
} else if (exp !== branch.expression) {
- eliminate_branch(branch);
+ eliminate_branch(branch, body[body.length - 1]);
continue;
}
}
@@ -2583,7 +2583,7 @@ merge(Compressor.prototype, {
}
body.push(branch);
}
- while (i < len) eliminate_branch(self.body[i++]);
+ while (i < len) eliminate_branch(self.body[i++], body[body.length - 1]);
if (body.length > 0) {
body[0].body = decl.concat(body[0].body);
}
@@ -2626,7 +2626,6 @@ merge(Compressor.prototype, {
return self;
function eliminate_branch(branch, prev) {
- if (!prev) prev = body[body.length - 1];
if (prev && !aborts(prev)) {
prev.body = prev.body.concat(branch.body);
} else {
diff --git a/test/compress/issue-1750.js b/test/compress/issue-1750.js
index c1448af..d18bc49 100644
--- a/test/compress/issue-1750.js
+++ b/test/compress/issue-1750.js
@@ -24,3 +24,31 @@ case_1: {
}
expect_stdout: "0 2"
}
+
+case_2: {
+ options = {
+ dead_code: true,
+ evaluate: true,
+ switches: true,
+ }
+ input: {
+ var a = 0, b = 1;
+ switch (0) {
+ default:
+ b = 2;
+ case a:
+ a = 3;
+ case 0:
+ }
+ console.log(a, b);
+ }
+ expect: {
+ var a = 0, b = 1;
+ switch (0) {
+ case a:
+ a = 3;
+ }
+ console.log(a, b);
+ }
+ expect_stdout: "3 1"
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list