more optimizations that v1 does and some cleanups

- a = a + x ==> a+=x
- joining consecutive var statements (hoisting is not always desirable)
- x == false ==> x == 0, x != true ==> x != 1
- x, x ==> x; x = exp(), x ==> x = exp()
- discarding useless break-s
This commit is contained in:
Mihai Bazon
2012-09-14 15:36:38 +03:00
parent 93b973c99d
commit 924aa58060
6 changed files with 256 additions and 79 deletions

View File

@@ -779,9 +779,11 @@ function OutputStream(options) {
AST_Call.prototype.print.call(self, output);
});
DEFPRINT(AST_Seq, function(self, output){
self.first.print(output);
output.comma();
self.second.print(output);
self.car.print(output);
if (self.cdr) {
output.comma();
self.cdr.print(output);
}
});
DEFPRINT(AST_Dot, function(self, output){
var expr = self.expression;
@@ -921,13 +923,12 @@ function OutputStream(options) {
while (i > 0) {
if (p instanceof AST_Statement && p.body === node)
return true;
if ((p instanceof AST_Seq && p.first === node ) ||
if ((p instanceof AST_Seq && p.car === node ) ||
(p instanceof AST_Call && p.expression === node ) ||
(p instanceof AST_Dot && p.expression === node ) ||
(p instanceof AST_Sub && p.expression === node ) ||
(p instanceof AST_Conditional && p.condition === node ) ||
(p instanceof AST_Binary && p.first === node ) ||
(p instanceof AST_Assign && p.first === node ) ||
(p instanceof AST_Binary && p.left === node ) ||
(p instanceof AST_UnaryPostfix && p.expression === node ))
{
node = p;