diff --git a/crates/oxc_ast/src/generated/derive_estree.rs b/crates/oxc_ast/src/generated/derive_estree.rs index 483082a81ecd5c..e346a8fc868bc8 100644 --- a/crates/oxc_ast/src/generated/derive_estree.rs +++ b/crates/oxc_ast/src/generated/derive_estree.rs @@ -1650,7 +1650,10 @@ impl Serialize for ImportDeclaration<'_> { let mut map = serializer.serialize_map(None)?; map.serialize_entry("type", "ImportDeclaration")?; self.span.serialize(serde::__private::ser::FlatMapSerializer(&mut map))?; - map.serialize_entry("specifiers", &crate::serialize::OptionVecDefault(&self.specifiers))?; + map.serialize_entry( + "specifiers", + &crate::serialize::OptionVecDefault::from(&self.specifiers), + )?; map.serialize_entry("source", &self.source)?; map.serialize_entry("phase", &self.phase)?; map.serialize_entry("withClause", &self.with_clause)?; diff --git a/crates/oxc_ast/src/serialize.rs b/crates/oxc_ast/src/serialize.rs index 120e0b6ad0ef85..f45fd9b2038646 100644 --- a/crates/oxc_ast/src/serialize.rs +++ b/crates/oxc_ast/src/serialize.rs @@ -6,7 +6,7 @@ use serde::{ Serialize, }; -use oxc_allocator::Box; +use oxc_allocator::{Box as ArenaBox, Vec as ArenaVec}; use oxc_span::{Atom, Span}; use oxc_syntax::number::BigintBase; @@ -211,7 +211,7 @@ struct SerFormalParameterRest<'a, 'b> { #[serde(flatten)] span: Span, argument: &'b BindingPatternKind<'a>, - type_annotation: &'b Option>>, + type_annotation: &'b Option>>, optional: bool, } @@ -241,7 +241,13 @@ impl Serialize for ElementsAndRest<'_, E, R> { } } -pub struct OptionVecDefault<'a, 'b, T: Serialize>(pub &'a Option>); +pub struct OptionVecDefault<'a, 'b, T: Serialize>(pub &'b Option>); + +impl<'a, 'b, T: Serialize> From<&'b Option>> for OptionVecDefault<'a, 'b, T> { + fn from(opt_vec: &'b Option>) -> Self { + Self(opt_vec) + } +} impl Serialize for OptionVecDefault<'_, '_, T> { fn serialize(&self, serializer: S) -> Result { diff --git a/tasks/ast_tools/src/derives/estree.rs b/tasks/ast_tools/src/derives/estree.rs index ce163b93fdb0bb..9d06af6d237432 100644 --- a/tasks/ast_tools/src/derives/estree.rs +++ b/tasks/ast_tools/src/derives/estree.rs @@ -218,7 +218,7 @@ fn generate_stmt_for_struct_field( let mut value = quote!( &self.#field_name_ident ); if let Some(via_str) = field.estree.via.as_deref() { let via_ty = parse_str::(via_str).unwrap(); - value = quote!( &#via_ty(#value) ); + value = quote!( &#via_ty::from(#value) ); } else if let Some(append_field_index) = field.estree.append_field_index { let append_from_ident = struct_def.fields[append_field_index].ident(); value = quote! {