aboutsummaryrefslogtreecommitdiff
path: root/lib/ast.js
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-08-21 15:45:05 +0300
committerMihai Bazon <mihai@bazon.net>2012-08-21 16:14:43 +0300
commitffe58a9961ced012b40c16b93f9fe2370293431b (patch)
treee1436f3ebfb25d1abe37be859c5a9622f8aaba47 /lib/ast.js
parent7ae1c600a24e2f43feb839c5fd1625f6261751b5 (diff)
downloadtracifyjs-ffe58a9961ced012b40c16b93f9fe2370293431b.tar.gz
tracifyjs-ffe58a9961ced012b40c16b93f9fe2370293431b.zip
cleaned up some mess and started the actual compressor
Diffstat (limited to 'lib/ast.js')
-rw-r--r--lib/ast.js35
1 files changed, 21 insertions, 14 deletions
diff --git a/lib/ast.js b/lib/ast.js
index bb2a07c0..1b75bd64 100644
--- a/lib/ast.js
+++ b/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 ]----- */