Skip to content

Commit 61f1d96

Browse files
Use isLikeNone to detect null/undefined for string enums (#4186)
1 parent 724b447 commit 61f1d96

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

crates/cli-support/src/js/binding.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -712,12 +712,11 @@ fn instruction(
712712
} => {
713713
let enum_val = js.pop();
714714
let enum_val_expr = string_enum_to_wasm(name, *invalid, &enum_val);
715+
js.cx.expose_is_like_none();
715716

716-
// e.g. someEnumVal == undefined ? 4 : (string_enum_to_wasm(someEnumVal))
717-
// |
718-
// double equals here in case it's null
717+
// e.g. isLikeNone(someEnumVal) ? 4 : (string_enum_to_wasm(someEnumVal))
719718
js.push(format!(
720-
"{enum_val} == undefined ? {hole} : ({enum_val_expr})"
719+
"isLikeNone({enum_val}) ? {hole} : ({enum_val_expr})"
721720
))
722721
}
723722

crates/cli/tests/reference/enums.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function get_name(color) {
5858
* @returns {any | undefined}
5959
*/
6060
export function option_string_enum_echo(color) {
61-
const ret = wasm.option_string_enum_echo(color == undefined ? 4 : ((__wbindgen_enum_ColorName.indexOf(color) + 1 || 4) - 1));
61+
const ret = wasm.option_string_enum_echo(isLikeNone(color) ? 4 : ((__wbindgen_enum_ColorName.indexOf(color) + 1 || 4) - 1));
6262
return __wbindgen_enum_ColorName[ret];
6363
}
6464

0 commit comments

Comments
 (0)