@@ -3,7 +3,8 @@ import { createServer } from "node:http";
33import { resolve , join } from "node:path" ;
44import { fileURLToPath , pathToFileURL } from "node:url" ;
55
6- import { componentNew , componentEmbed , transpile , preview1AdapterCommandPath } from "@bytecodealliance/jco" ;
6+ import { componentNew , componentEmbed , preview1AdapterCommandPath } from "@bytecodealliance/jco" ;
7+ import { transpile } from "../src/api.js" ;
78import { HTTPServer } from "@bytecodealliance/preview2-shim/http" ;
89
910import { suite , test , assert , describe } from "vitest" ;
@@ -228,3 +229,29 @@ suite("codegen determinism", () => {
228229 assert . deepEqual ( streamRx [ 0 ] . files , streamRx [ 1 ] . files ) ;
229230 } ) ;
230231} ) ;
232+
233+ // see: https://github.com/bytecodealliance/jco/issues/1400
234+ suite ( "--strict" , ( ) => {
235+ test ( "does not add checks when disabled" , async ( ) => {
236+ const component = await readFile ( join ( COMPONENT_FIXTURES_DIR , "adder.component.wasm" ) ) ;
237+ const { files } = await transpile ( component , { name : "adder" } ) ;
238+ const bindingsSource = new TextDecoder ( ) . decode ( files [ "adder.js" ] ) ;
239+ assert . isFalse (
240+ bindingsSource . includes ( "_requireValidNumericPrimitive('u32', val)" ) ,
241+ "numeric primitive check shoudl not be included" ,
242+ ) ;
243+ } ) ;
244+
245+ test ( "adds checks when enabled" , async ( ) => {
246+ const component = await readFile ( join ( COMPONENT_FIXTURES_DIR , "adder.component.wasm" ) ) ;
247+ const { files } = await transpile ( component , { name : "adder" , strict : true } ) ;
248+ const bindingsSource = new TextDecoder ( ) . decode ( files [ "adder.js" ] ) ;
249+ // Somewhat brittle, but we're looking for a *specific* call in the body of `toUint32(val)` below:
250+ assert . isOk (
251+ bindingsSource . includes (
252+ "_requireValidNumericPrimitive('u32', val)" ,
253+ "numeric primitive check should be included" ,
254+ ) ,
255+ ) ;
256+ } ) ;
257+ } ) ;
0 commit comments