MCPcopy Create free account
hub / github.com/BlaNKtext/webosu / makeModuleMap

Function makeModuleMap

js/lib/require.js:417–498  ·  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

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

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