Skip to content

Commit 407d892

Browse files
author
Guy Bedford
authored
gen-host-js: support undefined values in lowering for nullable options (#402)
* gen-host-js: support undefined values in lowering for nullable options * add a test * only explicit undefined test * tsignore
1 parent 9595240 commit 407d892

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

crates/gen-host-js/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,8 @@ impl Bindgen for FunctionBindgen<'_> {
18481848
self.src.js(&format!(
18491849
"\
18501850
switch (variant{tmp}) {{
1851-
case null: {{
1851+
case null:
1852+
case undefined: {{
18521853
{none}\
18531854
break;
18541855
}}

tests/runtime/variants/host.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ async function run() {
3636
wasm.testImports();
3737
assert.deepStrictEqual(wasm.roundtripOption(1), 1);
3838
assert.deepStrictEqual(wasm.roundtripOption(null), null);
39+
// @ts-ignore
40+
assert.deepStrictEqual(wasm.roundtripOption(undefined), null);
41+
// @ts-ignore
42+
assert.deepStrictEqual(wasm.roundtripOption(), null);
3943
assert.deepStrictEqual(wasm.roundtripOption(2), 2);
4044
assert.deepStrictEqual(wasm.roundtripResult({ tag: 'ok', val: 2 }), { tag: 'ok', val: 2 });
4145
assert.deepStrictEqual(wasm.roundtripResult({ tag: 'ok', val: 4 }), { tag: 'ok', val: 4 });

0 commit comments

Comments
 (0)