Skip to content

Commit

Permalink
fixes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinrp committed Jan 31, 2025
1 parent bd4ef5b commit c4e6440
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
15 changes: 6 additions & 9 deletions crates/js-component-bindgen/src/transpile_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,6 @@ impl JsBindgen<'_> {
}
}

// adds a default implementation of `getCoreModule`
if matches!(self.opts.instantiation, Some(InstantiationMode::Async)) {
uwriteln!(
compilation_promises,
"if (!getCoreModule) getCoreModule = (name) => {}(new URL(`./${{name}}`, import.meta.url));",
self.intrinsic(Intrinsic::FetchCompile)
);
}

// Setup the compilation data and compilation promises
let mut removed = BTreeSet::new();
for i in 0..self.core_module_cnt {
Expand Down Expand Up @@ -318,6 +309,12 @@ impl JsBindgen<'_> {
self.opts.instantiation.is_some(),
);

uwriteln!(
js_intrinsics,
"if (!getCoreModule) getCoreModule = (name) => {}(new URL(`./${{name}}`, import.meta.url));",
self.intrinsic(Intrinsic::FetchCompile)
);

if let Some(instantiation) = &self.opts.instantiation {
uwrite!(
output,
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export async function typesComponent (witPath, opts) {
features = { tag: 'list', val: opts.feature };
}

if (opts.defaultAsyncImports)
if (opts.asyncWasiImports)
opts.asyncImports = DEFAULT_ASYNC_IMPORTS.concat(opts.asyncImports || []);
if (opts.defaultAsyncExports)
if (opts.asyncWasiExports)
opts.asyncExports = DEFAULT_ASYNC_EXPORTS.concat(opts.asyncExports || []);

const asyncMode = !opts.asyncMode || opts.asyncMode === 'sync' ?
Expand Down Expand Up @@ -141,9 +141,9 @@ export async function transpile (componentPath, opts, program) {
if (opts.map)
opts.map = Object.fromEntries(opts.map.map(mapping => mapping.split('=')));

if (opts.defaultAsyncImports)
if (opts.asyncWasiImports)
opts.asyncImports = DEFAULT_ASYNC_IMPORTS.concat(opts.asyncImports || []);
if (opts.defaultAsyncExports)
if (opts.asyncWasiExports)
opts.asyncExports = DEFAULT_ASYNC_EXPORTS.concat(opts.asyncExports || []);

const { files } = await transpileComponent(component, opts);
Expand Down
8 changes: 4 additions & 4 deletions src/jco.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ program.command('transpile')
.option('--valid-lifting-optimization', 'optimize component binary validations assuming all lifted values are valid')
.addOption(new Option('--import-bindings [mode]', 'bindings mode for imports').choices(['js', 'optimized', 'hybrid', 'direct-optimized']).preset('js'))
.addOption(new Option('--async-mode [mode]', 'EXPERIMENTAL: use async imports and exports').choices(['sync', 'jspi']).preset('sync'))
.option('--default-async-imports', 'EXPERIMENTAL: default async component imports from WASI interfaces')
.option('--default-async-exports', 'EXPERIMENTAL: default async component exports from WASI interfaces')
.option('--async-wasi-imports', 'EXPERIMENTAL: async component imports from WASI interfaces')
.option('--async-wasi-exports', 'EXPERIMENTAL: async component exports from WASI interfaces')
.option('--async-imports <imports...>', 'EXPERIMENTAL: async component imports (examples: "wasi:io/[email protected]#poll", "wasi:io/poll#[method]pollable.block")')
.option('--async-exports <exports...>', 'EXPERIMENTAL: async component exports (examples: "wasi:cli/run@#run", "handle")')
.option('--tracing', 'emit `tracing` calls on function entry/exit')
Expand Down Expand Up @@ -82,8 +82,8 @@ program.command('types')
.option('--tla-compat', 'generates types for the TLA compat output with an async $init promise export')
.addOption(new Option('-I, --instantiation [mode]', 'type output for custom module instantiation').choices(['async', 'sync']).preset('async'))
.addOption(new Option('--async-mode [mode]', 'EXPERIMENTAL: use async imports and exports').choices(['sync', 'jspi']).preset('sync'))
.option('--default-async-imports', 'EXPERIMENTAL: default async component imports from WASI interfaces')
.option('--default-async-exports', 'EXPERIMENTAL: default async component exports from WASI interfaces')
.option('--async-wasi-imports', 'EXPERIMENTAL: async component imports from WASI interfaces')
.option('--async-wasi-exports', 'EXPERIMENTAL: async component exports from WASI interfaces')
.option('--async-imports <imports...>', 'EXPERIMENTAL: async component imports (examples: "wasi:io/[email protected]#poll", "wasi:io/poll#[method]pollable.block")')
.option('--async-exports <exports...>', 'EXPERIMENTAL: async component exports (examples: "wasi:cli/run@#run", "handle")')
.option('-q, --quiet', 'disable output summary')
Expand Down

0 comments on commit c4e6440

Please sign in to comment.