third_party/es6-module-loader/loader.js
function proceedToTranslate(loader, load, p) {
      p
      // 15.2.4.5.1 CallTranslate
      .then(function(source) {
        if (load.linkSets.length == 0)
          return;
        return loader.loaderObj.translate({ name: load.name, metadata: load.metadata, address: load.address, source: source });
      })

      // 15.2.4.5.2 CallInstantiate
      .then(function(source) {
        if (load.linkSets.length == 0)
          return;
        load.source = source;
        return loader.loaderObj.instantiate({ name: load.name, metadata: load.metadata, address: load.address, source: source });
      })

      // 15.2.4.5.3 InstantiateSucceeded
      .then(function(instantiateResult) {
        if (load.linkSets.length == 0)
          return;

        var depsList;
        if (instantiateResult === undefined) {
          if (!__global.traceur)
            throw new TypeError('Include Traceur for module syntax support');

          traceur = traceur || __global.traceur;
          load.address = load.address || 'anon' + ++anonCnt;

          console.assert(load.source, 'Non-empty source');

          try {
            var parser = new traceur.syntax.Parser(new traceur.syntax.SourceFile(load.address, load.source));
            var body = parser.parseModule();

            load.kind = 'declarative';

            depsList = getImports(body);

            var oldSourceMaps = traceur.options.sourceMaps;
            var oldModules = traceur.options.modules;

            traceur.options.sourceMaps = true;
            traceur.options.modules = 'instantiate';

            var reporter = new traceur.util.ErrorReporter();

            reporter.reportMessageInternal = function(location, kind, format, args) {
              throw new SyntaxError(kind, location.start && location.start.line_, location.start && location.start.column_);
            }

            // traceur expects its version of System
            var curSystem = __global.System;
            __global.System = __global.traceurSystem || curSystem;

            var tree = (new traceur.codegeneration.module.AttachModuleNameTransformer(load.name)).transformAny(body);
            tree = (new traceur.codegeneration.FromOptionsTransformer(reporter)).transform(tree);

            var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator({ file: load.address });
            var options = { sourceMapGenerator: sourceMapGenerator };

            var source = traceur.outputgeneration.TreeWriter.write(tree, options);

            if (__global.btoa)
              source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(options.sourceMap))) + '\n';

            // now run System.register
            var curRegister = System.register;
            
            System.register = function(name, deps, declare) {
              // store the registered declaration as load.declare
              load.declare = declare;
            }

            __eval(source, __global, load.name);
          }
          catch(e) {
            if (e.name == 'SyntaxError' || e.name == 'TypeError') 
              e.message = 'Evaluating ' + (load.name || load.address) + '\n\t' + e.message;
            if (curRegister)
              System.register = curRegister;
            if (curSystem)
              __global.System = curSystem;
            if (oldSourceMaps)
              traceur.options.sourceMaps = oldSourceMaps;
            if (oldModules)
              traceur.options.modules = oldModules;
            throw e;
          }
          System.register = curRegister;
          __global.System = curSystem;
          traceur.options.sourceMaps = oldSourceMaps;
          traceur.options.modules = oldModules;
        }
        else if (typeof instantiateResult == 'object') {
          depsList = instantiateResult.deps || [];
          load.execute = instantiateResult.execute;
          load.kind = 'dynamic';
        }
        else
          throw TypeError('Invalid instantiate return value');

        // 15.2.4.6 ProcessLoadDependencies
        load.dependencies = [];
        load.depsList = depsList
        var loadPromises = [];
        for (var i = 0, l = depsList.length; i < l; i++) (function(request) {
          loadPromises.push(
            requestLoad(loader, request, load.name, load.address)

            // 15.2.4.6.1 AddDependencyLoad (load is parentLoad)
            .then(function(depLoad) {

              console.assert(!load.dependencies.some(function(dep) {
                return dep.key == request;
              }), 'not already a dependency');

              load.dependencies.push({
                key: request,
                value: depLoad.name
              });

              if (depLoad.status != 'linked') {
                var linkSets = load.linkSets.concat([]);
                for (var i = 0, l = linkSets.length; i < l; i++)
                  addLoadToLinkSet(linkSets[i], depLoad);
              }

              // console.log('AddDependencyLoad ' + depLoad.name + ' for ' + load.name);
              // snapshot(loader);
            })
          );
        })(depsList[i]);

        return Promise.all(loadPromises);
      })

      // 15.2.4.6.2 LoadSucceeded
      .then(function() {
        // console.log('LoadSucceeded ' + load.name);
        // snapshot(loader);

        console.assert(load.status == 'loading', 'is loading');

        load.status = 'loaded';

        var linkSets = load.linkSets.concat([]);
        for (var i = 0, l = linkSets.length; i < l; i++)
          updateLinkSetOnLoad(linkSets[i], load);
      })

      // 15.2.4.5.4 LoadFailed
      ['catch'](function(exc) {
        console.assert(load.status == 'loading', 'is loading on fail');
        load.status = 'failed';
        load.exception = exc;

        var linkSets = load.linkSets.concat([]);
        for (var i = 0, l = linkSets.length; i < l; i++)
          linkSetFailed(linkSets[i], exc);

        console.assert(load.linkSets.length == 0, 'linkSets not removed');
      });
    }
