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
chore(ast): rename RestElement to BindingRestElement
  • Loading branch information
Dunqing authored and Boshen committed Jan 22, 2024
commit 2470b59ce3bad2efee508961780f4f3ca0adf6bf
8 changes: 4 additions & 4 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ pub struct ObjectPattern<'a> {
#[cfg_attr(feature = "serde", serde(flatten))]
pub span: Span,
pub properties: Vec<'a, BindingProperty<'a>>,
pub rest: Option<Box<'a, RestElement<'a>>>,
pub rest: Option<Box<'a, BindingRestElement<'a>>>,
}

impl<'a> ObjectPattern<'a> {
Expand Down Expand Up @@ -1514,7 +1514,7 @@ pub struct ArrayPattern<'a> {
#[cfg_attr(feature = "serde", serde(flatten))]
pub span: Span,
pub elements: Vec<'a, Option<BindingPattern<'a>>>,
pub rest: Option<Box<'a, RestElement<'a>>>,
pub rest: Option<Box<'a, BindingRestElement<'a>>>,
}

impl<'a> ArrayPattern<'a> {
Expand All @@ -1529,7 +1529,7 @@ impl<'a> ArrayPattern<'a> {

#[derive(Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))]
pub struct RestElement<'a> {
pub struct BindingRestElement<'a> {
#[cfg_attr(feature = "serde", serde(flatten))]
pub span: Span,
pub argument: BindingPattern<'a>,
Expand Down Expand Up @@ -1615,7 +1615,7 @@ pub struct FormalParameters<'a> {
pub span: Span,
pub kind: FormalParameterKind,
pub items: Vec<'a, FormalParameter<'a>>,
pub rest: Option<Box<'a, RestElement<'a>>>,
pub rest: Option<Box<'a, BindingRestElement<'a>>>,
}

impl<'a> FormalParameters<'a> {
Expand Down
10 changes: 5 additions & 5 deletions crates/oxc_ast/src/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ impl<'a> AstBuilder<'a> {
span: Span,
kind: FormalParameterKind,
items: Vec<'a, FormalParameter<'a>>,
rest: Option<Box<'a, RestElement<'a>>>,
rest: Option<Box<'a, BindingRestElement<'a>>>,
) -> Box<'a, FormalParameters<'a>> {
self.alloc(FormalParameters { span, kind, items, rest })
}
Expand Down Expand Up @@ -938,7 +938,7 @@ impl<'a> AstBuilder<'a> {
&self,
span: Span,
properties: Vec<'a, BindingProperty<'a>>,
rest: Option<Box<'a, RestElement<'a>>>,
rest: Option<Box<'a, BindingRestElement<'a>>>,
) -> BindingPatternKind<'a> {
BindingPatternKind::ObjectPattern(self.alloc(ObjectPattern { span, properties, rest }))
}
Expand Down Expand Up @@ -966,7 +966,7 @@ impl<'a> AstBuilder<'a> {
&self,
span: Span,
elements: Vec<'a, Option<BindingPattern<'a>>>,
rest: Option<Box<'a, RestElement<'a>>>,
rest: Option<Box<'a, BindingRestElement<'a>>>,
) -> BindingPatternKind<'a> {
BindingPatternKind::ArrayPattern(self.alloc(ArrayPattern { span, elements, rest }))
}
Expand All @@ -989,8 +989,8 @@ impl<'a> AstBuilder<'a> {
&self,
span: Span,
argument: BindingPattern<'a>,
) -> Box<'a, RestElement<'a>> {
self.alloc(RestElement { span, argument })
) -> Box<'a, BindingRestElement<'a>> {
self.alloc(BindingRestElement { span, argument })
}

pub fn property_key_identifier(&self, ident: IdentifierName) -> PropertyKey<'a> {
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_ast/src/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub enum AstKind<'a> {
Elision(Span),
ExpressionArrayElement(&'a Expression<'a>),
SpreadElement(&'a SpreadElement<'a>),
RestElement(&'a RestElement<'a>),
BindingRestElement(&'a BindingRestElement<'a>),

