Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove string enum type mentions from JS & TS #4175

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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