function proceedToTranslate(loader, load, p) {
      p
      // 15.2.4.5.1 CallTranslate
      .then(function(source) {
        if (load.linkSets.length == 0)
          return;
        return loader.loaderObj.translate({ name: load.name, metadata: load.metadata, address: load.address, source: source });
      })

      // 15.2.4.5.2 CallInstantiate
      .then(function(source) {
        if (load.linkSets.length == 0)
          return;
        load.source = source;
        return loader.loaderObj.instantiate({ name: load.name, metadata: load.metadata, address: load.address, source: source });
      })

      // 15.2.4.5.3 InstantiateSucceeded
      .then(function(instantiateResult) {
        if (load.linkSets.length == 0)
          return;

        var depsList;
        if (instantiateResult === undefined) {
          if (!__global.traceur)
            throw new TypeError('Include Traceur for module syntax support');

          traceur = traceur || __global.traceur;
          load.address = load.address || 'anon' + ++anonCnt;

          console.assert(load.source, 'Non-empty source');

          try {
            var parser = new traceur.syntax.Parser(new traceur.syntax.SourceFile(load.address, load.source));
            var body = parser.parseModule();

            load.kind = 'declarative';

            depsList = getImports(body);

            var oldSourceMaps = traceur.options.sourceMaps;
            var oldModules = traceur.options.modules;

            traceur.options.sourceMaps = true;
            traceur.options.modules = 'instantiate';

            var reporter = new traceur.util.ErrorReporter();

            reporter.reportMessageInternal = function(location, kind, format, args) {
              throw new SyntaxError(kind, location.start && location.start.line_, location.start && location.start.column_);
            }

            // traceur expects its version of System
            var curSystem = __global.System;
            __global.System = __global.traceurSystem || curSystem;

            var tree = (new traceur.codegeneration.module.AttachModuleNameTransformer(load.name)).transformAny(body);
            tree = (new traceur.codegeneration.FromOptionsTransformer(reporter)).transform(tree);

            var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator({ file: load.address });
            var options = { sourceMapGenerator: sourceMapGenerator };

            var source = traceur.outputgeneration.TreeWriter.write(tree, options);

            if (__global.btoa)
              source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(options.sourceMap))) + '\n';

            // now run System.register
            var curRegister = System.register;
            
            System.register = function(name, deps, declare) {
              // store the registered declaration as load.declare
              load.declare = declare;
            }

            __eval(source, __global, load.name);
          }
          catch(e) {
            if (e.name == 'SyntaxError' || e.name == 'TypeError') 
              e.message = 'Evaluating ' + (load.name || load.address) + '\n\t' + e.message;
            if (curRegister)
              System.register = curRegister;
            if (curSystem)
              __global.System = curSystem;
            if (oldSourceMaps)
              traceur.options.sourceMaps = oldSourceMaps;
            if (oldModules)
              traceur.options.modules = oldModules;
            throw e;
          }
          System.register = curRegister;
          __global.System = curSystem;
          traceur.options.sourceMaps = oldSourceMaps;
          traceur.options.modules = oldModules;
        }
        else if (typeof instantiateResult == 'object') {
          depsList = instantiateResult.deps || [];
          load.execute = instantiateResult.execute;
          load.kind = 'dynamic';
        }
        else
          throw TypeError('Invalid instantiate return value');

        // 15.2.4.6 ProcessLoadDependencies
        load.dependencies = [];
        load.depsList = depsList
        var loadPromises = [];
        for (var i = 0, l = depsList.length; i < l; i++) (function(request) {
          loadPromises.push(
            requestLoad(loader, request, load.name, load.address)

            // 15.2.4.6.1 AddDependencyLoad (load is parentLoad)
            .then(function(depLoad) {

              console.assert(!load.dependencies.some(function(dep) {
                return dep.key == request;
              }), 'not already a dependency');

              load.dependencies.push({
                key: request,
                value: depLoad.name
              });

              if (depLoad.status != 'linked') {
                var linkSets = load.linkSets.concat([]);
                for (var i = 0, l = linkSets.length; i < l; i++)
                  addLoadToLinkSet(linkSets[i], depLoad);
              }

              // console.log('AddDependencyLoad ' + depLoad.name + ' for ' + load.name);
              // snapshot(loader);
            })
          );
        })(depsList[i]);

        return Promise.all(loadPromises);
      })

      // 15.2.4.6.2 LoadSucceeded
      .then(function() {
        // console.log('LoadSucceeded ' + load.name);
        // snapshot(loader);

        console.assert(load.status == 'loading', 'is loading');

        load.status = 'loaded';

        var linkSets = load.linkSets.concat([]);
        for (var i = 0, l = linkSets.length; i < l; i++)
          updateLinkSetOnLoad(linkSets[i], load);
      })

      // 15.2.4.5.4 LoadFailed
      ['catch'](function(exc) {
        console.assert(load.status == 'loading', 'is loading on fail');
        load.status = 'failed';
        load.exception = exc;

        var linkSets = load.linkSets.concat([]);
        for (var i = 0, l = linkSets.length; i < l; i++)
          linkSetFailed(linkSets[i], exc);

        console.assert(load.linkSets.length == 0, 'linkSets not removed');
      });
    }
