Skip to content

Commit

Permalink
refactor(ast): align $[estree(via)] behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jan 19, 2025
1 parent d966e0a commit d688c7e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
7 changes: 3 additions & 4 deletions tasks/ast_tools/src/derives/estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tasks/ast_tools/src/markers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
);
}
Expand Down

0 comments on commit d688c7e

Please sign in to comment.