Class: Opal::Rewriters::MlhsArgs

Inherits:
Base
  • Object
show all
Defined in:
opal/lib/opal/rewriters/mlhs_args.rb

Overview

Rewrites

def m( (a, b), (c, d) ) body end

To

def m($mlhs_tmp1, $mlhs_tmp2) (a, b) = $mlhs_tmp1 (c, d) = $mlhs_tmp2 body end

Defined Under Namespace

Classes: Arguments, MlhsRewriter

Constant Summary

Constants inherited from Base

Base::DUMMY_LOCATION

Instance Attribute Summary

Attributes inherited from Base

#current_node

Instance Method Summary collapse

Methods inherited from Base

#append_to_body, #begin_with_stmts, #error, #prepend_to_body, #process, #s, s, #stmts_of

Instance Method Details

#on_def(node) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'opal/lib/opal/rewriters/mlhs_args.rb', line 22

def on_def(node)
  node = super(node)
  mid, args, body = *node

  arguments = Arguments.new(args)

  args = args.updated(nil, arguments.rewritten)
  if arguments.initialization
    body ||= s(:nil) # prevent returning mlhs assignment
    body = prepend_to_body(body, arguments.initialization)
  end

  node.updated(nil, [mid, args, body])
end

#on_defs(node) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'opal/lib/opal/rewriters/mlhs_args.rb', line 37

def on_defs(node)
  node = super(node)
  recv, mid, args, body = *node

  arguments = Arguments.new(args)

  args = args.updated(nil, arguments.rewritten)
  if arguments.initialization
    body ||= s(:nil) # prevent returning mlhs assignment
    body = prepend_to_body(body, arguments.initialization)
  end

  node.updated(nil, [recv, mid, args, body])
end

#on_iter(node) ⇒ Object


52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'opal/lib/opal/rewriters/mlhs_args.rb', line 52

def on_iter(node)
  node = super(node)
  args, body = *node

  arguments = Arguments.new(args)

  args = args.updated(nil, arguments.rewritten)
  if arguments.initialization
    body ||= s(:nil) # prevent returning mlhs assignment
    body = prepend_to_body(body, arguments.initialization)
  end

  node.updated(nil, [args, body])
end