Sha256: 4feaf7ba50b132f122561648218277aaca0c964661f03bc663da0034538b3d6a

Contents?: true

Size: 1.91 KB

Versions: 9

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

require 'opal/rewriters/opal_engine_check'
require 'opal/rewriters/for_rewriter'
require 'opal/rewriters/explicit_writer_return'
require 'opal/rewriters/js_reserved_words'
require 'opal/rewriters/block_to_iter'
require 'opal/rewriters/dot_js_syntax'
require 'opal/rewriters/pattern_matching'
require 'opal/rewriters/logical_operator_assignment'
require 'opal/rewriters/binary_operator_assignment'
require 'opal/rewriters/hashes/key_duplicates_rewriter'
require 'opal/rewriters/dump_args'
require 'opal/rewriters/mlhs_args'
require 'opal/rewriters/inline_args'
require 'opal/rewriters/numblocks'
require 'opal/rewriters/returnable_logic'
require 'opal/rewriters/forward_args'

module Opal
  class Rewriter
    class << self
      def list
        @list ||= []
      end

      def use(rewriter)
        list << rewriter
      end

      def delete(rewriter)
        list.delete(rewriter)
      end

      def disable
        @disabled = true
        yield
      ensure
        @disabled = false
      end

      def disabled?
        @disabled if defined?(@disabled)
      end
    end

    use Rewriters::OpalEngineCheck
    use Rewriters::ForRewriter
    use Rewriters::Numblocks
    use Rewriters::ForwardArgs
    use Rewriters::BlockToIter
    use Rewriters::DotJsSyntax
    use Rewriters::PatternMatching
    use Rewriters::JsReservedWords
    use Rewriters::LogicalOperatorAssignment
    use Rewriters::BinaryOperatorAssignment
    use Rewriters::ExplicitWriterReturn
    use Rewriters::Hashes::KeyDuplicatesRewriter
    use Rewriters::ReturnableLogic
    use Rewriters::DumpArgs
    use Rewriters::MlhsArgs
    use Rewriters::InlineArgs

    def initialize(sexp)
      @sexp = sexp
    end

    def process
      return @sexp if self.class.disabled?

      self.class.list.each do |rewriter_class|
        rewriter = rewriter_class.new
        @sexp = rewriter.process(@sexp)
      end

      @sexp
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
opal-1.4.1 lib/opal/rewriter.rb
opal-1.4.0 lib/opal/rewriter.rb
opal-1.4.0.alpha1 lib/opal/rewriter.rb
opal-1.3.2 lib/opal/rewriter.rb
opal-1.3.1 lib/opal/rewriter.rb
opal-1.3.0 lib/opal/rewriter.rb
opal-1.3.0.rc1 lib/opal/rewriter.rb
opal-1.3.0.alpha1 lib/opal/rewriter.rb
opal-1.2.0 lib/opal/rewriter.rb