class Traceur::Compiler

Attributes

compile_script_path[R]
default_compilation_options[R]
runner[R]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/traceur/compiler.rb, line 5
def initialize(opts = {})
  @runner = opts.fetch(:runner)
  @compile_script_path = opts.fetch(:compile_script_path)
  @default_compilation_options = opts.fetch(:default_compilation_options)
end

Public Instance Methods

compile(source, opts = {}) click to toggle source
# File lib/traceur/compiler.rb, line 11
def compile(source, opts = {})
  compile_file(tempfile(source), opts)
end
compile_file(infile, opts = {}) click to toggle source
# File lib/traceur/compiler.rb, line 15
def compile_file(infile, opts = {})
  options = default_compilation_options.merge(opts)
  outfile = Tempfile.new('out.js')
  runner.run(
    arguments: [compile_script_path, infile.path, outfile.path, options.to_json],
    on_error: ->(r) { raise CompilationError.parse(r.stderr) }
  ).stdout
  outfile.read
end

Private Instance Methods

tempfile(source) click to toggle source
# File lib/traceur/compiler.rb, line 27
def tempfile(source)
  Tempfile.new('in.js').tap do |f|
    f.write(source)
    f.close
  end
end