Small cleanup
authorMihai Bazon <mihai@bazon.net>
Wed, 12 Dec 2012 09:50:03 +0000 (11:50 +0200)
committerMihai Bazon <mihai@bazon.net>
Wed, 12 Dec 2012 09:51:55 +0000 (11:51 +0200)
lib/output.js

index 72f49b9..ee5e9d9 100644 (file)
@@ -340,23 +340,25 @@ function OutputStream(options) {
     /* -----[ utils ]----- */
 
     function DEFPRINT(nodetype, generator) {
-        nodetype.DEFMETHOD("print", function(stream, force_parens){
-            var self = this;
-            stream.push_node(self);
-            if (force_parens || self.needs_parens(stream)) {
-                stream.with_parens(function(){
-                    self.add_comments(stream);
-                    self.add_source_map(stream);
-                    generator(self, stream);
-                });
-            } else {
+        nodetype.DEFMETHOD("_codegen", generator);
+    };
+
+    AST_Node.DEFMETHOD("print", function(stream, force_parens){
+        var self = this, generator = self._codegen;
+        stream.push_node(self);
+        if (force_parens || self.needs_parens(stream)) {
+            stream.with_parens(function(){
                 self.add_comments(stream);
                 self.add_source_map(stream);
                 generator(self, stream);
-            }
-            stream.pop_node();
-        });
-    };
+            });
+        } else {
+            self.add_comments(stream);
+            self.add_source_map(stream);
+            generator(self, stream);
+        }
+        stream.pop_node();
+    });
 
     AST_Node.DEFMETHOD("print_to_string", function(options){
         var s = OutputStream(options);
@@ -902,7 +904,7 @@ function OutputStream(options) {
     DEFPRINT(AST_New, function(self, output){
         output.print("new");
         output.space();
-        AST_Call.prototype.print.call(self, output);
+        AST_Call.prototype._codegen(self, output);
     });
 
     AST_Seq.DEFMETHOD("_do_print", function(output){