This repository has been archived by the owner on Oct 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
plugin-traceur.js
60 lines (49 loc) · 1.73 KB
/
plugin-traceur.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SystemJS._loader.loadedTranspilerRuntime = true;
define(function(require, exports, module) {
var traceur = require('traceur');
function prepend(a, b) {
for (var p in b)
if (!(p in a))
a[p] = b[p];
return a;
}
exports.translate = function(load) {
var options = {
modules: 'instantiate',
script: false,
sourceMaps: this.builder ? 'memory' : 'inline',
filename: load.address,
inputSourceMap: load.metadata.sourceMap,
moduleName: false
};
if (load.metadata.traceurOptions)
prepend(options, load.metadata.traceurOptions);
if (this.traceurOptions)
prepend(options, this.traceurOptions);
var compiler = new traceur.Compiler(options);
load.metadata.format = 'register';
var transpiledSource = doTraceurCompile(load.source, compiler, options.filename);
var usesRuntime = transpiledSource.match(/\$traceurRuntime/);
if (this.builder) {
// this should not be a global but Traceur gives us no choice!
if (usesRuntime)
transpiledSource = transpiledSource.replace('System.register(["', 'System.register(["traceur-runtime", "').replace('System.register([]', 'System.register(["traceur-runtime"]');
load.metadata.sourceMap = JSON.parse(compiler.getSourceMap());
return transpiledSource;
}
else {
if (usesRuntime)
load.metadata.deps.push('traceur-runtime');
return '(function(__moduleName){' + transpiledSource + '\n})("' + load.name + '");\n//# sourceURL=' + load.address + '!transpiled';
}
};
function doTraceurCompile(source, compiler, filename) {
try {
return compiler.compile(source, filename);
}
catch(e) {
e.stack = e.stack || e.message;
throw e;
}
}
});