aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-04-26 23:44:53 +0100
committerGitHub <noreply@github.com>2020-04-27 06:44:53 +0800
commitbc2a4a3bb8c08139c53d0d595181010ead516d77 (patch)
treedd90d6e61c8686ab2188b5853526d57d0fee5975
parenta4a8ccea8c323f8a41a5f2e7df907f41876ff9f6 (diff)
downloadtracifyjs-bc2a4a3bb8c08139c53d0d595181010ead516d77.tar.gz
tracifyjs-bc2a4a3bb8c08139c53d0d595181010ead516d77.zip
fix corner case in `ie8` (#3824)
fixes #3823
-rw-r--r--lib/compress.js47
-rw-r--r--test/compress/ie8.js25
2 files changed, 58 insertions, 14 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 67884a13..a42095cf 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4906,20 +4906,39 @@ merge(Compressor.prototype, {
var consequent = this.consequent.drop_side_effect_free(compressor);
var alternative = this.alternative.drop_side_effect_free(compressor);
if (consequent === this.consequent && alternative === this.alternative) return this;
- if (!consequent) return alternative ? make_node(AST_Binary, this, {
- operator: "||",
- left: this.condition,
- right: alternative
- }) : this.condition.drop_side_effect_free(compressor);
- if (!alternative) return make_node(AST_Binary, this, {
- operator: "&&",
- left: this.condition,
- right: consequent
- });
- var node = this.clone();
- node.consequent = consequent;
- node.alternative = alternative;
- return node;
+ var exprs;
+ if (compressor.option("ie8")) {
+ exprs = [];
+ if (consequent instanceof AST_Function) {
+ exprs.push(consequent);
+ consequent = null;
+ }
+ if (alternative instanceof AST_Function) {
+ exprs.push(alternative);
+ alternative = null;
+ }
+ }
+ var node;
+ if (!consequent) {
+ node = alternative ? make_node(AST_Binary, this, {
+ operator: "||",
+ left: this.condition,
+ right: alternative
+ }) : this.condition.drop_side_effect_free(compressor);
+ } else if (!alternative) {
+ node = make_node(AST_Binary, this, {
+ operator: "&&",
+ left: this.condition,
+ right: consequent
+ });
+ } else {
+ node = this.clone();
+ node.consequent = consequent;
+ node.alternative = alternative;
+ }
+ if (!compressor.option("ie8")) return node;
+ if (node) exprs.push(node);
+ return make_sequence(this, exprs);
});
def(AST_Constant, return_null);
def(AST_Dot, function(compressor, first_in_statement) {
diff --git a/test/compress/ie8.js b/test/compress/ie8.js
index 4dfa7c6b..8f81b01b 100644
--- a/test/compress/ie8.js
+++ b/test/compress/ie8.js
@@ -2420,3 +2420,28 @@ issue_3750: {
}
expect_stdout: "PASS"
}
+
+issue_3823: {
+ options = {
+ ie8: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ for (var i = 0; i < 1; i++) {
+ var a = a ? function f() {
+ f;
+ } : 0;
+ console.log("PASS", typeof f);
+ }
+ }
+ expect: {
+ for (var i = 0; i < 1; i++) {
+ (function f() {
+ f;
+ });
+ console.log("PASS", typeof f);
+ }
+ }
+ expect_stdout: "PASS undefined"
+}