Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ast): put decorators before everything else. #4143

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,11 +1511,11 @@ pub struct FormalParameters<'a> {
pub struct FormalParameter<'a> {
#[cfg_attr(feature = "serialize", serde(flatten))]
pub span: Span,
pub decorators: Vec<'a, Decorator<'a>>,
pub pattern: BindingPattern<'a>,
pub accessibility: Option<TSAccessibility>,
pub readonly: bool,
pub r#override: bool,
pub decorators: Vec<'a, Decorator<'a>>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -1776,11 +1776,11 @@ pub struct AccessorProperty<'a> {
pub r#type: AccessorPropertyType,
#[cfg_attr(feature = "serialize", serde(flatten))]
pub span: Span,
pub decorators: Vec<'a, Decorator<'a>>,
pub key: PropertyKey<'a>,
pub value: Option<Expression<'a>>,
pub computed: bool,
pub r#static: bool,
pub decorators: Vec<'a, Decorator<'a>>,
}

#[visited_node]
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast_builder_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl<'a> AstBuilder<'a> {
span: Span,
pattern: BindingPattern<'a>,
) -> FormalParameter<'a> {
self.formal_parameter(span, pattern, None, false, false, self.vec())
self.formal_parameter(span, self.vec(), pattern, None, false, false)
}

