MCPcopy
hub / github.com/webpack/webpack / generate

Method generate

lib/wasm-sync/WebAssemblyGenerator.js:462–536  ·  view source on GitHub ↗

* Generates generated code for this runtime module. * @param {NormalModule} module module for which the code should be generated * @param {GenerateContext} generateContext context for generate * @returns {Source | null} generated code

(module, { moduleGraph, runtime })

Source from the content-addressed store, hash-verified

460 * @returns {Source | null} generated code
461 */
462 generate(module, { moduleGraph, runtime }) {
463 const bin =
464 /** @type {Buffer} */
465 (/** @type {Source} */ (module.originalSource()).source());
466
467 const initFuncId = t.identifier("");
468
469 // parse it
470 const ast = decode(bin, {
471 ignoreDataSection: true,
472 ignoreCodeSection: true,
473 ignoreCustomNameSection: true
474 });
475
476 const moduleContext = moduleContextFromModuleAST(ast.body[0]);
477
478 const importedGlobals = getImportedGlobals(ast);
479 const countImportedFunc = getCountImportedFunc(ast);
480 const startAtFuncOffset = moduleContext.getStart();
481 const nextFuncIndex = getNextFuncIndex(ast, countImportedFunc);
482 const nextTypeIndex = getNextTypeIndex(ast);
483
484 const usedDependencyMap = getUsedDependencyMap(
485 moduleGraph,
486 module,
487 this.options.mangleImports
488 );
489 const externalExports = new Set(
490 module.dependencies
491 .filter((d) => d instanceof WebAssemblyExportImportedDependency)
492 .map((d) => {
493 const wasmDep = /** @type {WebAssemblyExportImportedDependency} */ (
494 d
495 );
496 return wasmDep.exportName;
497 })
498 );
499
500 /** @type {t.Instruction[]} */
501 const additionalInitCode = [];
502
503 const transform = compose(
504 rewriteExportNames({
505 ast,
506 moduleGraph,
507 module,
508 externalExports,
509 runtime
510 }),
511
512 removeStartFunc({ ast }),
513
514 rewriteImportedGlobals({ ast, additionalInitCode }),
515
516 rewriteImports({
517 ast,
518 usedDependencyMap
519 }),

Callers

nothing calls this directly

Calls 15

decodeFunction · 0.85
getImportedGlobalsFunction · 0.85
getCountImportedFuncFunction · 0.85
getNextFuncIndexFunction · 0.85
getNextTypeIndexFunction · 0.85
getUsedDependencyMapFunction · 0.85
composeFunction · 0.85
rewriteExportNamesFunction · 0.85
removeStartFuncFunction · 0.85
rewriteImportedGlobalsFunction · 0.85
rewriteImportsFunction · 0.85
addInitFunctionFunction · 0.85

Tested by

no test coverage detected