Sha256: 2fdfae7f4830cd46ec108257b8ca034fe863a38f3c3014b97b6ae9e303c96bdb
Contents?: true
Size: 1.03 KB
Versions: 6
Compression:
Stored size: 1.03 KB
Contents
# frozen_string_literal: true require 'opal/ast/builder' require 'opal/rewriter' module Opal module Source class Buffer < Parser::Source::Buffer def self.recognize_encoding(string) super || Encoding::UTF_8 end end end class Parser < ::Parser::Ruby23 class << self attr_accessor :diagnostics_consumer def default_parser parser = super parser.diagnostics.all_errors_are_fatal = true parser.diagnostics.ignore_warnings = false if RUBY_ENGINE == 'opal' parser.diagnostics.consumer = ->(diag){} else parser.diagnostics.consumer = diagnostics_consumer end parser end end self.diagnostics_consumer = ->(diagnostic) { $stderr.puts(diagnostic.render) } 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 end
Version data entries
6 entries across 6 versions & 1 rubygems