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:
parent
813a5f1e1f
commit
2d54a45a80
3 changed files with 14 additions and 2 deletions
|
@ -1225,7 +1225,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
to = "" + name + ".length";
|
to = "9e9";
|
||||||
}
|
}
|
||||||
val = this.value.compile(o);
|
val = this.value.compile(o);
|
||||||
return "[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat(" + val + "))";
|
return "[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat(" + val + "))";
|
||||||
|
|
|
@ -982,7 +982,7 @@ exports.Assign = class Assign extends Base
|
||||||
to = to.compile(o) + ' - ' + fromRef
|
to = to.compile(o) + ' - ' + fromRef
|
||||||
to += ' + 1' unless exclusive
|
to += ' + 1' unless exclusive
|
||||||
else
|
else
|
||||||
to = "#{name}.length"
|
to = "9e9"
|
||||||
val = @value.compile(o)
|
val = @value.compile(o)
|
||||||
"[].splice.apply(#{name}, [#{fromDecl}, #{to}].concat(#{val}))"
|
"[].splice.apply(#{name}, [#{fromDecl}, #{to}].concat(#{val}))"
|
||||||
|
|
||||||
|
|
|
@ -163,3 +163,15 @@ test "splicing with expressions as endpoints", ->
|
||||||
ary = [0..9]
|
ary = [0..9]
|
||||||
ary[a+1...2*b+1] = [4]
|
ary[a+1...2*b+1] = [4]
|
||||||
arrayEq [0, 1, 4, 7, 8, 9], ary
|
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]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue