Class: Sprockets::Typescript::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets/typescript/compiler.rb

Defined Under Namespace

Classes: Console, Context, Unit

Constant Summary collapse

DEFAULT_LIB_PATH =
File.expand_path("../../../../bundledjs/lib.d.ts", __FILE__)

Instance Method Summary collapse

Constructor Details

#initializeCompiler

Returns a new instance of Compiler.



60
61
62
63
64
65
# File 'lib/sprockets/typescript/compiler.rb', line 60

def initialize
  @ctx = V8::Context.new
  %w(typescript.patched compiler).each do |filename|
    @ctx.load(File.expand_path("../../../../bundledjs/#{filename}.js", __FILE__))
  end
end

Instance Method Details

#compile(path, content, context = nil) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/sprockets/typescript/compiler.rb', line 71

def compile(path, content, context = nil)
  libdts = Unit.new(DEFAULT_LIB_PATH, File.read(DEFAULT_LIB_PATH))
  additional_units = [libdts]
  @ctx["Ruby"] = {
    "source" => Unit.new(path, content),
    "additionalUnits" => additional_units,
    "context" => context.nil? ? nil : Context.new(context),
    "console" => Console.new
  }
  @ctx.eval("Compiler.compile()")
end

#eval(*args) ⇒ Object



67
68
69
# File 'lib/sprockets/typescript/compiler.rb', line 67

def eval(*args)
  @ctx.eval(*args)
end