Skip to content

Commit c625644

Browse files
authored
Revert TS string enum generation (#4174)
1 parent bdcbc58 commit c625644

File tree

13 files changed

+8
-72
lines changed

13 files changed

+8
-72
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
* Added support for `Self` in complex type expressions in methods.
1212
[#4155](https://github.com/rustwasm/wasm-bindgen/pull/4155)
1313

14+
### Changed
15+
16+
* Sting enums are no longer generate TypeScript types.
17+
[#4174](https://github.com/rustwasm/wasm-bindgen/pull/4174)
18+
1419
### Fixed
1520

1621
* Fixed generated setters from WebIDL interface attributes binding to wrong JS method names.

crates/backend/src/ast.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,8 @@ pub struct StringEnum {
343343
pub variants: Vec<Ident>,
344344
/// The JS string values of the variants
345345
pub variant_values: Vec<String>,
346-
/// The doc comments on this enum, if any
347-
pub comments: Vec<String>,
348346
/// Attributes to apply to the Rust enum
349347
pub rust_attrs: Vec<syn::Attribute>,
350-
/// Whether to generate a typescript definition for this enum
351-
pub generate_typescript: bool,
352348
/// Path to wasm_bindgen
353349
pub wasm_bindgen: Path,
354350
}

crates/backend/src/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ impl ToTokens for ast::StringEnum {
11441144
fn to_tokens(&self, tokens: &mut TokenStream) {
11451145
let vis = &self.vis;
11461146
let enum_name = &self.name;
1147-
let name_str = self.js_name.to_string();
1147+
let name_str = &self.js_name;
11481148
let name_len = name_str.len() as u32;
11491149
let name_chars = name_str.chars().map(u32::from);
11501150
let variants = &self.variants;

crates/backend/src/encode.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,7 @@ fn shared_import_type<'a>(i: &'a ast::ImportType, intern: &'a Interner) -> Impor
362362
fn shared_import_enum<'a>(i: &'a ast::StringEnum, _intern: &'a Interner) -> StringEnum<'a> {
363363
StringEnum {
364364
name: &i.js_name,
365-
public: matches!(i.vis, syn::Visibility::Public(_)),
366-
generate_typescript: i.generate_typescript,
367365
variant_values: i.variant_values.iter().map(|x| &**x).collect(),
368-
comments: i.comments.iter().map(|s| &**s).collect(),
369366
}
370367
}
371368

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3816,32 +3816,12 @@ __wbg_set_wasm(wasm);"
38163816
}
38173817

38183818
fn generate_string_enum(&mut self, string_enum: &AuxStringEnum) -> Result<(), Error> {
3819-
let docs = format_doc_comments(&string_enum.comments, None);
3820-
38213819
let variants: Vec<_> = string_enum
38223820
.variant_values
38233821
.iter()
38243822
.map(|v| format!("\"{v}\""))
38253823
.collect();
38263824

3827-
if string_enum.generate_typescript {
3828-
self.typescript.push_str(&docs);
3829-
if string_enum.public {
3830-
self.typescript.push_str("export ");
3831-
}
3832-
self.typescript.push_str("type ");
3833-
self.typescript.push_str(&string_enum.name);
3834-
self.typescript.push_str(" = ");
3835-
3836-
if variants.is_empty() {
3837-
self.typescript.push_str("never");
3838-
} else {
3839-
self.typescript.push_str(&variants.join(" | "));
3840-
}
3841-
3842-
self.typescript.push_str(";\n");
3843-
}
3844-
38453825
self.global(&format!(
38463826
"const __wbindgen_enum_{name} = [{values}];\n",
38473827
name = string_enum.name,

crates/cli-support/src/wit/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,14 +868,11 @@ impl<'a> Context<'a> {
868868
fn string_enum(&mut self, string_enum: &decode::StringEnum<'_>) -> Result<(), Error> {
869869
let aux = AuxStringEnum {
870870
name: string_enum.name.to_string(),
871-
public: string_enum.public,
872-
comments: concatenate_comments(&string_enum.comments),
873871
variant_values: string_enum
874872
.variant_values
875873
.iter()
876874
.map(|v| v.to_string())
877875
.collect(),
878-
generate_typescript: string_enum.generate_typescript,
879876
};
880877
let mut result = Ok(());
881878
self.aux

crates/cli-support/src/wit/nonstandard.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,8 @@ pub struct AuxEnum {
179179
pub struct AuxStringEnum {
180180
/// The name of this enum
181181
pub name: String,
182-
/// Whether this enum is public
183-
pub public: bool,
184-
/// The copied Rust comments to forward to JS
185-
pub comments: String,
186182
/// A list of variants values
187183
pub variant_values: Vec<String>,
188-
/// Whether typescript bindings should be generated for this enum.
189-
pub generate_typescript: bool,
190184
}
191185

192186
#[derive(Debug)]

crates/cli/tests/reference/enums.d.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,3 @@ export enum ImplicitDiscriminant {
4343
C = 42,
4444
D = 43,
4545
}
46-
/**
47-
* The name of a color.
48-
*/
49-
export type ColorName = "green" | "yellow" | "red";
50-
/**
51-
* An unused string enum.
52-
*/
53-
export type FooBar = "foo" | "bar";
54-
type PrivateStringEnum = "foo" | "bar";

crates/cli/tests/reference/enums.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ export const ImplicitDiscriminant = Object.freeze({ A:0,"0":"A",B:1,"1":"B",C:42
8383

8484
const __wbindgen_enum_ColorName = ["green", "yellow", "red"];
8585

86-
const __wbindgen_enum_FooBar = ["foo", "bar"];
87-
88-
const __wbindgen_enum_PrivateStringEnum = ["foo", "bar"];
89-
9086
export function __wbindgen_throw(arg0, arg1) {
9187
throw new Error(getStringFromWasm0(arg0, arg1));
9288
};

crates/cli/tests/reference/enums.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,6 @@ pub fn option_string_enum_echo(color: Option<ColorName>) -> Option<ColorName> {
4545
color
4646
}
4747

48-
/// An unused string enum.
49-
#[wasm_bindgen(js_name = "FooBar")]
50-
pub enum UnusedStringEnum {
51-
Foo = "foo",
52-
Bar = "bar",
53-
}
54-
55-
#[wasm_bindgen]
56-
enum PrivateStringEnum {
57-
Foo = "foo",
58-
Bar = "bar",
59-
}
60-
6148
#[wasm_bindgen]
6249
pub enum ImplicitDiscriminant {
6350
A,

crates/macro-support/src/parser.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,8 +1321,6 @@ fn string_enum(
13211321
enum_: syn::ItemEnum,
13221322
program: &mut ast::Program,
13231323
js_name: String,
1324-
generate_typescript: bool,
1325-
comments: Vec<String>,
13261324
) -> Result<(), Diagnostic> {
13271325
let mut variants = vec![];
13281326
let mut variant_values = vec![];
@@ -1358,9 +1356,7 @@ fn string_enum(
13581356
js_name,
13591357
variants,
13601358
variant_values,
1361-
comments,
13621359
rust_attrs: enum_.attrs,
1363-
generate_typescript,
13641360
wasm_bindgen: program.wasm_bindgen.clone(),
13651361
}),
13661362
});
@@ -1410,7 +1406,7 @@ impl<'a> MacroParse<(&'a mut TokenStream, BindgenAttrs)> for syn::ItemEnum {
14101406
false
14111407
});
14121408
if is_string_enum {
1413-
return string_enum(self, program, js_name, generate_typescript, comments);
1409+
return string_enum(self, program, js_name);
14141410
}
14151411

14161412
match self.vis {

crates/shared/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ macro_rules! shared_api {
106106

107107
struct StringEnum<'a> {
108108
name: &'a str,
109-
public: bool,
110109
variant_values: Vec<&'a str>,
111-
comments: Vec<&'a str>,
112-
generate_typescript: bool,
113110
}
114111

115112
struct Export<'a> {

crates/shared/src/schema_hash_approval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// If the schema in this library has changed then:
99
// 1. Bump the version in `crates/shared/Cargo.toml`
1010
// 2. Change the `SCHEMA_VERSION` in this library to this new Cargo.toml version
11-
const APPROVED_SCHEMA_FILE_HASH: &str = "950257602071279980";
11+
const APPROVED_SCHEMA_FILE_HASH: &str = "2837603620805312754";
1212

1313
#[test]
1414
fn schema_version() {

0 commit comments

Comments
 (0)