* 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 })
| 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 | }), |
nothing calls this directly
no test coverage detected