aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-11-28 07:40:34 +0800
committerGitHub <noreply@github.com>2019-11-28 07:40:34 +0800
commit5a88c30d6598bc9ec6d3b81077a95ab6942da9cd (patch)
treedff8d0e511b33f8142c152bab5885b19eec36c80
parent168ae747ad8c8c48a0318eaaffd25e084521fb60 (diff)
downloadtracifyjs-5a88c30d6598bc9ec6d3b81077a95ab6942da9cd.tar.gz
tracifyjs-5a88c30d6598bc9ec6d3b81077a95ab6942da9cd.zip
enhance `assignments` (#3612)
-rw-r--r--lib/compress.js4
-rw-r--r--test/compress/assignment.js42
2 files changed, 40 insertions, 6 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 686a8d42..52c79a73 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -6720,8 +6720,8 @@ merge(Compressor.prototype, {
self.right = self.right.left;
}
}
- if ((self.operator == "+=" || self.operator == "-=")
- && self.left.is_number(compressor)
+ if ((self.operator == "-=" || self.operator == "+="
+ && (self.left.is_boolean(compressor) || self.left.is_number(compressor)))
&& self.right instanceof AST_Number
&& self.right.getValue() === 1) {
var op = self.operator.slice(0, -1);
diff --git a/test/compress/assignment.js b/test/compress/assignment.js
index 5ca7440a..2230272a 100644
--- a/test/compress/assignment.js
+++ b/test/compress/assignment.js
@@ -290,26 +290,60 @@ increment_decrement_2: {
expect_stdout: "42"
}
-issue_3375: {
+issue_3375_1: {
options = {
assignments: true,
reduce_vars: true,
}
input: {
- console.log(typeof function(b) {
+ function p(o) {
+ console.log(typeof o, o);
+ }
+ p(function(b) {
var a = b += 1;
--b;
return a;
}("object"));
}
expect: {
- console.log(typeof function(b) {
+ function p(o) {
+ console.log(typeof o, o);
+ }
+ p(function(b) {
var a = b += 1;
--b;
return a;
}("object"));
}
- expect_stdout: "string"
+ expect_stdout: "string object1"
+}
+
+issue_3375_2: {
+ options = {
+ assignments: true,
+ reduce_vars: true,
+ }
+ input: {
+ function p(o) {
+ console.log(typeof o, o);
+ }
+ p(function(b) {
+ var a = b -= 1;
+ --b;
+ return a;
+ }("object"));
+ }
+ expect: {
+ function p(o) {
+ console.log(typeof o, o);
+ }
+ p(function(b) {
+ var a = --b;
+ --b;
+ return a;
+ }("object"));
+ }
+ expect_stdout: "number NaN"
}
issue_3427: {