Sha256: 8425f94e9ab792d8a44bab3bbde0de72be4fd6e7675d8285c885ecc1f47c247a

Contents?: true

Size: 544 Bytes

Versions: 15

Compression:

Stored size: 544 Bytes

Contents

require 'opal/nodes/base'

module Opal
  module Nodes
    # A node responsible for extracting a single
    # optional argument
    #
    # def m(a=1)
    #
    class OptargNode < Base
      handle :optarg

      def compile
        optarg_name = @sexp[1].to_sym
        default_value = @sexp[2]
        var_name = variable(optarg_name)

        return if default_value[2] == :undefined

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

Version data entries

15 entries across 15 versions & 1 rubygems

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