Function(&'a Function<'a>),
FunctionBody(&'a FunctionBody<'a>),
Expand Down Expand Up @@ -401,7 +401,7 @@ impl<'a> GetSpan for AstKind<'a> {
Self::SpreadElement(x) => x.span,
Self::Elision(span) => *span,
Self::ExpressionArrayElement(x) => x.span(),
Self::RestElement(x) => x.span,
Self::BindingRestElement(x) => x.span,

Self::Function(x) => x.span,
Self::FunctionBody(x) => x.span,
Expand Down Expand Up @@ -574,7 +574,7 @@ impl<'a> AstKind<'a> {
Self::SpreadElement(_) => "SpreadElement".into(),
Self::Elision(_) => "Elision".into(),
Self::ExpressionArrayElement(_) => "ExpressionArrayElement".into(),
Self::RestElement(_) => "RestElement".into(),
Self::BindingRestElement(_) => "BindingRestElement".into(),

Self::Function(x) => format!(
"Function({})",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'a> BoundNames for AssignmentPattern<'a> {
}
}

impl<'a> BoundNames for RestElement<'a> {
impl<'a> BoundNames for BindingRestElement<'a> {
fn bound_names<F: FnMut(&BindingIdentifier)>(&self, f: &mut F) {
self.argument.bound_names(f);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,8 @@ pub trait Visit<'a>: Sized {
self.leave_node(kind);
}

fn visit_rest_element(&mut self, pat: &RestElement<'a>) {
let kind = AstKind::RestElement(self.alloc(pat));
fn visit_rest_element(&mut self, pat: &BindingRestElement<'a>) {
let kind = AstKind::BindingRestElement(self.alloc(pat));
self.enter_node(kind);
self.visit_binding_pattern(&pat.argument);
self.leave_node(kind);
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,8 +1213,8 @@ pub trait VisitMut<'a>: Sized {
self.leave_node(kind);
}

fn visit_rest_element(&mut self, pat: &mut RestElement<'a>) {
let kind = AstKind::RestElement(self.alloc(pat));
fn visit_rest_element(&mut self, pat: &mut BindingRestElement<'a>) {
let kind = AstKind::BindingRestElement(self.alloc(pat));
self.enter_node(kind);
self.visit_binding_pattern(&mut pat.argument);
self.leave_node(kind);
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for BindingProperty<'a> {
}
}

impl<'a, const MINIFY: bool> Gen<MINIFY> for RestElement<'a> {
impl<'a, const MINIFY: bool> Gen<MINIFY> for BindingRestElement<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
p.print_ellipsis();
self.argument.gen(p, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl NoExplicitAny {
debug_assert!(matches!(node.kind(), AstKind::TSAnyKeyword(_)));
ctx.nodes()
.iter_parents(node.id())
.any(|parent| matches!(parent.kind(), AstKind::RestElement(_)))
.any(|parent| matches!(parent.kind(), AstKind::BindingRestElement(_)))
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_parser/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub struct ClassDeclaration(#[label] pub Span);
#[derive(Debug, Error, Diagnostic)]
#[error("A rest element must be last in a destructuring pattern")]
#[diagnostic()]
pub struct RestElementLast(#[label] pub Span);
pub struct BindingRestElementLast(#[label] pub Span);

#[derive(Debug, Error, Diagnostic)]
#[error("A rest parameter must be last in a parameter list")]
Expand All @@ -141,12 +141,12 @@ pub struct SpreadLastElement(#[label] pub Span);
#[derive(Debug, Error, Diagnostic)]
#[error("Unexpected trailing comma after rest element")]
#[diagnostic()]
pub struct RestElementTrailingComma(#[label] pub Span);
pub struct BindingRestElementTrailingComma(#[label] pub Span);

#[derive(Debug, Error, Diagnostic)]
#[error("Invalid rest element")]
#[diagnostic(help("Expected identifier in rest element"))]
pub struct InvalidRestElement(#[label] pub Span);
pub struct InvalidBindingRestElement(#[label] pub Span);

#[derive(Debug, Error, Diagnostic)]
#[error("Cannot assign to this expression")]
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_parser/src/js/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ impl<'a> Parser<'a> {
}

/// Section 14.3.3 Binding Rest Property
pub(crate) fn parse_rest_element(&mut self) -> Result<Box<'a, RestElement<'a>>> {
pub(crate) fn parse_rest_element(&mut self) -> Result<Box<'a, BindingRestElement<'a>>> {
let span = self.start_span();
self.bump_any(); // advance `...`
let argument = self.parse_binding_pattern()?;
let span = self.end_span(span);

if self.at(Kind::Comma) {
if self.peek_at(Kind::RBrack) {
self.error(diagnostics::RestElementTrailingComma(self.cur_token().span()));
self.error(diagnostics::BindingRestElementTrailingComma(self.cur_token().span()));
} else if !self.ctx.has_ambient() {
self.error(diagnostics::RestElementLast(span));
self.error(diagnostics::BindingRestElementLast(span));
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/js/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<'a> CoverGrammar<'a, ArrayExpression<'a>> for ArrayAssignmentTarget<'a> {
if i == len - 1 {
rest = Some(AssignmentTarget::cover(elem.unbox().argument, p)?);
if let Some(span) = expr.trailing_comma {
p.error(diagnostics::RestElementTrailingComma(span));
p.error(diagnostics::BindingRestElementTrailingComma(span));
}
} else {
return Err(diagnostics::SpreadLastElement(elem.span).into());
Expand Down
12 changes: 6 additions & 6 deletions crates/oxc_parser/src/js/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a> SeparatedList<'a> for ObjectExpressionProperties<'a> {
/// ObjectPattern.properties
pub struct ObjectPatternProperties<'a> {
pub elements: Vec<'a, BindingProperty<'a>>,
pub rest: Option<oxc_allocator::Box<'a, RestElement<'a>>>,
pub rest: Option<oxc_allocator::Box<'a, BindingRestElement<'a>>>,
}

impl<'a> SeparatedList<'a> for ObjectPatternProperties<'a> {
Expand All @@ -81,10 +81,10 @@ impl<'a> SeparatedList<'a> for ObjectPatternProperties<'a> {
if p.cur_kind() == Kind::Dot3 {
let rest = p.parse_rest_element()?;
if !matches!(&rest.argument.kind, BindingPatternKind::BindingIdentifier(_)) {
p.error(diagnostics::InvalidRestElement(rest.argument.span()));
p.error(diagnostics::InvalidBindingRestElement(rest.argument.span()));
}
if let Some(r) = self.rest.replace(rest) {
p.error(diagnostics::RestElementLast(r.span));
p.error(diagnostics::BindingRestElementLast(r.span));
}
} else {
let prop = p.parse_binding_property()?;
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<'a> SeparatedList<'a> for ArrayExpressionList<'a> {
/// ArrayPattern.elements
pub struct ArrayPatternList<'a> {
pub elements: Vec<'a, Option<BindingPattern<'a>>>,
pub rest: Option<oxc_allocator::Box<'a, RestElement<'a>>>,
pub rest: Option<oxc_allocator::Box<'a, BindingRestElement<'a>>>,
}

impl<'a> SeparatedList<'a> for ArrayPatternList<'a> {
Expand All @@ -156,7 +156,7 @@ impl<'a> SeparatedList<'a> for ArrayPatternList<'a> {
Kind::Dot3 => {
let rest = p.parse_rest_element()?;
if let Some(r) = self.rest.replace(rest) {
p.error(diagnostics::RestElementLast(r.span));
p.error(diagnostics::BindingRestElementLast(r.span));
}
}
_ => {
Expand Down Expand Up @@ -233,7 +233,7 @@ impl<'a> SeparatedList<'a> for SequenceExpressionList<'a> {
/// Function Parameters
pub struct FormalParameterList<'a> {
pub elements: Vec<'a, FormalParameter<'a>>,
pub rest: Option<oxc_allocator::Box<'a, RestElement<'a>>>,
pub rest: Option<oxc_allocator::Box<'a, BindingRestElement<'a>>>,
pub this_param: Option<TSThisParameter<'a>>,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2120,7 +2120,7 @@ impl<'a> Format<'a> for BindingProperty<'a> {
}
}

impl<'a> Format<'a> for RestElement<'a> {
impl<'a> Format<'a> for BindingRestElement<'a> {
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
array!(p, ss!("..."), format!(p, self.argument))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_semantic/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl<'a> Binder for Function<'a> {
}
}

impl<'a> Binder for RestElement<'a> {
impl<'a> Binder for BindingRestElement<'a> {
// Binds the FormalParameters's rest of a function or method.
fn bind(&self, builder: &mut SemanticBuilder) {
let parent_kind = builder.nodes.parent_kind(builder.current_node_id).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ impl<'a> SemanticBuilder<'a> {
&self.nodes,
);
}
AstKind::RestElement(element) => {
AstKind::BindingRestElement(element) => {
element.bind(self);
}
AstKind::FormalParameter(param) => {
Expand Down