Sha256: 6903f92408452122ab654dec7839dd9a2869be5ac19006c0390392726de148b9

Contents?: true

Size: 1.39 KB

Versions: 33

Compression:

Stored size: 1.39 KB

Contents

require 'ruby2js'

module Ruby2JS
  module Filter
    module MatchAll
      include SEXP

      # ensure matchAll is before Functions in the filter list
      def self.reorder(filters)
        if \
          defined? Ruby2JS::Filter::Functions and
          filters.include? Ruby2JS::Filter::Functions
        then
          filters = filters.dup
          matchAll = filters.delete(Ruby2JS::Filter::MatchAll)
          filters.insert filters.index(Ruby2JS::Filter::Functions), matchAll
        else
          filters
        end
      end

      def on_block(node)
        return super if es2020

        # only process each/forEach blocks
        call = node.children.first
        return super unless
          [:each, :forEach].include? call.children[1] and
          call.children.first.type == :send and
          node.children[1].children.length == 1

        # only process matchAll requests with simple expressions
        call = call.children.first
        return super unless
          call.children[1] == :matchAll and
          call.children[2].type == :send and
          call.children[2].children.first == nil and
          call.children[2].children.length == 2

        process s(:while,
          s(:lvasgn, node.children[1].children[0].children[0],
            s(:send, call.children[2], :exec, call.children.first)),
          node.children[2])
      end
    end

    DEFAULTS.push MatchAll
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

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