Sha256: 2e32668aed5dec1f77dc615d9374748cb1bb0f063ec612e91d1ba76e6c4bd14c

Contents?: true

Size: 912 Bytes

Versions: 16

Compression:

Stored size: 912 Bytes

Contents

# frozen_string_literal: true

require 'opal/nodes/base'

module Opal
  module Nodes
    module Args
      # This node is responsible for extracting a single
      # splat keyword argument from $kwargs
      #
      # $kwargs always exist (as argument when inlining is possible
      # and as a local variable when it's not)
      #
      class ExtractKwrestarg < Base
        handle :extract_kwrestarg
        children :name

        def compile
          # def m(**)
          # arguments are assigned to `$kw_rest_arg` for super call
          name = self.name || '$kw_rest_arg'

          add_temp name

          helper :kwrestargs

          push "#{name} = $kwrestargs($kwargs, #{used_kwargs})"
        end

        def used_kwargs
          args = scope.used_kwargs.map do |arg_name|
            "'#{arg_name}': true"
          end

          "{#{args.join ','}}"
        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_kwrestarg.rb
opal-1.8.2 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.8.1 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.8.0 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.8.0.beta1 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.7.4 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.8.0.alpha1 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.7.3 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.7.2 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.7.1 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.7.0 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.7.0.rc1 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.6.1 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.6.0 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.6.0.rc1 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.6.0.alpha1 lib/opal/nodes/args/extract_kwrestarg.rb