From f783e9537f35cd1cecfd86e07cc24b124896bd76 Mon Sep 17 00:00:00 2001 From: antoniomuso Date: Sun, 6 Mar 2022 12:27:25 +0100 Subject: [PATCH] feat(napi): allow empty enums --- crates/macro/src/parser/mod.rs | 3 --- examples/napi/__test__/typegen.spec.ts.md | 3 +++ examples/napi/__test__/typegen.spec.ts.snap | Bin 2841 -> 2851 bytes examples/napi/index.d.ts | 3 +++ examples/napi/src/enum.rs | 3 +++ 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/macro/src/parser/mod.rs b/crates/macro/src/parser/mod.rs index cae6fd52..97c180f4 100644 --- a/crates/macro/src/parser/mod.rs +++ b/crates/macro/src/parser/mod.rs @@ -884,9 +884,6 @@ impl ConvertToAST for syn::ItemEnum { Visibility::Public(_) => {} _ => bail_span!(self, "only public enum allowed"), } - if self.variants.is_empty() { - bail_span!(self, "cannot export empty enum to JS"); - } self.attrs.push(Attribute { pound_token: Default::default(), diff --git a/examples/napi/__test__/typegen.spec.ts.md b/examples/napi/__test__/typegen.spec.ts.md index 922e7ee0..abc7f874 100644 --- a/examples/napi/__test__/typegen.spec.ts.md +++ b/examples/napi/__test__/typegen.spec.ts.md @@ -65,6 +65,9 @@ Generated by [AVA](https://avajs.dev). /** Tasty */␊ Duck = 2␊ }␊ + export const enum Empty {␊ + ␊ + }␊ /** You could break the step and for an new continuous value. */␊ export const enum CustomNumEnum {␊ One = 1,␊ diff --git a/examples/napi/__test__/typegen.spec.ts.snap b/examples/napi/__test__/typegen.spec.ts.snap index d1341ed1309a1b13d53cb27c92fe7ee86f8fe4f0..993f8591bcb89e94e96ecd2d0f9aad44505ebb8a 100644 GIT binary patch literal 2851 zcmV+;3*7WURzV{h<8U$3)AHE6x@YSEb z!hgT}<5yq*{_LA44~dc?k5wn&k`6;g9zI!vO{O;=Ih(jkGbJ8bo&gz7Nxyr%|LEjY z1F)M!q>A_UA#oNBS!y9h zS?nt=Vz8h3UZjEaS{>3&Q#ySiRm$V>E6w5!Q<6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