function proceedToTranslate ( loader , load , p ) { p // 15.2.4.5.1 CallTranslate . then ( function ( source ) { if ( load . linkSets . length == 0 ) return ; return loader . loaderObj . translate ( { name : load . name , metadata : load . metadata , address : load . address , source : source } ) ; } ) // 15.2.4.5.2 CallInstantiate . then ( function ( source ) { if ( load . linkSets . length == 0 ) return ; load . source = source ; return loader . loaderObj . instantiate ( { name : load . name , metadata : load . metadata , address : load . address , source : source } ) ; } ) // 15.2.4.5.3 InstantiateSucceeded . then ( function ( instantiateResult ) { if ( load . linkSets . length == 0 ) return ; var depsList ; if ( instantiateResult === undefined ) { if ( ! __global . traceur ) throw new TypeError ( 'Include Traceur for module syntax support' ) ; traceur = traceur || __global . traceur ; load . address = load . address || 'anon' + ++ anonCnt ; console . assert ( load . source , 'Non-empty source' ) ; try { var parser = new traceur . syntax . Parser ( new traceur . syntax . SourceFile ( load . address , load . source ) ) ; var body = parser . parseModule ( ) ; load . kind = 'declarative' ; depsList = getImports ( body ) ; var oldSourceMaps = traceur . options . sourceMaps ; var oldModules = traceur . options . modules ; traceur . options . sourceMaps = true ; traceur . options . modules = 'instantiate' ; var reporter = new traceur . util . ErrorReporter ( ) ; reporter . reportMessageInternal = function ( location , kind , format , args ) { throw new SyntaxError ( kind , location . start && location . start . line_ , location . start && location . start . column_ ) ; } // traceur expects its version of System var curSystem = __global . System ; __global . System = __global . traceurSystem || curSystem ; var tree = ( new traceur . codegeneration . module . AttachModuleNameTransformer ( load . name ) ) . transformAny ( body ) ; tree = ( new traceur . codegeneration . FromOptionsTransformer ( reporter ) ) . transform ( tree ) ; var sourceMapGenerator = new traceur . outputgeneration . SourceMapGenerator ( { file : load . address } ) ; var options = { sourceMapGenerator : sourceMapGenerator } ; var source = traceur . outputgeneration . TreeWriter . write ( tree , options ) ; if ( __global . btoa ) source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa ( unescape ( encodeURIComponent ( options . sourceMap ) ) ) + '\n' ; // now run System.register var curRegister = System . register ; System . register = function ( name , deps , declare ) { // store the registered declaration as load.declare load . declare = declare ; } __eval ( source , __global , load . name ) ; } catch ( e ) { if ( e . name == 'SyntaxError' || e . name == 'TypeError' ) e . message = 'Evaluating ' + ( load . name || load . address ) + '\n\t' + e . message ; if ( curRegister ) System . register = curRegister ; if ( curSystem ) __global . System = curSystem ; if ( oldSourceMaps ) traceur . options . sourceMaps = oldSourceMaps ; if ( oldModules ) traceur . options . modules = oldModules ; throw e ; } System . register = curRegister ; __global . System = curSystem ; traceur . options . sourceMaps = oldSourceMaps ; traceur . options . modules = oldModules ; } else if ( typeof instantiateResult == 'object' ) { depsList = instantiateResult . deps || [ ] ; load . execute = instantiateResult . execute ; load . kind = 'dynamic' ; } else throw TypeError ( 'Invalid instantiate return value' ) ; // 15.2.4.6 ProcessLoadDependencies load . dependencies = [ ] ; load . depsList = depsList var loadPromises = [ ] ; for ( var i = 0 , l = depsList . length ; i < l ; i ++ ) ( function ( request ) { loadPromises . push ( requestLoad ( loader , request , load . name , load . address ) // 15.2.4.6.1 AddDependencyLoad (load is parentLoad) . then ( function ( depLoad ) { console . assert ( ! load . dependencies . some ( function ( dep ) { return dep . key == request ; } ) , 'not already a dependency' ) ; load . dependencies . push ( { key : request , value : depLoad . name } ) ; if ( depLoad . status != 'linked' ) { var linkSets = load . linkSets . concat ( [ ] ) ; for ( var i = 0 , l = linkSets . length ; i < l ; i ++ ) addLoadToLinkSet ( linkSets [ i ] , depLoad ) ; } // console.log('AddDependencyLoad ' + depLoad.name + ' for ' + load.name); // snapshot(loader); } ) ) ; } ) ( depsList [ i ] ) ; return Promise . all ( loadPromises ) ; } ) // 15.2.4.6.2 LoadSucceeded . then ( function ( ) { // console.log('LoadSucceeded ' + load.name); // snapshot(loader); console . assert ( load . status == 'loading' , 'is loading' ) ; load . status = 'loaded' ; var linkSets = load . linkSets . concat ( [ ] ) ; for ( var i = 0 , l = linkSets . length ; i < l ; i ++ ) updateLinkSetOnLoad ( linkSets [ i ] , load ) ; } ) // 15.2.4.5.4 LoadFailed [ 'catch' ] ( function ( exc ) { console . assert ( load . status == 'loading' , 'is loading on fail' ) ; load . status = 'failed' ; load . exception = exc ; var linkSets = load . linkSets . concat ( [ ] ) ; for ( var i = 0 , l = linkSets . length ; i < l ; i ++ ) linkSetFailed ( linkSets [ i ] , exc ) ; console . assert ( load . linkSets . length == 0 , 'linkSets not removed' ) ; } ) ; }
15.2.4.5
15 . 2 . 4 . 5