MCPcopy
hub / github.com/webpack/webpack / codeGeneration

Method codeGeneration

lib/optimize/ConcatenatedModule.js:1400–2377  ·  view source on GitHub ↗

* Generates code and runtime requirements for this module. * @param {CodeGenerationContext} context context for code generation * @returns {CodeGenerationResult} result

({
		dependencyTemplates,
		runtimeTemplate,
		moduleGraph,
		chunkGraph,
		runtime: generationRuntime,
		runtimes,
		codeGenerationResults
	})

Source from the content-addressed store, hash-verified

1398 * @returns {CodeGenerationResult} result
1399 */
1400 codeGeneration({
1401 dependencyTemplates,
1402 runtimeTemplate,
1403 moduleGraph,
1404 chunkGraph,
1405 runtime: generationRuntime,
1406 runtimes,
1407 codeGenerationResults
1408 }) {
1409 const { concatenatedModuleInfo } = ConcatenatedModule.getCompilationHooks(
1410 this.compilation
1411 );
1412
1413 /** @type {RuntimeRequirements} */
1414 const runtimeRequirements = new Set();
1415 const runtime = intersectRuntime(generationRuntime, this._runtime);
1416
1417 const requestShortener = runtimeTemplate.requestShortener;
1418 // Meta info for each module
1419 const [modulesWithInfo, moduleToInfoMap] = this._getModulesWithInfo(
1420 moduleGraph,
1421 runtime
1422 );
1423
1424 // Set with modules that need a generated namespace object
1425 /** @type {NeededNamespaceObjects} */
1426 const neededNamespaceObjects = new Set();
1427
1428 // Set with modules whose mangled namespace escapes as a whole value and
1429 // therefore needs a decoupled namespace object keyed by the original names
1430 /** @type {Set<ConcatenatedModuleInfo | ExternalModuleInfo>} */
1431 const neededEscapeNamespaceObjects = new Set();
1432
1433 // List of all used names to avoid conflicts
1434 const allUsedNames = new Set(RESERVED_NAMES);
1435
1436 // Generate source code and analyse scopes
1437 // Prepare a ReplaceSource for the final source
1438 for (const info of moduleToInfoMap.values()) {
1439 this._analyseModule(
1440 moduleToInfoMap,
1441 info,
1442 dependencyTemplates,
1443 runtimeTemplate,
1444 moduleGraph,
1445 chunkGraph,
1446 runtime,
1447 runtimes,
1448 /** @type {CodeGenerationResults} */
1449 (codeGenerationResults),
1450 allUsedNames
1451 );
1452 }
1453
1454 // Updated Top level declarations are created by renaming
1455 /** @type {TopLevelDeclarations} */
1456 const topLevelDeclarations = new Set();
1457

Callers 1

_analyseModuleMethod · 0.45

Calls 15

_getModulesWithInfoMethod · 0.95
_analyseModuleMethod · 0.95
intersectRuntimeFunction · 0.85
getFinalBindingFunction · 0.85
getUsedNamesInScopeInfoFunction · 0.85
addScopeSymbolsFunction · 0.85
getAllReferencesFunction · 0.85
getPathInAstFunction · 0.85
findNewNameFunction · 0.85
getFinalNameFunction · 0.85
propertyNameFunction · 0.85
valueFunction · 0.85

Tested by

no test coverage detected