Skip to content
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
8 changes: 4 additions & 4 deletions apps/oxlint/src-js/generated/deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2367,13 +2367,13 @@ function deserializeFormalParameters(pos) {
optional: false,
typeAnnotation: null,
value: null,
start: (start = deserializeU32(pos + 8)),
end: (end = deserializeU32(pos + 12)),
start: (start = deserializeU32(pos + 32)),
end: (end = deserializeU32(pos + 36)),
range: [start, end],
parent: previousParent,
});
rest.argument = deserializeBindingPattern(pos + 16);
rest.typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 32);
rest.argument = deserializeBindingPattern(pos + 40);
rest.typeAnnotation = deserializeOptionBoxTSTypeAnnotation(pos + 56);
if (rest.typeAnnotation !== null) {
end = rest.typeAnnotation.end;
rest.end = end;
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,7 @@ pub enum FormalParameterKind {
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, UnstableAddress)]
pub struct FormalParameterRest<'a> {
pub span: Span,
pub decorators: Vec<'a, Decorator<'a>>,
pub rest: BindingRestElement<'a>,
pub type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
}
Expand Down
14 changes: 8 additions & 6 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,12 @@ const _: () = {
assert!(align_of::<FormalParameterKind>() == 1);

// Padding: 0 bytes
assert!(size_of::<FormalParameterRest>() == 40);
assert!(size_of::<FormalParameterRest>() == 64);
assert!(align_of::<FormalParameterRest>() == 8);
assert!(offset_of!(FormalParameterRest, span) == 0);
assert!(offset_of!(FormalParameterRest, rest) == 8);
assert!(offset_of!(FormalParameterRest, type_annotation) == 32);
assert!(offset_of!(FormalParameterRest, decorators) == 8);
assert!(offset_of!(FormalParameterRest, rest) == 32);
assert!(offset_of!(FormalParameterRest, type_annotation) == 56);

// Padding: 0 bytes
assert!(size_of::<FunctionBody>() == 56);
Expand Down Expand Up @@ -2233,11 +2234,12 @@ const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
assert!(align_of::<FormalParameterKind>() == 1);

// Padding: 0 bytes
assert!(size_of::<FormalParameterRest>() == 28);
assert!(size_of::<FormalParameterRest>() == 44);
assert!(align_of::<FormalParameterRest>() == 4);
assert!(offset_of!(FormalParameterRest, span) == 0);
assert!(offset_of!(FormalParameterRest, rest) == 8);
assert!(offset_of!(FormalParameterRest, type_annotation) == 24);
assert!(offset_of!(FormalParameterRest, decorators) == 8);
assert!(offset_of!(FormalParameterRest, rest) == 24);
assert!(offset_of!(FormalParameterRest, type_annotation) == 40);

// Padding: 0 bytes
assert!(size_of::<FunctionBody>() == 40);
Expand Down
16 changes: 14 additions & 2 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6177,19 +6177,26 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `decorators`
/// * `rest`
/// * `type_annotation`
#[inline]
pub fn formal_parameter_rest<T1>(
self,
span: Span,
decorators: Vec<'a, Decorator<'a>>,
rest: BindingRestElement<'a>,
type_annotation: T1,
) -> FormalParameterRest<'a>
where
T1: IntoIn<'a, Option<Box<'a, TSTypeAnnotation<'a>>>>,
{
FormalParameterRest { span, rest, type_annotation: type_annotation.into_in(self.allocator) }
FormalParameterRest {
span,
decorators,
rest,
type_annotation: type_annotation.into_in(self.allocator),
}
}

/// Build a [`FormalParameterRest`], and store it in the memory arena.
Expand All @@ -6199,19 +6206,24 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `decorators`
/// * `rest`
/// * `type_annotation`
#[inline]
pub fn alloc_formal_parameter_rest<T1>(
self,
span: Span,
decorators: Vec<'a, Decorator<'a>>,
rest: BindingRestElement<'a>,
type_annotation: T1,
) -> Box<'a, FormalParameterRest<'a>>
where
T1: IntoIn<'a, Option<Box<'a, TSTypeAnnotation<'a>>>>,
{
Box::new_in(self.formal_parameter_rest(span, rest, type_annotation), self.allocator)
Box::new_in(
self.formal_parameter_rest(span, decorators, rest, type_annotation),
self.allocator,
)
}

/// Build a [`FunctionBody`].
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3655,6 +3655,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for FormalParameterRest<'_> {
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
FormalParameterRest {
span: CloneIn::clone_in(&self.span, allocator),
decorators: CloneIn::clone_in(&self.decorators, allocator),
rest: CloneIn::clone_in(&self.rest, allocator),
type_annotation: CloneIn::clone_in(&self.type_annotation, allocator),
}
Expand All @@ -3663,6 +3664,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for FormalParameterRest<'_> {
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
FormalParameterRest {
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
decorators: CloneIn::clone_in_with_semantic_ids(&self.decorators, allocator),
rest: CloneIn::clone_in_with_semantic_ids(&self.rest, allocator),
type_annotation: CloneIn::clone_in_with_semantic_ids(&self.type_annotation, allocator),
}
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_ast/src/generated/derive_content_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,8 @@ impl ContentEq for FormalParameterKind {

impl ContentEq for FormalParameterRest<'_> {
fn content_eq(&self, other: &Self) -> bool {
ContentEq::content_eq(&self.rest, &other.rest)
ContentEq::content_eq(&self.decorators, &other.decorators)
&& ContentEq::content_eq(&self.rest, &other.rest)
&& ContentEq::content_eq(&self.type_annotation, &other.type_annotation)
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast/src/generated/derive_dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ impl<'a> Dummy<'a> for FormalParameterRest<'a> {
fn dummy(allocator: &'a Allocator) -> Self {
Self {
span: Dummy::dummy(allocator),
decorators: Dummy::dummy(allocator),
rest: Dummy::dummy(allocator),
type_annotation: Dummy::dummy(allocator),
}
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast_visit/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2500,6 +2500,7 @@ pub mod walk {
let kind = AstKind::FormalParameterRest(visitor.alloc(it));
visitor.enter_node(kind);
visitor.visit_span(&it.span);
visitor.visit_decorators(&it.decorators);
visitor.visit_binding_rest_element(&it.rest);
if let Some(type_annotation) = &it.type_annotation {
visitor.visit_ts_type_annotation(type_annotation);
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast_visit/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2583,6 +2583,7 @@ pub mod walk_mut {
let kind = AstType::FormalParameterRest;
visitor.enter_node(kind);
visitor.visit_span(&mut it.span);
visitor.visit_decorators(&mut it.decorators);
visitor.visit_binding_rest_element(&mut it.rest);
if let Some(type_annotation) = &mut it.type_annotation {
visitor.visit_ts_type_annotation(type_annotation);
Expand Down
11 changes: 11 additions & 0 deletions crates/oxc_formatter/src/ast_nodes/generated/ast_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4375,6 +4375,17 @@ impl<'a> AstNode<'a, FormalParameter<'a>> {
}

impl<'a> AstNode<'a, FormalParameterRest<'a>> {
#[inline]
pub fn decorators(&self) -> &AstNode<'a, Vec<'a, Decorator<'a>>> {
let following_span_start = self.inner.rest.span().start;
self.allocator.alloc(AstNode {
inner: &self.inner.decorators,
allocator: self.allocator,
parent: AstNodes::FormalParameterRest(transmute_self(self)),
following_span_start,
})
}

#[inline]
pub fn rest(&self) -> &AstNode<'a, BindingRestElement<'a>> {
let following_span_start = self
Expand Down
30 changes: 23 additions & 7 deletions crates/oxc_parser/src/js/function.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use oxc_allocator::Box;
use oxc_allocator::{Box, Vec};
use oxc_ast::ast::*;
use oxc_span::{GetSpan, Span};

Expand Down Expand Up @@ -118,27 +118,43 @@ impl<'a> ParserImpl<'a> {
break;
}

let span = self.start_span();
let decorators = self.parse_decorators();

if self.at(Kind::Dot3) {
let rest_element = self.parse_rest_element_for_formal_parameter();
let rest_span = rest_element.span;
let type_annotation =
if self.is_ts { self.parse_ts_type_annotation() } else { None };

let are_decorators_allowed =
matches!(func_kind, FunctionKind::ClassMethod | FunctionKind::Constructor)
&& self.is_ts;
if !are_decorators_allowed {
for decorator in &decorators {
self.error(diagnostics::decorators_are_not_valid_here(decorator.span));
}
}

rest = Some(self.ast.alloc_formal_parameter_rest(
rest_span,
self.end_span(span),
decorators,
rest_element,
type_annotation,
));
} else {
list.push(self.parse_formal_parameter(func_kind));
list.push(self.parse_formal_parameter_with_decorators(func_kind, span, decorators));
}
}

(list, rest)
}

fn parse_formal_parameter(&mut self, func_kind: FunctionKind) -> FormalParameter<'a> {
let span = self.start_span();
let decorators = self.parse_decorators();
fn parse_formal_parameter_with_decorators(
&mut self,
func_kind: FunctionKind,
span: u32,
decorators: Vec<'a, Decorator<'a>>,
) -> FormalParameter<'a> {
let modifiers = self.parse_modifiers(false, false);
if self.is_ts {
let allowed_modifiers = if func_kind == FunctionKind::Constructor {
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2258,6 +2258,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
self.enter_node(kind);
param.bind(self);
self.visit_span(&param.span);
self.visit_decorators(&param.decorators);
self.visit_binding_rest_element(&param.rest);
if let Some(type_annotation) = &param.type_annotation {
self.visit_ts_type_annotation(type_annotation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ impl<'a> ClassProperties<'a, '_> {
ctx.generate_uid("args", constructor_scope_id, SymbolFlags::FunctionScopedVariable);
let rest_element =
ctx.ast.binding_rest_element(SPAN, args_binding.create_binding_pattern(ctx));
params_rest = Some(ctx.ast.alloc_formal_parameter_rest(SPAN, rest_element, NONE));
params_rest =
Some(ctx.ast.alloc_formal_parameter_rest(SPAN, ctx.ast.vec(), rest_element, NONE));
stmts.push(ctx.ast.statement_expression(SPAN, create_super_call(&args_binding, ctx)));
}
// TODO: Should these have the span of the original `PropertyDefinition`s?
Expand Down Expand Up @@ -311,7 +312,8 @@ impl<'a> ClassProperties<'a, '_> {
{
let rest_element =
ctx.ast.binding_rest_element(SPAN, args_binding.create_binding_pattern(ctx));
let rest = ctx.ast.alloc_formal_parameter_rest(SPAN, rest_element, NONE);
let rest =
ctx.ast.alloc_formal_parameter_rest(SPAN, ctx.ast.vec(), rest_element, NONE);
ctx.ast.alloc_formal_parameters(
SPAN,
FormalParameterKind::ArrowFormalParameters,
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_transformer/src/utils/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ pub fn create_class_constructor<'a, 'c>(
let args_binding = ctx.generate_uid("args", scope_id, SymbolFlags::FunctionScopedVariable);
let rest_element =
ctx.ast.binding_rest_element(SPAN, args_binding.create_binding_pattern(ctx));
params_rest = Some(ctx.ast.alloc_formal_parameter_rest(SPAN, rest_element, NONE));
params_rest =
Some(ctx.ast.alloc_formal_parameter_rest(SPAN, ctx.ast.vec(), rest_element, NONE));
ctx.ast.vec_from_iter(
iter::once(ctx.ast.statement_expression(SPAN, create_super_call(&args_binding, ctx)))
.chain(stmts_iter),
Expand Down
Loading
Loading