/*
 * Traceur and Babel transpile hook for Loader
 */
(function(Loader) {
  // use Traceur by default
  Loader.prototype.transpiler = 'traceur';

  Loader.prototype.transpile = function(load) {
    return this['import'](this.transpiler).then(function(transpiler) {
      if (transpiler.__useDefault)
        transpiler = transpiler['default'];
      return 'var __moduleAddress = "' + load.address + '";' + (transpiler.Compiler ? traceurTranspile : babelTranspile).call(this, load, transpiler);
    });
  }

  var g = __global;

  Loader.prototype.instantiate = function(load) {
    // load transpiler as a global (avoiding System clobbering)
    if (load.name === this.transpiler)
      return {
        deps: [],
        execute: function() {
          var curSystem = g.System;
          var curLoader = g.Reflect.Loader;
          __eval('(function(require,exports,module){' + load.source + '})();', g, load);
          g.System = curSystem;
          g.Reflect.Loader = curLoader;
          return System.newModule({ 'default': g[load.name], __useDefault: true });
        }
      };
  }

  function traceurTranspile(load, traceur) {
    var options = this.traceurOptions || {};
    options.modules = 'instantiate';
    options.script = false;
    options.sourceMaps = 'inline';
    options.filename = load.address;
    options.inputSourceMap = load.metadata.sourceMap;

    var compiler = new traceur.Compiler(options);
    var source = doTraceurCompile(load.source, compiler, options.filename);

    // add "!eval" to end of Traceur sourceURL
    // I believe this does something?
    source += '!eval';

    return source;
  }
  function doTraceurCompile(source, compiler, filename) {
    try {
      return compiler.compile(source, filename);
    }
    catch(e) {
      // traceur throws an error array
      throw e[0];
    }
  }

  function babelTranspile(load, babel) {
    var options = this.babelOptions || {};
    options.modules = 'system';
    options.sourceMap = 'inline';
    options.filename = load.address;
    options.code = true;
    options.ast = false;
    options.blacklist = options.blacklist || [];
    options.blacklist.push('react');

    var source = babel.transform(load.source, options).code;

    // add "!eval" to end of Babel sourceURL
    // I believe this does something?
    return source + '\n//# sourceURL=' + load.address + '!eval';
  }


})(__global.LoaderPolyfill);
@@ -2079,28 +2079,18 @@
     
-options.blacklist = 
+%0A    if (!
 opti
@@ -2106,16 +2106,12 @@
 list
- %7C%7C %5B%5D;%0A
+)%0A  
     
@@ -2131,22 +2131,20 @@
 list
-.push(
+ = %5B
 'react'
-)
+%5D
 ;%0A%0A 

allow blacklist overrides