Sha256: 328479750aff3221facab4487aee4bb918da69311a7ef585cb49d85172a01e59

Contents?: true

Size: 687 Bytes

Versions: 3

Compression:

Stored size: 687 Bytes

Contents

# frozen_string_literal: true

module Unparser
  class Emitter
    # Emitter control flow modifiers
    class FlowModifier < self
      MAP = {
        return: 'return',
        next:   'next',
        break:  'break'
      }.freeze

      private_constant(*constants(false))

      handle(*MAP.keys)

    private

      def dispatch
        write(MAP.fetch(node.type))

        if children.one? && n_if?(children.first)
          ws
          emitter(children.first).emit_ternary
        else
          emit_arguments unless children.empty?
        end
      end

      def emit_arguments
        ws
        delimited(children)
      end
    end # Return
  end # Emitter
end # Unparser

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
unparser-0.5.6 lib/unparser/emitter/flow_modifier.rb
unparser-0.5.5 lib/unparser/emitter/flow_modifier.rb
unparser-0.5.4 lib/unparser/emitter/flow_modifier.rb