From 808af545e33f0140dd82849b4234a1614a57a09c Mon Sep 17 00:00:00 2001 From: Tom Lauwaerts Date: Thu, 13 Aug 2026 14:45:10 +0200 Subject: [PATCH] Support prebuild wasm --- src/manage/Compiler.ts | 11 +++++++++++ src/sourcemap/SourceMapFactory.ts | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/manage/Compiler.ts b/src/manage/Compiler.ts index 7a0282d..fd92b49 100644 --- a/src/manage/Compiler.ts +++ b/src/manage/Compiler.ts @@ -25,10 +25,12 @@ export interface CompileOutput { export class CompilerFactory { private readonly wat: WatCompiler; + private readonly wasm: WasmCompiler; private readonly asc: AsScriptCompiler; constructor(wabt: string) { this.wat = new WatCompiler(wabt); + this.wasm = new WasmCompiler(wabt); this.asc = new AsScriptCompiler(wabt); } @@ -38,6 +40,8 @@ export class CompilerFactory { case 'wast' : case 'wat' : return this.wat; + case 'wasm' : + return this.wasm; case 'ts' : return this.asc; } @@ -150,6 +154,13 @@ export class WatCompiler extends Compiler { } } +/** A precompiled WebAssembly module can be uploaded without recompilation. */ +export class WasmCompiler extends WatCompiler { + public compile(program: string, _dir?: string): Promise { + return Promise.resolve({file: program}); + } +} + export class AsScriptCompiler extends Compiler { private readonly wabt: string; diff --git a/src/sourcemap/SourceMapFactory.ts b/src/sourcemap/SourceMapFactory.ts index 67efb64..b48fb18 100644 --- a/src/sourcemap/SourceMapFactory.ts +++ b/src/sourcemap/SourceMapFactory.ts @@ -20,6 +20,11 @@ export class SourceMapFactory { case 'wat' : compiled = await this.compilerFactory.pickCompiler(source).compile(source); return new WatMapper(compiled.out ?? '', tmpdir ?? path.dirname(compiled.file), WABT).mapping(); + case 'wasm' : + // Precompiled modules do not carry a WAT source mapping. The + // module can still be executed; requests that need source + // locations simply have no mapping to resolve against. + return new SourceMap.Mapping(); case 'ts' : return new AsScriptMapper(source ?? '', tmpdir ?? path.dirname(source)).mapping(); }