class Opal::Nodes::MassAssignNode
def compile_masgn(lhs_items, array, len = nil)
def compile_masgn(lhs_items, array, len = nil) pre_splat = lhs_items.take_while { |child| child.type != :splat } post_splat = lhs_items.drop(pre_splat.size) pre_splat.each_with_index do |child, idx| compile_assignment(child, array, idx, len) end unless post_splat.empty? splat = post_splat.shift if post_splat.empty? # trailing splat if part = splat.children[0] helper :slice part = part.dup << s(:js_tmp, "$slice(#{array}, #{pre_splat.size})") push ', ' push expr(part) end else tmp = scope.new_temp # end index for items consumed by splat push ", #{tmp} = #{array}.length - #{post_splat.size}" push ", #{tmp} = (#{tmp} < #{pre_splat.size}) ? #{pre_splat.size} : #{tmp}" if part = splat.children[0] helper :slice part = part.dup << s(:js_tmp, "$slice(#{array}, #{pre_splat.size}, #{tmp})") push ', ' push expr(part) end post_splat.each_with_index do |child, idx| if idx == 0 compile_assignment(child, array, tmp) else compile_assignment(child, array, "#{tmp} + #{idx}") end end scope.queue_temp(tmp) end end end