diff --git a/lib/nodes.js b/lib/nodes.js index 54c538f0..011f3668 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -971,7 +971,7 @@ _b = this.params; for (i = 0, _c = _b.length; i < _c; i++) { param = _b[i]; - if (typeof splat !== "undefined" && splat !== null) { + if (splat) { if (param.attach) { param.assign = new AssignNode(new ValueNode(literal('this'), [new AccessorNode(param.value)])); this.body.expressions.splice(splat.index + 1, 0, param.assign); diff --git a/src/nodes.coffee b/src/nodes.coffee index 56488caf..a40095d4 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -874,7 +874,7 @@ exports.CodeNode = class CodeNode extends BaseNode splat = undefined params = [] for param, i in @params - if splat? + if splat if param.attach param.assign = new AssignNode new ValueNode literal('this'), [new AccessorNode param.value] @body.expressions.splice splat.index + 1, 0, param.assign @@ -919,12 +919,14 @@ exports.CodeNode = class CodeNode extends BaseNode # 'splat', where it gathers up a block of the parameters into an array. exports.ParamNode = class ParamNode extends BaseNode - class: 'ParamNode' + class: 'ParamNode' children: ['name'] - constructor: (@name, @attach, @splat) -> @value = literal @name + constructor: (@name, @attach, @splat) -> + @value = literal @name - compileNode: (o) -> @value.compile o + compileNode: (o) -> + @value.compile o toString: (idt) -> if @attach then (literal "@#@name").toString idt else @value.toString idt @@ -959,9 +961,9 @@ exports.SplatNode = class SplatNode extends BaseNode end = if @trailings.length then ", #len - #{@trailings.length}" for trailing, idx in @trailings if trailing.attach - assign = trailing.assign - trailing = literal o.scope.freeVariable() - assign.value = trailing + assign = trailing.assign + trailing = literal o.scope.freeVariable() + assign.value = trailing pos = @trailings.length - idx o.scope.assign(trailing.compile(o), "arguments[#variadic ? #len - #pos : #{@index + idx}]") "#name = #{utility('slice')}.call(arguments, #@index#end)" diff --git a/test/test_arguments.coffee b/test/test_arguments.coffee index 63eefa18..4ca4254f 100644 --- a/test/test_arguments.coffee +++ b/test/test_arguments.coffee @@ -32,4 +32,12 @@ ok context.arg is 1 ok context.arg is 3 ((@arg...) ->).call context, 1, 2, 3 -ok context.arg.join ' ' is '1 2 3' \ No newline at end of file +ok context.arg.join ' ' is '1 2 3' + +class Klass + constructor: (@one, @two) -> + +obj = new Klass 1, 2 + +ok obj.one is 1 +ok obj.two is 2 \ No newline at end of file