From 997859c42ee2e37eb6cab418397cf1c73c15a9d9 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Sun, 19 Jan 2025 20:44:32 +0000 Subject: [PATCH] refactor(ast): align `#[estree(via)]` behavior (#8599) Follow-on after #8564. Aligned the behavior of `#[estree(via)]` for fields with `#[estree(via)]` for structs. --- crates/oxc_ast/src/ast/js.rs | 2 +- tasks/ast_tools/src/derives/estree.rs | 7 +++---- tasks/ast_tools/src/markers.rs | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 4a5b77526..cdb06e507 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -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")] + #[estree(via = crate::serialize::OptionVecDefault, type = "Array")] pub specifiers: Option>>, pub source: StringLiteral<'a>, pub phase: Option, diff --git a/tasks/ast_tools/src/derives/estree.rs b/tasks/ast_tools/src/derives/estree.rs index 097cb494f..7ca285f91 100644 --- a/tasks/ast_tools/src/derives/estree.rs +++ b/tasks/ast_tools/src/derives/estree.rs @@ -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 { diff --git a/tasks/ast_tools/src/markers.rs b/tasks/ast_tools/src/markers.rs index b47d3513a..edcde3db6 100644 --- a/tasks/ast_tools/src/markers.rs +++ b/tasks/ast_tools/src/markers.rs @@ -286,7 +286,7 @@ impl Parse for ESTreeFieldAttribute { "via" => { input.parse::()?; assert!( - via.replace(input.parse::()?.value()).is_none(), + via.replace(input.parse::()?.to_token_stream().to_string()).is_none(), "Duplicate estree(with)" ); }