Class: Ruby2JS::Filter::Processor

Inherits:
Parser::AST::Processor
  • Object
show all
Defined in:
lib/ruby2js.rb

Constant Summary collapse

BINARY_OPERATORS =
Converter::OPERATORS[2..-1].flatten

Instance Method Summary collapse

Instance Method Details

#on_attr(node) ⇒ Object

handle all of the ‘invented’ ast types



19
# File 'lib/ruby2js.rb', line 19

def on_attr(node); on_send(node); end

#on_autoreturn(node) ⇒ Object



20
# File 'lib/ruby2js.rb', line 20

def on_autoreturn(node); on_return(node); end

#on_constructor(node) ⇒ Object



21
# File 'lib/ruby2js.rb', line 21

def on_constructor(node); on_def(node); end

#on_defp(node) ⇒ Object



22
# File 'lib/ruby2js.rb', line 22

def on_defp(node); on_defs(node); end

#on_method(node) ⇒ Object



23
# File 'lib/ruby2js.rb', line 23

def on_method(node); on_send(node); end

#on_prop(node) ⇒ Object



24
# File 'lib/ruby2js.rb', line 24

def on_prop(node); on_array(node); end

#on_prototype(node) ⇒ Object



25
# File 'lib/ruby2js.rb', line 25

def on_prototype(node); on_begin(node); end

#on_send(node) ⇒ Object

convert map(&:symbol) to a block



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ruby2js.rb', line 30

def on_send(node)
  if node.children.length > 2 and node.children.last.type == :block_pass
    method = node.children.last.children.first.children.last
    if BINARY_OPERATORS.include? method
      return on_block s(:block, s(:send, *node.children[0..-2]),
        s(:args, s(:arg, :a), s(:arg, :b)), s(:return,
        process(s(:send, s(:lvar, :a), method, s(:lvar, :b)))))
    else
      return on_block s(:block, s(:send, *node.children[0..-2]),
        s(:args, s(:arg, :item)), s(:return,
        process(s(:attr, s(:lvar, :item), method))))
    end
  end
  super
end

#on_sendw(node) ⇒ Object



26
# File 'lib/ruby2js.rb', line 26

def on_sendw(node); on_send(node); end

#on_undefined?(node) ⇒ Boolean

Returns:

  • (Boolean)


27
# File 'lib/ruby2js.rb', line 27

def on_undefined?(node); on_defined?(node); end