20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/traceur_compiler.rb', line 20
def self.context
return @context unless @context.nil?
@context = ExecJS.compile(contents)
@context.exec <<-stubs
console = {
error: function () { },
log: function () { }
};
stubs
@context.exec <<-compile
compile = function (contents, options) {
for (var key in options) {
traceur.options[key] = options[key];
}
var project = new traceur.semantics.symbols.Project(''),
reporter = new traceur.util.ErrorReporter();
reporter.reportMessageInternal = function (location, format, args) {
throw new Error(traceur.util.ErrorReporter.format(location, format, args));
};
project.addFile(new traceur.syntax.SourceFile('unknown', contents));
var response = traceur.codegeneration.Compiler.compile(reporter, project, false);
return traceur.outputgeneration.ProjectWriter.write(response, {});
}
compile
@context
end
|