-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
es6.js
35 lines (27 loc) · 1.31 KB
/
es6.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
define(['amd-loader', './traceur-compiler'], function(amdLoader, traceur) {
return amdLoader('es6', 'js', function(name, source, req, callback, errback, config) {
var url = req.toUrl(name) + '.js';
var project = new traceur.semantics.symbols.Project(url);
traceur.options = config.traceur;
traceur.options.sourceMaps = true;
var reporter = new traceur.util.ErrorReporter();
reporter.reportMessageInternal = function(location, kind, format, args) {
errback(location + '\n ' + format + '\n ' + args + '\n');
}
var sourceFile = new traceur.syntax.SourceFile(name, source);
project.addFile(sourceFile);
var res = traceur.codegeneration.Compiler.compile(reporter, project, false);
var options;
if (traceur.options.sourceMaps) {
var config = {file: 'traceured.js'};
var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator(config);
options = {sourceMapGenerator: sourceMapGenerator};
}
var source = traceur.outputgeneration.ProjectWriter.write(res, options);
var sourceMap = JSON.parse(options.sourceMap);
//sourceMap.sourcesContent = [null, null, null, null];
// nb make this work
source += '\n//@ sourceMappingURL=data:application/json;base64,' + btoa(JSON.stringify(options.sourceMap));
callback(source);
});
});