#[inline]
Expand Down
20 changes: 10 additions & 10 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3814,26 +3814,26 @@ impl<'a> AstBuilder<'a> {
pub fn formal_parameter(
self,
span: Span,
decorators: Vec<'a, Decorator<'a>>,
pattern: BindingPattern<'a>,
accessibility: Option<TSAccessibility>,
readonly: bool,
r#override: bool,
decorators: Vec<'a, Decorator<'a>>,
) -> FormalParameter<'a> {
FormalParameter { span, pattern, accessibility, readonly, r#override, decorators }
FormalParameter { span, decorators, pattern, accessibility, readonly, r#override }
}

#[inline]
pub fn alloc_formal_parameter(
self,
span: Span,
decorators: Vec<'a, Decorator<'a>>,
pattern: BindingPattern<'a>,
accessibility: Option<TSAccessibility>,
readonly: bool,
r#override: bool,
decorators: Vec<'a, Decorator<'a>>,
) -> Box<'a, FormalParameter<'a>> {
self.formal_parameter(span, pattern, accessibility, readonly, r#override, decorators)
self.formal_parameter(span, decorators, pattern, accessibility, readonly, r#override)
.into_in(self.allocator)
}

Expand Down Expand Up @@ -4131,14 +4131,14 @@ impl<'a> AstBuilder<'a> {
self,
r#type: AccessorPropertyType,
span: Span,
decorators: Vec<'a, Decorator<'a>>,
key: PropertyKey<'a>,
value: Option<Expression<'a>>,
computed: bool,
r#static: bool,
decorators: Vec<'a, Decorator<'a>>,
) -> ClassElement<'a> {
ClassElement::AccessorProperty(self.alloc(
self.accessor_property(r#type, span, key, value, computed, r#static, decorators),
self.accessor_property(r#type, span, decorators, key, value, computed, r#static),
))
}

Expand Down Expand Up @@ -4510,27 +4510,27 @@ impl<'a> AstBuilder<'a> {
self,
r#type: AccessorPropertyType,
span: Span,
decorators: Vec<'a, Decorator<'a>>,
key: PropertyKey<'a>,
value: Option<Expression<'a>>,
computed: bool,
r#static: bool,
decorators: Vec<'a, Decorator<'a>>,
) -> AccessorProperty<'a> {
AccessorProperty { r#type, span, key, value, computed, r#static, decorators }
AccessorProperty { r#type, span, decorators, key, value, computed, r#static }
}

#[inline]
pub fn alloc_accessor_property(
self,
r#type: AccessorPropertyType,
span: Span,
decorators: Vec<'a, Decorator<'a>>,
key: PropertyKey<'a>,
value: Option<Expression<'a>>,
computed: bool,
r#static: bool,
decorators: Vec<'a, Decorator<'a>>,
) -> Box<'a, AccessorProperty<'a>> {
self.accessor_property(r#type, span, key, value, computed, r#static, decorators)
self.accessor_property(r#type, span, decorators, key, value, computed, r#static)
.into_in(self.allocator)
}

Expand Down
54 changes: 27 additions & 27 deletions crates/oxc_ast/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ pub trait Visit<'a>: Sized {
walk_formal_parameter(self, it);
}

#[inline]
fn visit_decorators(&mut self, it: &Vec<'a, Decorator<'a>>) {
walk_decorators(self, it);
}

#[inline]
fn visit_decorator(&mut self, it: &Decorator<'a>) {
walk_decorator(self, it);
}

#[inline]
fn visit_binding_pattern(&mut self, it: &BindingPattern<'a>) {
walk_binding_pattern(self, it);
Expand Down Expand Up @@ -625,16 +635,6 @@ pub trait Visit<'a>: Sized {
walk_js_doc_unknown_type(self, it);
}

#[inline]
fn visit_decorators(&mut self, it: &Vec<'a, Decorator<'a>>) {
walk_decorators(self, it);
}

#[inline]
fn visit_decorator(&mut self, it: &Decorator<'a>) {
walk_decorator(self, it);
}

#[inline]
fn visit_function_body(&mut self, it: &FunctionBody<'a>) {
walk_function_body(self, it);
Expand Down Expand Up @@ -1745,8 +1745,23 @@ pub mod walk {
pub fn walk_formal_parameter<'a, V: Visit<'a>>(visitor: &mut V, it: &FormalParameter<'a>) {
let kind = AstKind::FormalParameter(visitor.alloc(it));
visitor.enter_node(kind);
visitor.visit_binding_pattern(&it.pattern);
visitor.visit_decorators(&it.decorators);
visitor.visit_binding_pattern(&it.pattern);
visitor.leave_node(kind);
}

#[inline]
pub fn walk_decorators<'a, V: Visit<'a>>(visitor: &mut V, it: &Vec<'a, Decorator<'a>>) {
for el in it.iter() {
visitor.visit_decorator(el);
}
}

#[inline]
pub fn walk_decorator<'a, V: Visit<'a>>(visitor: &mut V, it: &Decorator<'a>) {
let kind = AstKind::Decorator(visitor.alloc(it));
visitor.enter_node(kind);
visitor.visit_expression(&it.expression);
visitor.leave_node(kind);
}

Expand Down Expand Up @@ -2543,21 +2558,6 @@ pub mod walk {
// NOTE: AstKind doesn't exists!
}

#[inline]
pub fn walk_decorators<'a, V: Visit<'a>>(visitor: &mut V, it: &Vec<'a, Decorator<'a>>) {
for el in it.iter() {
visitor.visit_decorator(el);
}
}

#[inline]
pub fn walk_decorator<'a, V: Visit<'a>>(visitor: &mut V, it: &Decorator<'a>) {
let kind = AstKind::Decorator(visitor.alloc(it));
visitor.enter_node(kind);
visitor.visit_expression(&it.expression);
visitor.leave_node(kind);
}

#[inline]
pub fn walk_function_body<'a, V: Visit<'a>>(visitor: &mut V, it: &FunctionBody<'a>) {
let kind = AstKind::FunctionBody(visitor.alloc(it));
Expand Down Expand Up @@ -3053,11 +3053,11 @@ pub mod walk {
#[inline]
pub fn walk_accessor_property<'a, V: Visit<'a>>(visitor: &mut V, it: &AccessorProperty<'a>) {
// NOTE: AstKind doesn't exists!
visitor.visit_decorators(&it.decorators);
visitor.visit_property_key(&it.key);
if let Some(value) = &it.value {
visitor.visit_expression(value);
}
visitor.visit_decorators(&it.decorators);
}

#[inline]
Expand Down
54 changes: 27 additions & 27 deletions crates/oxc_ast/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ pub trait VisitMut<'a>: Sized {
walk_formal_parameter(self, it);
}

#[inline]
fn visit_decorators(&mut self, it: &mut Vec<'a, Decorator<'a>>) {
walk_decorators(self, it);
}

#[inline]
fn visit_decorator(&mut self, it: &mut Decorator<'a>) {
walk_decorator(self, it);
}

#[inline]
fn visit_binding_pattern(&mut self, it: &mut BindingPattern<'a>) {
walk_binding_pattern(self, it);
Expand Down Expand Up @@ -614,16 +624,6 @@ pub trait VisitMut<'a>: Sized {
walk_js_doc_unknown_type(self, it);
}

#[inline]
fn visit_decorators(&mut self, it: &mut Vec<'a, Decorator<'a>>) {
walk_decorators(self, it);
}

#[inline]
fn visit_decorator(&mut self, it: &mut Decorator<'a>) {
walk_decorator(self, it);
}

#[inline]
fn visit_function_body(&mut self, it: &mut FunctionBody<'a>) {
walk_function_body(self, it);
Expand Down Expand Up @@ -1770,8 +1770,23 @@ pub mod walk_mut {
) {
let kind = AstType::FormalParameter;
visitor.enter_node(kind);
visitor.visit_binding_pattern(&mut it.pattern);
visitor.visit_decorators(&mut it.decorators);
visitor.visit_binding_pattern(&mut it.pattern);
visitor.leave_node(kind);
}

#[inline]
pub fn walk_decorators<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut Vec<'a, Decorator<'a>>) {
for el in it.iter_mut() {
visitor.visit_decorator(el);
}
}

#[inline]
pub fn walk_decorator<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut Decorator<'a>) {
let kind = AstType::Decorator;
visitor.enter_node(kind);
visitor.visit_expression(&mut it.expression);
visitor.leave_node(kind);
}

Expand Down Expand Up @@ -2646,21 +2661,6 @@ pub mod walk_mut {
// NOTE: AstType doesn't exists!
}

#[inline]
pub fn walk_decorators<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut Vec<'a, Decorator<'a>>) {
for el in it.iter_mut() {
visitor.visit_decorator(el);
}
}

#[inline]
pub fn walk_decorator<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut Decorator<'a>) {
let kind = AstType::Decorator;
visitor.enter_node(kind);
visitor.visit_expression(&mut it.expression);
visitor.leave_node(kind);
}

#[inline]
pub fn walk_function_body<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut FunctionBody<'a>) {
let kind = AstType::FunctionBody;
Expand Down Expand Up @@ -3186,11 +3186,11 @@ pub mod walk_mut {
it: &mut AccessorProperty<'a>,
) {
// NOTE: AstType doesn't exists!
visitor.visit_decorators(&mut it.decorators);
visitor.visit_property_key(&mut it.key);
if let Some(value) = &mut it.value {
visitor.visit_expression(value);
}
visitor.visit_decorators(&mut it.decorators);
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_isolated_declarations/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,11 @@ impl<'a> IsolatedDeclarations<'a> {
let new_element = self.ast.class_element_accessor_property(
property.r#type,
property.span,
self.ast.vec(),
self.ast.copy(&property.key),
None,
property.computed,
property.r#static,
self.ast.vec(),
);
elements.push(new_element);
}
Expand Down Expand Up @@ -525,7 +525,7 @@ impl<'a> IsolatedDeclarations<'a> {
) -> Box<'a, FormalParameters<'a>> {
let pattern = BindingPattern { kind, type_annotation, optional: false };
let parameter =
self.ast.formal_parameter(SPAN, pattern, None, false, false, self.ast.vec());
self.ast.formal_parameter(SPAN, self.ast.vec(), pattern, None, false, false);
let items = self.ast.vec1(parameter);
self.ast.alloc_formal_parameters(
SPAN,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_isolated_declarations/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<'a> IsolatedDeclarations<'a> {
);
}

Some(self.ast.formal_parameter(param.span, pattern, None, false, false, self.ast.vec()))
Some(self.ast.formal_parameter(param.span, self.ast.vec(), pattern, None, false, false))
}

pub fn transform_formal_parameters(
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/js/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,11 @@ impl<'a> ParserImpl<'a> {
Ok(self.ast.class_element_accessor_property(
r#type,
self.end_span(span),
decorators,
key,
value,
computed,
r#static,
decorators,
))
}
}
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/js/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ impl<'a> ParserImpl<'a> {
let decorators = self.consume_decorators();
Ok(self.ast.formal_parameter(
self.end_span(span),
decorators,
pattern,
modifiers.accessibility(),
modifiers.contains_readonly(),
modifiers.contains_override(),
decorators,
))
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/typescript/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<'a> TypeScriptEnum<'a> {
let id = ast.binding_pattern(kind, Option::<TSTypeAnnotation>::None, false);

// ((Foo) => {
let params = ast.formal_parameter(SPAN, id, None, false, false, ast.vec());
let params = ast.formal_parameter(SPAN, ast.vec(), id, None, false, false);
let params = ast.vec1(params);
let params = ast.alloc_formal_parameters(
SPAN,
Expand Down
Loading
Loading