aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-01-04 09:24:28 +0800
committerGitHub <noreply@github.com>2020-01-04 09:24:28 +0800
commit1988495d712c4eeabd89068b4da3420e2e5eb50f (patch)
tree807ef0676bd7d0b6e3c7c973745dfa79b9fcd7fd
parentfdc10086dafa3b1fbbb686f333b0b7b8e3bb70e5 (diff)
downloadtracifyjs-1988495d712c4eeabd89068b4da3420e2e5eb50f.tar.gz
tracifyjs-1988495d712c4eeabd89068b4da3420e2e5eb50f.zip
fix corner case in `conditionals` (#3669)
fixes #3668
-rw-r--r--lib/compress.js4
-rw-r--r--test/compress/conditionals.js31
2 files changed, 33 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index fcfe95f7..7e55da5a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -5114,8 +5114,8 @@ merge(Compressor.prototype, {
var exit = make_node(self.body.CTOR, self, {
value: make_node(AST_Conditional, self, {
condition : self.condition,
- consequent : self.body.value || make_node(AST_Undefined, self.body),
- alternative : self.alternative.value || make_node(AST_Undefined, self.alternative)
+ consequent : self.body.value || make_node(AST_Undefined, self.body).transform(compressor),
+ alternative : self.alternative.value || make_node(AST_Undefined, self.alternative).transform(compressor)
})
});
if (exit instanceof AST_Return) {
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js
index 3f3df72d..2049b401 100644
--- a/test/compress/conditionals.js
+++ b/test/compress/conditionals.js
@@ -1578,3 +1578,34 @@ issue_3576: {
}
expect_stdout: "PASS"
}
+
+issue_3668: {
+ options = {
+ conditionals: true,
+ if_return: true,
+ }
+ input: {
+ function f() {
+ try {
+ var undefined = typeof f;
+ if (!f) return undefined;
+ return;
+ } catch (e) {
+ return "FAIL";
+ }
+ }
+ console.log(f());
+ }
+ expect: {
+ function f() {
+ try {
+ var undefined = typeof f;
+ return f ? void 0 : undefined;
+ } catch (e) {
+ return "FAIL";
+ }
+ }
+ console.log(f());
+ }
+ expect_stdout: "undefined"
+}