Sha256: f53b8642f99a4124831e3a44afdbd9a6e887210e7933b71f17f833e740fa47af

Contents?: true

Size: 1018 Bytes

Versions: 1

Compression:

Stored size: 1018 Bytes

Contents

# frozen_string_literal: true

require 'ripper'

module Preval
  SyntaxError = Class.new(SyntaxError)

  class << self
    attr_reader :visitors

    def process(source)
      visitors.inject(source) { |accum, visitor| visitor.process(accum) }
    end
  end

  @visitors = []
end

require 'preval/format'
require 'preval/node'
require 'preval/parser'
require 'preval/version'
require 'preval/visitor'

require 'preval/visitors/arithmetic'
require 'preval/visitors/loops'
require 'preval/visitors/micro'

if defined?(Bootsnap)
  load_iseq = RubyVM::InstructionSequence.method(:load_iseq)

  if load_iseq.source_location[0].include?('/bootsnap/')
    Bootsnap::CompileCache::ISeq.singleton_class.prepend(
      Module.new do
        def input_to_storage(source, path)
          source = Preval.process(source)
          RubyVM::InstructionSequence.compile(source, path, path).to_binary
        rescue SyntaxError
          raise Bootsnap::CompileCache::Uncompilable, 'syntax error'
        end
      end
    )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
preval-0.3.0 lib/preval.rb