made --nodes output prettier

This commit is contained in:
satyr 2010-09-27 04:47:52 +09:00
parent ecb23d15c4
commit bc87d9ed3d
4 changed files with 21 additions and 28 deletions

View File

@ -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 {

View File

@ -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;
})();

View File

@ -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

View File

@ -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