MCPcopy Create free account
hub / github.com/PrairieLearn/PrairieLearn / makeModuleMap

Function makeModuleMap

public/javascripts/require.js:414–493  ·  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

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

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