refactor(ast): s/ArrowExpression/ArrowFunctionExpression to align estree

This commit is contained in:
Boshen 2024-02-21 21:14:46 +08:00
parent ff6a337453
commit e6b391a24f
51 changed files with 102 additions and 93 deletions

View file

@ -58,7 +58,7 @@ pub enum Expression<'a> {
Super(Box<'a, Super>),
ArrayExpression(Box<'a, ArrayExpression<'a>>),
ArrowExpression(Box<'a, ArrowExpression<'a>>),
ArrowFunctionExpression(Box<'a, ArrowFunctionExpression<'a>>),
AssignmentExpression(Box<'a, AssignmentExpression<'a>>),
AwaitExpression(Box<'a, AwaitExpression<'a>>),
BinaryExpression(Box<'a, BinaryExpression<'a>>),
@ -238,7 +238,7 @@ impl<'a> Expression<'a> {
}
pub fn is_function(&self) -> bool {
matches!(self, Expression::FunctionExpression(_) | Expression::ArrowExpression(_))
matches!(self, Expression::FunctionExpression(_) | Expression::ArrowFunctionExpression(_))
}
pub fn is_call_expression(&self) -> bool {
@ -1852,7 +1852,7 @@ impl<'a> FunctionBody<'a> {
#[derive(Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))]
#[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))]
pub struct ArrowExpression<'a> {
pub struct ArrowFunctionExpression<'a> {
pub span: Span,
/// Is the function body an arrow expression? i.e. `() => expr` instead of `() => {}`
pub expression: bool,
@ -1865,8 +1865,8 @@ pub struct ArrowExpression<'a> {
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
}
impl<'a> ArrowExpression<'a> {
/// Get expression part of `ArrowExpression`: `() => expression_part`.
impl<'a> ArrowFunctionExpression<'a> {
/// Get expression part of `ArrowFunctionExpression`: `() => expression_part`.
pub fn get_expression(&self) -> Option<&Expression<'a>> {
if self.expression {
if let Statement::ExpressionStatement(expr_stmt) = &self.body.statements[0] {

View file

@ -412,7 +412,7 @@ impl<'a> AstBuilder<'a> {
type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
) -> Expression<'a> {
Expression::ArrowExpression(self.alloc(ArrowExpression {
Expression::ArrowFunctionExpression(self.alloc(ArrowFunctionExpression {
span,
expression,
r#async,

View file

@ -57,7 +57,7 @@ pub enum AstKind<'a> {
Super(&'a Super),
ArrayExpression(&'a ArrayExpression<'a>),
ArrowExpression(&'a ArrowExpression<'a>),
ArrowFunctionExpression(&'a ArrowFunctionExpression<'a>),
AssignmentExpression(&'a AssignmentExpression<'a>),
AwaitExpression(&'a AwaitExpression<'a>),
BinaryExpression(&'a BinaryExpression<'a>),
@ -243,7 +243,7 @@ impl<'a> AstKind<'a> {
}
pub fn is_function_like(self) -> bool {
matches!(self, Self::Function(_) | Self::ArrowExpression(_))
matches!(self, Self::Function(_) | Self::ArrowFunctionExpression(_))
}
pub fn identifier_name(self) -> Option<Atom> {
@ -289,7 +289,7 @@ impl<'a> AstKind<'a> {
Expression::MetaProperty(e) => Self::MetaProperty(e),
Expression::Super(e) => Self::Super(e),
Expression::ArrayExpression(e) => Self::ArrayExpression(e),
Expression::ArrowExpression(e) => Self::ArrowExpression(e),
Expression::ArrowFunctionExpression(e) => Self::ArrowFunctionExpression(e),
Expression::AssignmentExpression(e) => Self::AssignmentExpression(e),
Expression::AwaitExpression(e) => Self::AwaitExpression(e),
Expression::BinaryExpression(e) => Self::BinaryExpression(e),
@ -377,7 +377,7 @@ impl<'a> GetSpan for AstKind<'a> {
Self::Super(x) => x.span,
Self::ArrayExpression(x) => x.span,
Self::ArrowExpression(x) => x.span,
Self::ArrowFunctionExpression(x) => x.span,
Self::AssignmentExpression(x) => x.span,
Self::AwaitExpression(x) => x.span,
Self::BinaryExpression(x) => x.span,
@ -557,7 +557,7 @@ impl<'a> AstKind<'a> {
Self::Super(_) => "Super".into(),
Self::ArrayExpression(_) => "ArrayExpression".into(),
Self::ArrowExpression(_) => "ArrowExpression".into(),
Self::ArrowFunctionExpression(_) => "ArrowFunctionExpression".into(),
Self::AssignmentExpression(_) => "AssignmentExpression".into(),
Self::AwaitExpression(_) => "AwaitExpression".into(),
Self::BinaryExpression(b) => format!("BinaryExpression{}", b.operator.as_str()).into(),

View file

@ -1,9 +1,10 @@
use oxc_syntax::precedence::{GetPrecedence, Precedence};
use crate::ast::{
ArrowExpression, AssignmentExpression, AwaitExpression, BinaryExpression, CallExpression,
ConditionalExpression, Expression, ImportExpression, LogicalExpression, MemberExpression,
NewExpression, SequenceExpression, UnaryExpression, UpdateExpression, YieldExpression,
ArrowFunctionExpression, AssignmentExpression, AwaitExpression, BinaryExpression,
CallExpression, ConditionalExpression, Expression, ImportExpression, LogicalExpression,
MemberExpression, NewExpression, SequenceExpression, UnaryExpression, UpdateExpression,
YieldExpression,
};
impl<'a> GetPrecedence for Expression<'a> {
@ -12,7 +13,7 @@ impl<'a> GetPrecedence for Expression<'a> {
Self::SequenceExpression(expr) => expr.precedence(),
Self::AssignmentExpression(expr) => expr.precedence(),
Self::YieldExpression(expr) => expr.precedence(),
Self::ArrowExpression(expr) => expr.precedence(),
Self::ArrowFunctionExpression(expr) => expr.precedence(),
Self::ConditionalExpression(expr) => expr.precedence(),
Self::LogicalExpression(expr) => expr.precedence(),
Self::BinaryExpression(expr) => expr.precedence(),
@ -39,7 +40,7 @@ impl<'a> GetPrecedence for YieldExpression<'a> {
}
}
impl<'a> GetPrecedence for ArrowExpression<'a> {
impl<'a> GetPrecedence for ArrowFunctionExpression<'a> {
fn precedence(&self) -> Precedence {
Precedence::Arrow
}

View file

@ -43,7 +43,7 @@ impl<'a> GetSpan for Expression<'a> {
Self::MetaProperty(e) => e.span,
Self::Super(e) => e.span,
Self::ArrayExpression(e) => e.span,
Self::ArrowExpression(e) => e.span,
Self::ArrowFunctionExpression(e) => e.span,
Self::AssignmentExpression(e) => e.span,
Self::AwaitExpression(e) => e.span,
Self::BinaryExpression(e) => e.span,

View file

@ -562,7 +562,7 @@ pub trait Visit<'a>: Sized {
Expression::MetaProperty(meta) => self.visit_meta_property(meta),
Expression::ArrayExpression(expr) => self.visit_array_expression(expr),
Expression::ArrowExpression(expr) => self.visit_arrow_expression(expr),
Expression::ArrowFunctionExpression(expr) => self.visit_arrow_expression(expr),
Expression::AssignmentExpression(expr) => self.visit_assignment_expression(expr),
Expression::AwaitExpression(expr) => self.visit_await_expression(expr),
Expression::BinaryExpression(expr) => self.visit_binary_expression(expr),
@ -669,8 +669,8 @@ pub trait Visit<'a>: Sized {
self.leave_node(kind);
}
fn visit_arrow_expression(&mut self, expr: &ArrowExpression<'a>) {
let kind = AstKind::ArrowExpression(self.alloc(expr));
fn visit_arrow_expression(&mut self, expr: &ArrowFunctionExpression<'a>) {
let kind = AstKind::ArrowFunctionExpression(self.alloc(expr));
self.enter_scope(ScopeFlags::Function | ScopeFlags::Arrow);
self.enter_node(kind);
self.visit_formal_parameters(&expr.params);

View file

@ -555,7 +555,7 @@ pub trait VisitMut<'a>: Sized {
Expression::MetaProperty(meta) => self.visit_meta_property(meta),
Expression::ArrayExpression(expr) => self.visit_array_expression(expr),
Expression::ArrowExpression(expr) => self.visit_arrow_expression(expr),
Expression::ArrowFunctionExpression(expr) => self.visit_arrow_expression(expr),
Expression::AssignmentExpression(expr) => self.visit_assignment_expression(expr),
Expression::AwaitExpression(expr) => self.visit_await_expression(expr),
Expression::BinaryExpression(expr) => self.visit_binary_expression(expr),
@ -659,8 +659,8 @@ pub trait VisitMut<'a>: Sized {
self.leave_node(kind);
}
fn visit_arrow_expression(&mut self, expr: &mut ArrowExpression<'a>) {
let kind = AstKind::ArrowExpression(self.alloc(expr));
fn visit_arrow_expression(&mut self, expr: &mut ArrowFunctionExpression<'a>) {
let kind = AstKind::ArrowFunctionExpression(self.alloc(expr));
self.enter_scope(ScopeFlags::Function | ScopeFlags::Arrow);
self.enter_node(kind);
self.visit_formal_parameters(&mut expr.params);

View file

@ -927,7 +927,7 @@ impl<'a, const MINIFY: bool> GenExpr<MINIFY> for Expression<'a> {
Self::ArrayExpression(expr) => expr.gen(p, ctx),
Self::ObjectExpression(expr) => expr.gen_expr(p, precedence, ctx),
Self::FunctionExpression(expr) => expr.gen(p, ctx),
Self::ArrowExpression(expr) => expr.gen_expr(p, precedence, ctx),
Self::ArrowFunctionExpression(expr) => expr.gen_expr(p, precedence, ctx),
Self::YieldExpression(expr) => expr.gen_expr(p, precedence, ctx),
Self::UpdateExpression(expr) => expr.gen_expr(p, precedence, ctx),
Self::UnaryExpression(expr) => expr.gen_expr(p, precedence, ctx),
@ -1465,7 +1465,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for PropertyKey<'a> {
}
}
impl<'a, const MINIFY: bool> GenExpr<MINIFY> for ArrowExpression<'a> {
impl<'a, const MINIFY: bool> GenExpr<MINIFY> for ArrowFunctionExpression<'a> {
fn gen_expr(&self, p: &mut Codegen<{ MINIFY }>, precedence: Precedence, ctx: Context) {
p.wrap(precedence > Precedence::Assign, |p| {
if self.r#async {

View file

@ -77,7 +77,7 @@ pub trait IsConstant<'a, 'b> {
impl<'a, 'b> IsConstant<'a, 'b> for Expression<'a> {
fn is_constant(&self, in_boolean_position: bool, ctx: &LintContext<'a>) -> bool {
match self {
Self::ArrowExpression(_)
Self::ArrowFunctionExpression(_)
| Self::FunctionExpression(_)
| Self::ClassExpression(_)
| Self::ObjectExpression(_) => true,
@ -202,7 +202,7 @@ impl<'a> IsPrivate for PropertyDefinition<'a> {
}
}
/// Return the innermost `Function` or `ArrowExpression` Node
/// Return the innermost `Function` or `ArrowFunctionExpression` Node
/// enclosing the specified node
pub fn get_enclosing_function<'a, 'b>(
node: &'b AstNode<'a>,
@ -213,7 +213,8 @@ pub fn get_enclosing_function<'a, 'b>(
if matches!(current_node.kind(), AstKind::Program(_)) {
return None;
}
if matches!(current_node.kind(), AstKind::Function(_) | AstKind::ArrowExpression(_)) {
if matches!(current_node.kind(), AstKind::Function(_) | AstKind::ArrowFunctionExpression(_))
{
return Some(current_node);
}
current_node = ctx.nodes().parent_node(current_node.id()).unwrap();

View file

@ -53,7 +53,9 @@ impl MissingThrow {
for node_id in node_ancestors {
match ctx.nodes().kind(node_id) {
// ignore arrow `const foo = () => new Error()`
AstKind::ArrowExpression(arrow_expr) if arrow_expr.expression => return false,
AstKind::ArrowFunctionExpression(arrow_expr) if arrow_expr.expression => {
return false
}
AstKind::ArrayExpression(_) | AstKind::Function(_) => break,
_ => {}
}

View file

@ -85,7 +85,9 @@ impl Rule for ArrayCallbackReturn {
let (function_body, always_explicit_return) = match node.kind() {
// Async, generator, and single expression arrow functions
// always have explicit return value
AstKind::ArrowExpression(arrow) => (&arrow.body, arrow.r#async || arrow.expression),
AstKind::ArrowFunctionExpression(arrow) => {
(&arrow.body, arrow.r#async || arrow.expression)
}
AstKind::Function(function) => {
if let Some(body) = &function.body {
(body, function.r#async || function.generator)
@ -136,7 +138,7 @@ impl Rule for ArrayCallbackReturn {
}
/// Code ported from [eslint](https://github.com/eslint/eslint/blob/main/lib/rules/array-callback-return.js)
/// We're currently on a `Function` or `ArrowExpression`, findout if it is an argument
/// We're currently on a `Function` or `ArrowFunctionExpression`, findout if it is an argument
/// to the target array methods we're interested in.
pub fn get_array_method_name<'a>(
node: &AstNode<'a>,

View file

@ -59,7 +59,7 @@ impl Rule for GetterReturn {
AstKind::Function(func) if !func.is_typescript_syntax() => {
self.run_diagnostic(node, ctx, func.span);
}
AstKind::ArrowExpression(expr) => {
AstKind::ArrowFunctionExpression(expr) => {
self.run_diagnostic(node, ctx, expr.span);
}
_ => {}

View file

@ -59,7 +59,7 @@ impl Rule for NoAsyncPromiseExecutor {
return;
};
let mut span = match expression.get_inner_expression() {
Expression::ArrowExpression(arrow) if arrow.r#async => arrow.span,
Expression::ArrowFunctionExpression(arrow) if arrow.r#async => arrow.span,
Expression::FunctionExpression(func) if func.r#async => func.span,
_ => return,

View file

@ -78,7 +78,7 @@ impl Rule for NoCondAssign {
Self::emit_diagnostic(ctx, expr);
}
AstKind::Function(_)
| AstKind::ArrowExpression(_)
| AstKind::ArrowFunctionExpression(_)
| AstKind::Program(_) => break,
_ => {}
}

View file

@ -158,7 +158,7 @@ impl NoConstantBinaryExpression {
match expr.get_inner_expression() {
Expression::ObjectExpression(_)
| Expression::ArrayExpression(_)
| Expression::ArrowExpression(_)
| Expression::ArrowFunctionExpression(_)
| Expression::FunctionExpression(_)
| Expression::ClassExpression(_)
| Expression::NewExpression(_)
@ -236,7 +236,7 @@ impl NoConstantBinaryExpression {
match expr {
Expression::ObjectExpression(_)
| Expression::ClassExpression(_)
| Expression::ArrowExpression(_)
| Expression::ArrowFunctionExpression(_)
| Expression::FunctionExpression(_) => true,
Expression::ArrayExpression(array_expr) => {
array_expr.elements.is_empty()
@ -282,7 +282,7 @@ impl NoConstantBinaryExpression {
match expr {
Expression::ObjectExpression(_)
| Expression::ArrayExpression(_)
| Expression::ArrowExpression(_)
| Expression::ArrowFunctionExpression(_)
| Expression::FunctionExpression(_)
| Expression::NewExpression(_)
| Expression::TemplateLiteral(_)
@ -342,7 +342,7 @@ impl NoConstantBinaryExpression {
match expr {
Expression::ObjectExpression(_)
| Expression::ArrayExpression(_)
| Expression::ArrowExpression(_)
| Expression::ArrowFunctionExpression(_)
| Expression::FunctionExpression(_)
| Expression::ClassExpression(_)
| Expression::RegExpLiteral(_) => true,

View file

@ -53,7 +53,7 @@ fn is_in_tail_call_position<'a>(node: &AstNode<'a>, ctx: &LintContext<'a>) -> bo
if let Some(parent) = ctx.nodes().parent_node(node.id()) {
let parent_kind = parent.kind();
match parent_kind {
AstKind::ArrowExpression(arrow_expr) => {
AstKind::ArrowFunctionExpression(arrow_expr) => {
// async () => { await b(); })
// `epxression` property is false
return arrow_expr.expression;

View file

@ -64,7 +64,7 @@ impl Rule for NoThisBeforeSuper {
let mut basic_blocks_with_local_violations = HashMap::<NodeIndex, Vec<AstNodeId>>::new();
for node in semantic.nodes().iter() {
match node.kind() {
AstKind::Function(_) | AstKind::ArrowExpression(_) => {
AstKind::Function(_) | AstKind::ArrowFunctionExpression(_) => {
if Self::is_wanted_node(node, ctx) {
wanted_nodes.push(node);
}

View file

@ -162,7 +162,7 @@ fn check_assert_function_used<'a>(
return check_statements(&body.statements, assert_function_names, ctx);
}
}
Expression::ArrowExpression(arrow_expr) => {
Expression::ArrowFunctionExpression(arrow_expr) => {
let body = &arrow_expr.body;
return check_statements(&body.statements, assert_function_names, ctx);
}

View file

@ -135,7 +135,7 @@ fn run<'a>(possible_jest_node: &PossibleJestNode<'a, '_>, ctx: &LintContext<'a>)
ctx.diagnostic(NoDoneCallbackDiagnostic::NoDoneCallback(span));
}
Expression::ArrowExpression(arrow_expr) => {
Expression::ArrowFunctionExpression(arrow_expr) => {
if arrow_expr.params.parameters_count() != 1 + callback_arg_index {
return;
}

View file

@ -174,7 +174,7 @@ fn is_correct_place_to_call_expect<'a>(
};
}
}
AstKind::ArrowExpression(_) => {
AstKind::ArrowFunctionExpression(_) => {
let grandparent = ctx.nodes().parent_node(parent.id())?;
// `test('foo', () => expect(1).toBe(1))`
// `const foo = () => expect(1).toBe(1)`

View file

@ -79,7 +79,7 @@ fn check_call_expression<'a>(
continue;
};
match arg_expr {
Expression::ArrowExpression(arrow_expr) => {
Expression::ArrowFunctionExpression(arrow_expr) => {
check_test_return_statement(&arrow_expr.body, ctx);
}
Expression::FunctionExpression(func_expr) => {

View file

@ -120,7 +120,7 @@ fn is_string_type(arg: &Argument) -> bool {
fn is_empty_function(expr: &CallExpression) -> bool {
match &expr.arguments[1] {
Argument::Expression(Expression::ArrowExpression(arrow)) => arrow.body.is_empty(),
Argument::Expression(Expression::ArrowFunctionExpression(arrow)) => arrow.body.is_empty(),
Argument::Expression(Expression::FunctionExpression(func)) => {
let Some(func_body) = &func.body else {
return false;

View file

@ -113,7 +113,7 @@ fn run<'a>(possible_jest_node: &PossibleJestNode<'a, '_>, ctx: &LintContext<'a>)
diagnostic(ctx, span, Message::UnexpectedReturnInDescribe);
}
}
Expression::ArrowExpression(arrow_expr) => {
Expression::ArrowFunctionExpression(arrow_expr) => {
if arrow_expr.r#async {
diagnostic(ctx, arrow_expr.span, Message::NoAsyncDescribeCallback);
}

View file

@ -249,7 +249,7 @@ fn is_acceptable_return_node<'a, 'b>(
let Some(parent) = ctx.nodes().parent_node(node.id()) else { return false };
node = parent;
}
AstKind::ArrowExpression(arrow_expr) => return arrow_expr.expression,
AstKind::ArrowFunctionExpression(arrow_expr) => return arrow_expr.expression,
AstKind::AwaitExpression(_) => return true,
_ => return false,
}

View file

@ -99,7 +99,7 @@ impl Rule for NoAsyncClientComponent {
{
// `binding_ident.name` MUST be > 0 chars
if binding_ident.name.chars().next().unwrap().is_uppercase() {
if let Some(Expression::ArrowExpression(arrow_expr)) =
if let Some(Expression::ArrowFunctionExpression(arrow_expr)) =
&var_declarator.init
{
if arrow_expr.r#async {

View file

@ -90,7 +90,7 @@ fn is_in_array_or_iter<'a, 'b>(
};
match parent.kind() {
AstKind::ArrowExpression(arrow_expr) => {
AstKind::ArrowFunctionExpression(arrow_expr) => {
let is_arrow_expr_statement = matches!(
arrow_expr.body.statements.first(),
Some(Statement::ExpressionStatement(_))

View file

@ -59,7 +59,7 @@ impl Rule for NoRenderReturnValue {
let scope_id = parent_node.scope_id();
if ctx.scopes().get_flags(scope_id).is_arrow() {
if let AstKind::ArrowExpression(e) =
if let AstKind::ArrowFunctionExpression(e) =
ctx.nodes().kind(ctx.scopes().get_node_id(scope_id))
{
if e.expression {

View file

@ -72,7 +72,7 @@ impl Rule for RequireRenderReturn {
ClassElement::PropertyDefinition(pd)
if pd.key.is_specific_static_name("render") =>
{
if let Some(Expression::ArrowExpression(ref ae)) = pd.value {
if let Some(Expression::ArrowFunctionExpression(ref ae)) = pd.value {
Some((&ae.body, ae.expression))
} else {
None

View file

@ -71,7 +71,7 @@ fn check_jsx_element<'a>(jsx_elem: &JSXElement<'a>, ctx: &LintContext<'a>) {
fn check_expression(expr: &Expression) -> Option<Span> {
match expr.without_parenthesized() {
Expression::ArrowExpression(expr) => Some(expr.span),
Expression::ArrowFunctionExpression(expr) => Some(expr.span),
Expression::FunctionExpression(expr) => Some(expr.span),
Expression::CallExpression(expr) => {
if is_constructor_matching_name(&expr.callee, "Function") {

View file

@ -148,7 +148,7 @@ impl CatchErrorName {
let expr = expr.without_parenthesized();
if let Expression::ArrowExpression(arrow_expr) = expr {
if let Expression::ArrowFunctionExpression(arrow_expr) = expr {
if let Some(arg0) = arrow_expr.params.items.first() {
if let BindingPatternKind::BindingIdentifier(v) = &arg0.pattern.kind {
if self.is_name_allowed(&v.name) {

View file

@ -104,7 +104,7 @@ fn is_simple_operation(node: &CallExpression) -> bool {
};
let function_body = match callback_arg {
// `array.reduce((accumulator, element) => accumulator + element)`
Expression::ArrowExpression(callback) => &callback.body,
Expression::ArrowFunctionExpression(callback) => &callback.body,
Expression::FunctionExpression(callback) => {
let Some(body) = &callback.body else {
return false;

View file

@ -81,7 +81,7 @@ impl Rule for NoInvalidRemoveEventListener {
if !matches!(
listener,
Expression::FunctionExpression(_)
| Expression::ArrowExpression(_)
| Expression::ArrowFunctionExpression(_)
| Expression::CallExpression(_)
) {
return;
@ -106,7 +106,7 @@ impl Rule for NoInvalidRemoveEventListener {
Expression::FunctionExpression(func_expr) => {
Span::new(func_expr.span.start, func_expr.params.span.end)
}
Expression::ArrowExpression(arrow_expr) => {
Expression::ArrowFunctionExpression(arrow_expr) => {
Span::new(arrow_expr.span.start, arrow_expr.body.span.start)
}
Expression::CallExpression(_) => listener_span,

View file

@ -76,7 +76,7 @@ impl Rule for NoUnnecessaryAwait {
fn not_promise(expr: &Expression) -> bool {
match expr {
Expression::ArrayExpression(_)
| Expression::ArrowExpression(_)
| Expression::ArrowFunctionExpression(_)
| Expression::AwaitExpression(_)
| Expression::BinaryExpression(_)
| Expression::ClassExpression(_)

View file

@ -55,7 +55,8 @@ impl Rule for NoUnreadableIife {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
let AstKind::CallExpression(call_expr) = node.kind() else { return };
let Expression::ArrowExpression(arrow_expr) = &call_expr.callee.without_parenthesized()
let Expression::ArrowFunctionExpression(arrow_expr) =
&call_expr.callee.without_parenthesized()
else {
return;
};

View file

@ -114,7 +114,7 @@ fn get_function_like_node<'a, 'b>(
};
match fnx.kind() {
AstKind::ArrowExpression(arrow_expr) => Some((arrow_expr.r#async, parent)),
AstKind::ArrowFunctionExpression(arrow_expr) => Some((arrow_expr.r#async, parent)),
AstKind::Function(func) => Some((func.r#async, parent)),
_ => None,
}

View file

@ -83,7 +83,7 @@ fn check_array_flat_map_case<'a>(call_expr: &CallExpression<'a>, ctx: &LintConte
return;
};
let Expression::ArrowExpression(first_argument) = first_argument else {
let Expression::ArrowFunctionExpression(first_argument) = first_argument else {
return;
};
@ -112,7 +112,7 @@ fn check_array_reduce_case<'a>(call_expr: &CallExpression<'a>, ctx: &LintContext
if !is_method_call(call_expr, None, Some(&["reduce"]), Some(2), Some(2)) {
return;
}
let Argument::Expression(Expression::ArrowExpression(first_argument)) =
let Argument::Expression(Expression::ArrowFunctionExpression(first_argument)) =
call_expr.arguments.first().unwrap()
else {
return;

View file

@ -70,7 +70,7 @@ impl Rule for PreferDomNodeRemove {
if matches!(
expr,
Expression::ArrayExpression(_)
| Expression::ArrowExpression(_)
| Expression::ArrowFunctionExpression(_)
| Expression::ClassExpression(_)
| Expression::FunctionExpression(_)
| Expression::ObjectExpression(_)

View file

@ -55,7 +55,7 @@ declare_oxc_lint!(
impl Rule for PreferNativeCoercionFunctions {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
match node.kind() {
AstKind::ArrowExpression(arrow_expr) => {
AstKind::ArrowFunctionExpression(arrow_expr) => {
if arrow_expr.r#async || arrow_expr.params.items.len() == 0 {
return;
}

View file

@ -16,7 +16,7 @@ pub fn is_node_value_not_dom_node(expr: &Expression) -> bool {
matches!(
expr,
Expression::ArrayExpression(_)
| Expression::ArrowExpression(_)
| Expression::ArrowFunctionExpression(_)
| Expression::ClassExpression(_)
| Expression::FunctionExpression(_)
| Expression::ObjectExpression(_)

View file

@ -30,7 +30,7 @@ pub trait IsLiteralValue<'a, 'b> {
impl<'a, 'b> IsLiteralValue<'a, 'b> for Expression<'a> {
fn is_literal_value(&self, include_functions: bool) -> bool {
match self {
Self::FunctionExpression(_) | Self::ArrowExpression(_) => include_functions,
Self::FunctionExpression(_) | Self::ArrowFunctionExpression(_) => include_functions,
Self::ArrayExpression(expr) => {
expr.elements.iter().all(|element| element.is_literal_value(include_functions))
}
@ -460,7 +460,7 @@ pub fn get_boolean_value(expr: &Expression) -> Option<bool> {
match expr {
Expression::RegExpLiteral(_)
| Expression::ArrayExpression(_)
| Expression::ArrowExpression(_)
| Expression::ArrowFunctionExpression(_)
| Expression::ClassExpression(_)
| Expression::FunctionExpression(_)
| Expression::NewExpression(_)

View file

@ -565,7 +565,7 @@ impl<'a> Compressor<'a> {
) -> Option<Expression<'a>> {
if argument.is_literal_value(true) {
let type_name = match argument {
Expression::FunctionExpression(_) | Expression::ArrowExpression(_) => {
Expression::FunctionExpression(_) | Expression::ArrowFunctionExpression(_) => {
Some("function")
}
Expression::StringLiteral(_) | Expression::TemplateLiteral(_) => Some("string"),

View file

@ -7,7 +7,7 @@ use crate::{
pub(super) fn print_arrow_function<'a>(
p: &mut Prettier<'a>,
expr: &ArrowExpression<'a>,
expr: &ArrowFunctionExpression<'a>,
) -> Doc<'a> {
let mut parts = p.vec();

View file

@ -162,11 +162,11 @@ fn choose_layout<'a>(
if should_use_chain_formatting {
if !is_tail {
return Layout::Chain;
} else if let Expression::ArrowExpression(arrow_expr) = right_expr {
} else if let Expression::ArrowFunctionExpression(arrow_expr) = right_expr {
if let Some(Statement::ExpressionStatement(expr_stmt)) =
arrow_expr.body.statements.first()
{
if let Expression::ArrowExpression(_) = expr_stmt.expression {
if let Expression::ArrowFunctionExpression(_) = expr_stmt.expression {
return Layout::ChainTailArrowChain;
}
}
@ -279,7 +279,7 @@ fn has_complex_type_annotation(expr: &AssignmentLikeNode) -> bool {
fn is_arrow_function_variable_declarator(expr: &AssignmentLikeNode) -> bool {
match expr {
AssignmentLikeNode::VariableDeclarator(variable_declarator) => {
if let Some(Expression::ArrowExpression(_)) = &variable_declarator.init {
if let Some(Expression::ArrowFunctionExpression(_)) = &variable_declarator.init {
return true;
}
false

View file

@ -30,7 +30,7 @@ pub(super) fn print_block<'a>(
&& !(matches!(
parent,
AstKind::FunctionBody(_)
| AstKind::ArrowExpression(_)
| AstKind::ArrowFunctionExpression(_)
| AstKind::ObjectExpression(_)
| AstKind::Function(_)
| AstKind::ForStatement(_)

View file

@ -190,7 +190,7 @@ fn should_expand_first_arg<'a>(arguments: &Vec<'a, Argument<'a>>) -> bool {
let first_check = match first_arg {
Expression::FunctionExpression(_) => true,
Expression::ArrowExpression(arrow) => !arrow.expression,
Expression::ArrowFunctionExpression(arrow) => !arrow.expression,
_ => false,
};
@ -198,7 +198,7 @@ fn should_expand_first_arg<'a>(arguments: &Vec<'a, Argument<'a>>) -> bool {
&& !matches!(
second_arg,
Expression::FunctionExpression(_)
| Expression::ArrowExpression(_)
| Expression::ArrowFunctionExpression(_)
| Expression::ConditionalExpression(_)
)
&& is_hopefully_short_call_argument(second_arg)
@ -215,7 +215,7 @@ fn should_expand_last_arg(args: &Vec<'_, Argument<'_>>) -> bool {
&& (args.len() != 2
|| !matches!(
penultimate_arg,
Some(Argument::Expression(Expression::ArrowExpression(_)))
Some(Argument::Expression(Expression::ArrowFunctionExpression(_)))
)
|| !matches!(last_arg, Expression::ArrayExpression(_)))
}
@ -354,7 +354,7 @@ fn could_expand_arg(arg: &Expression, arrow_chain_recursion: bool) -> bool {
Expression::ArrayExpression(expr) => expr.elements.len() > 0,
Expression::BinaryExpression(expr) => could_expand_arg(&expr.left, arrow_chain_recursion),
Expression::FunctionExpression(_) => true,
Expression::ArrowExpression(expr) => {
Expression::ArrowFunctionExpression(expr) => {
if !expr.expression {
return true;
}

View file

@ -62,7 +62,7 @@ pub(super) fn print_function_parameters<'a>(
params: &FormalParameters<'a>,
) -> Doc<'a> {
let mut parts = p.vec();
let is_arrow_function = matches!(p.parent_kind(), AstKind::ArrowExpression(_));
let is_arrow_function = matches!(p.parent_kind(), AstKind::ArrowFunctionExpression(_));
let need_parens =
!is_arrow_function || p.options.arrow_parens.is_always() || params.items.len() != 1;
if need_parens {

View file

@ -1196,7 +1196,7 @@ impl<'a> Format<'a> for Expression<'a> {
Self::ArrayExpression(expr) => expr.format(p),
Self::ObjectExpression(expr) => expr.format(p),
Self::FunctionExpression(expr) => expr.format(p),
Self::ArrowExpression(expr) => expr.format(p),
Self::ArrowFunctionExpression(expr) => expr.format(p),
Self::YieldExpression(expr) => expr.format(p),
Self::UpdateExpression(expr) => expr.format(p),
Self::UnaryExpression(expr) => expr.format(p),
@ -1622,9 +1622,9 @@ impl<'a> Format<'a> for PropertyKey<'a> {
}
}
impl<'a> Format<'a> for ArrowExpression<'a> {
impl<'a> Format<'a> for ArrowFunctionExpression<'a> {
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
wrap!(p, self, ArrowExpression, { arrow_function::print_arrow_function(p, self) })
wrap!(p, self, ArrowFunctionExpression, { arrow_function::print_arrow_function(p, self) })
}
}

View file

@ -80,7 +80,7 @@ impl<'a> Prettier<'a> {
false
}
AstKind::AssignmentExpression(assign_expr) => match parent_kind {
AstKind::ArrowExpression(arrow_expr)
AstKind::ArrowFunctionExpression(arrow_expr)
if arrow_expr
.get_expression()
.is_some_and(|e| e.span() == assign_expr.span) =>
@ -168,7 +168,7 @@ impl<'a> Prettier<'a> {
AstKind::TaggedTemplateExpression(_) => true,
_ => false,
},
AstKind::ArrowExpression(e) => match parent_kind {
AstKind::ArrowFunctionExpression(e) => match parent_kind {
AstKind::CallExpression(call_expr) => call_expr.callee.span() == e.span,
AstKind::NewExpression(new_expr) => new_expr.callee.span() == e.span,
AstKind::MemberExpression(member_expr) => member_expr.object().span() == e.span,
@ -196,7 +196,7 @@ impl<'a> Prettier<'a> {
AstKind::Class(class) => {
if let Some(h) = &class.super_class {
match kind {
AstKind::ArrowExpression(e) if e.span == h.span() => return true,
AstKind::ArrowFunctionExpression(e) if e.span == h.span() => return true,
AstKind::AssignmentExpression(e) if e.span == h.span() => return true,
AstKind::AwaitExpression(e) if e.span == h.span() => return true,
AstKind::BinaryExpression(e) if e.span == h.span() => return true,
@ -245,7 +245,7 @@ impl<'a> Prettier<'a> {
match self.parent_kind() {
AstKind::ReturnStatement(_) | AstKind::ForStatement(_) => false,
AstKind::ExpressionStatement(expr) => expr.expression.span() != span,
AstKind::ArrowExpression(expr) => expr.body.span != span,
AstKind::ArrowFunctionExpression(expr) => expr.body.span != span,
_ => true,
}
}
@ -253,7 +253,7 @@ impl<'a> Prettier<'a> {
fn check_object_expression(&self, obj_expr: &ObjectExpression<'a>) -> bool {
let mut arrow_expr = None;
for kind in self.stack.iter().rev() {
if let AstKind::ArrowExpression(e) = kind {
if let AstKind::ArrowFunctionExpression(e) = kind {
e.get_expression();
arrow_expr = Some(e);
break;

View file

@ -52,7 +52,7 @@ pub struct SemanticBuilder<'a> {
pub current_node_flags: NodeFlags,
pub current_symbol_flags: SymbolFlags,
pub current_scope_id: ScopeId,
/// Stores current `AstKind::Function` and `AstKind::ArrowExpression` during AST visit
/// Stores current `AstKind::Function` and `AstKind::ArrowFunctionExpression` during AST visit
pub function_stack: Vec<AstNodeId>,
// To make a namespace/module value like
// we need the to know the modules we are inside
@ -1591,8 +1591,8 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
}
}
fn visit_arrow_expression(&mut self, expr: &ArrowExpression<'a>) {
let kind = AstKind::ArrowExpression(self.alloc(expr));
fn visit_arrow_expression(&mut self, expr: &ArrowFunctionExpression<'a>) {
let kind = AstKind::ArrowFunctionExpression(self.alloc(expr));
self.enter_scope(ScopeFlags::Function | ScopeFlags::Arrow);
/* cfg */
@ -1656,7 +1656,7 @@ impl<'a> SemanticBuilder<'a> {
self.add_current_node_id_to_current_scope();
self.make_all_namespaces_valuelike();
}
AstKind::ArrowExpression(_) => {
AstKind::ArrowFunctionExpression(_) => {
self.function_stack.push(self.current_node_id);
self.add_current_node_id_to_current_scope();
self.make_all_namespaces_valuelike();
@ -1780,7 +1780,7 @@ impl<'a> SemanticBuilder<'a> {
self.label_builder.leave_function_or_static_block();
self.function_stack.pop();
}
AstKind::ArrowExpression(_) => {
AstKind::ArrowFunctionExpression(_) => {
self.function_stack.pop();
}
AstKind::TSModuleBlock(_) => {

View file

@ -444,7 +444,7 @@ fn check_directive(directive: &Directive, ctx: &SemanticBuilder<'_>) {
if matches!(ctx.nodes.kind(ctx.scope.get_node_id(ctx.current_scope_id)),
AstKind::Function(Function { params, .. })
| AstKind::ArrowExpression(ArrowExpression { params, .. })
| AstKind::ArrowFunctionExpression(ArrowFunctionExpression { params, .. })
if !params.is_simple_parameter_list())
{
ctx.error(IllegalUseStrict(directive.span));
@ -1146,7 +1146,9 @@ fn is_in_formal_parameters<'a>(node: &AstNode<'a>, ctx: &SemanticBuilder<'a>) ->
for node_id in ctx.nodes.ancestors(node.id()).skip(1) {
match ctx.nodes.kind(node_id) {
AstKind::FormalParameter(_) => return true,
AstKind::Program(_) | AstKind::Function(_) | AstKind::ArrowExpression(_) => break,
AstKind::Program(_) | AstKind::Function(_) | AstKind::ArrowFunctionExpression(_) => {
break
}
_ => {}
}
}

View file

@ -109,7 +109,7 @@ impl<'a> ArrowFunctions<'a> {
}
pub fn transform_expression(&mut self, expr: &mut Expression<'a>) {
if let Expression::ArrowExpression(arrow_expr) = expr {
if let Expression::ArrowFunctionExpression(arrow_expr) = expr {
let mut body = self.ast.copy(&arrow_expr.body);
if arrow_expr.expression {