Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit 180852b

Browse files
committed
run transpilers through module registry
1 parent cd4fbae commit 180852b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/transpiler.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@
44
(function(Loader) {
55
// Returns an array of ModuleSpecifiers
66
var transpiler, transpilerModule;
7-
var isNode = typeof window == 'undefined' && typeof WorkerGlobalScope == 'undefined';
87

98
// use Traceur by default
109
Loader.prototype.transpiler = 'traceur';
1110

1211
Loader.prototype.transpile = function(load) {
1312
if (!transpiler) {
14-
if (this.transpiler == 'babel') {
15-
transpiler = babelTranspile;
16-
transpilerModule = isNode ? require('babel-core') : __global.babel;
13+
transpilerModule = this.get('@' + this.transpiler);
14+
15+
if (transpilerModule) {
16+
transpilerModule = transpilerModule['default'];
1717
}
1818
else {
19-
transpiler = traceurTranspile;
20-
transpilerModule = isNode ? require('traceur') : __global.traceur;
19+
transpilerModule = __global[this.transpiler] || typeof require != 'undefined' && require(this.transpiler == 'babel' ? 'babel-core' : 'traceur');
20+
if (!transpilerModule)
21+
throw new TypeError('Include Traceur or Babel for module syntax support.');
22+
this.set('@' + this.transpiler, this.newModule({ 'default': transpilerModule, __useDefault: true }));
2123
}
22-
23-
if (!transpilerModule)
24-
throw new TypeError('Include Traceur or Babel for module syntax support.');
24+
25+
if (this.transpiler == 'babel')
26+
transpiler = babelTranspile;
27+
else if (this.transpiler == 'traceur')
28+
transpiler = traceurTranspile;
2529
}
2630

2731
return 'var __moduleAddress = "' + load.address + '";' + transpiler.call(this, load);

0 commit comments

Comments
 (0)