[Pkg-javascript-commits] [uglifyjs] 157/228: preserve side effects in switch expression (#1694)
Jonas Smedegaard
dr at jones.dk
Sat Apr 15 14:25:26 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 f5952933a00bac8c9d794d5b0e3d5f8d6173c4a9
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Mon Mar 27 02:32:46 2017 +0800
preserve side effects in switch expression (#1694)
fixes #1690
---
lib/compress.js | 15 ++++++++-------
test/compress/switch.js | 26 ++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 8350ba2..9ed368c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2560,10 +2560,9 @@ merge(Compressor.prototype, {
fallthrough = !aborts(exact_match);
}
while (i < len) extract_declarations_from_unreachable_code(compressor, self.body[i++], decl);
- if (body.length == 0) return make_node(AST_BlockStatement, self, {
- body: decl
- }).optimize(compressor);
- body[0].body = decl.concat(body[0].body);
+ if (body.length > 0) {
+ body[0].body = decl.concat(body[0].body);
+ }
self.body = body;
}
while (branch = self.body[self.body.length - 1]) {
@@ -2575,9 +2574,11 @@ merge(Compressor.prototype, {
&& branch.expression.has_side_effects(compressor)) break;
self.body.pop();
}
- if (compressor.option("conditionals") && self.body.length == 0) {
- return make_node(AST_SimpleStatement, self, {
- body: self.expression
+ if (decl && self.body.length == 0) {
+ return make_node(AST_BlockStatement, self, {
+ body: decl.concat(make_node(AST_SimpleStatement, self.expression, {
+ body: self.expression
+ }))
}).optimize(compressor);
}
if (body && body.length == 1 && (body[0] === exact_match || body[0] === default_branch)) {
diff --git a/test/compress/switch.js b/test/compress/switch.js
index 2025d91..654a838 100644
--- a/test/compress/switch.js
+++ b/test/compress/switch.js
@@ -553,3 +553,29 @@ issue_1680_2: {
}
expect_stdout: true
}
+
+issue_1690_1: {
+ options = {
+ dead_code: true,
+ }
+ input: {
+ switch (console.log("PASS")) {}
+ }
+ expect: {
+ console.log("PASS");
+ }
+ expect_stdout: "PASS"
+}
+
+issue_1690_2: {
+ options = {
+ dead_code: false,
+ }
+ input: {
+ switch (console.log("PASS")) {}
+ }
+ expect: {
+ switch (console.log("PASS")) {}
+ }
+ expect_stdout: "PASS"
+}
--
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