diff options
author | kzc <kzc@users.noreply.github.com> | 2017-03-26 04:36:33 -0400 |
---|---|---|
committer | Alex Lam S.L <alexlamsl@gmail.com> | 2017-03-26 16:36:33 +0800 |
commit | 5509e51098274b28b8574246011767ba0be66edd (patch) | |
tree | c4304e33761aac0d5abe6f6ea3f83d4fc8258cf7 /lib | |
parent | 94f84727ce454c3ecf5206ac79dba4a21ec6deb6 (diff) | |
download | tracifyjs-5509e51098274b28b8574246011767ba0be66edd.tar.gz tracifyjs-5509e51098274b28b8574246011767ba0be66edd.zip |
optimize conditional when condition symbol matches consequent (#1684)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js index 8d1ef8ac..70bbb7fc 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3565,8 +3565,19 @@ merge(Compressor.prototype, { alternative: self.consequent }); } + var condition = self.condition; var consequent = self.consequent; var alternative = self.alternative; + // x?x:y --> x||y + if (condition instanceof AST_SymbolRef + && consequent instanceof AST_SymbolRef + && condition.definition() === consequent.definition()) { + return make_node(AST_Binary, self, { + operator: "||", + left: condition, + right: alternative + }); + } // if (foo) exp = something; else exp = something_else; // | // v |