Skip to content

Commit f7d19f5

Browse files
committed
drying up compileSplice
1 parent d42f7da commit f7d19f5

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

lib/nodes.js

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

src/nodes.coffee

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -966,21 +966,18 @@ exports.Assign = class Assign extends Base
966966
# Compile the assignment from an array splice literal, using JavaScript's
967967
# `Array#splice` method.
968968
compileSplice: (o) ->
969-
{range} = @variable.properties.pop()
970-
name = @variable.compile o
971-
excl = range.exclusive
972-
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']
977-
unless to
978-
if range.from and range.from.isSimpleNumber() and range.to.isSimpleNumber()
979-
to = +range.to.compile(o) - +fromRef
980-
to += 1 unless excl
969+
{range: {from, to, exclusive}} = @variable.properties.pop()
970+
name = @variable.compile o
971+
[fromDecl, fromRef] = if from then from.cache(o, LEVEL_OP) else ['0', '0']
972+
if to
973+
if from and from.isSimpleNumber() and to.isSimpleNumber()
974+
to = +to.compile(o) - +fromRef
975+
to += 1 unless exclusive
981976
else
982-
to = range.to.compile(o) + ' - ' + fromRef
983-
to += ' + 1' unless excl
977+
to = to.compile(o) + ' - ' + fromRef
978+
to += ' + 1' unless exclusive
979+
else
980+
to = "#{name}.length"
984981
val = @value.compile(o)
985982
"[].splice.apply(#{name}, [#{fromDecl}, #{to}].concat(#{val}))"
986983

0 commit comments

Comments
 (0)