Skip to content

Commit 68c793a

Browse files
feat(jco): add --strict option for enabling bindgen type checks
1 parent 075e700 commit 68c793a

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

packages/jco/src/cmd/transpile.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function guestTypes(witPath: any, opts: any): Promise<void>;
1717
* outDir?: string,
1818
* features?: string[] | 'all',
1919
* guest?: bool,
20+
* strict?: bool,
2021
* }} opts
2122
* @returns {Promise<{ [filename: string]: Uint8Array }>}
2223
*/
@@ -33,6 +34,7 @@ export function typesComponent(
3334
outDir?: string;
3435
features?: string[] | "all";
3536
guest?: boolean;
37+
strict?: boolean;
3638
},
3739
): Promise<{
3840
[filename: string]: Uint8Array;

packages/jco/src/cmd/transpile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,8 @@ export async function transpileComponent(component, opts = {}) {
153153
// Let's define `instantiation` from `--instantiation` if it's present.
154154
if (opts.instantiation) {
155155
instantiation = { tag: opts.instantiation };
156-
}
157-
// Otherwise, if `--js` is present, an `instantiate` function is required.
158-
else if (opts.js) {
156+
} else if (opts.js) {
157+
// Otherwise, if `--js` is present, an `instantiate` function is required.
159158
instantiation = { tag: "async" };
160159
}
161160

@@ -200,6 +199,7 @@ export async function transpileComponent(component, opts = {}) {
200199
noNamespacedExports: opts.namespacedExports === false,
201200
multiMemory: opts.multiMemory === true,
202201
idlImports: opts.experimentalIdlImports === true,
202+
strict: opts.strict === true,
203203
});
204204

205205
let outDir = (opts.outDir ?? "").replace(/\\/g, "/");

packages/jco/src/cmd/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function guestTypes(witPath: any, opts: any): Promise<void>;
1313
* outDir?: string,
1414
* features?: string[] | 'all',
1515
* guest?: bool,
16+
* strict?: bool,
1617
* }} opts
1718
* @returns {Promise<{ [filename: string]: Uint8Array }>}
1819
*/
@@ -29,6 +30,7 @@ export function typesComponent(
2930
outDir?: string;
3031
features?: string[] | "all";
3132
guest?: boolean;
33+
strict?: boolean;
3234
},
3335
): Promise<{
3436
[filename: string]: Uint8Array;

packages/jco/src/cmd/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export async function typesComponent(witPath, opts) {
140140
world: opts.worldName,
141141
features,
142142
guest: opts.guest ?? false,
143+
strict: opts.strict === true,
143144
asyncMode: asyncModeObj,
144145
}).map(([name, file]) => [`${outDir}${name}`, file]);
145146
} catch (err) {

packages/jco/src/jco.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ program
128128
.option("-q, --quiet", "disable output summary")
129129
.option("--no-namespaced-exports", "disable namespaced exports for typescript compatibility")
130130
.option("--multi-memory", "optimized output for Wasm multi-memory")
131+
.option("--strict", "generate bindings with strict type checking")
131132
.allowExcessArguments(true)
132133
.action(asyncAction(transpile));
133134

@@ -164,6 +165,7 @@ program
164165
.option("--feature <feature>", "enable one specific WIT feature (repeatable)", collectOptions, [])
165166
.option("--all-features", "enable all features")
166167
.option("--wasm-opt-bin <path-to-wasm-opt>', 'wasm-opt binary path (default: 'binaryen/bin/wasm-opt')")
168+
.option("--strict", "generate bindings with strict type checking")
167169
.action(asyncAction(types));
168170

169171
program
@@ -186,6 +188,7 @@ program
186188
.choices(["sync", "jspi"])
187189
.preset("sync"),
188190
)
191+
.option("--strict", "generate bindings with strict type checking")
189192
.action(asyncAction(guestTypes));
190193

191194
program

0 commit comments

Comments
 (0)