mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
feat(ast): generate node ID setters for enums (#27500)
Generate `set_node_id` alongside `node_id` for AST enums whose variants expose node IDs. This lets transformations restore the original comment owner on rebuilt nodes through the enum API, using the same inline dispatch as the getter.
This commit is contained in:
1 parent
9c35461498
commit
5d91db8d21
2 files changed
+923
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -193,6 +193,11 @@ fn generate_for_enum(enum_def: &EnumDef, schema: &Schema) -> Option<TokenStream>
|
||||
|
||||
let enum_ty = enum_def.ty_anon(schema);
|
||||
let get_doc = format!(" Get [`NodeId`] of [`{}`].", enum_def.name());
|
||||
let set_doc = format!(" Set [`NodeId`] of [`{}`].", enum_def.name());
|
||||
let setters = enum_def.all_variants(schema).map(|variant| {
|
||||
let variant_ident = variant.ident();
|
||||
quote!( Self::#variant_ident(it) => it.set_node_id(node_id) )
|
||||
});
|
||||
|
||||
Some(quote! {
|
||||
///@@line_break
|
||||
@@ -204,6 +209,14 @@ fn generate_for_enum(enum_def: &EnumDef, schema: &Schema) -> Option<TokenStream>
|
||||
#(#matches),*
|
||||
}
|
||||
}
|
||||
|
||||
#[doc = #set_doc]
|
||||
#maybe_inline
|
||||
pub fn set_node_id(&self, node_id: NodeId) {
|
||||
match self {
|
||||
#(#setters),*
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user