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

Commit adba021

Browse files
committed
pick up transpilers from globals if necessary
1 parent 2716186 commit adba021

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/transpiler.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,26 @@
22
* Traceur and Babel transpile hook for Loader
33
*/
44
(function(Loader) {
5+
var g = __global;
6+
7+
function getTranspilerModule(globalName) {
8+
return System.newModule({ 'default': g[globalName], __useDefault: true });
9+
}
10+
var firstRun = true;
11+
512
// use Traceur by default
613
Loader.prototype.transpiler = 'traceur';
714

815
Loader.prototype.transpile = function(load) {
16+
// pick up Transpiler modules from existing globals on first run if set
17+
if (firstRun) {
18+
if (g.traceur && !this.has('traceur'))
19+
this.set('traceur', getTranspilerModule('traceur'));
20+
if (g.babel && !this.has('babel'))
21+
this.set('babel', getTranspilerModule('babel'));
22+
firstRun = false;
23+
}
24+
925
var self = this;
1026
return self['import'](self.transpiler).then(function(transpiler) {
1127
if (transpiler.__useDefault)
@@ -14,8 +30,6 @@
1430
});
1531
};
1632

17-
var g = __global;
18-
1933
Loader.prototype.instantiate = function(load) {
2034
// load transpiler as a global (avoiding System clobbering)
2135
if (load.name === this.transpiler)
@@ -24,10 +38,10 @@
2438
execute: function() {
2539
var curSystem = g.System;
2640
var curLoader = g.Reflect.Loader;
27-
__eval('(function(require,exports,module){' + load.source + '})();', g, load);
41+
__eval(load.source, g, load);
2842
g.System = curSystem;
2943
g.Reflect.Loader = curLoader;
30-
return System.newModule({ 'default': g[load.name], __useDefault: true });
44+
return getTranspilerModule(load.name);
3145
}
3246
};
3347
};

0 commit comments

Comments
 (0)