MCPcopy
hub / github.com/requirejs/requirejs / makeModuleMap

Function makeModuleMap

require.js:416–497  ·  view source on GitHub ↗

* 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 m

(name, parentModuleMap, isNormalized, applyMap)

Source from the content-addressed store, hash-verified

414 * @returns {Object}
415 */
416 function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) {
417 var url, pluginModule, suffix, nameParts,
418 prefix = null,
419 parentName = parentModuleMap ? parentModuleMap.name : null,
420 originalName = name,
421 isDefine = true,
422 normalizedName = '';
423
424 //If no name, then it means it is a require call, generate an
425 //internal name.
426 if (!name) {
427 isDefine = false;
428 name = '_@r' + (requireCounter += 1);
429 }
430
431 nameParts = splitPrefix(name);
432 prefix = nameParts[0];
433 name = nameParts[1];
434
435 if (prefix) {
436 prefix = normalize(prefix, parentName, applyMap);
437 pluginModule = getOwn(defined, prefix);
438 }
439
440 //Account for relative paths if there is a base name.
441 if (name) {
442 if (prefix) {
443 if (isNormalized) {
444 normalizedName = name;
445 } else if (pluginModule && pluginModule.normalize) {
446 //Plugin is loaded, use its normalize method.
447 normalizedName = pluginModule.normalize(name, function (name) {
448 return normalize(name, parentName, applyMap);
449 });
450 } else {
451 // If nested plugin references, then do not try to
452 // normalize, as it will not normalize correctly. This
453 // places a restriction on resourceIds, and the longer
454 // term solution is not to normalize until plugins are
455 // loaded and all normalizations to allow for async
456 // loading of a loader plugin. But for now, fixes the
457 // common uses. Details in #1131
458 normalizedName = name.indexOf('!') === -1 ?
459 normalize(name, parentName, applyMap) :
460 name;
461 }
462 } else {
463 //A regular module.
464 normalizedName = normalize(name, parentName, applyMap);
465
466 //Normalized name may be a plugin ID due to map config
467 //application in normalize. The map config values must
468 //already be normalized, so do not need to redo that part.
469 nameParts = splitPrefix(normalizedName);
470 prefix = nameParts[0];
471 normalizedName = nameParts[1];
472 isNormalized = true;
473

Callers 3

newContextFunction · 0.85
callGetModuleFunction · 0.85
localRequireFunction · 0.85

Calls 3

splitPrefixFunction · 0.85
normalizeFunction · 0.85
getOwnFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…