1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

merging tesco's branch for issue #535

This commit is contained in:
Jeremy Ashkenas 2010-07-28 07:34:28 -04:00
parent 9026069f79
commit a80d8d55c4
3 changed files with 19 additions and 9 deletions

View file

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

View file

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

View file

@ -33,3 +33,11 @@ ok context.arg is 3
((@arg...) ->).call context, 1, 2, 3
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