Skip to content

Commit 9605c03

Browse files
Binaryen on transform (#2832)
* Expose binaryen instance on transform * Fix invalid import in generated output
1 parent de174c5 commit 9605c03

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

cli/index.d.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,18 @@ export function createMemoryStream(fn?: (chunk: Uint8Array | string) => void): M
240240
/** Compatible TypeScript compiler options for syntax highlighting etc. */
241241
export const tscOptions: Record<string,unknown>;
242242

243-
import { Program, Parser, Module } from "../src";
243+
import binaryen from "../lib/binaryen";
244+
import { Program, Parser } from "../src";
244245

245246
/** Compiler transform base class. */
246247
export abstract class Transform {
247248

248249
/** Program reference. */
249250
readonly program: Program;
250251

252+
/** Binaryen reference. */
253+
readonly binaryen: typeof binaryen;
254+
251255
/** Base directory. */
252256
readonly baseDir: string;
253257

@@ -276,5 +280,5 @@ export abstract class Transform {
276280
afterInitialize?(program: Program): void | Promise<void>;
277281

278282
/** Called when compilation is complete, before the module is being validated. */
279-
afterCompile?(module: Module): void | Promise<void>;
283+
afterCompile?(module: binaryen.Module): void | Promise<void>;
280284
}

cli/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ export async function main(argv, options) {
450450
if (typeof transform === "function") {
451451
Object.assign(transform.prototype, {
452452
program,
453+
binaryen,
453454
baseDir,
454455
stdout,
455456
stderr,

scripts/build-dts.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,13 @@ export function generateCli() {
373373
prefix,
374374
stdout,
375375
resolveModuleImport: ({ importedModuleId, currentModuleId }) => {
376-
return currentModuleId == "cli/index" && importedModuleId == "../src"
377-
? prefix + "/src/index"
378-
: null;
376+
if (currentModuleId == "cli/index" && importedModuleId == "../src")
377+
return prefix + "/src/index";
378+
379+
if (importedModuleId == "binaryen")
380+
return "binaryen";
381+
382+
return null;
379383
},
380384
});
381385

0 commit comments

Comments
 (0)