Skip to content

Commit

Permalink
Remove string enum type mentions from JS & TS (#4175)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Oct 10, 2024
1 parent c625644 commit 32da211
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@

### 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

* 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)
Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/js/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
4 changes: 2 additions & 2 deletions crates/cli-support/src/wit/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -312,7 +312,7 @@ impl InstructionBuilder<'_, '_> {
hole,
} => {
self.instruction(
&[AdapterType::StringEnum(name.clone()).option()],
&[AdapterType::StringEnum.option()],
Instruction::OptionStringEnumToWasm {
name: name.clone(),
invalid: *invalid,
Expand Down
4 changes: 2 additions & 2 deletions crates/cli-support/src/wit/outgoing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl InstructionBuilder<'_, '_> {
name: name.clone(),
hole: *hole,
},
&[AdapterType::StringEnum(String::from(name)).option()],
&[AdapterType::StringEnum.option()],
);
}
Descriptor::RustStruct(name) => {
Expand Down Expand Up @@ -538,7 +538,7 @@ impl InstructionBuilder<'_, '_> {
Instruction::WasmToStringEnum {
name: name.to_string(),
},
&[AdapterType::StringEnum(String::from(name))],
&[AdapterType::StringEnum],
);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/wit/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub enum AdapterType {
Option(Box<AdapterType>),
Struct(String),
Enum(String),
StringEnum(String),
StringEnum,
NamedExternref(String),
Function,
NonNull,
Expand Down
10 changes: 5 additions & 5 deletions crates/cli/tests/reference/enums.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/tests/reference/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ export function option_enum_echo(color) {

/**
* @param {Color} color
* @returns {ColorName}
* @returns {any}
*/
export function get_name(color) {
const ret = wasm.get_name(color);
return __wbindgen_enum_ColorName[ret];
}

/**
* @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));
Expand Down

0 comments on commit 32da211

Please sign in to comment.