diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 70fc5c036..7402bfd1e 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -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>>, } -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] { diff --git a/crates/oxc_ast/src/ast_builder.rs b/crates/oxc_ast/src/ast_builder.rs index 3ee249dd3..d137f9249 100644 --- a/crates/oxc_ast/src/ast_builder.rs +++ b/crates/oxc_ast/src/ast_builder.rs @@ -412,7 +412,7 @@ impl<'a> AstBuilder<'a> { type_parameters: Option>>, return_type: Option>>, ) -> Expression<'a> { - Expression::ArrowExpression(self.alloc(ArrowExpression { + Expression::ArrowFunctionExpression(self.alloc(ArrowFunctionExpression { span, expression, r#async, diff --git a/crates/oxc_ast/src/ast_kind.rs b/crates/oxc_ast/src/ast_kind.rs index 92e524adb..b86d1c5a4 100644 --- a/crates/oxc_ast/src/ast_kind.rs +++ b/crates/oxc_ast/src/ast_kind.rs @@ -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 { @@ -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(), diff --git a/crates/oxc_ast/src/precedence.rs b/crates/oxc_ast/src/precedence.rs index f2b7217cb..443b6ea1a 100644 --- a/crates/oxc_ast/src/precedence.rs +++ b/crates/oxc_ast/src/precedence.rs @@ -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 } diff --git a/crates/oxc_ast/src/span.rs b/crates/oxc_ast/src/span.rs index 904b6bb72..2df67eb59 100644 --- a/crates/oxc_ast/src/span.rs +++ b/crates/oxc_ast/src/span.rs @@ -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, diff --git a/crates/oxc_ast/src/visit.rs b/crates/oxc_ast/src/visit.rs index fc1c30237..830ed1752 100644 --- a/crates/oxc_ast/src/visit.rs +++ b/crates/oxc_ast/src/visit.rs @@ -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); diff --git a/crates/oxc_ast/src/visit_mut.rs b/crates/oxc_ast/src/visit_mut.rs index 36760161b..9b791237e 100644 --- a/crates/oxc_ast/src/visit_mut.rs +++ b/crates/oxc_ast/src/visit_mut.rs @@ -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); diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 5977ed267..cb06f0021 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -927,7 +927,7 @@ impl<'a, const MINIFY: bool> GenExpr 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 for PropertyKey<'a> { } } -impl<'a, const MINIFY: bool> GenExpr for ArrowExpression<'a> { +impl<'a, const MINIFY: bool> GenExpr 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 { diff --git a/crates/oxc_linter/src/ast_util.rs b/crates/oxc_linter/src/ast_util.rs index c393368d5..0d436e28c 100644 --- a/crates/oxc_linter/src/ast_util.rs +++ b/crates/oxc_linter/src/ast_util.rs @@ -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(); diff --git a/crates/oxc_linter/src/rules/deepscan/missing_throw.rs b/crates/oxc_linter/src/rules/deepscan/missing_throw.rs index 9b8fd6064..84c038e42 100644 --- a/crates/oxc_linter/src/rules/deepscan/missing_throw.rs +++ b/crates/oxc_linter/src/rules/deepscan/missing_throw.rs @@ -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, _ => {} } diff --git a/crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs b/crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs index 67294ebef..cc652f94a 100644 --- a/crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs +++ b/crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs @@ -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>, diff --git a/crates/oxc_linter/src/rules/eslint/getter_return.rs b/crates/oxc_linter/src/rules/eslint/getter_return.rs index a9df4c8a0..24c6ce800 100644 --- a/crates/oxc_linter/src/rules/eslint/getter_return.rs +++ b/crates/oxc_linter/src/rules/eslint/getter_return.rs @@ -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); } _ => {} diff --git a/crates/oxc_linter/src/rules/eslint/no_async_promise_executor.rs b/crates/oxc_linter/src/rules/eslint/no_async_promise_executor.rs index 4cfdd6dd2..3672c37c5 100644 --- a/crates/oxc_linter/src/rules/eslint/no_async_promise_executor.rs +++ b/crates/oxc_linter/src/rules/eslint/no_async_promise_executor.rs @@ -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, diff --git a/crates/oxc_linter/src/rules/eslint/no_cond_assign.rs b/crates/oxc_linter/src/rules/eslint/no_cond_assign.rs index 9988d7787..1252376ae 100644 --- a/crates/oxc_linter/src/rules/eslint/no_cond_assign.rs +++ b/crates/oxc_linter/src/rules/eslint/no_cond_assign.rs @@ -78,7 +78,7 @@ impl Rule for NoCondAssign { Self::emit_diagnostic(ctx, expr); } AstKind::Function(_) - | AstKind::ArrowExpression(_) + | AstKind::ArrowFunctionExpression(_) | AstKind::Program(_) => break, _ => {} } diff --git a/crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs b/crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs index 16744f4a4..56506c1b7 100644 --- a/crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs +++ b/crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs @@ -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, diff --git a/crates/oxc_linter/src/rules/eslint/no_return_await.rs b/crates/oxc_linter/src/rules/eslint/no_return_await.rs index 4a07cfbe2..8856560cf 100644 --- a/crates/oxc_linter/src/rules/eslint/no_return_await.rs +++ b/crates/oxc_linter/src/rules/eslint/no_return_await.rs @@ -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; diff --git a/crates/oxc_linter/src/rules/eslint/no_this_before_super.rs b/crates/oxc_linter/src/rules/eslint/no_this_before_super.rs index d9c243c31..b6dcfe79a 100644 --- a/crates/oxc_linter/src/rules/eslint/no_this_before_super.rs +++ b/crates/oxc_linter/src/rules/eslint/no_this_before_super.rs @@ -64,7 +64,7 @@ impl Rule for NoThisBeforeSuper { let mut basic_blocks_with_local_violations = HashMap::>::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); } diff --git a/crates/oxc_linter/src/rules/jest/expect_expect.rs b/crates/oxc_linter/src/rules/jest/expect_expect.rs index da8cc2ea7..690dbbcb9 100644 --- a/crates/oxc_linter/src/rules/jest/expect_expect.rs +++ b/crates/oxc_linter/src/rules/jest/expect_expect.rs @@ -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); } diff --git a/crates/oxc_linter/src/rules/jest/no_done_callback.rs b/crates/oxc_linter/src/rules/jest/no_done_callback.rs index 4691c7a5b..81f5eae84 100644 --- a/crates/oxc_linter/src/rules/jest/no_done_callback.rs +++ b/crates/oxc_linter/src/rules/jest/no_done_callback.rs @@ -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; } diff --git a/crates/oxc_linter/src/rules/jest/no_standalone_expect.rs b/crates/oxc_linter/src/rules/jest/no_standalone_expect.rs index 6d9c8d389..020427e0a 100644 --- a/crates/oxc_linter/src/rules/jest/no_standalone_expect.rs +++ b/crates/oxc_linter/src/rules/jest/no_standalone_expect.rs @@ -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)` diff --git a/crates/oxc_linter/src/rules/jest/no_test_return_statement.rs b/crates/oxc_linter/src/rules/jest/no_test_return_statement.rs index b62379086..8c8d62031 100644 --- a/crates/oxc_linter/src/rules/jest/no_test_return_statement.rs +++ b/crates/oxc_linter/src/rules/jest/no_test_return_statement.rs @@ -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) => { diff --git a/crates/oxc_linter/src/rules/jest/prefer_todo.rs b/crates/oxc_linter/src/rules/jest/prefer_todo.rs index 721c734d2..e6ef72f59 100644 --- a/crates/oxc_linter/src/rules/jest/prefer_todo.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_todo.rs @@ -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; diff --git a/crates/oxc_linter/src/rules/jest/valid_describe_callback.rs b/crates/oxc_linter/src/rules/jest/valid_describe_callback.rs index c06d1f01d..123b4075e 100644 --- a/crates/oxc_linter/src/rules/jest/valid_describe_callback.rs +++ b/crates/oxc_linter/src/rules/jest/valid_describe_callback.rs @@ -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); } diff --git a/crates/oxc_linter/src/rules/jest/valid_expect.rs b/crates/oxc_linter/src/rules/jest/valid_expect.rs index e7254e180..8db7eff95 100644 --- a/crates/oxc_linter/src/rules/jest/valid_expect.rs +++ b/crates/oxc_linter/src/rules/jest/valid_expect.rs @@ -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, } diff --git a/crates/oxc_linter/src/rules/nextjs/no_async_client_component.rs b/crates/oxc_linter/src/rules/nextjs/no_async_client_component.rs index c328a3133..16762bdec 100644 --- a/crates/oxc_linter/src/rules/nextjs/no_async_client_component.rs +++ b/crates/oxc_linter/src/rules/nextjs/no_async_client_component.rs @@ -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 { diff --git a/crates/oxc_linter/src/rules/react/jsx_key.rs b/crates/oxc_linter/src/rules/react/jsx_key.rs index 2a94a3b8a..f4d87b4f9 100644 --- a/crates/oxc_linter/src/rules/react/jsx_key.rs +++ b/crates/oxc_linter/src/rules/react/jsx_key.rs @@ -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(_)) diff --git a/crates/oxc_linter/src/rules/react/no_render_return_value.rs b/crates/oxc_linter/src/rules/react/no_render_return_value.rs index 1a1cc703c..8b8ab508e 100644 --- a/crates/oxc_linter/src/rules/react/no_render_return_value.rs +++ b/crates/oxc_linter/src/rules/react/no_render_return_value.rs @@ -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 { diff --git a/crates/oxc_linter/src/rules/react/require_render_return.rs b/crates/oxc_linter/src/rules/react/require_render_return.rs index db2da80b7..113cf03f0 100644 --- a/crates/oxc_linter/src/rules/react/require_render_return.rs +++ b/crates/oxc_linter/src/rules/react/require_render_return.rs @@ -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 diff --git a/crates/oxc_linter/src/rules/react_perf/jsx_no_new_function_as_prop.rs b/crates/oxc_linter/src/rules/react_perf/jsx_no_new_function_as_prop.rs index 085ebe331..add9a7ae8 100644 --- a/crates/oxc_linter/src/rules/react_perf/jsx_no_new_function_as_prop.rs +++ b/crates/oxc_linter/src/rules/react_perf/jsx_no_new_function_as_prop.rs @@ -71,7 +71,7 @@ fn check_jsx_element<'a>(jsx_elem: &JSXElement<'a>, ctx: &LintContext<'a>) { fn check_expression(expr: &Expression) -> Option { 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") { diff --git a/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs b/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs index 80b723183..92cb5c511 100644 --- a/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs +++ b/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs @@ -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) { diff --git a/crates/oxc_linter/src/rules/unicorn/no_array_reduce.rs b/crates/oxc_linter/src/rules/unicorn/no_array_reduce.rs index 7b37ba147..60a021f74 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_array_reduce.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_array_reduce.rs @@ -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; diff --git a/crates/oxc_linter/src/rules/unicorn/no_invalid_remove_event_listener.rs b/crates/oxc_linter/src/rules/unicorn/no_invalid_remove_event_listener.rs index dd0502c4b..0254b88de 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_invalid_remove_event_listener.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_invalid_remove_event_listener.rs @@ -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, diff --git a/crates/oxc_linter/src/rules/unicorn/no_unnecessary_await.rs b/crates/oxc_linter/src/rules/unicorn/no_unnecessary_await.rs index c31051b6b..cb1260e7d 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_unnecessary_await.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_unnecessary_await.rs @@ -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(_) diff --git a/crates/oxc_linter/src/rules/unicorn/no_unreadable_iife.rs b/crates/oxc_linter/src/rules/unicorn/no_unreadable_iife.rs index cf80233ad..fb1809345 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_unreadable_iife.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_unreadable_iife.rs @@ -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; }; diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_promise_resolve_reject.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_promise_resolve_reject.rs index 8ecabd555..0b8cc5792 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_promise_resolve_reject.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_promise_resolve_reject.rs @@ -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, } diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_array_flat.rs b/crates/oxc_linter/src/rules/unicorn/prefer_array_flat.rs index 9680acf3f..332deb69c 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_array_flat.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_array_flat.rs @@ -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; diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_remove.rs b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_remove.rs index b0cc110c4..aa2ee522b 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_remove.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_remove.rs @@ -70,7 +70,7 @@ impl Rule for PreferDomNodeRemove { if matches!( expr, Expression::ArrayExpression(_) - | Expression::ArrowExpression(_) + | Expression::ArrowFunctionExpression(_) | Expression::ClassExpression(_) | Expression::FunctionExpression(_) | Expression::ObjectExpression(_) diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs b/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs index 69bf859db..1c889904a 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs @@ -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; } diff --git a/crates/oxc_linter/src/utils/unicorn.rs b/crates/oxc_linter/src/utils/unicorn.rs index 5824ad11c..f3afcbebb 100644 --- a/crates/oxc_linter/src/utils/unicorn.rs +++ b/crates/oxc_linter/src/utils/unicorn.rs @@ -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(_) diff --git a/crates/oxc_minifier/src/compressor/ast_util.rs b/crates/oxc_minifier/src/compressor/ast_util.rs index 5962f036c..f6ce33a83 100644 --- a/crates/oxc_minifier/src/compressor/ast_util.rs +++ b/crates/oxc_minifier/src/compressor/ast_util.rs @@ -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 { match expr { Expression::RegExpLiteral(_) | Expression::ArrayExpression(_) - | Expression::ArrowExpression(_) + | Expression::ArrowFunctionExpression(_) | Expression::ClassExpression(_) | Expression::FunctionExpression(_) | Expression::NewExpression(_) diff --git a/crates/oxc_minifier/src/compressor/fold.rs b/crates/oxc_minifier/src/compressor/fold.rs index 712d834e3..84369e842 100644 --- a/crates/oxc_minifier/src/compressor/fold.rs +++ b/crates/oxc_minifier/src/compressor/fold.rs @@ -565,7 +565,7 @@ impl<'a> Compressor<'a> { ) -> Option> { 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"), diff --git a/crates/oxc_prettier/src/format/arrow_function.rs b/crates/oxc_prettier/src/format/arrow_function.rs index b8d29ccd8..ddca629d8 100644 --- a/crates/oxc_prettier/src/format/arrow_function.rs +++ b/crates/oxc_prettier/src/format/arrow_function.rs @@ -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(); diff --git a/crates/oxc_prettier/src/format/assignment.rs b/crates/oxc_prettier/src/format/assignment.rs index b0179082f..3b7cfe62f 100644 --- a/crates/oxc_prettier/src/format/assignment.rs +++ b/crates/oxc_prettier/src/format/assignment.rs @@ -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 diff --git a/crates/oxc_prettier/src/format/block.rs b/crates/oxc_prettier/src/format/block.rs index ac0cf0eff..9d56bd043 100644 --- a/crates/oxc_prettier/src/format/block.rs +++ b/crates/oxc_prettier/src/format/block.rs @@ -30,7 +30,7 @@ pub(super) fn print_block<'a>( && !(matches!( parent, AstKind::FunctionBody(_) - | AstKind::ArrowExpression(_) + | AstKind::ArrowFunctionExpression(_) | AstKind::ObjectExpression(_) | AstKind::Function(_) | AstKind::ForStatement(_) diff --git a/crates/oxc_prettier/src/format/call_arguments.rs b/crates/oxc_prettier/src/format/call_arguments.rs index 4c5a3618c..3afbe7c8e 100644 --- a/crates/oxc_prettier/src/format/call_arguments.rs +++ b/crates/oxc_prettier/src/format/call_arguments.rs @@ -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; } diff --git a/crates/oxc_prettier/src/format/function_parameters.rs b/crates/oxc_prettier/src/format/function_parameters.rs index ee5857e69..738f66673 100644 --- a/crates/oxc_prettier/src/format/function_parameters.rs +++ b/crates/oxc_prettier/src/format/function_parameters.rs @@ -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 { diff --git a/crates/oxc_prettier/src/format/mod.rs b/crates/oxc_prettier/src/format/mod.rs index d08ef41a0..1dc4f8ec9 100644 --- a/crates/oxc_prettier/src/format/mod.rs +++ b/crates/oxc_prettier/src/format/mod.rs @@ -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) }) } } diff --git a/crates/oxc_prettier/src/needs_parens.rs b/crates/oxc_prettier/src/needs_parens.rs index e2f2c1d22..07e0d8e1f 100644 --- a/crates/oxc_prettier/src/needs_parens.rs +++ b/crates/oxc_prettier/src/needs_parens.rs @@ -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; diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index 107d943a8..343d3fb95 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -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, // 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(_) => { diff --git a/crates/oxc_semantic/src/checker/javascript.rs b/crates/oxc_semantic/src/checker/javascript.rs index 4e1d8ef66..469626b88 100644 --- a/crates/oxc_semantic/src/checker/javascript.rs +++ b/crates/oxc_semantic/src/checker/javascript.rs @@ -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 + } _ => {} } } diff --git a/crates/oxc_transformer/src/es2015/arrow_functions.rs b/crates/oxc_transformer/src/es2015/arrow_functions.rs index 79456e4a9..3385ca49a 100644 --- a/crates/oxc_transformer/src/es2015/arrow_functions.rs +++ b/crates/oxc_transformer/src/es2015/arrow_functions.rs @@ -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 {