merging in matehat's curry branch. cleaning some loose ends up. adding some tests.

This commit is contained in:
Jeremy Ashkenas
2010-03-18 00:42:26 -04:00
parent 1f87094628
commit 0c6ee52cfc
10 changed files with 33 additions and 49 deletions

View File

@@ -393,22 +393,22 @@ exports.CallNode: class CallNode extends BaseNode
# After `Underscore.bind` from [Underscore](http://documentcloud.github.com/underscore/).
exports.CurryNode: class CurryNode extends CallNode
type: 'Curry'
constructor: (meth, args) ->
@children: flatten [@meth: meth, @context: args[0], @args: (args.slice(1) or [])]
arguments: (o) ->
for arg in @args
return @compile_splat_arguments(o) if arg instanceof SplatNode
(new ArrayNode(@args)).compile o
compile_node: (o) ->
body: Expressions.wrap([literal('func.apply(obj || {}, args.concat(Array.prototype.slice.call(arguments, 0)));')])
body: Expressions.wrap([literal('func.apply(obj, args.concat(Array.prototype.slice.call(arguments, 0)));')])
curried: new CodeNode([], body)
curry: new CodeNode([literal('func'), literal('obj'), literal('args')], Expressions.wrap([curried]))
(new ParentheticalNode(new CallNode(curry, [@meth, @context, literal(@arguments(o))]))).compile o
#### ExtendsNode