From 32da2116237b17ef8fbbd379c1c7b7b510972105 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Thu, 10 Oct 2024 23:49:27 +0200 Subject: [PATCH] Remove string enum type mentions from JS & TS (#4175) --- CHANGELOG.md | 5 ++++- crates/cli-support/src/js/binding.rs | 2 +- crates/cli-support/src/wit/incoming.rs | 4 ++-- crates/cli-support/src/wit/outgoing.rs | 4 ++-- crates/cli-support/src/wit/standard.rs | 2 +- crates/cli/tests/reference/enums.d.ts | 10 +++++----- crates/cli/tests/reference/enums.js | 6 +++--- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0540bf5bab7..ae459e0cab8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ ### Changed -* Sting enums are no longer generate TypeScript types. +* String enums are no longer generate TypeScript types. [#4174](https://github.com/rustwasm/wasm-bindgen/pull/4174) ### Fixed @@ -21,6 +21,9 @@ * Fixed generated setters from WebIDL interface attributes binding to wrong JS method names. [#4170](https://github.com/rustwasm/wasm-bindgen/pull/4170) +* Fix string enums showing up in JS documentation and TypeScript bindings without corresponding types. + [#4175](https://github.com/rustwasm/wasm-bindgen/pull/4175) + -------------------------------------------------------------------------------- ## [0.2.94](https://github.com/rustwasm/wasm-bindgen/compare/0.2.93...0.2.94) diff --git a/crates/cli-support/src/js/binding.rs b/crates/cli-support/src/js/binding.rs index bb4864e54a8..27d58549ba6 100644 --- a/crates/cli-support/src/js/binding.rs +++ b/crates/cli-support/src/js/binding.rs @@ -1441,7 +1441,7 @@ fn adapter2ts(ty: &AdapterType, dst: &mut String) { AdapterType::NamedExternref(name) => dst.push_str(name), AdapterType::Struct(name) => dst.push_str(name), AdapterType::Enum(name) => dst.push_str(name), - AdapterType::StringEnum(name) => dst.push_str(name), + AdapterType::StringEnum => dst.push_str("any"), AdapterType::Function => dst.push_str("any"), } } diff --git a/crates/cli-support/src/wit/incoming.rs b/crates/cli-support/src/wit/incoming.rs index a1a6ee196b4..06c7160cb63 100644 --- a/crates/cli-support/src/wit/incoming.rs +++ b/crates/cli-support/src/wit/incoming.rs @@ -110,7 +110,7 @@ impl InstructionBuilder<'_, '_> { }, Descriptor::StringEnum { name, invalid, .. } => { self.instruction( - &[AdapterType::StringEnum(name.clone())], + &[AdapterType::StringEnum], Instruction::StringEnumToWasm { name: name.clone(), invalid: *invalid, @@ -312,7 +312,7 @@ impl InstructionBuilder<'_, '_> { hole, } => { self.instruction( - &[AdapterType::StringEnum(name.clone()).option()], + &[AdapterType::StringEnum.option()], Instruction::OptionStringEnumToWasm { name: name.clone(), invalid: *invalid, diff --git a/crates/cli-support/src/wit/outgoing.rs b/crates/cli-support/src/wit/outgoing.rs index 020d8b1702f..a3563551bb5 100644 --- a/crates/cli-support/src/wit/outgoing.rs +++ b/crates/cli-support/src/wit/outgoing.rs @@ -295,7 +295,7 @@ impl InstructionBuilder<'_, '_> { name: name.clone(), hole: *hole, }, - &[AdapterType::StringEnum(String::from(name)).option()], + &[AdapterType::StringEnum.option()], ); } Descriptor::RustStruct(name) => { @@ -538,7 +538,7 @@ impl InstructionBuilder<'_, '_> { Instruction::WasmToStringEnum { name: name.to_string(), }, - &[AdapterType::StringEnum(String::from(name))], + &[AdapterType::StringEnum], ); } diff --git a/crates/cli-support/src/wit/standard.rs b/crates/cli-support/src/wit/standard.rs index c96430c6411..aee0e0845e9 100644 --- a/crates/cli-support/src/wit/standard.rs +++ b/crates/cli-support/src/wit/standard.rs @@ -86,7 +86,7 @@ pub enum AdapterType { Option(Box), Struct(String), Enum(String), - StringEnum(String), + StringEnum, NamedExternref(String), Function, NonNull, diff --git a/crates/cli/tests/reference/enums.d.ts b/crates/cli/tests/reference/enums.d.ts index 412cac3fe21..86e3e28d560 100644 --- a/crates/cli/tests/reference/enums.d.ts +++ b/crates/cli/tests/reference/enums.d.ts @@ -12,14 +12,14 @@ export function enum_echo(color: Color): Color; export function option_enum_echo(color?: Color): Color | undefined; /** * @param {Color} color - * @returns {ColorName} + * @returns {any} */ -export function get_name(color: Color): ColorName; +export function get_name(color: Color): any; /** - * @param {ColorName | undefined} [color] - * @returns {ColorName | undefined} + * @param {any | undefined} [color] + * @returns {any | undefined} */ -export function option_string_enum_echo(color?: ColorName): ColorName | undefined; +export function option_string_enum_echo(color?: any): any | undefined; /** * A color. */ diff --git a/crates/cli/tests/reference/enums.js b/crates/cli/tests/reference/enums.js index 58eb0460b81..e69baa01e95 100644 --- a/crates/cli/tests/reference/enums.js +++ b/crates/cli/tests/reference/enums.js @@ -46,7 +46,7 @@ export function option_enum_echo(color) { /** * @param {Color} color - * @returns {ColorName} + * @returns {any} */ export function get_name(color) { const ret = wasm.get_name(color); @@ -54,8 +54,8 @@ export function get_name(color) { } /** - * @param {ColorName | undefined} [color] - * @returns {ColorName | undefined} + * @param {any | undefined} [color] + * @returns {any | undefined} */ export function option_string_enum_echo(color) { const ret = wasm.option_string_enum_echo(color == undefined ? 4 : ((__wbindgen_enum_ColorName.indexOf(color) + 1 || 4) - 1));