Sha256: deeadf0f591537f47e6f1b64e34b2a4377a247964a8890d05ed5641a12747ac8

Contents?: true

Size: 901 Bytes

Versions: 6

Compression:

Stored size: 901 Bytes

Contents

# frozen_string_literal: true

require 'opal/nodes/base'

module Opal
  module Nodes
    module Args
      # Compiles extraction of a single inline optional argument
      # def m(a = 1); end
      #       ^^^^^
      #
      # This node doesn't exist in the original AST,
      # InlineArgs rewriter creates it to simplify compilation
      #
      # Sometimes the argument can't be inlined.
      # In such cases InlineArgs rewriter replaces
      #   s(:optarg, :arg_name, ...default value...)
      # to:
      #   s(:fakearg) + s(:extract_post_optarg, :arg_name, ...default value...)
      #
      class ExtractOptargNode < Base
        handle :extract_optarg
        children :name, :default_value

        def compile
          return if default_value.children[1] == :undefined

          line "if (#{name} == null) #{name} = ", expr(default_value), ";"
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opal-1.5.1 lib/opal/nodes/args/extract_optarg.rb
opal-1.5.0 lib/opal/nodes/args/extract_optarg.rb
opal-1.5.0.rc1 lib/opal/nodes/args/extract_optarg.rb
opal-1.4.1 lib/opal/nodes/args/extract_optarg.rb
opal-1.4.0 lib/opal/nodes/args/extract_optarg.rb
opal-1.4.0.alpha1 lib/opal/nodes/args/extract_optarg.rb