diff options
author | 2021-09-23 17:32:39 -0700 | |
---|---|---|
committer | 2021-09-23 17:32:39 -0700 | |
commit | b150df34e0b66160f76c56b5dd47dfa643c13d85 (patch) | |
tree | af74e5d56a64834b660b6204d8f0d7a159bcb4bb | |
parent | da80c3b309e30eb0654f6adfbfaf42d4a2c5dc0b (diff) | |
download | bun-b150df34e0b66160f76c56b5dd47dfa643c13d85.tar.gz bun-b150df34e0b66160f76c56b5dd47dfa643c13d85.tar.zst bun-b150df34e0b66160f76c56b5dd47dfa643c13d85.zip |
Fix another simplification bug
-rw-r--r-- | src/js_parser/js_parser.zig | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index 8fde5fcbd..74d670d00 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -11632,22 +11632,18 @@ pub fn NewParser( e_.no = p.visitExpr(e_.no); p.is_control_flow_dead = old; - // we diverge from esbuild here a little - // esbuild rewrites something like "(a, true) ? b : c" => "a, b" - // we don't do that, since the goal isn't minifying - // though there are some cases where _not_ doing this potentially - // leads to unnecessary imports - if (side_effects.side_effects == .no_side_effects) { - - // "(1 ? fn : 2)()" => "fn()" - // "(1 ? this.fn : 2)" => "this.fn" - // "(1 ? this.fn : 2)()" => "(0, this.fn)()" - if (is_call_target and e_.yes.hasValueForThisInCall()) { - return p.e(E.Number{ .value = 0 }, e_.test_.loc).joinWithComma(e_.yes, p.allocator); - } + if (side_effects.side_effects == .could_have_side_effects) { + return Expr.joinWithComma(SideEffects.simpifyUnusedExpr(p, e_.test_) orelse p.e(E.Missing{}, e_.test_.loc), e_.yes, p.allocator); + } - return e_.yes; + // "(1 ? fn : 2)()" => "fn()" + // "(1 ? this.fn : 2)" => "this.fn" + // "(1 ? this.fn : 2)()" => "(0, this.fn)()" + if (is_call_target and e_.yes.hasValueForThisInCall()) { + return p.e(E.Number{ .value = 0 }, e_.test_.loc).joinWithComma(e_.yes, p.allocator); } + + return e_.yes; } else { // "false ? dead : live" const old = p.is_control_flow_dead; @@ -11656,17 +11652,18 @@ pub fn NewParser( p.is_control_flow_dead = old; e_.no = p.visitExpr(e_.no); - if (side_effects.side_effects == .no_side_effects) { - - // "(1 ? fn : 2)()" => "fn()" - // "(1 ? this.fn : 2)" => "this.fn" - // "(1 ? this.fn : 2)()" => "(0, this.fn)()" - if (is_call_target and e_.no.hasValueForThisInCall()) { - return p.e(E.Number{ .value = 0 }, e_.test_.loc).joinWithComma(e_.no, p.allocator); - } + // "(a, false) ? b : c" => "a, c" + if (side_effects.side_effects == .could_have_side_effects) { + return Expr.joinWithComma(SideEffects.simpifyUnusedExpr(p, e_.test_) orelse p.e(E.Missing{}, e_.test_.loc), e_.no, p.allocator); + } - return e_.no; + // "(1 ? fn : 2)()" => "fn()" + // "(1 ? this.fn : 2)" => "this.fn" + // "(1 ? this.fn : 2)()" => "(0, this.fn)()" + if (is_call_target and e_.no.hasValueForThisInCall()) { + return p.e(E.Number{ .value = 0 }, e_.test_.loc).joinWithComma(e_.no, p.allocator); } + return e_.no; } } }, |