1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
# frozen_string_literal: true
module Unparser
class Emitter
# Emitter for multiple assignment left hand side
class MLHS < self
handle :mlhs
NO_COMMA = %i[arg splat mlhs restarg].freeze
private_constant(*constants(false))
private
def dispatch
if children.one?
emit_one_child_mlhs
else
emit_many
end
end
def emit_one_child_mlhs
child = children.first
parentheses do
emitter(child).emit_mlhs
write(',') unless NO_COMMA.include?(child.type)
end
end
def emit_many
parentheses do
delimited(children) do |node|
emitter(node).emit_mlhs
end
end
end
end # MLHS
end # Emitter
end # Unaprser
|