module Ruby2JS::Filter::MatchAll

Public Class Methods

reorder(filters) click to toggle source

ensure matchAll is before Functions in the filter list

# File lib/ruby2js/filter/matchAll.rb, line 9
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

Public Instance Methods

on_block(node) click to toggle source
Calls superclass method
# File lib/ruby2js/filter/matchAll.rb, line 22
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