Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/manage/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -38,6 +40,8 @@ export class CompilerFactory {
case 'wast' :
case 'wat' :
return this.wat;
case 'wasm' :
return this.wasm;
case 'ts' :
return this.asc;
}
Expand Down Expand Up @@ -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<CompileOutput> {
return Promise.resolve({file: program});
}
}

export class AsScriptCompiler extends Compiler {
private readonly wabt: string;

Expand Down
5 changes: 5 additions & 0 deletions src/sourcemap/SourceMapFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading