MCPcopy
hub / github.com/webpack/webpack / getMode

Function getMode

lib/dependencies/HarmonyExportImportedSpecifierDependency.js:309–469  ·  view source on GitHub ↗
(moduleGraph, dep, runtimeKey)

Source from the content-addressed store, hash-verified

307 * @returns {ExportMode} the export mode
308 */
309const getMode = (moduleGraph, dep, runtimeKey) => {
310 const importedModule = moduleGraph.getModule(dep);
311
312 if (!importedModule) {
313 const mode = new ExportMode("missing");
314
315 mode.userRequest = dep.userRequest;
316
317 return mode;
318 }
319
320 const name = dep.name;
321 const runtime = keyToRuntime(runtimeKey);
322 const parentModule = /** @type {Module} */ (moduleGraph.getParentModule(dep));
323 const exportsInfo = moduleGraph.getExportsInfo(parentModule);
324
325 if (
326 name
327 ? exportsInfo.getUsed(name, runtime) === UsageState.Unused
328 : exportsInfo.isUsed(runtime) === false
329 ) {
330 const mode = new ExportMode("unused");
331
332 mode.name = name || "*";
333
334 return mode;
335 }
336
337 const importedExportsType = importedModule.getExportsType(
338 moduleGraph,
339 /** @type {BuildMeta} */
340 (parentModule.buildMeta).strictHarmonyModule
341 );
342
343 const ids = dep.getIds(moduleGraph);
344
345 // Special handling for reexporting the default export
346 // from non-namespace modules
347 if (name && ids.length > 0 && ids[0] === "default") {
348 switch (importedExportsType) {
349 case "dynamic": {
350 const mode = new ExportMode("reexport-dynamic-default");
351
352 mode.name = name;
353
354 return mode;
355 }
356 case "default-only":
357 case "default-with-named": {
358 const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
359 const mode = new ExportMode("reexport-named-default");
360
361 mode.name = name;
362 mode.partialNamespaceExportInfo = exportInfo;
363
364 return mode;
365 }
366 }

Callers

nothing calls this directly

Calls 12

keyToRuntimeFunction · 0.85
getParentModuleMethod · 0.80
getExportsInfoMethod · 0.80
isUsedMethod · 0.80
getModuleMethod · 0.45
getUsedMethod · 0.45
getExportsTypeMethod · 0.45
getIdsMethod · 0.45
getReadOnlyExportInfoMethod · 0.45
getStarReexportsMethod · 0.45
hasMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected