* Creates a module mapping that includes plugin prefix, module * name, and path. If parentModuleMap is provided it will * also normalize the name via require.normalize() * * @param {String} name the module name * @param {String} [parentModuleMap] parent module map * for
(name, parentModuleMap, isNormalized, applyMap)
| 438 | * @returns {Object} |
| 439 | */ |
| 440 | function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) { |
| 441 | var url, |
| 442 | pluginModule, |
| 443 | suffix, |
| 444 | nameParts, |
| 445 | prefix = null, |
| 446 | parentName = parentModuleMap ? parentModuleMap.name : null, |
| 447 | originalName = name, |
| 448 | isDefine = true, |
| 449 | normalizedName = '' |
| 450 | |
| 451 | //If no name, then it means it is a require call, generate an |
| 452 | //internal name. |
| 453 | if (!name) { |
| 454 | isDefine = false |
| 455 | name = '_@r' + (requireCounter += 1) |
| 456 | } |
| 457 | |
| 458 | nameParts = splitPrefix(name) |
| 459 | prefix = nameParts[0] |
| 460 | name = nameParts[1] |
| 461 | |
| 462 | if (prefix) { |
| 463 | prefix = normalize(prefix, parentName, applyMap) |
| 464 | pluginModule = getOwn(defined, prefix) |
| 465 | } |
| 466 | |
| 467 | //Account for relative paths if there is a base name. |
| 468 | if (name) { |
| 469 | if (prefix) { |
| 470 | if (pluginModule && pluginModule.normalize) { |
| 471 | //Plugin is loaded, use its normalize method. |
| 472 | normalizedName = pluginModule.normalize(name, function (name) { |
| 473 | return normalize(name, parentName, applyMap) |
| 474 | }) |
| 475 | } else { |
| 476 | // If nested plugin references, then do not try to |
| 477 | // normalize, as it will not normalize correctly. This |
| 478 | // places a restriction on resourceIds, and the longer |
| 479 | // term solution is not to normalize until plugins are |
| 480 | // loaded and all normalizations to allow for async |
| 481 | // loading of a loader plugin. But for now, fixes the |
| 482 | // common uses. Details in #1131 |
| 483 | normalizedName = name.indexOf('!') === -1 ? normalize(name, parentName, applyMap) : name |
| 484 | } |
| 485 | } else { |
| 486 | //A regular module. |
| 487 | normalizedName = normalize(name, parentName, applyMap) |
| 488 | |
| 489 | //Normalized name may be a plugin ID due to map config |
| 490 | //application in normalize. The map config values must |
| 491 | //already be normalized, so do not need to redo that part. |
| 492 | nameParts = splitPrefix(normalizedName) |
| 493 | prefix = nameParts[0] |
| 494 | normalizedName = nameParts[1] |
| 495 | isNormalized = true |
| 496 | |
| 497 | url = context.nameToUrl(normalizedName) |
no test coverage detected