aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-08-27 11:00:22 +0300
committerMihai Bazon <mihai@bazon.net>2012-08-27 11:00:22 +0300
commit4437e7af1931f995686511938ad80f704ef5925e (patch)
treeae89a9a95df661fccd7beea9216492bfd3a43631 /lib
parenta8e49f15361cce98fdecb20535df4b4f0de553ca (diff)
downloadtracifyjs-4437e7af1931f995686511938ad80f704ef5925e.tar.gz
tracifyjs-4437e7af1931f995686511938ad80f704ef5925e.zip
fix compressing `a,b; return c;` into `return a,b,c;`
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js
index f23d4cd0..857d1bba 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -158,8 +158,7 @@ function Compressor(options, false_by_default) {
}
else if (compressor.option("warnings")) {
stat.walk(new TreeWalker(function(node){
- if (node instanceof AST_Definitions
- || node instanceof AST_Defun) {
+ if (node instanceof AST_Definitions || node instanceof AST_Defun) {
compressor.warn("Declarations in unreachable code! [{line},{col}]", node.start);
if (node instanceof AST_Definitions) {
node = node.clone();
@@ -169,11 +168,13 @@ function Compressor(options, false_by_default) {
else if (node instanceof AST_Defun) {
a.push(node);
}
- return true;
+ return true; // no point to descend
}
- if (node instanceof AST_Scope)
+ if (node instanceof AST_Scope) {
+ // also don't descend any other nested scopes
return true;
- }))
+ }
+ }));
};
} else {
a.push(stat);
@@ -185,6 +186,7 @@ function Compressor(options, false_by_default) {
}, []);
}
+ // XXX: this is destructive -- it modifies tree nodes.
function sequencesize(statements) {
var prev = null, last = statements.length - 1;
if (last) statements = statements.reduce(function(a, cur, i){
@@ -196,8 +198,9 @@ function Compressor(options, false_by_default) {
});
prev.body = seq;
}
- else if (i == last && cur instanceof AST_Exit
- && cur.value && a.length == 1) {
+ else if (i == last
+ && cur instanceof AST_Exit && cur.value
+ && a.length == 1 && prev instanceof AST_SimpleStatement) {
// it only makes sense to do this transformation
// if the AST gets to a single statement.
var seq = make_node(AST_Seq, prev, {