Conversation
|
Sorry for the silence — this PR has had no review at all since you opened it, and that is on us, not on you. Here is a real one. Everything below was reproduced on this branch ( Summary
1–4 are design calls; 5 and 6 are one-line fixes. 1. The derive panics on a non-identifier serde tag#[derive(Tsify)]
#[tsify(discriminants)]
#[serde(tag = "a-b")]
enum Internal { A { x: i32 }, B }
This should be a 2. Enum member names are not escaped#[derive(Tsify)]
#[tsify(value_enum)]
enum Quoted {
#[serde(rename = "a\"b")]
A,
}export enum Quoted {
"a"b" = "a"b",
}
3. Non-identifier variant names break the reference site
#[derive(Tsify)]
#[tsify(discriminants, rename_variants)]
#[serde(tag = "t")]
enum Raw { r#type { x: i32 }, r#struct { y: i32 } }export enum RawT {
"r#type" = "type",
"r#struct" = "struct",
}
export type Raw = { t: RawT.r#type; x: number } | { t: RawT.r#struct; y: number };Two things are wrong here. The member id keeps the
#[tsify(discriminants)]
#[serde(tag = "t", rename_all = "kebab-case")]
enum Kebab { SomeName { x: i32 }, OtherName { y: i32 } }export type Kebab = { t: KebabT.some-name; x: number } | { t: KebabT.other-name; y: number };4. The generated enum can collide with the type's own name#[derive(Tsify)]
#[tsify(discriminants = "Collide")]
#[serde(tag = "t")]
enum Collide { A { x: i32 }, B }export enum Collide { A = "A", B = "B" }
export type Collide = { t: Collide.A; x: number } | { t: Collide.B };Two types picking the same discriminant name collide the same way, and the JS side then emits two 5. The wasm-bindgen floor has to move to 0.2.115
The middle row is the dangerous one: it builds, and the duplicate lands in the 6. clippy fails on one character
7. The affix does not reach the generated enum name#[tsify(type_prefix = "Ts", discriminants)]
#[serde(tag = "t")]
enum Affixed { A { x: i32 }, B }export enum AffixedT { A = "A", B = "B" }
export type TsAffixed = { t: AffixedT.A; x: number } | { t: AffixedT.B };Every other generated name goes through A second half to this landed after you opened the PR. 8.
|
(see #80)
Adds two different kinds of enums:
Can be generated with enums (possibly along namespaces)
Generates
A limited subset of rust enums (only unit variants, externally tagged) can be turned into value enums.
The
rename_variantsis another new keyword. It makes sure that serde only renames the discriminant, and not the type referring to it. It also works with namespaces:The idea behind the name
rename_variants, that it could be extended to pass values defining how the variant should be renamed, which is unimplemented rn, open to adjust the naming.