core/modules.js
function moduleLoaded(resolve, requires, modName, data, loadedModuleData, alreadyMinified){
    // Check for any modules used from this module that we don't already have
    var newRequires = getModulesRequired(data);
    console.log(" - "+modName+" requires "+JSON.stringify(newRequires));
    // if we need new modules, set them to load and get their promises
    var newPromises = [];
    for (var i in newRequires) {
      if (requires.indexOf(newRequires[i])<0) {
        console.log("   Queueing "+newRequires[i]);
        requires.push(newRequires[i]);
        newPromises.push(loadModule(requires, newRequires[i], loadedModuleData));
      } else {
        console.log("   Already loading "+newRequires[i]);
      }
    }

    var loadProcessedModule = function (module) {
      // add the module to the beginning of our array
      if (Espruino.Config.MODULE_AS_FUNCTION)
        loadedModuleData.unshift("Modules.addCached(" + JSON.stringify(module.name) + ",function(){" + module.code + "});");
      else
        loadedModuleData.unshift("Modules.addCached(" + JSON.stringify(module.name) + "," + JSON.stringify(module.code) + ");");
      // if we needed to load something, wait until we have all promises complete before resolving our promise!
      Promise.all(newPromises).then(function(){ resolve(); });
    }
    if (alreadyMinified)
      loadProcessedModule({code:data,name:modName});
    else
      Espruino.callProcessor("transformModuleForEspruino", {code:data,name:modName}, loadProcessedModule);
  }
function moduleLoaded(resolve, requires, modName, data, loadedModuleData, alreadyMinified){
    // Check for any modules used from this module that we don't already have
    var newRequires = getModulesRequired(data);
    console.log(" - "+modName+" requires "+JSON.stringify(newRequires));
    // if we need new modules, set them to load and get their promises
    var newPromises = [];
    for (var i in newRequires) {
      if (requires.indexOf(newRequires[i])<0) {
        console.log("   Queueing "+newRequires[i]);
        requires.push(newRequires[i]);
        newPromises.push(loadModule(requires, newRequires[i], loadedModuleData));
      } else {
        console.log("   Already loading "+newRequires[i]);
      }
    }

    var loadProcessedModule = function (module) {
      // add the module to the beginning of our array
      if (Espruino.Config.MODULE_AS_FUNCTION)
        loadedModuleData.unshift("Modules.addCached(" + JSON.stringify(module.name) + ",function(){" + module.code + "});");
      else
        loadedModuleData.unshift("Modules.addCached(" + JSON.stringify(module.name) + "," + JSON.stringify(module.code) + ");");
      // if we needed to load something, wait until we have all promises complete before resolving our promise!
      Promise.all(newPromises).then(function(){ resolve(); });
    }
    if (alreadyMinified)
      loadProcessedModule({code:data,name:modName});
    else
      Espruino.callProcessor("transformModuleForEspruino", {code:data,name:modName}, loadProcessedModule);
  }
function moduleLoaded ( resolve , requires , modName , data , loadedModuleData , alreadyMinified ) { // Check for any modules used from this module that we don't already have var newRequires = getModulesRequired ( data ) ; console . log ( " - " + modName + " requires " + JSON . stringify ( newRequires ) ) ; // if we need new modules, set them to load and get their promises var newPromises = [ ] ; for ( var i in newRequires ) { if ( requires . indexOf ( newRequires [ i ] ) < 0 ) { console . log ( "   Queueing " + newRequires [ i ] ) ; requires . push ( newRequires [ i ] ) ; newPromises . push ( loadModule ( requires , newRequires [ i ] , loadedModuleData ) ) ; } else { console . log ( "   Already loading " + newRequires [ i ] ) ; } } var loadProcessedModule = function ( module ) { // add the module to the beginning of our array if ( Espruino . Config . MODULE_AS_FUNCTION ) loadedModuleData . unshift ( "Modules.addCached(" + JSON . stringify ( module . name ) + ",function(){" + module . code + "});" ) ; else loadedModuleData . unshift ( "Modules.addCached(" + JSON . stringify ( module . name ) + "," + JSON . stringify ( module . code ) + ");" ) ; // if we needed to load something, wait until we have all promises complete before resolving our promise! Promise . all ( newPromises ) . then ( function ( ) { resolve ( ) ; } ) ; } if ( alreadyMinified ) loadProcessedModule ( { code : data , name : modName } ) ; else Espruino . callProcessor ( "transformModuleForEspruino" , { code : data , name : modName } , loadProcessedModule ) ; }
Called from loadModule when a module is loaded. Parse it for other modules it might use
and resolve dfd after all submodules have been loaded
Called from loadModule when a module is loaded . Parse it for other modules it might use and resolve dfd after all submodules have been loaded