Module: Ruby2JS::Filter::Return
- Includes:
- SEXP
- Defined in:
- lib/ruby2js/filter/return.rb
Constant Summary collapse
- EXPRESSIONS =
[ :array, :float, :hash, :if, :int, :lvar, :nil, :send ]
Instance Method Summary collapse
Methods included from SEXP
Instance Method Details
#on_block(node) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby2js/filter/return.rb', line 10 def on_block(node) node = super return node unless node.type == :block children = node.children.dup children[-1] = s(:nil) if children.last == nil node.updated nil, [*children[0..1], s(:autoreturn, *children[2..-1])] end |
#on_def(node) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ruby2js/filter/return.rb', line 21 def on_def(node) node = super return node unless node.type == :def or node.type == :deff return node if [:constructor, :initialize].include?(node.children.first) children = node.children[1..-1] children[-1] = s(:nil) if children.last == nil node.updated nil, [node.children[0], children.first, s(:autoreturn, *children[1..-1])] end |
#on_deff(node) ⇒ Object
34 35 36 |
# File 'lib/ruby2js/filter/return.rb', line 34 def on_deff(node) on_def(node) end |
#on_defs(node) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/ruby2js/filter/return.rb', line 38 def on_defs(node) node = super return node unless node.type == :defs children = node.children[3..-1] children[-1] = s(:nil) if children.last == nil node.updated nil, [*node.children[0..2], s(:autoreturn, *children)] end |