[Pkg-javascript-commits] [uglifyjs] 322/491: fix `collapse_vars` on `switch` (#2578)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:49 UTC 2018
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.
commit f2ad54267945ed96f4e84ade21af262c6ffd1d23
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Mon Dec 11 18:11:09 2017 +0800
fix `collapse_vars` on `switch` (#2578)
---
lib/compress.js | 10 +++-----
test/compress/collapse_vars.js | 58 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 61 insertions(+), 7 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 434becb..ce61ce9 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -873,14 +873,12 @@ merge(Compressor.prototype, {
node.expression = node.expression.transform(scanner);
for (var i = 0, len = node.body.length; !abort && i < len; i++) {
var branch = node.body[i];
- if (branch instanceof AST_Case)
+ if (branch instanceof AST_Case) {
branch.expression = branch.expression.transform(scanner);
+ if (side_effects || !replace_all) break;
+ }
}
- for (i = 0; !abort && i < len; i++) {
- var branch = node.body[i];
- for (var j = 0, len2 = branch.body.length; j < len2; j++)
- branch.body[j] = branch.body[j].transform(scanner);
- }
+ abort = true;
return node;
}
// Skip nodes before `candidate` as quickly as possible
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index ab86c6b..2136b2f 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -1749,7 +1749,7 @@ for_init: {
}
}
-switch_case: {
+switch_case_1: {
options = {
collapse_vars: true,
unused: true,
@@ -1777,6 +1777,62 @@ switch_case: {
}
}
+switch_case_2: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ var a = 1, b = 2;
+ switch (b++) {
+ case b:
+ var c = a;
+ var a;
+ break;
+ }
+ console.log(a);
+ }
+ expect: {
+ var a = 1, b = 2;
+ switch (b++) {
+ case b:
+ var c = a;
+ var a;
+ break;
+ }
+ console.log(a);
+ }
+ expect_stdout: "1"
+}
+
+switch_case_3: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ var a = 1, b = 2;
+ switch (a) {
+ case a:
+ var b;
+ break;
+ case b:
+ break;
+ }
+ console.log(b);
+ }
+ expect: {
+ var a = 1, b = 2;
+ switch (a) {
+ case a:
+ var b;
+ break;
+ case b:
+ break;
+ }
+ console.log(b);
+ }
+ expect_stdout: "2"
+}
+
issue_27: {
options = {
collapse_vars: true,
--
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