MCPcopy
hub / github.com/vitejs/vite / parseWasm

Function parseWasm

packages/vite/src/node/plugins/wasm.ts:190–215  ·  view source on GitHub ↗
(wasmFilePath: string)

Source from the content-addressed store, hash-verified

188}
189
190async function parseWasm(wasmFilePath: string): Promise<WasmInfo> {
191 try {
192 const wasmBinary = await fsp.readFile(wasmFilePath)
193 const wasmModule = await WebAssembly.compile(wasmBinary)
194 const importMap: Record<string, string[]> = Object.create(null)
195 for (const item of WebAssembly.Module.imports(wasmModule)) {
196 importMap[item.module] ??= []
197 importMap[item.module].push(item.name)
198 }
199 const imports = Object.entries(importMap).map(([from, names]) => ({
200 from,
201 names,
202 }))
203
204 const exports = WebAssembly.Module.exports(wasmModule).map(
205 (item) => item.name,
206 )
207
208 return { imports, exports }
209 } catch (e) {
210 throw new Error(
211 `Failed to parse WASM file "${wasmFilePath}": ${(e as Error).message}`,
212 { cause: e },
213 )
214 }
215}
216
217function generateGlueCode(
218 wasmInfo: WasmInfo,

Callers 1

handlerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected