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

Commit

Permalink
run transpilers through module registry
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Mar 7, 2015
1 parent cd4fbae commit 180852b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/transpiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@
(function(Loader) {
// Returns an array of ModuleSpecifiers
var transpiler, transpilerModule;
var isNode = typeof window == 'undefined' && typeof WorkerGlobalScope == 'undefined';

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

Loader.prototype.transpile = function(load) {
if (!transpiler) {
if (this.transpiler == 'babel') {
transpiler = babelTranspile;
transpilerModule = isNode ? require('babel-core') : __global.babel;
transpilerModule = this.get('@' + this.transpiler);

if (transpilerModule) {
transpilerModule = transpilerModule['default'];
}
else {
transpiler = traceurTranspile;
transpilerModule = isNode ? require('traceur') : __global.traceur;
transpilerModule = __global[this.transpiler] || typeof require != 'undefined' && require(this.transpiler == 'babel' ? 'babel-core' : 'traceur');
if (!transpilerModule)
throw new TypeError('Include Traceur or Babel for module syntax support.');
this.set('@' + this.transpiler, this.newModule({ 'default': transpilerModule, __useDefault: true }));
}

if (!transpilerModule)
throw new TypeError('Include Traceur or Babel for module syntax support.');

if (this.transpiler == 'babel')
transpiler = babelTranspile;
else if (this.transpiler == 'traceur')
transpiler = traceurTranspile;
}

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

0 comments on commit 180852b

Please # to comment.