Sha256: be88c8907648e3066d05d967297342ff0d46d588c4cc9b2aa0b423d8cd06bd57

Contents?: true

Size: 886 Bytes

Versions: 11

Compression:

Stored size: 886 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
          line "#{name} = Opal.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

11 entries across 11 versions & 1 rubygems

Version Path
opal-1.5.1 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.5.0 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.5.0.rc1 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.4.1 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.4.0 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.4.0.alpha1 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.3.2 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.3.1 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.3.0 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.3.0.rc1 lib/opal/nodes/args/extract_kwrestarg.rb
opal-1.3.0.alpha1 lib/opal/nodes/args/extract_kwrestarg.rb