Skip to content

Commit d42f7da

Browse files
committed
Issue #943 -- splices with expressions.
1 parent 53363e6 commit d42f7da

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

Cakefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ runTests = (CoffeeScript) ->
165165
try
166166
fn()
167167
catch e
168-
e.message = description if description?
169-
e.source = fn.toString() if fn.toString?
168+
e.description = description if description?
169+
e.source = fn.toString() if fn.toString?
170170
failures.push file: currentFile, error: e
171171

172172
# A recursive functional equivalence helper; uses egal for testing equivalence.
@@ -197,7 +197,8 @@ runTests = (CoffeeScript) ->
197197
jsFile = file.replace(/\.coffee$/,'.js')
198198
match = error.stack?.match(new RegExp(fail.file+":(\\d+):(\\d+)"))
199199
[match, line, col] = match if match
200-
log "\n #{error.message}", red if error.message
200+
log "\n #{error.toString()}", red
201+
log " #{error.description}", red if error.description
201202
log " #{jsFile}: line #{line or 'unknown'}, column #{col or 'unknown'}", red
202203
console.log " #{error.source}" if error.source
203204

lib/nodes.js

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -969,17 +969,20 @@ exports.Assign = class Assign extends Base
969969
{range} = @variable.properties.pop()
970970
name = @variable.compile o
971971
excl = range.exclusive
972-
from = if range.from then range.from.compile(o) else '0'
973972
to = "#{name}.length" unless range.to
973+
if range.from
974+
[fromDecl, fromRef] = range.from.cache o, LEVEL_OP
975+
else
976+
[fromDecl, fromRef] = ['0', '0']
974977
unless to
975978
if range.from and range.from.isSimpleNumber() and range.to.isSimpleNumber()
976-
to = +range.to.compile(o) - +from
979+
to = +range.to.compile(o) - +fromRef
977980
to += 1 unless excl
978981
else
979-
to = range.to.compile(o) + ' - ' + from
982+
to = range.to.compile(o) + ' - ' + fromRef
980983
to += ' + 1' unless excl
981984
val = @value.compile(o)
982-
"[].splice.apply(#{name}, [#{from}, #{to}].concat(#{val}))"
985+
"[].splice.apply(#{name}, [#{fromDecl}, #{to}].concat(#{val}))"
983986

984987
#### Code
985988

@@ -1193,6 +1196,8 @@ exports.Op = class Op extends Base
11931196

11941197
children: ['first', 'second']
11951198

1199+
isSimpleNumber: NO
1200+
11961201
isUnary: ->
11971202
not @second
11981203

test/ranges_slices_and_splices.coffee

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,9 @@ test "splicing with variables as endpoints", ->
153153
ary[a...b] = [5]
154154
arrayEq [0, 5, 8, 9], ary
155155

156-
# currently broken:
157-
# test "splicing with expressions as endpoints", ->
158-
# [a, b] = [1, 3]
159-
#
160-
# ary = [0..9]
161-
# ary[ a+1 .. 2*b+1 ] = [4]
162-
# arrayEq [0, 1, 4, 7, 8, 9], ary
156+
test "splicing with expressions as endpoints", ->
157+
[a, b] = [1, 3]
158+
159+
ary = [0..9]
160+
ary[ a+1 .. 2*b+1 ] = [4]
161+
arrayEq [0, 1, 4, 8, 9], ary

0 commit comments

Comments
 (0)