mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(ast)!: remove AstKind::ExpressionArrayElement and AstKind::ClassHeritage (#6740)
closes #6392
This commit is contained in:
parent
e8f8409d01
commit
202c7f66c7
17 changed files with 14 additions and 133 deletions
|
|
@ -1839,7 +1839,6 @@ pub struct Class<'a> {
|
||||||
/// class Foo extends Bar {}
|
/// class Foo extends Bar {}
|
||||||
/// // ^^^
|
/// // ^^^
|
||||||
/// ```
|
/// ```
|
||||||
#[visit(as(ClassHeritage))]
|
|
||||||
pub super_class: Option<Expression<'a>>,
|
pub super_class: Option<Expression<'a>>,
|
||||||
/// Type parameters passed to super class.
|
/// Type parameters passed to super class.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -298,7 +298,6 @@ impl<'a> AstKind<'a> {
|
||||||
Self::AssignmentTargetWithDefault(_) => "AssignmentTargetWithDefault".into(),
|
Self::AssignmentTargetWithDefault(_) => "AssignmentTargetWithDefault".into(),
|
||||||
Self::SpreadElement(_) => "SpreadElement".into(),
|
Self::SpreadElement(_) => "SpreadElement".into(),
|
||||||
Self::Elision(_) => "Elision".into(),
|
Self::Elision(_) => "Elision".into(),
|
||||||
Self::ExpressionArrayElement(_) => "ExpressionArrayElement".into(),
|
|
||||||
Self::BindingRestElement(_) => "BindingRestElement".into(),
|
Self::BindingRestElement(_) => "BindingRestElement".into(),
|
||||||
|
|
||||||
Self::Function(x) => format!("Function({})", or_anonymous(x.id.as_ref())).into(),
|
Self::Function(x) => format!("Function({})", or_anonymous(x.id.as_ref())).into(),
|
||||||
|
|
@ -314,7 +313,6 @@ impl<'a> AstKind<'a> {
|
||||||
Self::Class(c) => format!("Class({})", or_anonymous(c.id.as_ref())).into(),
|
Self::Class(c) => format!("Class({})", or_anonymous(c.id.as_ref())).into(),
|
||||||
Self::TSClassImplements(_) => "TSClassImplements".into(),
|
Self::TSClassImplements(_) => "TSClassImplements".into(),
|
||||||
Self::ClassBody(_) => "ClassBody".into(),
|
Self::ClassBody(_) => "ClassBody".into(),
|
||||||
Self::ClassHeritage(_) => "ClassHeritage".into(),
|
|
||||||
Self::StaticBlock(_) => "StaticBlock".into(),
|
Self::StaticBlock(_) => "StaticBlock".into(),
|
||||||
Self::PropertyDefinition(_) => "PropertyDefinition".into(),
|
Self::PropertyDefinition(_) => "PropertyDefinition".into(),
|
||||||
Self::MethodDefinition(_) => "MethodDefinition".into(),
|
Self::MethodDefinition(_) => "MethodDefinition".into(),
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,6 @@ pub enum AstType {
|
||||||
ArrowFunctionExpression,
|
ArrowFunctionExpression,
|
||||||
YieldExpression,
|
YieldExpression,
|
||||||
Class,
|
Class,
|
||||||
ClassHeritage,
|
|
||||||
ClassBody,
|
ClassBody,
|
||||||
MethodDefinition,
|
MethodDefinition,
|
||||||
PropertyDefinition,
|
PropertyDefinition,
|
||||||
|
|
@ -175,7 +174,6 @@ pub enum AstType {
|
||||||
JSXSpreadAttribute,
|
JSXSpreadAttribute,
|
||||||
JSXIdentifier,
|
JSXIdentifier,
|
||||||
JSXText,
|
JSXText,
|
||||||
ExpressionArrayElement,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Untyped AST Node Kind
|
/// Untyped AST Node Kind
|
||||||
|
|
@ -263,7 +261,6 @@ pub enum AstKind<'a> {
|
||||||
ArrowFunctionExpression(&'a ArrowFunctionExpression<'a>),
|
ArrowFunctionExpression(&'a ArrowFunctionExpression<'a>),
|
||||||
YieldExpression(&'a YieldExpression<'a>),
|
YieldExpression(&'a YieldExpression<'a>),
|
||||||
Class(&'a Class<'a>),
|
Class(&'a Class<'a>),
|
||||||
ClassHeritage(&'a Expression<'a>),
|
|
||||||
ClassBody(&'a ClassBody<'a>),
|
ClassBody(&'a ClassBody<'a>),
|
||||||
MethodDefinition(&'a MethodDefinition<'a>),
|
MethodDefinition(&'a MethodDefinition<'a>),
|
||||||
PropertyDefinition(&'a PropertyDefinition<'a>),
|
PropertyDefinition(&'a PropertyDefinition<'a>),
|
||||||
|
|
@ -348,7 +345,6 @@ pub enum AstKind<'a> {
|
||||||
JSXSpreadAttribute(&'a JSXSpreadAttribute<'a>),
|
JSXSpreadAttribute(&'a JSXSpreadAttribute<'a>),
|
||||||
JSXIdentifier(&'a JSXIdentifier<'a>),
|
JSXIdentifier(&'a JSXIdentifier<'a>),
|
||||||
JSXText(&'a JSXText<'a>),
|
JSXText(&'a JSXText<'a>),
|
||||||
ExpressionArrayElement(&'a Expression<'a>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> GetSpan for AstKind<'a> {
|
impl<'a> GetSpan for AstKind<'a> {
|
||||||
|
|
@ -437,7 +433,6 @@ impl<'a> GetSpan for AstKind<'a> {
|
||||||
Self::ArrowFunctionExpression(it) => it.span(),
|
Self::ArrowFunctionExpression(it) => it.span(),
|
||||||
Self::YieldExpression(it) => it.span(),
|
Self::YieldExpression(it) => it.span(),
|
||||||
Self::Class(it) => it.span(),
|
Self::Class(it) => it.span(),
|
||||||
Self::ClassHeritage(it) => it.span(),
|
|
||||||
Self::ClassBody(it) => it.span(),
|
Self::ClassBody(it) => it.span(),
|
||||||
Self::MethodDefinition(it) => it.span(),
|
Self::MethodDefinition(it) => it.span(),
|
||||||
Self::PropertyDefinition(it) => it.span(),
|
Self::PropertyDefinition(it) => it.span(),
|
||||||
|
|
@ -522,7 +517,6 @@ impl<'a> GetSpan for AstKind<'a> {
|
||||||
Self::JSXSpreadAttribute(it) => it.span(),
|
Self::JSXSpreadAttribute(it) => it.span(),
|
||||||
Self::JSXIdentifier(it) => it.span(),
|
Self::JSXIdentifier(it) => it.span(),
|
||||||
Self::JSXText(it) => it.span(),
|
Self::JSXText(it) => it.span(),
|
||||||
Self::ExpressionArrayElement(it) => it.span(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1266,15 +1260,6 @@ impl<'a> AstKind<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn as_class_heritage(&self) -> Option<&'a Expression<'a>> {
|
|
||||||
if let Self::ClassHeritage(v) = self {
|
|
||||||
Some(*v)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_class_body(&self) -> Option<&'a ClassBody<'a>> {
|
pub fn as_class_body(&self) -> Option<&'a ClassBody<'a>> {
|
||||||
if let Self::ClassBody(v) = self {
|
if let Self::ClassBody(v) = self {
|
||||||
|
|
@ -2034,13 +2019,4 @@ impl<'a> AstKind<'a> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn as_expression_array_element(&self) -> Option<&'a Expression<'a>> {
|
|
||||||
if let Self::ExpressionArrayElement(v) = self {
|
|
||||||
Some(*v)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -207,11 +207,6 @@ pub trait Visit<'a>: Sized {
|
||||||
walk_elision(self, it);
|
walk_elision(self, it);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_expression_array_element(&mut self, it: &Expression<'a>) {
|
|
||||||
walk_expression_array_element(self, it);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_arrow_function_expression(&mut self, it: &ArrowFunctionExpression<'a>) {
|
fn visit_arrow_function_expression(&mut self, it: &ArrowFunctionExpression<'a>) {
|
||||||
walk_arrow_function_expression(self, it);
|
walk_arrow_function_expression(self, it);
|
||||||
|
|
@ -801,11 +796,6 @@ pub trait Visit<'a>: Sized {
|
||||||
walk_class(self, it);
|
walk_class(self, it);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_class_heritage(&mut self, it: &Expression<'a>) {
|
|
||||||
walk_class_heritage(self, it);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_ts_class_implementses(&mut self, it: &Vec<'a, TSClassImplements<'a>>) {
|
fn visit_ts_class_implementses(&mut self, it: &Vec<'a, TSClassImplements<'a>>) {
|
||||||
walk_ts_class_implementses(self, it);
|
walk_ts_class_implementses(self, it);
|
||||||
|
|
@ -1670,7 +1660,7 @@ pub mod walk {
|
||||||
ArrayExpressionElement::SpreadElement(it) => visitor.visit_spread_element(it),
|
ArrayExpressionElement::SpreadElement(it) => visitor.visit_spread_element(it),
|
||||||
ArrayExpressionElement::Elision(it) => visitor.visit_elision(it),
|
ArrayExpressionElement::Elision(it) => visitor.visit_elision(it),
|
||||||
match_expression!(ArrayExpressionElement) => {
|
match_expression!(ArrayExpressionElement) => {
|
||||||
visitor.visit_expression_array_element(it.to_expression())
|
visitor.visit_expression(it.to_expression())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
visitor.leave_node(kind);
|
visitor.leave_node(kind);
|
||||||
|
|
@ -1691,13 +1681,6 @@ pub mod walk {
|
||||||
visitor.leave_node(kind);
|
visitor.leave_node(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_expression_array_element<'a, V: Visit<'a>>(visitor: &mut V, it: &Expression<'a>) {
|
|
||||||
let kind = AstKind::ExpressionArrayElement(visitor.alloc(it));
|
|
||||||
visitor.enter_node(kind);
|
|
||||||
visitor.visit_expression(it);
|
|
||||||
visitor.leave_node(kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn walk_arrow_function_expression<'a, V: Visit<'a>>(
|
pub fn walk_arrow_function_expression<'a, V: Visit<'a>>(
|
||||||
visitor: &mut V,
|
visitor: &mut V,
|
||||||
|
|
@ -2950,7 +2933,7 @@ pub mod walk {
|
||||||
visitor.visit_ts_type_parameter_declaration(type_parameters);
|
visitor.visit_ts_type_parameter_declaration(type_parameters);
|
||||||
}
|
}
|
||||||
if let Some(super_class) = &it.super_class {
|
if let Some(super_class) = &it.super_class {
|
||||||
visitor.visit_class_heritage(super_class);
|
visitor.visit_expression(super_class);
|
||||||
}
|
}
|
||||||
if let Some(super_type_parameters) = &it.super_type_parameters {
|
if let Some(super_type_parameters) = &it.super_type_parameters {
|
||||||
visitor.visit_ts_type_parameter_instantiation(super_type_parameters);
|
visitor.visit_ts_type_parameter_instantiation(super_type_parameters);
|
||||||
|
|
@ -2963,13 +2946,6 @@ pub mod walk {
|
||||||
visitor.leave_node(kind);
|
visitor.leave_node(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_class_heritage<'a, V: Visit<'a>>(visitor: &mut V, it: &Expression<'a>) {
|
|
||||||
let kind = AstKind::ClassHeritage(visitor.alloc(it));
|
|
||||||
visitor.enter_node(kind);
|
|
||||||
visitor.visit_expression(it);
|
|
||||||
visitor.leave_node(kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn walk_ts_class_implementses<'a, V: Visit<'a>>(
|
pub fn walk_ts_class_implementses<'a, V: Visit<'a>>(
|
||||||
visitor: &mut V,
|
visitor: &mut V,
|
||||||
|
|
|
||||||
|
|
@ -199,11 +199,6 @@ pub trait VisitMut<'a>: Sized {
|
||||||
walk_elision(self, it);
|
walk_elision(self, it);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_expression_array_element(&mut self, it: &mut Expression<'a>) {
|
|
||||||
walk_expression_array_element(self, it);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_arrow_function_expression(&mut self, it: &mut ArrowFunctionExpression<'a>) {
|
fn visit_arrow_function_expression(&mut self, it: &mut ArrowFunctionExpression<'a>) {
|
||||||
walk_arrow_function_expression(self, it);
|
walk_arrow_function_expression(self, it);
|
||||||
|
|
@ -796,11 +791,6 @@ pub trait VisitMut<'a>: Sized {
|
||||||
walk_class(self, it);
|
walk_class(self, it);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_class_heritage(&mut self, it: &mut Expression<'a>) {
|
|
||||||
walk_class_heritage(self, it);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_ts_class_implementses(&mut self, it: &mut Vec<'a, TSClassImplements<'a>>) {
|
fn visit_ts_class_implementses(&mut self, it: &mut Vec<'a, TSClassImplements<'a>>) {
|
||||||
walk_ts_class_implementses(self, it);
|
walk_ts_class_implementses(self, it);
|
||||||
|
|
@ -1689,7 +1679,7 @@ pub mod walk_mut {
|
||||||
ArrayExpressionElement::SpreadElement(it) => visitor.visit_spread_element(it),
|
ArrayExpressionElement::SpreadElement(it) => visitor.visit_spread_element(it),
|
||||||
ArrayExpressionElement::Elision(it) => visitor.visit_elision(it),
|
ArrayExpressionElement::Elision(it) => visitor.visit_elision(it),
|
||||||
match_expression!(ArrayExpressionElement) => {
|
match_expression!(ArrayExpressionElement) => {
|
||||||
visitor.visit_expression_array_element(it.to_expression_mut())
|
visitor.visit_expression(it.to_expression_mut())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
visitor.leave_node(kind);
|
visitor.leave_node(kind);
|
||||||
|
|
@ -1710,16 +1700,6 @@ pub mod walk_mut {
|
||||||
visitor.leave_node(kind);
|
visitor.leave_node(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_expression_array_element<'a, V: VisitMut<'a>>(
|
|
||||||
visitor: &mut V,
|
|
||||||
it: &mut Expression<'a>,
|
|
||||||
) {
|
|
||||||
let kind = AstType::ExpressionArrayElement;
|
|
||||||
visitor.enter_node(kind);
|
|
||||||
visitor.visit_expression(it);
|
|
||||||
visitor.leave_node(kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn walk_arrow_function_expression<'a, V: VisitMut<'a>>(
|
pub fn walk_arrow_function_expression<'a, V: VisitMut<'a>>(
|
||||||
visitor: &mut V,
|
visitor: &mut V,
|
||||||
|
|
@ -3077,7 +3057,7 @@ pub mod walk_mut {
|
||||||
visitor.visit_ts_type_parameter_declaration(type_parameters);
|
visitor.visit_ts_type_parameter_declaration(type_parameters);
|
||||||
}
|
}
|
||||||
if let Some(super_class) = &mut it.super_class {
|
if let Some(super_class) = &mut it.super_class {
|
||||||
visitor.visit_class_heritage(super_class);
|
visitor.visit_expression(super_class);
|
||||||
}
|
}
|
||||||
if let Some(super_type_parameters) = &mut it.super_type_parameters {
|
if let Some(super_type_parameters) = &mut it.super_type_parameters {
|
||||||
visitor.visit_ts_type_parameter_instantiation(super_type_parameters);
|
visitor.visit_ts_type_parameter_instantiation(super_type_parameters);
|
||||||
|
|
@ -3090,13 +3070,6 @@ pub mod walk_mut {
|
||||||
visitor.leave_node(kind);
|
visitor.leave_node(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_class_heritage<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut Expression<'a>) {
|
|
||||||
let kind = AstType::ClassHeritage;
|
|
||||||
visitor.enter_node(kind);
|
|
||||||
visitor.visit_expression(it);
|
|
||||||
visitor.leave_node(kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn walk_ts_class_implementses<'a, V: VisitMut<'a>>(
|
pub fn walk_ts_class_implementses<'a, V: VisitMut<'a>>(
|
||||||
visitor: &mut V,
|
visitor: &mut V,
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ impl<'s, 'a> Symbol<'s, 'a> {
|
||||||
// e.g. `const x = [function foo() {}]`
|
// e.g. `const x = [function foo() {}]`
|
||||||
// Only considered used if the array containing the symbol is used.
|
// Only considered used if the array containing the symbol is used.
|
||||||
| AstKind::ArrayExpressionElement(_)
|
| AstKind::ArrayExpressionElement(_)
|
||||||
| AstKind::ExpressionArrayElement(_)
|
|
||||||
| AstKind::ArrayExpression(_)
|
| AstKind::ArrayExpression(_)
|
||||||
// a ? b : function foo() {}
|
// a ? b : function foo() {}
|
||||||
// Only considered used if the function is the test or the selected branch,
|
// Only considered used if the function is the test or the selected branch,
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,6 @@ impl<'s, 'a> Symbol<'s, 'a> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
AstKind::VariableDeclaration(_)
|
AstKind::VariableDeclaration(_)
|
||||||
| AstKind::ExpressionArrayElement(_)
|
|
||||||
| AstKind::ArrayExpressionElement(_)
|
| AstKind::ArrayExpressionElement(_)
|
||||||
| AstKind::ArrayExpression(_)
|
| AstKind::ArrayExpression(_)
|
||||||
| AstKind::ParenthesizedExpression(_)
|
| AstKind::ParenthesizedExpression(_)
|
||||||
|
|
|
||||||
|
|
@ -293,12 +293,7 @@ fn get_parent_with_ignore<'a, 'b>(
|
||||||
let mut node = node;
|
let mut node = node;
|
||||||
loop {
|
loop {
|
||||||
let parent = ctx.nodes().parent_node(node.id())?;
|
let parent = ctx.nodes().parent_node(node.id())?;
|
||||||
if !matches!(
|
if !matches!(parent.kind(), AstKind::Argument(_) | AstKind::ArrayExpressionElement(_)) {
|
||||||
parent.kind(),
|
|
||||||
AstKind::Argument(_)
|
|
||||||
| AstKind::ExpressionArrayElement(_)
|
|
||||||
| AstKind::ArrayExpressionElement(_)
|
|
||||||
) {
|
|
||||||
// we don't want to report `Promise.all([invalidExpectCall_1, invalidExpectCall_2])` twice.
|
// we don't want to report `Promise.all([invalidExpectCall_1, invalidExpectCall_2])` twice.
|
||||||
// so we need mark whether the node is the first item of an array.
|
// so we need mark whether the node is the first item of an array.
|
||||||
// if it not the first item, we ignore it in `find_promise_call_expression_node`.
|
// if it not the first item, we ignore it in `find_promise_call_expression_node`.
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ impl Rule for PreferEventTarget {
|
||||||
};
|
};
|
||||||
|
|
||||||
match parent.kind() {
|
match parent.kind() {
|
||||||
AstKind::ClassHeritage(_) => {}
|
AstKind::Class(_) => {}
|
||||||
AstKind::NewExpression(new_expr) => {
|
AstKind::NewExpression(new_expr) => {
|
||||||
let Expression::Identifier(callee_ident) = &new_expr.callee else {
|
let Expression::Identifier(callee_ident) = &new_expr.callee else {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -734,7 +734,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
|
||||||
self.visit_ts_type_parameter_declaration(type_parameters);
|
self.visit_ts_type_parameter_declaration(type_parameters);
|
||||||
}
|
}
|
||||||
if let Some(super_class) = &class.super_class {
|
if let Some(super_class) = &class.super_class {
|
||||||
self.visit_class_heritage(super_class);
|
self.visit_expression(super_class);
|
||||||
}
|
}
|
||||||
if let Some(super_type_parameters) = &class.super_type_parameters {
|
if let Some(super_type_parameters) = &class.super_type_parameters {
|
||||||
self.visit_ts_type_parameter_instantiation(super_type_parameters);
|
self.visit_ts_type_parameter_instantiation(super_type_parameters);
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ SCOPES
|
||||||
"flags": "ReferenceFlags(Read)",
|
"flags": "ReferenceFlags(Read)",
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"name": "A",
|
"name": "A",
|
||||||
"node_id": 13
|
"node_id": 12
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -67,7 +67,7 @@ SCOPES
|
||||||
"flags": "ReferenceFlags(Type)",
|
"flags": "ReferenceFlags(Type)",
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"name": "T",
|
"name": "T",
|
||||||
"node_id": 17
|
"node_id": 16
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ SCOPES
|
||||||
"flags": "ReferenceFlags(Read)",
|
"flags": "ReferenceFlags(Read)",
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"name": "A",
|
"name": "A",
|
||||||
"node_id": 7
|
"node_id": 6
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ SCOPES
|
||||||
"flags": "ReferenceFlags(Type)",
|
"flags": "ReferenceFlags(Type)",
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"name": "A",
|
"name": "A",
|
||||||
"node_id": 11
|
"node_id": 10
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ SCOPES
|
||||||
"flags": "ReferenceFlags(Read)",
|
"flags": "ReferenceFlags(Read)",
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"name": "A",
|
"name": "A",
|
||||||
"node_id": 9
|
"node_id": 8
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ SCOPES
|
||||||
"flags": "ReferenceFlags(Read)",
|
"flags": "ReferenceFlags(Read)",
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"name": "A",
|
"name": "A",
|
||||||
"node_id": 7
|
"node_id": 6
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,11 +84,6 @@ pub fn blacklist((ident, _): &(Ident, Type)) -> bool {
|
||||||
!BLACK_LIST.contains(&ident.to_string().as_str())
|
!BLACK_LIST.contains(&ident.to_string().as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn aliased_nodes() -> [(Ident, Type); 1] {
|
|
||||||
use syn::parse_quote as pq;
|
|
||||||
[(pq!(ExpressionArrayElement), pq!(Expression<'a>))]
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn process_types(def: &TypeDef, _: &LateCtx) -> Vec<(Ident, Type)> {
|
pub fn process_types(def: &TypeDef, _: &LateCtx) -> Vec<(Ident, Type)> {
|
||||||
let aliases = match def {
|
let aliases = match def {
|
||||||
TypeDef::Enum(enum_) => enum_
|
TypeDef::Enum(enum_) => enum_
|
||||||
|
|
@ -140,7 +135,6 @@ impl Generator for AstKindGenerator {
|
||||||
)
|
)
|
||||||
.flat_map(|it| process_types(it, ctx))
|
.flat_map(|it| process_types(it, ctx))
|
||||||
.filter(blacklist)
|
.filter(blacklist)
|
||||||
.chain(aliased_nodes())
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let types: Vec<Variant> =
|
let types: Vec<Variant> =
|
||||||
|
|
|
||||||
|
|
@ -272,26 +272,6 @@ impl<'a> VisitBuilder<'a> {
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
match def {
|
match def {
|
||||||
// TODO: this one is a hot-fix to prevent flattening aliased `Expression`s,
|
|
||||||
// Such as `ExpressionArrayElement` and `ClassHeritage`.
|
|
||||||
// Shouldn't be an edge case, <https://github.com/oxc-project/oxc/issues/4060>
|
|
||||||
TypeDef::Enum(enum_)
|
|
||||||
if enum_.name == "Expression"
|
|
||||||
&& visit_as.as_ref().is_some_and(|it| {
|
|
||||||
it == "ExpressionArrayElement" || it == "ClassHeritage"
|
|
||||||
}) =>
|
|
||||||
{
|
|
||||||
let kind = self.kind_type(visit_as.as_ref().unwrap());
|
|
||||||
(
|
|
||||||
quote! {
|
|
||||||
let kind = #kind;
|
|
||||||
visitor.enter_node(kind);
|
|
||||||
visitor.visit_expression(it);
|
|
||||||
visitor.leave_node(kind);
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
TypeDef::Enum(enum_) => self.generate_enum_walk(enum_, visit_as),
|
TypeDef::Enum(enum_) => self.generate_enum_walk(enum_, visit_as),
|
||||||
TypeDef::Struct(struct_) => self.generate_struct_walk(struct_, visit_as),
|
TypeDef::Struct(struct_) => self.generate_struct_walk(struct_, visit_as),
|
||||||
}
|
}
|
||||||
|
|
@ -378,20 +358,12 @@ impl<'a> VisitBuilder<'a> {
|
||||||
let snake_name = type_name.to_case(Case::Snake);
|
let snake_name = type_name.to_case(Case::Snake);
|
||||||
let match_macro = format_ident!("match_{snake_name}");
|
let match_macro = format_ident!("match_{snake_name}");
|
||||||
let match_macro = quote!(#match_macro!(#ident));
|
let match_macro = quote!(#match_macro!(#ident));
|
||||||
// HACK: edge case till we get attributes to work with inheritance.
|
|
||||||
let visit_as = if ident == "ArrayExpressionElement"
|
|
||||||
&& super_.name().inner_name() == "Expression"
|
|
||||||
{
|
|
||||||
Some(format_ident!("ExpressionArrayElement"))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
let to_child = if self.is_mut {
|
let to_child = if self.is_mut {
|
||||||
format_ident!("to_{snake_name}_mut")
|
format_ident!("to_{snake_name}_mut")
|
||||||
} else {
|
} else {
|
||||||
format_ident!("to_{snake_name}")
|
format_ident!("to_{snake_name}")
|
||||||
};
|
};
|
||||||
let visit = self.get_visitor(def, false, visit_as);
|
let visit = self.get_visitor(def, false, None);
|
||||||
Some(quote!(#match_macro => visitor.#visit(it.#to_child())))
|
Some(quote!(#match_macro => visitor.#visit(it.#to_child())))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue