Self-compiler can compile splats.

This commit is contained in:
Jeremy Ashkenas
2010-02-09 21:44:34 -05:00
parent ae4f6309e8
commit fd80d784f4
4 changed files with 41 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
(function(){
var AccessorNode, ArrayNode, AssignNode, CallNode, ClosureNode, CodeNode, CommentNode, Expressions, ExtendsNode, IndexNode, LiteralNode, Node, ObjectNode, PushNode, RangeNode, ReturnNode, SliceNode, TAB, TRAILING_WHITESPACE, ThisNode, ValueNode, any, compact, del, dup, flatten, inherit, merge, statement;
var AccessorNode, ArrayNode, AssignNode, CallNode, ClosureNode, CodeNode, CommentNode, Expressions, ExtendsNode, IndexNode, LiteralNode, Node, ObjectNode, PushNode, RangeNode, ReturnNode, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThisNode, ValueNode, any, compact, del, dup, flatten, inherit, merge, statement;
var __hasProp = Object.prototype.hasOwnProperty;
process.mixin(require('./scope'));
// The abstract base class for all CoffeeScript nodes.
@@ -980,4 +980,22 @@
return true;
}
}));
// A splat, either as a parameter to a function, an argument to a call,
// or in a destructuring assignment.
SplatNode = (exports.SplatNode = inherit(Node, {
constructor: function constructor(name) {
this.children = [(this.name = name)];
return this;
},
compile_node: function compile_node(o) {
return this.index ? this.compile_param(o) : this.name.compile(o);
},
compile_param: function compile_param(o) {
o.scope.find(this.name);
return this.name + ' = Array.prototype.slice.call(arguments, ' + this.index + ')';
},
compile_value: function compile_value(o, name, index) {
return "Array.prototype.slice.call(" + this.name + ', ' + this.index + ')';
}
}));
})();