aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-10-03 13:08:03 +0300
committerMihai Bazon <mihai@bazon.net>2012-10-03 13:08:03 +0300
commitc11de17e99fed5181f4be6e7a803aa92edce5459 (patch)
tree5e57b0a278e4105ceb29a081a390b54804022b54
parente0f5075e45b8914d2543238565f771d4822117ca (diff)
downloadtracifyjs-c11de17e99fed5181f4be6e7a803aa92edce5459.tar.gz
tracifyjs-c11de17e99fed5181f4be6e7a803aa92edce5459.zip
added option for side-effect-free statements, fix test
-rw-r--r--lib/compress.js11
-rw-r--r--test/compress/conditionals.js17
2 files changed, 24 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js
index e318038a..423d049b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -64,6 +64,7 @@ function Compressor(options, false_by_default) {
if_return : !false_by_default,
join_vars : !false_by_default,
cascade : !false_by_default,
+ side_effects : !false_by_default,
warnings : true,
global_defs : {}
@@ -998,9 +999,11 @@ merge(Compressor.prototype, {
});
OPT(AST_SimpleStatement, function(self, compressor){
- if (!self.body.has_side_effects()) {
- compressor.warn("Dropping side-effect-free statement [{file}:{line},{col}]", self.start);
- return make_node(AST_EmptyStatement, self);
+ if (compressor.option("side_effects")) {
+ if (!self.body.has_side_effects()) {
+ compressor.warn("Dropping side-effect-free statement [{file}:{line},{col}]", self.start);
+ return make_node(AST_EmptyStatement, self);
+ }
}
return self;
});
@@ -1153,7 +1156,7 @@ merge(Compressor.prototype, {
operator: "&&",
left: self.condition,
right: self.body.condition
- });
+ }).transform(compressor);
self.body = self.body.body;
}
if (aborts(self.body)) {
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js
index bc4624d1..dc2bb671 100644
--- a/test/compress/conditionals.js
+++ b/test/compress/conditionals.js
@@ -124,3 +124,20 @@ ifs_5: {
}
}
}
+
+ifs_6: {
+ options = {
+ conditionals: true,
+ comparisons: true
+ };
+ input: {
+ if (!foo && !bar && !baz && !boo) {
+ x = 10;
+ } else {
+ x = 20;
+ }
+ }
+ expect: {
+ x = foo || bar || baz || boo ? 20 : 10;
+ }
+}