made --nodes output prettier
This commit is contained in:
parent
ecb23d15c4
commit
bc87d9ed3d
|
@ -112,7 +112,7 @@
|
||||||
if (o.tokens) {
|
if (o.tokens) {
|
||||||
return printTokens(CoffeeScript.tokens(t.input));
|
return printTokens(CoffeeScript.tokens(t.input));
|
||||||
} else if (o.nodes) {
|
} else if (o.nodes) {
|
||||||
return puts(CoffeeScript.nodes(t.input).toString());
|
return puts(CoffeeScript.nodes(t.input).toString().trim());
|
||||||
} else if (o.run) {
|
} else if (o.run) {
|
||||||
return CoffeeScript.run(t.input, t.options);
|
return CoffeeScript.run(t.input, t.options);
|
||||||
} else {
|
} else {
|
||||||
|
|
30
lib/nodes.js
30
lib/nodes.js
|
@ -275,8 +275,8 @@
|
||||||
end = this.isStatement(o) ? ';' : '';
|
end = this.isStatement(o) ? ';' : '';
|
||||||
return idt + this.value + end;
|
return idt + this.value + end;
|
||||||
};
|
};
|
||||||
LiteralNode.prototype.toString = function(idt) {
|
LiteralNode.prototype.toString = function() {
|
||||||
return '"' + this.value + '"';
|
return ' "' + this.value + '"';
|
||||||
};
|
};
|
||||||
return LiteralNode;
|
return LiteralNode;
|
||||||
})();
|
})();
|
||||||
|
@ -1135,19 +1135,6 @@
|
||||||
CodeNode.prototype.traverseChildren = function(crossScope, func) {
|
CodeNode.prototype.traverseChildren = function(crossScope, func) {
|
||||||
return crossScope ? CodeNode.__super__.traverseChildren.call(this, crossScope, func) : null;
|
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;
|
return CodeNode;
|
||||||
})();
|
})();
|
||||||
exports.ParamNode = (function() {
|
exports.ParamNode = (function() {
|
||||||
|
@ -1165,8 +1152,17 @@
|
||||||
ParamNode.prototype.compileNode = function(o) {
|
ParamNode.prototype.compileNode = function(o) {
|
||||||
return this.value.compile(o);
|
return this.value.compile(o);
|
||||||
};
|
};
|
||||||
ParamNode.prototype.toString = function(idt) {
|
ParamNode.prototype.toString = function() {
|
||||||
return this.attach ? (literal('@' + this.name)).toString(idt) : this.value.toString(idt);
|
var _ref2, name;
|
||||||
|
_ref2 = this;
|
||||||
|
name = _ref2.name;
|
||||||
|
if (this.attach) {
|
||||||
|
name = '@' + name;
|
||||||
|
}
|
||||||
|
if (this.splat) {
|
||||||
|
name += '...';
|
||||||
|
}
|
||||||
|
return literal(name).toString();
|
||||||
};
|
};
|
||||||
return ParamNode;
|
return ParamNode;
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -101,7 +101,7 @@ compileScript = (file, input, base) ->
|
||||||
t = task = {file, input, options}
|
t = task = {file, input, options}
|
||||||
CoffeeScript.emit 'compile', task
|
CoffeeScript.emit 'compile', task
|
||||||
if o.tokens then printTokens CoffeeScript.tokens t.input
|
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 if o.run then CoffeeScript.run t.input, t.options
|
||||||
else
|
else
|
||||||
t.output = CoffeeScript.compile t.input, t.options
|
t.output = CoffeeScript.compile t.input, t.options
|
||||||
|
|
|
@ -252,8 +252,7 @@ exports.LiteralNode = class LiteralNode extends BaseNode
|
||||||
end = if @isStatement(o) then ';' else ''
|
end = if @isStatement(o) then ';' else ''
|
||||||
idt + @value + end
|
idt + @value + end
|
||||||
|
|
||||||
toString: (idt) ->
|
toString: -> ' "' + @value + '"'
|
||||||
'"' + @value + '"'
|
|
||||||
|
|
||||||
#### ReturnNode
|
#### ReturnNode
|
||||||
|
|
||||||
|
@ -957,11 +956,6 @@ exports.CodeNode = class CodeNode extends BaseNode
|
||||||
# unless crossScope is true
|
# unless crossScope is true
|
||||||
traverseChildren: (crossScope, func) -> super(crossScope, func) if crossScope
|
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
|
#### ParamNode
|
||||||
|
|
||||||
# A parameter in a function definition. Beyond a typical Javascript parameter,
|
# A parameter in a function definition. Beyond a typical Javascript parameter,
|
||||||
|
@ -979,8 +973,11 @@ exports.ParamNode = class ParamNode extends BaseNode
|
||||||
compileNode: (o) ->
|
compileNode: (o) ->
|
||||||
@value.compile o
|
@value.compile o
|
||||||
|
|
||||||
toString: (idt) ->
|
toString: ->
|
||||||
if @attach then (literal '@' + @name).toString idt else @value.toString idt
|
{name} = @
|
||||||
|
name = '@' + name if @attach
|
||||||
|
name += '...' if @splat
|
||||||
|
literal(name).toString()
|
||||||
|
|
||||||
#### SplatNode
|
#### SplatNode
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue