Sha256: e8982453bc8ca6022af14549c3660c278bff29649a683e05b1da7bcbf1740dd9

Contents?: true

Size: 678 Bytes

Versions: 15

Compression:

Stored size: 678 Bytes

Contents

require 'opal/nodes/args/initialize_kwargs'

module Opal
  module Nodes
    # A node responsible for extracting a
    # single *optional* keyword argument
    #
    # def m(kw: 1)
    #
    class KwoptArgNode < InitializeKwargsNode
      handle :kwoptarg

      def compile
        initialize_kw_args_if_needed

        kwoptarg_name = @sexp[1].to_sym
        default_value = @sexp[2]
        var_name = variable(kwoptarg_name)
        add_temp var_name

        line "if ((#{var_name} = $kwargs.$$smap['#{kwoptarg_name}']) == null) {"
        line "  #{var_name} = ", expr(default_value)
        line "}"

        scope.used_kwargs << kwoptarg_name
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
opal-0.10.6 lib/opal/nodes/args/kwoptarg.rb
opal-0.10.6.beta lib/opal/nodes/args/kwoptarg.rb
opal-0.10.5 lib/opal/nodes/args/kwoptarg.rb
opal-0.10.4 lib/opal/nodes/args/kwoptarg.rb
opal-0.10.3 lib/opal/nodes/args/kwoptarg.rb
opal-0.10.2 lib/opal/nodes/args/kwoptarg.rb
opal-0.10.1 lib/opal/nodes/args/kwoptarg.rb
opal-0.10.0 lib/opal/nodes/args/kwoptarg.rb
opal-0.10.0.rc2 lib/opal/nodes/args/kwoptarg.rb
opal-0.10.0.rc1 lib/opal/nodes/args/kwoptarg.rb
opal-0.10.0.beta5 lib/opal/nodes/args/kwoptarg.rb
opal-0.10.0.beta4 lib/opal/nodes/args/kwoptarg.rb
opal-0.10.0.beta3 lib/opal/nodes/args/kwoptarg.rb
opal-0.10.0.beta2 lib/opal/nodes/args/kwoptarg.rb
opal-0.10.0.beta1 lib/opal/nodes/args/kwoptarg.rb