lib/utils.js
function getCanonicalNamePlain(loader, normalized, isPlugin) {
  // now just reverse apply paths rules to get canonical name
  var pathMatch;

  // first check exact path matches
  for (var p in loader.paths) {
    if (loader.paths[p].indexOf('*') != -1)
      continue;

    var curPath = normalizePath(loader, loader.paths[p], isPlugin);

    // always stop on first exact match
    if (normalized === curPath)
      return p;

    // support trailing / in paths rules
    else if (curPath[curPath.length - 1] == '/' &&
        normalized.substr(0, curPath.length - 1) == curPath.substr(0, curPath.length - 1) &&
        (normalized.length < curPath.length || normalized[curPath.length - 1] == curPath[curPath.length - 1])) {
      // first case is that canonicalize('src') = 'app' for 'app/': 'src/'
      return normalized.length < curPath.length ? p.substr(0, p.length - 1) : p + normalized.substr(curPath.length);
    }
  }

  // then wildcard matches
  var pathMatchLength = 0;
  var curMatchLength;
  if (!pathMatch)
    for (var p in loader.paths) {
      if (loader.paths[p].indexOf('*') == -1)
        continue;

      // normalize the output path
      var curPath = normalizePath(loader, loader.paths[p], true);

      // do reverse match
      var wIndex = curPath.indexOf('*');
      if (normalized.substr(0, wIndex) === curPath.substr(0, wIndex)
        && normalized.substr(normalized.length - curPath.length + wIndex + 1) === curPath.substr(wIndex + 1)) {
        curMatchLength = curPath.split('/').length;
        if (curMatchLength >= pathMatchLength) {
          pathMatch = p.replace('*', normalized.substr(wIndex, normalized.length - curPath.length + 1));
          pathMatchLength = curMatchLength;
        }
      }
    }

  // when no path was matched, act like the standard rule is *: baseURL/*
  if (!pathMatch) {
    if (normalized.substr(0, loader.baseURL.length) == loader.baseURL)
      pathMatch = normalized.substr(loader.baseURL.length);
    else if (normalized.match(absURLRegEx))
      throw new Error('Unable to calculate canonical name to bundle ' + normalized + '. Ensure that this module sits within the baseURL or a wildcard path config.');
    else
      pathMatch = normalized;
  }

  return pathMatch;
}
function getCanonicalNamePlain(loader, normalized, isPlugin) {
  // now just reverse apply paths rules to get canonical name
  var pathMatch;

  // first check exact path matches
  for (var p in loader.paths) {
    if (loader.paths[p].indexOf('*') != -1)
      continue;

    var curPath = normalizePath(loader, loader.paths[p], isPlugin);

    // always stop on first exact match
    if (normalized === curPath)
      return p;

    // support trailing / in paths rules
    else if (curPath[curPath.length - 1] == '/' &&
        normalized.substr(0, curPath.length - 1) == curPath.substr(0, curPath.length - 1) &&
        (normalized.length < curPath.length || normalized[curPath.length - 1] == curPath[curPath.length - 1])) {
      // first case is that canonicalize('src') = 'app' for 'app/': 'src/'
      return normalized.length < curPath.length ? p.substr(0, p.length - 1) : p + normalized.substr(curPath.length);
    }
  }

  // then wildcard matches
  var pathMatchLength = 0;
  var curMatchLength;
  if (!pathMatch)
    for (var p in loader.paths) {
      if (loader.paths[p].indexOf('*') == -1)
        continue;

      // normalize the output path
      var curPath = normalizePath(loader, loader.paths[p], true);

      // do reverse match
      var wIndex = curPath.indexOf('*');
      if (normalized.substr(0, wIndex) === curPath.substr(0, wIndex)
        && normalized.substr(normalized.length - curPath.length + wIndex + 1) === curPath.substr(wIndex + 1)) {
        curMatchLength = curPath.split('/').length;
        if (curMatchLength >= pathMatchLength) {
          pathMatch = p.replace('*', normalized.substr(wIndex, normalized.length - curPath.length + 1));
          pathMatchLength = curMatchLength;
        }
      }
    }

  // when no path was matched, act like the standard rule is *: baseURL/*
  if (!pathMatch) {
    if (normalized.substr(0, loader.baseURL.length) == loader.baseURL)
      pathMatch = normalized.substr(loader.baseURL.length);
    else if (normalized.match(absURLRegEx))
      throw new Error('Unable to calculate canonical name to bundle ' + normalized + '. Ensure that this module sits within the baseURL or a wildcard path config.');
    else
      pathMatch = normalized;
  }

  return pathMatch;
}
function getCanonicalNamePlain ( loader , normalized , isPlugin ) { // now just reverse apply paths rules to get canonical name var pathMatch ; // first check exact path matches for ( var p in loader . paths ) { if ( loader . paths [ p ] . indexOf ( '*' ) != - 1 ) continue ; var curPath = normalizePath ( loader , loader . paths [ p ] , isPlugin ) ; // always stop on first exact match if ( normalized === curPath ) return p ; // support trailing / in paths rules else if ( curPath [ curPath . length - 1 ] == '/' && normalized . substr ( 0 , curPath . length - 1 ) == curPath . substr ( 0 , curPath . length - 1 ) && ( normalized . length < curPath . length || normalized [ curPath . length - 1 ] == curPath [ curPath . length - 1 ] ) ) { // first case is that canonicalize('src') = 'app' for 'app/': 'src/' return normalized . length < curPath . length ? p . substr ( 0 , p . length - 1 ) : p + normalized . substr ( curPath . length ) ; } } // then wildcard matches var pathMatchLength = 0 ; var curMatchLength ; if ( ! pathMatch ) for ( var p in loader . paths ) { if ( loader . paths [ p ] . indexOf ( '*' ) == - 1 ) continue ; // normalize the output path var curPath = normalizePath ( loader , loader . paths [ p ] , true ) ; // do reverse match var wIndex = curPath . indexOf ( '*' ) ; if ( normalized . substr ( 0 , wIndex ) === curPath . substr ( 0 , wIndex ) && normalized . substr ( normalized . length - curPath . length + wIndex + 1 ) === curPath . substr ( wIndex + 1 ) ) { curMatchLength = curPath . split ( '/' ) . length ; if ( curMatchLength >= pathMatchLength ) { pathMatch = p . replace ( '*' , normalized . substr ( wIndex , normalized . length - curPath . length + 1 ) ) ; pathMatchLength = curMatchLength ; } } } // when no path was matched, act like the standard rule is *: baseURL/* if ( ! pathMatch ) { if ( normalized . substr ( 0 , loader . baseURL . length ) == loader . baseURL ) pathMatch = normalized . substr ( loader . baseURL . length ) ; else if ( normalized . match ( absURLRegEx ) ) throw new Error ( 'Unable to calculate canonical name to bundle ' + normalized + '. Ensure that this module sits within the baseURL or a wildcard path config.' ) ; else pathMatch = normalized ; } return pathMatch ; }
syntax-free getCanonicalName just reverse-applies paths and defulatJSExtension to determine the canonical
syntax - free getCanonicalName just reverse - applies paths and defulatJSExtension to determine the canonical