checkpoint
This commit is contained in:
@@ -64,6 +64,7 @@ function Compressor(options, false_by_default) {
|
||||
evaluate : !false_by_default,
|
||||
booleans : !false_by_default,
|
||||
dwloops : !false_by_default,
|
||||
hoist : !false_by_default,
|
||||
|
||||
warnings : true
|
||||
});
|
||||
@@ -140,7 +141,7 @@ function Compressor(options, false_by_default) {
|
||||
statements = eliminate_dead_code(statements, compressor);
|
||||
}
|
||||
if (compressor.option("sequences")) {
|
||||
statements = sequencesize(statements);
|
||||
statements = sequencesize(statements, compressor);
|
||||
}
|
||||
return statements;
|
||||
};
|
||||
@@ -157,7 +158,7 @@ function Compressor(options, false_by_default) {
|
||||
}
|
||||
return a;
|
||||
}, []);
|
||||
}
|
||||
};
|
||||
|
||||
function eliminate_dead_code(statements, compressor) {
|
||||
var has_quit = false;
|
||||
@@ -194,7 +195,7 @@ function Compressor(options, false_by_default) {
|
||||
}
|
||||
return a;
|
||||
}, []);
|
||||
}
|
||||
};
|
||||
|
||||
// XXX: this is destructive -- it modifies tree nodes.
|
||||
function sequencesize(statements) {
|
||||
@@ -227,7 +228,7 @@ function Compressor(options, false_by_default) {
|
||||
return a;
|
||||
}, []);
|
||||
return statements;
|
||||
}
|
||||
};
|
||||
|
||||
/* -----[ boolean/negation helpers ]----- */
|
||||
|
||||
@@ -479,6 +480,18 @@ function Compressor(options, false_by_default) {
|
||||
return self;
|
||||
});
|
||||
|
||||
SQUEEZE(AST_Scope, function(self, compressor){
|
||||
self = self.clone();
|
||||
self.hoist_declarations(compressor);
|
||||
self.body = tighten_body(self.body, compressor);
|
||||
return self;
|
||||
});
|
||||
|
||||
AST_Scope.DEFMETHOD("hoist_declarations", function(compressor){
|
||||
if (compressor.option("hoist")) {
|
||||
}
|
||||
});
|
||||
|
||||
SQUEEZE(AST_EmptyStatement, function(self, compressor){
|
||||
return self;
|
||||
});
|
||||
@@ -559,6 +572,7 @@ function Compressor(options, false_by_default) {
|
||||
// “has no side effects”; also it doesn't work for cases like
|
||||
// `x && true`, though it probably should.
|
||||
var cond = self.condition.evaluate(compressor);
|
||||
self.condition = cond[0];
|
||||
if (cond.length == 2) {
|
||||
if (cond[1]) {
|
||||
AST_Node.warn("Condition always true [{line},{col}]", self.condition.start);
|
||||
@@ -568,6 +582,13 @@ function Compressor(options, false_by_default) {
|
||||
return self.alternative || make_node(AST_EmptyStatement, self);
|
||||
}
|
||||
}
|
||||
if (self.condition instanceof AST_UnaryPrefix
|
||||
&& self.condition.operator == "!") {
|
||||
self.condition = self.condition.expression;
|
||||
var tmp = self.body;
|
||||
self.body = self.alternative || make_node(AST_EmptyStatement, self);
|
||||
self.alternative = tmp;
|
||||
}
|
||||
if (self.body instanceof AST_SimpleStatement
|
||||
&& self.alternative instanceof AST_SimpleStatement) {
|
||||
return make_node(AST_SimpleStatement, self, {
|
||||
@@ -578,7 +599,9 @@ function Compressor(options, false_by_default) {
|
||||
}).optimize(compressor)
|
||||
});
|
||||
}
|
||||
if ((!self.alternative || self.alternative instanceof AST_EmptyStatement) && self.body instanceof AST_SimpleStatement) {
|
||||
if ((!self.alternative
|
||||
|| self.alternative instanceof AST_EmptyStatement)
|
||||
&& self.body instanceof AST_SimpleStatement) {
|
||||
return make_node(AST_SimpleStatement, self, {
|
||||
body: make_node(AST_Binary, self, {
|
||||
operator : "&&",
|
||||
@@ -589,7 +612,7 @@ function Compressor(options, false_by_default) {
|
||||
}
|
||||
if (self.body instanceof AST_EmptyStatement
|
||||
&& self.alternative
|
||||
&& !(self.alternative instanceof AST_EmptyStatement)) {
|
||||
&& self.alternative instanceof AST_SimpleStatement) {
|
||||
return make_node(AST_SimpleStatement, self, {
|
||||
body: make_node(AST_Binary, self, {
|
||||
operator : "||",
|
||||
@@ -656,6 +679,7 @@ function Compressor(options, false_by_default) {
|
||||
|
||||
SQUEEZE(AST_Lambda, function(self, compressor){
|
||||
self = self.clone();
|
||||
self.hoist_declarations(compressor);
|
||||
if (self.name) self.name = self.name.squeeze(compressor);
|
||||
self.argnames = do_list(self.argnames, compressor);
|
||||
self.body = self.body.squeeze(compressor);
|
||||
|
||||
Reference in New Issue
Block a user