fix compressing a,b; return c; into return a,b,c;

This commit is contained in:
Mihai Bazon
2012-08-27 11:00:22 +03:00
parent a8e49f1536
commit 4437e7af19

View File

@@ -158,8 +158,7 @@ function Compressor(options, false_by_default) {
} }
else if (compressor.option("warnings")) { else if (compressor.option("warnings")) {
stat.walk(new TreeWalker(function(node){ stat.walk(new TreeWalker(function(node){
if (node instanceof AST_Definitions if (node instanceof AST_Definitions || node instanceof AST_Defun) {
|| node instanceof AST_Defun) {
compressor.warn("Declarations in unreachable code! [{line},{col}]", node.start); compressor.warn("Declarations in unreachable code! [{line},{col}]", node.start);
if (node instanceof AST_Definitions) { if (node instanceof AST_Definitions) {
node = node.clone(); node = node.clone();
@@ -169,11 +168,13 @@ function Compressor(options, false_by_default) {
else if (node instanceof AST_Defun) { else if (node instanceof AST_Defun) {
a.push(node); a.push(node);
} }
return true; // no point to descend
}
if (node instanceof AST_Scope) {
// also don't descend any other nested scopes
return true; return true;
} }
if (node instanceof AST_Scope) }));
return true;
}))
}; };
} else { } else {
a.push(stat); a.push(stat);
@@ -185,6 +186,7 @@ function Compressor(options, false_by_default) {
}, []); }, []);
} }
// XXX: this is destructive -- it modifies tree nodes.
function sequencesize(statements) { function sequencesize(statements) {
var prev = null, last = statements.length - 1; var prev = null, last = statements.length - 1;
if (last) statements = statements.reduce(function(a, cur, i){ if (last) statements = statements.reduce(function(a, cur, i){
@@ -196,8 +198,9 @@ function Compressor(options, false_by_default) {
}); });
prev.body = seq; prev.body = seq;
} }
else if (i == last && cur instanceof AST_Exit else if (i == last
&& cur.value && a.length == 1) { && cur instanceof AST_Exit && cur.value
&& a.length == 1 && prev instanceof AST_SimpleStatement) {
// it only makes sense to do this transformation // it only makes sense to do this transformation
// if the AST gets to a single statement. // if the AST gets to a single statement.
var seq = make_node(AST_Seq, prev, { var seq = make_node(AST_Seq, prev, {