Module: TraceurCompiler::Source

Defined in:
lib/traceur_compiler.rb

Class Method Summary collapse

Class Method Details

.contentsObject



16
17
18
# File 'lib/traceur_compiler.rb', line 16

def self.contents
	@contents ||= File.read(path)
end

.contextObject



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

.pathObject



7
8
9
# File 'lib/traceur_compiler.rb', line 7

def self.path
	@path ||= ENV['TRACEUR_COMPILER_SOURCE_PATH'] || bundled_path
end

.path=(path) ⇒ Object



11
12
13
14
# File 'lib/traceur_compiler.rb', line 11

def self.path=(path)
	@contents = @context = nil
	@path = path
end