mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +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 struct ImportDeclaration<'a> {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
/// `None` for `import 'foo'`, `Some([])` for `import {} from 'foo'`
|
/// `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 specifiers: Option<Vec<'a, ImportDeclarationSpecifier<'a>>>,
|
||||||
pub source: StringLiteral<'a>,
|
pub source: StringLiteral<'a>,
|
||||||
pub phase: Option<ImportPhase>,
|
pub phase: Option<ImportPhase>,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ use crate::{
|
||||||
serialize::{enum_variant_name, get_always_flatten_structs, get_type_tag},
|
serialize::{enum_variant_name, get_always_flatten_structs, get_type_tag},
|
||||||
EnumDef, FieldDef, GetGenerics, GetIdent, Schema, StructDef, TypeDef,
|
EnumDef, FieldDef, GetGenerics, GetIdent, Schema, StructDef, TypeDef,
|
||||||
},
|
},
|
||||||
util::ToIdent,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{define_derive, Derive};
|
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 {
|
} else if let Some(via) = &field.markers.derive_attributes.estree.via {
|
||||||
let with_ident = with.to_ident();
|
let via_tokens: TokenStream = via.parse().unwrap();
|
||||||
fields.push(quote! {
|
fields.push(quote! {
|
||||||
map.serialize_entry(
|
map.serialize_entry(
|
||||||
#name,
|
#name,
|
||||||
&crate::serialize::#with_ident(&self.#ident)
|
&#via_tokens(&self.#ident)
|
||||||
)?;
|
)?;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@ impl Parse for ESTreeFieldAttribute {
|
||||||
"via" => {
|
"via" => {
|
||||||
input.parse::<Token![=]>()?;
|
input.parse::<Token![=]>()?;
|
||||||
assert!(
|
assert!(
|
||||||
via.replace(input.parse::<LitStr>()?.value()).is_none(),
|
via.replace(input.parse::<Path>()?.to_token_stream().to_string()).is_none(),
|
||||||
"Duplicate estree(with)"
|
"Duplicate estree(with)"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue