refactor(ast): rename RestElement to BindingRestElement (#2116)

close: #2115
This commit is contained in:
Dunqing 2024-01-22 14:28:35 +08:00 committed by GitHub
parent 8bccdab2e9
commit 766ca63aa0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 35 additions and 35 deletions

View file

@ -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> {
@ -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> {
@ -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>,
@ -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> {

View file

@ -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 })
}
@ -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 }))
}
@ -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 }))
}
@ -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> {

View file

@ -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>),
@ -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,
@ -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({})",

View file

@ -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);
}

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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(_)))
}
}

View file

@ -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")]
@ -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")]

View file

@ -48,7 +48,7 @@ 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()?;
@ -56,9 +56,9 @@ impl<'a> Parser<'a> {
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));
}
}

View file

@ -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());

View file

@ -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> {
@ -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()?;
@ -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> {
@ -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));
}
}
_ => {
@ -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>>,
}

View file

@ -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))
}

View file

@ -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();

View file

@ -450,7 +450,7 @@ impl<'a> SemanticBuilder<'a> {
&self.nodes,
);
}
AstKind::RestElement(element) => {
AstKind::BindingRestElement(element) => {
element.bind(self);
}
AstKind::FormalParameter(param) => {