|
4 | 4 | (function(Loader) {
|
5 | 5 | // Returns an array of ModuleSpecifiers
|
6 | 6 | var transpiler, transpilerModule;
|
7 |
| - var isNode = typeof window == 'undefined' && typeof WorkerGlobalScope == 'undefined'; |
8 | 7 |
|
9 | 8 | // use Traceur by default
|
10 | 9 | Loader.prototype.transpiler = 'traceur';
|
11 | 10 |
|
12 | 11 | Loader.prototype.transpile = function(load) {
|
13 | 12 | 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']; |
17 | 17 | }
|
18 | 18 | 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 })); |
21 | 23 | }
|
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; |
25 | 29 | }
|
26 | 30 |
|
27 | 31 | return 'var __moduleAddress = "' + load.address + '";' + transpiler.call(this, load);
|
|
0 commit comments