Class: Traceur::Compiler
- Inherits:
-
Object
- Object
- Traceur::Compiler
- Defined in:
- lib/traceur/compiler.rb
Instance Method Summary collapse
- #compile(source, opts = {}) ⇒ Object
- #compile_file(infile, opts = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
#initialize(opts = {}) ⇒ Compiler
Returns a new instance of Compiler.
5 6 7 8 9 |
# File 'lib/traceur/compiler.rb', line 5 def initialize(opts = {}) @runner = opts.fetch(:runner) @compile_script_path = opts.fetch(:compile_script_path) = opts.fetch(:default_compilation_options) end |
Instance Method Details
#compile(source, opts = {}) ⇒ Object
11 12 13 |
# File 'lib/traceur/compiler.rb', line 11 def compile(source, opts = {}) compile_file(tempfile(source), opts) end |
#compile_file(infile, opts = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/traceur/compiler.rb', line 15 def compile_file(infile, opts = {}) = .merge(opts) outfile = Tempfile.new('out.js') runner.run( arguments: [compile_script_path, infile.path, outfile.path, .to_json], on_error: ->(r) { raise CompilationError.parse(r.stderr) } ).stdout outfile.read end |