mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
refactor(ast): order AST type fields in visitation order (#3228)
Reorder the fields in a couple of AST types. `walk_*` functions in `oxc_traverse` visit the fields in the order they appear in AST. So this change means that decorators are visited before classes and methods that they decorate.
This commit is contained in:
parent
c84c116ac3
commit
4208733180
4 changed files with 564 additions and 562 deletions
|
|
@ -2343,13 +2343,13 @@ pub struct Class<'a> {
|
|||
pub r#type: ClassType,
|
||||
#[cfg_attr(feature = "serialize", serde(flatten))]
|
||||
pub span: Span,
|
||||
pub decorators: Vec<'a, Decorator<'a>>,
|
||||
pub id: Option<BindingIdentifier<'a>>,
|
||||
pub super_class: Option<Expression<'a>>,
|
||||
pub body: Box<'a, ClassBody<'a>>,
|
||||
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
|
||||
pub super_type_parameters: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
|
||||
pub implements: Option<Vec<'a, TSClassImplements<'a>>>,
|
||||
pub decorators: Vec<'a, Decorator<'a>>,
|
||||
/// Valid Modifiers: `export`, `abstract`
|
||||
pub modifiers: Modifiers<'a>,
|
||||
}
|
||||
|
|
@ -2499,6 +2499,7 @@ pub struct MethodDefinition<'a> {
|
|||
pub r#type: MethodDefinitionType,
|
||||
#[cfg_attr(feature = "serialize", serde(flatten))]
|
||||
pub span: Span,
|
||||
pub decorators: Vec<'a, Decorator<'a>>,
|
||||
pub key: PropertyKey<'a>,
|
||||
pub value: Box<'a, Function<'a>>, // FunctionExpression
|
||||
pub kind: MethodDefinitionKind,
|
||||
|
|
@ -2507,7 +2508,6 @@ pub struct MethodDefinition<'a> {
|
|||
pub r#override: bool,
|
||||
pub optional: bool,
|
||||
pub accessibility: Option<TSAccessibility>,
|
||||
pub decorators: Vec<'a, Decorator<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
|
|
|
|||
|
|
@ -937,13 +937,13 @@ impl<'a> AstBuilder<'a> {
|
|||
self.alloc(Class {
|
||||
r#type,
|
||||
span,
|
||||
decorators,
|
||||
id,
|
||||
super_class,
|
||||
body,
|
||||
type_parameters,
|
||||
super_type_parameters,
|
||||
implements,
|
||||
decorators,
|
||||
modifiers,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -2346,10 +2346,16 @@ pub(crate) unsafe fn walk_class<'a, Tr: Traverse<'a>>(
|
|||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
traverser.enter_class(&mut *node, ctx);
|
||||
ctx.push_stack(Ancestor::ClassId(ancestor::ClassWithoutId(node)));
|
||||
ctx.push_stack(Ancestor::ClassDecorators(ancestor::ClassWithoutDecorators(node)));
|
||||
for item in (*((node as *mut u8).add(ancestor::OFFSET_CLASS_DECORATORS) as *mut Vec<Decorator>))
|
||||
.iter_mut()
|
||||
{
|
||||
walk_decorator(traverser, item as *mut _, ctx);
|
||||
}
|
||||
if let Some(field) =
|
||||
&mut *((node as *mut u8).add(ancestor::OFFSET_CLASS_ID) as *mut Option<BindingIdentifier>)
|
||||
{
|
||||
ctx.retag_stack(AncestorType::ClassId);
|
||||
walk_binding_identifier(traverser, field as *mut _, ctx);
|
||||
}
|
||||
if let Some(field) =
|
||||
|
|
@ -2385,12 +2391,6 @@ pub(crate) unsafe fn walk_class<'a, Tr: Traverse<'a>>(
|
|||
walk_ts_class_implements(traverser, item as *mut _, ctx);
|
||||
}
|
||||
}
|
||||
ctx.retag_stack(AncestorType::ClassDecorators);
|
||||
for item in (*((node as *mut u8).add(ancestor::OFFSET_CLASS_DECORATORS) as *mut Vec<Decorator>))
|
||||
.iter_mut()
|
||||
{
|
||||
walk_decorator(traverser, item as *mut _, ctx);
|
||||
}
|
||||
ctx.pop_stack();
|
||||
traverser.exit_class(&mut *node, ctx);
|
||||
}
|
||||
|
|
@ -2444,7 +2444,16 @@ pub(crate) unsafe fn walk_method_definition<'a, Tr: Traverse<'a>>(
|
|||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
traverser.enter_method_definition(&mut *node, ctx);
|
||||
ctx.push_stack(Ancestor::MethodDefinitionKey(ancestor::MethodDefinitionWithoutKey(node)));
|
||||
ctx.push_stack(Ancestor::MethodDefinitionDecorators(
|
||||
ancestor::MethodDefinitionWithoutDecorators(node),
|
||||
));
|
||||
for item in (*((node as *mut u8).add(ancestor::OFFSET_METHOD_DEFINITION_DECORATORS)
|
||||
as *mut Vec<Decorator>))
|
||||
.iter_mut()
|
||||
{
|
||||
walk_decorator(traverser, item as *mut _, ctx);
|
||||
}
|
||||
ctx.retag_stack(AncestorType::MethodDefinitionKey);
|
||||
walk_property_key(
|
||||
traverser,
|
||||
(node as *mut u8).add(ancestor::OFFSET_METHOD_DEFINITION_KEY) as *mut PropertyKey,
|
||||
|
|
@ -2457,13 +2466,6 @@ pub(crate) unsafe fn walk_method_definition<'a, Tr: Traverse<'a>>(
|
|||
as *mut Box<Function>)) as *mut _,
|
||||
ctx,
|
||||
);
|
||||
ctx.retag_stack(AncestorType::MethodDefinitionDecorators);
|
||||
for item in (*((node as *mut u8).add(ancestor::OFFSET_METHOD_DEFINITION_DECORATORS)
|
||||
as *mut Vec<Decorator>))
|
||||
.iter_mut()
|
||||
{
|
||||
walk_decorator(traverser, item as *mut _, ctx);
|
||||
}
|
||||
ctx.pop_stack();
|
||||
traverser.exit_method_definition(&mut *node, ctx);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue