feat(ast): enter/leave ClassBody and PrivateInExpression (#1792)

This commit is contained in:
Dunqing 2023-12-25 10:52:21 +08:00 committed by GitHub
parent 1feec95a94
commit d41e3fd268
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -468,9 +468,12 @@ pub trait Visit<'a>: Sized {
} }
fn visit_class_body(&mut self, body: &ClassBody<'a>) { fn visit_class_body(&mut self, body: &ClassBody<'a>) {
let kind = AstKind::ClassBody(self.alloc(body));
self.enter_node(kind);
for elem in &body.body { for elem in &body.body {
self.visit_class_element(elem); self.visit_class_element(elem);
} }
self.leave_node(kind);
} }
fn visit_class_element(&mut self, elem: &ClassElement<'a>) { fn visit_class_element(&mut self, elem: &ClassElement<'a>) {
@ -836,8 +839,11 @@ pub trait Visit<'a>: Sized {
} }
fn visit_private_in_expression(&mut self, expr: &PrivateInExpression<'a>) { fn visit_private_in_expression(&mut self, expr: &PrivateInExpression<'a>) {
let kind = AstKind::PrivateInExpression(self.alloc(expr));
self.enter_node(kind);
self.visit_private_identifier(&expr.left); self.visit_private_identifier(&expr.left);
self.visit_expression(&expr.right); self.visit_expression(&expr.right);
self.leave_node(kind);
} }
fn visit_sequence_expression(&mut self, expr: &SequenceExpression<'a>) { fn visit_sequence_expression(&mut self, expr: &SequenceExpression<'a>) {

View file

@ -51,7 +51,11 @@ impl Rule for ConstructorSuper {
if ctor.kind != MethodDefinitionKind::Constructor || ctor.value.body.is_none() { if ctor.kind != MethodDefinitionKind::Constructor || ctor.value.body.is_none() {
return; return;
} }
let Some(AstKind::Class(class)) = ctx.nodes().parent_kind(node.id()) else { return }; let Some(AstKind::Class(class)) =
ctx.nodes().parent_id(node.id()).and_then(|id| ctx.nodes().parent_kind(id))
else {
return;
};
// In cases where there's no super-class, calling 'super()' inside the constructor // In cases where there's no super-class, calling 'super()' inside the constructor
// is handled by the parser. // is handled by the parser.