aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-10-03 15:41:11 +0300
committerMihai Bazon <mihai@bazon.net>2012-10-03 15:41:11 +0300
commit3412498795cfeb4c5700c39e05f895c96412695f (patch)
treef4a87bdcef8d6ded9d46625b81ee48aa44212bd3 /lib
parent9221ad62dbca2d9cccd252ddc1344f221767bc96 (diff)
downloadtracifyjs-3412498795cfeb4c5700c39e05f895c96412695f.tar.gz
tracifyjs-3412498795cfeb4c5700c39e05f895c96412695f.zip
AST cleanup (dropped AST_StatementBase)
Diffstat (limited to 'lib')
-rw-r--r--lib/ast.js42
-rw-r--r--lib/compress.js4
2 files changed, 24 insertions, 22 deletions
diff --git a/lib/ast.js b/lib/ast.js
index 185328a1..d80d7152 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -114,31 +114,28 @@ AST_Node.warn = function(txt, props) {
/* -----[ statements ]----- */
-var AST_StatementBase = DEFNODE("StatementBase", null, {
+var AST_Statement = DEFNODE("Statement", null, {
+ $documentation: "Base class of all statements",
});
-var AST_Statement = DEFNODE("Statement", "body", {
- $documentation: "Base class of all statements",
+var AST_Debugger = DEFNODE("Debugger", null, {
+ $documentation: "Represents a debugger statement",
+}, AST_Statement);
+
+var AST_Directive = DEFNODE("Directive", "value scope", {
+ $documentation: "Represents a directive, like \"use strict\";",
+}, AST_Statement);
+
+var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
+ $documentation: "A statement consisting of an expression, i.e. a = 1 + 2.",
_walk: function(visitor) {
return visitor._visit(this, function(){
this.body._walk(visitor);
});
}
-}, AST_StatementBase);
-
-var AST_Debugger = DEFNODE("Debugger", null, {
- $documentation: "Represents a debugger statement"
-}, AST_StatementBase);
-
-var AST_Directive = DEFNODE("Directive", "value scope", {
- $documentation: "Represents a directive, like \"use strict\";"
-}, AST_StatementBase);
-
-var AST_SimpleStatement = DEFNODE("SimpleStatement", null, {
- $documentation: "A statement consisting of an expression, i.e. a = 1 + 2."
}, AST_Statement);
-var AST_BlockStatement = DEFNODE("BlockStatement", null, {
+var AST_BlockStatement = DEFNODE("BlockStatement", "body", {
$documentation: "A block statement.",
_walk: function(visitor) {
return visitor._visit(this, function(){
@@ -158,7 +155,7 @@ function walk_body(node, visitor) {
});
};
-var AST_Block = DEFNODE("Block", null, {
+var AST_Block = DEFNODE("Block", "body", {
$documentation: "A block of statements (usually always bracketed)",
_walk: function(visitor) {
return visitor._visit(this, function(){
@@ -174,8 +171,13 @@ var AST_EmptyStatement = DEFNODE("EmptyStatement", null, {
}
}, AST_Statement);
-var AST_StatementWithBody = DEFNODE("StatementWithBody", null, {
- $documentation: "Base class for all statements that contain one nested body: `For`, `ForIn`, `Do`, `While`, `With`."
+var AST_StatementWithBody = DEFNODE("StatementWithBody", "body", {
+ $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);
+ });
+ }
}, AST_Statement);
var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", {
@@ -325,7 +327,7 @@ var AST_If = DEFNODE("If", "condition alternative", {
/* -----[ SWITCH ]----- */
-var AST_Switch = DEFNODE("Switch", "expression", {
+var AST_Switch = DEFNODE("Switch", "body expression", {
$documentation: "A `switch` statement",
_walk: function(visitor) {
return visitor._visit(this, function(){
diff --git a/lib/compress.js b/lib/compress.js
index 423d049b..1319d798 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -162,7 +162,7 @@ merge(Compressor.prototype, {
if (thing === null) return [];
if (thing instanceof AST_BlockStatement) return thing.body;
if (thing instanceof AST_EmptyStatement) return [];
- if (thing instanceof AST_StatementBase) return [ thing ];
+ if (thing instanceof AST_Statement) return [ thing ];
throw new Error("Can't convert thing to statement array");
};
@@ -741,7 +741,7 @@ merge(Compressor.prototype, {
return thing && thing.aborts();
};
(function(def){
- def(AST_StatementBase, function(){ return null });
+ def(AST_Statement, function(){ return null });
def(AST_Jump, function(){ return this });
def(AST_BlockStatement, function(){
var n = this.body.length;