Sha256: 87acad22bc6cf033ad56d23b9fc7257291af371e1272f88fe5454f2c66fc711c

Contents?: true

Size: 895 Bytes

Versions: 16

Compression:

Stored size: 895 Bytes

Contents

# frozen_string_literal: true

require 'opal/nodes/base'

module Opal
  module Nodes
    module Args
      # This node is responsible for extracting a single
      # optional post-argument
      #
      # args_to_keep is the number of required post-arguments
      #
      #   def m(a = 1, b, c, d); end
      # becomes something like:
      #   if post_args.length > 3
      #     a = post_args[0]
      #     post_args = post_args[1..-1]
      #   end
      #
      class ExtractPostOptarg < Base
        handle :extract_post_optarg
        children :name, :default_value, :args_to_keep

        def compile
          add_temp name

          line "if ($post_args.length > #{args_to_keep}) #{name} = $post_args.shift();"

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

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.8.2 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.8.1 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.8.0 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.8.0.beta1 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.7.4 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.8.0.alpha1 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.7.3 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.7.2 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.7.1 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.7.0 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.7.0.rc1 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.6.1 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.6.0 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.6.0.rc1 lib/opal/nodes/args/extract_post_optarg.rb
opal-1.6.0.alpha1 lib/opal/nodes/args/extract_post_optarg.rb