cleaned up some mess and started the actual compressor
This commit is contained in:
35
lib/ast.js
35
lib/ast.js
@@ -35,6 +35,9 @@ var AST_Token = DEFNODE("Token", "type value line col pos endpos nlb comments_be
|
||||
}, null);
|
||||
|
||||
var AST_Node = DEFNODE("Node", "start end", {
|
||||
clone: function() {
|
||||
return new this.CTOR(this);
|
||||
},
|
||||
$documentation: "Base class of all AST nodes",
|
||||
_walk: function(visitor) {
|
||||
return visitor._visit(this);
|
||||
@@ -44,9 +47,10 @@ var AST_Node = DEFNODE("Node", "start end", {
|
||||
}
|
||||
}, null);
|
||||
|
||||
AST_Node.warn_function = noop;
|
||||
AST_Node.warn_function = null;
|
||||
AST_Node.warn = function(txt, props) {
|
||||
AST_Node.warn_function(string_template(txt, props));
|
||||
if (AST_Node.warn_function)
|
||||
AST_Node.warn_function(string_template(txt, props));
|
||||
};
|
||||
|
||||
var AST_Debugger = DEFNODE("Debugger", null, {
|
||||
@@ -86,10 +90,9 @@ var AST_BlockStatement = DEFNODE("BlockStatement", null, {
|
||||
$documentation: "A block statement.",
|
||||
_walk: function(visitor) {
|
||||
return visitor._visit(this, function(){
|
||||
var a = this.body, i = 0, n = a.length;
|
||||
while (i < n) {
|
||||
a[i++]._walk(visitor);
|
||||
}
|
||||
this.body.forEach(function(stat){
|
||||
stat._walk(visitor);
|
||||
});
|
||||
});
|
||||
}
|
||||
}, AST_Statement);
|
||||
@@ -135,9 +138,8 @@ var AST_ForIn = DEFNODE("ForIn", "init name object", {
|
||||
$documentation: "A `for ... in` statement",
|
||||
_walk: function(visitor) {
|
||||
return visitor._visit(this, function(){
|
||||
if (this.init) this.init._walk(visitor);
|
||||
else if (this.name) this.name._walk(visitor);
|
||||
if (this.object) this.object._walk(visitor);
|
||||
this.init._walk(visitor);
|
||||
this.object._walk(visitor);
|
||||
this.body._walk(visitor);
|
||||
});
|
||||
}
|
||||
@@ -295,7 +297,7 @@ var AST_Try = DEFNODE("Try", "btry bcatch bfinally", {
|
||||
// IE which simply introduces the name in the surrounding scope. If
|
||||
// we ever want to fix this then AST_Catch should inherit from
|
||||
// AST_Scope.
|
||||
var AST_Catch = DEFNODE("Catch", "argname", {
|
||||
var AST_Catch = DEFNODE("Catch", "argname body", {
|
||||
$documentation: "A `catch` node; only makes sense as part of a `try` statement",
|
||||
_walk: function(visitor) {
|
||||
return visitor._visit(this, function(){
|
||||
@@ -303,11 +305,16 @@ var AST_Catch = DEFNODE("Catch", "argname", {
|
||||
this.body._walk(visitor);
|
||||
});
|
||||
}
|
||||
}, AST_BlockStatement);
|
||||
});
|
||||
|
||||
var AST_Finally = DEFNODE("Finally", null, {
|
||||
$documentation: "A `finally` node; only makes sense as part of a `try` statement"
|
||||
}, AST_BlockStatement);
|
||||
var AST_Finally = DEFNODE("Finally", "body", {
|
||||
$documentation: "A `finally` node; only makes sense as part of a `try` statement",
|
||||
_walk: function(visitor) {
|
||||
return visitor._visit(this, function(){
|
||||
this.body._walk(visitor);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/* -----[ VAR/CONST ]----- */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user