node_modules/grunt-angular-builder/tasks/middleware/makeReleaseBuild.js
/**
 * Determine which modules can be optimized.
 * @param {Context} context The execution context for the middleware stack.
 */
Determine which modules can be optimized.
@param {Context} context The execution context for the middleware stack.
Determine which modules can be optimized . @param { Context } context The execution context for the middleware stack .
function scanForOptimization (context)
{
  var module, verboseOut = context.grunt.log.verbose;
  Object.keys (context.modules).forEach (function (name)
  {
    if (context.modules.hasOwnProperty (name)) {
      module = context.modules[name];
      if (!module.external)
        module.filePaths ().forEach (function (path)
        {
          if (!context.filesRefCount[path])
            context.filesRefCount[path] = 1;
          else {
            verboseOut.writeln (util.csprintf ('white',
              'Not optimizing <cyan>%</cyan> because it shares some/all of its files with other modules.', name));
            ++context.filesRefCount[path];
            module.optimize = false;
          }
        });
    }
  });
  scan (context.options.mainModule, true);
  function scan (moduleName, first)
  {
    var module = context.modules[moduleName];
    if (!module)
      throw new Error (sprintf ("Module '%' was not found.", moduleName));
    if (module.external)
      return false;
    if (!module.optimize) {
      if (first)
        module.nonOptimizedContainer = true;
      disableOptimizationsForChildrenOf (module);
      return true;
    }
    for (var i = 0, m = module.requires.length, any = false; i < m; ++i)
      if (scan (module.requires[i])) 
        any = true;
    if (any)
      module.nonOptimizedContainer = true;
    return false;
  }
  function disableOptimizationsForChildrenOf (module)
  {
    if (module.external)
      return;
    for (var i = 0, m = module.requires.length; i < m; ++i) {
      var sub = context.modules[module.requires[i]];
      if (sub.external)
        continue;
      if (sub.optimize)
        verboseOut.writeln (util.csprintf ('white', "Also disabling optimizations for <cyan>%</cyan>.", sub.name.cyan));
      sub.optimize = false;
      disableOptimizationsForChildrenOf (sub);
    }
  }
}
function scanForOptimization ( context ) { var module , verboseOut = context . grunt . log . verbose ; Object . keys ( context . modules ) . forEach ( function ( name ) { if ( context . modules . hasOwnProperty ( name ) ) { module = context . modules [ name ] ; if ( ! module . external ) module . filePaths ( ) . forEach ( function ( path ) { if ( ! context . filesRefCount [ path ] ) context . filesRefCount [ path ] = 1 ; else { verboseOut . writeln ( util . csprintf ( 'white' , 'Not optimizing <cyan>%</cyan> because it shares some/all of its files with other modules.' , name ) ) ; ++ context . filesRefCount [ path ] ; module . optimize = false ; } } ) ; } } ) ; scan ( context . options . mainModule , true ) ; function scan ( moduleName , first ) { var module = context . modules [ moduleName ] ; if ( ! module ) throw new Error ( sprintf ( "Module '%' was not found." , moduleName ) ) ; if ( module . external ) return false ; if ( ! module . optimize ) { if ( first ) module . nonOptimizedContainer = true ; disableOptimizationsForChildrenOf ( module ) ; return true ; } for ( var i = 0 , m = module . requires . length , any = false ; i < m ; ++ i ) if ( scan ( module . requires [ i ] ) ) any = true ; if ( any ) module . nonOptimizedContainer = true ; return false ; } function disableOptimizationsForChildrenOf ( module ) { if ( module . external ) return ; for ( var i = 0 , m = module . requires . length ; i < m ; ++ i ) { var sub = context . modules [ module . requires [ i ] ] ; if ( sub . external ) continue ; if ( sub . optimize ) verboseOut . writeln ( util . csprintf ( 'white' , "Also disabling optimizations for <cyan>%</cyan>." , sub . name . cyan ) ) ; sub . optimize = false ; disableOptimizationsForChildrenOf ( sub ) ; } } }
Determine which modules can be optimized.
Determine which modules can be optimized .
// Track repeated files to determine which modules can be optimized. // Determine which modules can act as containers for non-optimized sections of code. /**
   * Search for unoptimizable modules.
   * @param {string} moduleName
   * @param {boolean?} first=false Is this the root module?
   * @returns {boolean} `true` if the module is not optimizable.
   */ // Ignore the module if it's external. //Note: scan() still must be called for ALL submodules!