aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ast.js27
-rw-r--r--lib/compress.js16
-rw-r--r--lib/transform.js4
3 files changed, 17 insertions, 30 deletions
diff --git a/lib/ast.js b/lib/ast.js
index fde1ca1a..39a84a65 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -123,7 +123,7 @@ var AST_Directive = DEFNODE("Directive", "value scope", {
}, AST_Statement);
var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
- $documentation: "A statement consisting of an expression, i.e. a = 1 + 2.",
+ $documentation: "A statement consisting of an expression, i.e. a = 1 + 2",
_walk: function(visitor) {
return visitor._visit(this, function(){
this.body._walk(visitor);
@@ -131,17 +131,6 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
}
}, AST_Statement);
-var AST_BlockStatement = DEFNODE("BlockStatement", "body", {
- $documentation: "A block statement.",
- _walk: function(visitor) {
- return visitor._visit(this, function(){
- this.body.forEach(function(stat){
- stat._walk(visitor);
- });
- });
- }
-}, AST_Statement);
-
function walk_body(node, visitor) {
if (node.body instanceof AST_Statement) {
node.body._walk(visitor);
@@ -152,7 +141,7 @@ function walk_body(node, visitor) {
};
var AST_Block = DEFNODE("Block", "body", {
- $documentation: "A block of statements (usually always bracketed)",
+ $documentation: "A body of statements (usually bracketed)",
_walk: function(visitor) {
return visitor._visit(this, function(){
walk_body(this, visitor);
@@ -160,15 +149,19 @@ var AST_Block = DEFNODE("Block", "body", {
}
}, AST_Statement);
+var AST_BlockStatement = DEFNODE("BlockStatement", null, {
+ $documentation: "A block statement",
+}, AST_Block);
+
var AST_EmptyStatement = DEFNODE("EmptyStatement", null, {
- $documentation: "The empty statement (empty block or simply a semicolon).",
+ $documentation: "The empty statement (empty block or simply a semicolon)",
_walk: function(visitor) {
return visitor._visit(this);
}
}, AST_Statement);
var AST_StatementWithBody = DEFNODE("StatementWithBody", "body", {
- $documentation: "Base class for all statements that contain one nested body: `For`, `ForIn`, `Do`, `While`, `With`.",
+ $documentation: "Base class for all statements that contain one nested body: `For`, `ForIn`, `Do`, `While`, `With`",
_walk: function(visitor) {
return visitor._visit(this, function(){
this.body._walk(visitor);
@@ -187,7 +180,7 @@ var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", {
}, AST_StatementWithBody);
var AST_DWLoop = DEFNODE("DWLoop", "condition", {
- $documentation: "Base class for do/while statements.",
+ $documentation: "Base class for do/while statements",
_walk: function(visitor) {
return visitor._visit(this, function(){
this.condition._walk(visitor);
@@ -469,7 +462,7 @@ var AST_Call = DEFNODE("Call", "expression args", {
});
var AST_New = DEFNODE("New", null, {
- $documentation: "An object instantiation. Derives from a function call since it has exactly the same properties."
+ $documentation: "An object instantiation. Derives from a function call since it has exactly the same properties"
}, AST_Call);
var AST_Seq = DEFNODE("Seq", "car cdr", {
diff --git a/lib/compress.js b/lib/compress.js
index 6709d8e6..abb00c29 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -682,15 +682,13 @@ merge(Compressor.prototype, {
def(AST_Constant, function(){ return false });
def(AST_This, function(){ return false });
- function block(){
+ def(AST_Block, function(){
for (var i = this.body.length; --i >= 0;) {
if (this.body[i].has_side_effects())
return true;
}
return false;
- };
- def(AST_Block, block);
- def(AST_BlockStatement, block);
+ });
def(AST_SimpleStatement, function(){
if (this.body instanceof AST_Function) return false;
@@ -780,6 +778,11 @@ merge(Compressor.prototype, {
return self.label.references.length == 0 ? self.body : self;
});
+ OPT(AST_Block, function(self, compressor){
+ self.body = tighten_body(self.body, compressor);
+ return self;
+ });
+
OPT(AST_BlockStatement, function(self, compressor){
self.body = tighten_body(self.body, compressor);
switch (self.body.length) {
@@ -789,11 +792,6 @@ merge(Compressor.prototype, {
return self;
});
- OPT(AST_Block, function(self, compressor){
- self.body = tighten_body(self.body, compressor);
- return self;
- });
-
AST_Scope.DEFMETHOD("drop_unused", function(compressor){
var self = this;
if (compressor.option("unused")
diff --git a/lib/transform.js b/lib/transform.js
index db228beb..e19210f9 100644
--- a/lib/transform.js
+++ b/lib/transform.js
@@ -93,10 +93,6 @@ TreeTransformer.prototype = new TreeWalker;
self.body = self.body.transform(tw);
});
- _(AST_BlockStatement, function(self, tw){
- self.body = do_list(self.body, tw);
- });
-
_(AST_Block, function(self, tw){
self.body = do_list(self.body, tw);
});