Sha256: 43b9dc236ee38c7596caac5fe839bbaba0e14461a13218b5c704a0d38367b83b

Contents?: true

Size: 1.08 KB

Versions: 21

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Opal
  module Parser
    module DefaultConfig
      module ClassMethods
        attr_accessor :diagnostics_consumer

        def default_parser
          parser = super
          parser.diagnostics.all_errors_are_fatal = true
          parser.diagnostics.ignore_warnings      = false
          parser.diagnostics.consumer             = diagnostics_consumer
          parser
        end
      end

      def self.included(klass)
        klass.extend(ClassMethods)
        klass.diagnostics_consumer = ->(diagnostic) do
          if RUBY_ENGINE != 'opal'
            $stderr.puts(diagnostic.render)
          end
        end
      end

      def initialize(*)
        super(Opal::AST::Builder.new)
      end

      def parse(source_buffer)
        parsed = super
        rewriten = rewrite(parsed)
        rewriten
      end

      def rewrite(node)
        Opal::Rewriter.new(node).process
      end
    end

    class << self
      attr_accessor :default_parser_class

      def default_parser
        default_parser_class.default_parser
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
opal-1.4.1 lib/opal/parser/default_config.rb
opal-1.4.0 lib/opal/parser/default_config.rb
opal-1.4.0.alpha1 lib/opal/parser/default_config.rb
opal-1.3.2 lib/opal/parser/default_config.rb
opal-1.3.1 lib/opal/parser/default_config.rb
opal-1.3.0 lib/opal/parser/default_config.rb
opal-1.3.0.rc1 lib/opal/parser/default_config.rb
opal-1.3.0.alpha1 lib/opal/parser/default_config.rb
opal-1.2.0 lib/opal/parser/default_config.rb
opal-1.2.0.beta1 lib/opal/parser/default_config.rb
opal-1.1.1 lib/opal/parser/default_config.rb
opal-1.1.1.rc1 lib/opal/parser/default_config.rb
opal-1.1.0 lib/opal/parser/default_config.rb
opal-1.1.0.rc1 lib/opal/parser/default_config.rb
opal-1.0.5 lib/opal/parser/default_config.rb
opal-1.0.4 lib/opal/parser/default_config.rb
opal-1.0.3 lib/opal/parser/default_config.rb
opal-1.0.2 lib/opal/parser/default_config.rb
opal-1.0.1 lib/opal/parser/default_config.rb
opal-1.0.0 lib/opal/parser/default_config.rb