From 1db307abbfde1d503017053dc9d7d4df031ce0e3 Mon Sep 17 00:00:00 2001 From: Boshen Date: Tue, 5 Mar 2024 13:48:43 +0800 Subject: [PATCH] feat(ast): serialize `BindingPattern` to estree (#2610) --- crates/oxc_ast/src/ast/js.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 89500f597..3a1e4acf6 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -1595,9 +1595,15 @@ pub struct DebuggerStatement { /// Destructuring Binding Patterns /// * #[derive(Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))] +#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))] #[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] pub struct BindingPattern<'a> { + // Flatten the attributes because estree has no `BindingPattern` + #[cfg_attr(feature = "serde", serde(flatten))] + #[cfg_attr( + all(feature = "serde", feature = "wasm"), + tsify(type = "(BindingIdentifier | ObjectPattern | ArrayPattern | AssignmentPattern)") + )] pub kind: BindingPatternKind<'a>, pub type_annotation: Option>>, pub optional: bool, @@ -1611,7 +1617,6 @@ impl<'a> BindingPattern<'a> { #[derive(Debug, Hash)] #[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))] -#[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] pub enum BindingPatternKind<'a> { /// `const a = 1` BindingIdentifier(Box<'a, BindingIdentifier<'a>>),