aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnthony Van de Gejuchte <anthonyvdgent@gmail.com>2017-02-18 18:56:18 +0800
committeralexlamsl <alexlamsl@gmail.com>2017-02-18 18:56:18 +0800
commitdd31d12a9110b34c1b45a72b6e1f2b64c2d7afe9 (patch)
tree1aa21b366261d20c0dfa4e5adc7d39f568499784 /lib
parent7f8d72d9d37396f2da05d5d824f74bd414c30119 (diff)
downloadtracifyjs-dd31d12a9110b34c1b45a72b6e1f2b64c2d7afe9.tar.gz
tracifyjs-dd31d12a9110b34c1b45a72b6e1f2b64c2d7afe9.zip
Improve optimizing `function() { if(c){return foo} bar();}`
closes #1437
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 4e45df92..04aa1072 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -546,7 +546,7 @@ merge(Compressor.prototype, {
var self = compressor.self();
var multiple_if_returns = has_multiple_if_returns(statements);
var in_lambda = self instanceof AST_Lambda;
- var ret = [];
+ var ret = []; // Optimized statements, build from tail to front
loop: for (var i = statements.length; --i >= 0;) {
var stat = statements[i];
switch (true) {
@@ -607,19 +607,21 @@ merge(Compressor.prototype, {
ret = funs.concat([ stat.transform(compressor) ]);
continue loop;
}
+
//---
- // XXX: what was the intention of this case?
+ // if (a) return b; if (c) return d; e; ==> return a ? b : c ? d : void e;
+ //
// if sequences is not enabled, this can lead to an endless loop (issue #866).
// however, with sequences on this helps producing slightly better output for
// the example code.
if (compressor.option("sequences")
+ && i > 0 && statements[i - 1] instanceof AST_If && statements[i - 1].body instanceof AST_Return
&& ret.length == 1 && in_lambda && ret[0] instanceof AST_SimpleStatement
- && (!stat.alternative || stat.alternative instanceof AST_SimpleStatement)) {
+ && !stat.alternative) {
CHANGED = true;
ret.push(make_node(AST_Return, ret[0], {
value: make_node(AST_Undefined, ret[0])
}).transform(compressor));
- ret = as_statement_array(stat.alternative).concat(ret);
ret.unshift(stat);
continue loop;
}