mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(ast): align #[estree(via)] behavior (#8599)
Follow-on after #8564. Aligned the behavior of `#[estree(via)]` for fields with `#[estree(via)]` for structs.
This commit is contained in:
parent
4ff6e85137
commit
997859c42e
3 changed files with 5 additions and 6 deletions
|
|
@ -2196,7 +2196,7 @@ pub struct ImportExpression<'a> {
|
|||
pub struct ImportDeclaration<'a> {
|
||||
pub span: Span,
|
||||
/// `None` for `import 'foo'`, `Some([])` for `import {} from 'foo'`
|
||||
#[estree(via = "OptionVecDefault", type = "Array<ImportDeclarationSpecifier>")]
|
||||
#[estree(via = crate::serialize::OptionVecDefault, type = "Array<ImportDeclarationSpecifier>")]
|
||||
pub specifiers: Option<Vec<'a, ImportDeclarationSpecifier<'a>>>,
|
||||
pub source: StringLiteral<'a>,
|
||||
pub phase: Option<ImportPhase>,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ use crate::{
|
|||
serialize::{enum_variant_name, get_always_flatten_structs, get_type_tag},
|
||||
EnumDef, FieldDef, GetGenerics, GetIdent, Schema, StructDef, TypeDef,
|
||||
},
|
||||
util::ToIdent,
|
||||
};
|
||||
|
||||
use super::{define_derive, Derive};
|
||||
|
|
@ -142,12 +141,12 @@ fn serialize_struct(def: &StructDef, schema: &Schema) -> TokenStream {
|
|||
}
|
||||
)?;
|
||||
});
|
||||
} else if let Some(with) = &field.markers.derive_attributes.estree.via {
|
||||
let with_ident = with.to_ident();
|
||||
} else if let Some(via) = &field.markers.derive_attributes.estree.via {
|
||||
let via_tokens: TokenStream = via.parse().unwrap();
|
||||
fields.push(quote! {
|
||||
map.serialize_entry(
|
||||
#name,
|
||||
&crate::serialize::#with_ident(&self.#ident)
|
||||
&#via_tokens(&self.#ident)
|
||||
)?;
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ impl Parse for ESTreeFieldAttribute {
|
|||
"via" => {
|
||||
input.parse::<Token![=]>()?;
|
||||
assert!(
|
||||
via.replace(input.parse::<LitStr>()?.value()).is_none(),
|
||||
via.replace(input.parse::<Path>()?.to_token_stream().to_string()).is_none(),
|
||||
"Duplicate estree(with)"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue