Class: Opal::Nodes::InlineArgs

Inherits:
Base
  • Object
show all
Defined in:
opal/lib/opal/nodes/inline_args.rb

Overview

def args list

Instance Attribute Summary

Attributes inherited from Base

#compiler, #type

Instance Method Summary collapse

Methods inherited from Base

#add_gvar, #add_ivar, #add_local, #add_temp, #children, children, #class_variable_owner, #closest_module_node, #comments, #compile_to_fragments, #error, #expr, #expr?, #expr_or_nil, #fragment, handle, handlers, #has_rescue_else?, #helper, #in_ensure, #in_ensure?, #in_while?, #initialize, #process, #push, #recv, #recv?, #s, #scope, #stmt, #stmt?, truthy_optimize?, #unshift, #while_loop, #with_temp, #wrap

Methods included from Helpers

#conditional_send, #current_indent, #empty_line, #indent, #js_falsy, #js_truthy, #js_truthy_optimize, #line, #mid_to_jsid, #property, #valid_name?

Constructor Details

This class inherits a constructor from Opal::Nodes::Base

Instance Method Details

#add_arg(arg) ⇒ Object

If the argument has a name, we should mark it as an argument for current scope Otherwise, these args will be interpreted in the child scope as local variables



54
55
56
57
# File 'opal/lib/opal/nodes/inline_args.rb', line 54

def add_arg(arg)
  arg_name, _ = *arg
  scope.add_arg(arg_name) if arg_name
end

#arg_namesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'opal/lib/opal/nodes/inline_args.rb', line 14

def arg_names
  done_kwargs = false

  children.inject([]) do |result, arg|
    case arg.type
    when :kwarg, :kwoptarg, :kwrestarg
      unless done_kwargs
        done_kwargs = true
        result << '$kwargs'
      end
      add_arg(arg)
    when :mlhs
      tmp = scope.next_temp
      result << tmp
      scope.mlhs_mapping[arg] = tmp
    when :arg, :optarg
      arg_name, _ = *arg
      if !arg.meta[:inline] && arg_name[0] != '$'
        arg_name = "$#{arg_name}"
      end
      result << arg_name
      add_arg(arg)
    when :restarg
      # To make function.length working
      # in cases like def m(*rest)
      tmp_arg_name = scope.next_temp + "_rest"
      result << tmp_arg_name
      add_arg(arg)
    else
      raise "Unknown argument type #{arg.inspect}"
    end

    result
  end
end

#compileObject



10
11
12
# File 'opal/lib/opal/nodes/inline_args.rb', line 10

def compile
  push(arg_names.join(', '))
end