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

splicing to the end of a one-time expression.

This commit is contained in:
Jeremy Ashkenas 2010-12-23 14:02:46 -08:00
parent 813a5f1e1f
commit 2d54a45a80
3 changed files with 14 additions and 2 deletions

View file

@ -1225,7 +1225,7 @@
}
}
} else {
to = "" + name + ".length";
to = "9e9";
}
val = this.value.compile(o);
return "[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat(" + val + "))";

View file

@ -982,7 +982,7 @@ exports.Assign = class Assign extends Base
to = to.compile(o) + ' - ' + fromRef
to += ' + 1' unless exclusive
else
to = "#{name}.length"
to = "9e9"
val = @value.compile(o)
"[].splice.apply(#{name}, [#{fromDecl}, #{to}].concat(#{val}))"

View file

@ -163,3 +163,15 @@ test "splicing with expressions as endpoints", ->
ary = [0..9]
ary[a+1...2*b+1] = [4]
arrayEq [0, 1, 4, 7, 8, 9], ary
test "splicing to the end, against a one-time function", ->
ary = null
fn = ->
if ary
throw 'err'
else
ary = [1, 2, 3]
fn()[0..] = 1
arrayEq ary, [1]