diff --git a/lib/command.js b/lib/command.js index 8a6940ff..72a5a197 100644 --- a/lib/command.js +++ b/lib/command.js @@ -112,7 +112,7 @@ if (o.tokens) { return printTokens(CoffeeScript.tokens(t.input)); } else if (o.nodes) { - return puts(CoffeeScript.nodes(t.input).toString()); + return puts(CoffeeScript.nodes(t.input).toString().trim()); } else if (o.run) { return CoffeeScript.run(t.input, t.options); } else { diff --git a/lib/nodes.js b/lib/nodes.js index 61acf5a7..616e96c4 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -275,8 +275,8 @@ end = this.isStatement(o) ? ';' : ''; return idt + this.value + end; }; - LiteralNode.prototype.toString = function(idt) { - return '"' + this.value + '"'; + LiteralNode.prototype.toString = function() { + return ' "' + this.value + '"'; }; return LiteralNode; })(); @@ -1135,19 +1135,6 @@ CodeNode.prototype.traverseChildren = function(crossScope, func) { return crossScope ? CodeNode.__super__.traverseChildren.call(this, crossScope, func) : null; }; - CodeNode.prototype.toString = function(idt) { - var _i, _len, _ref2, _result, child, children; - idt || (idt = ''); - children = (function() { - _result = []; _ref2 = this.collectChildren(); - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - child = _ref2[_i]; - _result.push(child.toString(idt + TAB)); - } - return _result; - }).call(this).join(''); - return '\n' + idt + children; - }; return CodeNode; })(); exports.ParamNode = (function() { @@ -1165,8 +1152,17 @@ ParamNode.prototype.compileNode = function(o) { return this.value.compile(o); }; - ParamNode.prototype.toString = function(idt) { - return this.attach ? (literal('@' + this.name)).toString(idt) : this.value.toString(idt); + ParamNode.prototype.toString = function() { + var _ref2, name; + _ref2 = this; + name = _ref2.name; + if (this.attach) { + name = '@' + name; + } + if (this.splat) { + name += '...'; + } + return literal(name).toString(); }; return ParamNode; })(); diff --git a/src/command.coffee b/src/command.coffee index 3465e48c..46109f7e 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -101,7 +101,7 @@ compileScript = (file, input, base) -> t = task = {file, input, options} CoffeeScript.emit 'compile', task if o.tokens then printTokens CoffeeScript.tokens t.input - else if o.nodes then puts CoffeeScript.nodes(t.input).toString() + else if o.nodes then puts CoffeeScript.nodes(t.input).toString().trim() else if o.run then CoffeeScript.run t.input, t.options else t.output = CoffeeScript.compile t.input, t.options diff --git a/src/nodes.coffee b/src/nodes.coffee index 0031bb1d..b646827b 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -252,8 +252,7 @@ exports.LiteralNode = class LiteralNode extends BaseNode end = if @isStatement(o) then ';' else '' idt + @value + end - toString: (idt) -> - '"' + @value + '"' + toString: -> ' "' + @value + '"' #### ReturnNode @@ -957,11 +956,6 @@ exports.CodeNode = class CodeNode extends BaseNode # unless crossScope is true traverseChildren: (crossScope, func) -> super(crossScope, func) if crossScope - toString: (idt) -> - idt or= '' - children = (child.toString(idt + TAB) for child in @collectChildren()).join('') - '\n' + idt + children - #### ParamNode # A parameter in a function definition. Beyond a typical Javascript parameter, @@ -979,8 +973,11 @@ exports.ParamNode = class ParamNode extends BaseNode compileNode: (o) -> @value.compile o - toString: (idt) -> - if @attach then (literal '@' + @name).toString idt else @value.toString idt + toString: -> + {name} = @ + name = '@' + name if @attach + name += '...' if @splat + literal(name).toString() #### SplatNode