From d41e3fd268ff7783ec863eb664a78268b8dec54f Mon Sep 17 00:00:00 2001 From: Dunqing Date: Mon, 25 Dec 2023 10:52:21 +0800 Subject: [PATCH] feat(ast): enter/leave ClassBody and PrivateInExpression (#1792) --- crates/oxc_ast/src/visit.rs | 6 ++++++ crates/oxc_linter/src/rules/eslint/constructor_super.rs | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/oxc_ast/src/visit.rs b/crates/oxc_ast/src/visit.rs index 5c97b6c3e..176f740fb 100644 --- a/crates/oxc_ast/src/visit.rs +++ b/crates/oxc_ast/src/visit.rs @@ -468,9 +468,12 @@ pub trait Visit<'a>: Sized { } 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 { self.visit_class_element(elem); } + self.leave_node(kind); } 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>) { + let kind = AstKind::PrivateInExpression(self.alloc(expr)); + self.enter_node(kind); self.visit_private_identifier(&expr.left); self.visit_expression(&expr.right); + self.leave_node(kind); } fn visit_sequence_expression(&mut self, expr: &SequenceExpression<'a>) { diff --git a/crates/oxc_linter/src/rules/eslint/constructor_super.rs b/crates/oxc_linter/src/rules/eslint/constructor_super.rs index 60af5a55c..827a877ae 100644 --- a/crates/oxc_linter/src/rules/eslint/constructor_super.rs +++ b/crates/oxc_linter/src/rules/eslint/constructor_super.rs @@ -51,7 +51,11 @@ impl Rule for ConstructorSuper { if ctor.kind != MethodDefinitionKind::Constructor || ctor.value.body.is_none() { 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 // is handled by the parser.