Sha256: 1d183864fc3715344225ce1d0a93ddf5f1efa7a3b65fa775faec2bbfef3bbe36

Contents?: true

Size: 1.2 KB

Versions: 21

Compression:

Stored size: 1.2 KB

Contents

require 'ruby2js'

module Ruby2JS
  module Filter
    module Return
      include SEXP

      EXPRESSIONS = [ :array, :float, :hash, :if, :int, :lvar, :nil, :send ]

      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

      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

      def on_deff(node)
        on_def(node)
      end

      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
    end

    DEFAULTS.push Return
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
ruby2js-5.1.1 lib/ruby2js/filter/return.rb
ruby2js-5.1.0 lib/ruby2js/filter/return.rb
ruby2js-5.0.1 lib/ruby2js/filter/return.rb
ruby2js-5.0.0 lib/ruby2js/filter/return.rb
ruby2js-4.2.2 lib/ruby2js/filter/return.rb
ruby2js-4.2.1 lib/ruby2js/filter/return.rb
ruby2js-4.2.0 lib/ruby2js/filter/return.rb
ruby2js-4.1.7 lib/ruby2js/filter/return.rb
ruby2js-4.1.6 lib/ruby2js/filter/return.rb
ruby2js-4.1.5 lib/ruby2js/filter/return.rb
ruby2js-4.1.4 lib/ruby2js/filter/return.rb
ruby2js-4.1.3 lib/ruby2js/filter/return.rb
ruby2js-4.1.2 lib/ruby2js/filter/return.rb
ruby2js-4.1.1 lib/ruby2js/filter/return.rb
ruby2js-4.1.0 lib/ruby2js/filter/return.rb
ruby2js-4.0.5 lib/ruby2js/filter/return.rb
ruby2js-4.0.4 lib/ruby2js/filter/return.rb
ruby2js-4.0.3 lib/ruby2js/filter/return.rb
ruby2js-4.0.2 lib/ruby2js/filter/return.rb
ruby2js-4.0.1 lib/ruby2js/filter/return.rb