aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-03-11 15:54:43 +0800
committerGitHub <noreply@github.com>2018-03-11 15:54:43 +0800
commitb9f72a4a81d69a7dd782a5ee70f7eee1cb4aa0e0 (patch)
tree7f4699b6e606a3e44a731083d1796c0ccc779056
parentfc6ebd04a59024dfd3b40b43825a007c62bac2b3 (diff)
downloadtracifyjs-b9f72a4a81d69a7dd782a5ee70f7eee1cb4aa0e0.tar.gz
tracifyjs-b9f72a4a81d69a7dd782a5ee70f7eee1cb4aa0e0.zip
handle `case` correctly under `reduce_vars` (#2993)
fixes #2992
-rw-r--r--lib/compress.js21
-rw-r--r--test/compress/reduce_vars.js30
2 files changed, 45 insertions, 6 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 2f109a17..1b52f83e 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -517,6 +517,15 @@ merge(Compressor.prototype, {
pop(tw);
return true;
});
+ def(AST_Case, function(tw) {
+ push(tw);
+ this.expression.walk(tw);
+ pop(tw);
+ push(tw);
+ walk_body(this, tw);
+ pop(tw);
+ return true;
+ });
def(AST_Conditional, function(tw) {
this.condition.walk(tw);
push(tw);
@@ -527,6 +536,12 @@ merge(Compressor.prototype, {
pop(tw);
return true;
});
+ def(AST_Default, function(tw, descend) {
+ push(tw);
+ descend();
+ pop(tw);
+ return true;
+ });
def(AST_Defun, function(tw, descend, compressor) {
this.inlined = false;
var save_ids = tw.safe_ids;
@@ -624,12 +639,6 @@ merge(Compressor.prototype, {
pop(tw);
return true;
});
- def(AST_SwitchBranch, function(tw, descend) {
- push(tw);
- descend();
- pop(tw);
- return true;
- });
def(AST_SymbolCatch, function() {
this.definition().fixed = false;
});
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 836d7fe2..815dff32 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -5545,3 +5545,33 @@ issue_2919: {
}
expect_stdout: "function"
}
+
+issue_2992: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ }
+ input: {
+ var c = "PASS";
+ (function f(b) {
+ switch (0) {
+ case 0:
+ case b = 1:
+ b && (c = "FAIL");
+ }
+ })();
+ console.log(c);
+ }
+ expect: {
+ var c = "PASS";
+ (function f(b) {
+ switch (0) {
+ case 0:
+ case b = 1:
+ b && (c = "FAIL");
+ }
+ })();
+ console.log(c);
+ }
+ expect_stdout: "PASS"
+}