feat(ast): remove generator property from ArrowFunction (#2260)

ArrowFunction doesn't support generator.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*
This commit is contained in:
Dunqing 2024-02-02 12:01:19 +08:00 committed by GitHub
parent 0ae28dd159
commit 2578bb3d64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 5 additions and 20 deletions

View file

@ -1827,7 +1827,6 @@ pub struct ArrowExpression<'a> {
pub span: Span,
/// Is the function body an arrow expression? i.e. `() => expr` instead of `() => {}`
pub expression: bool,
pub generator: bool,
pub r#async: bool,
pub params: Box<'a, FormalParameters<'a>>,
/// See `expression` for whether this arrow expression returns an expression.

View file

@ -407,7 +407,6 @@ impl<'a> AstBuilder<'a> {
&self,
span: Span,
expression: bool,
generator: bool,
r#async: bool,
params: Box<'a, FormalParameters<'a>>,
body: Box<'a, FunctionBody<'a>>,
@ -417,7 +416,6 @@ impl<'a> AstBuilder<'a> {
Expression::ArrowExpression(self.alloc(ArrowExpression {
span,
expression,
generator,
r#async,
params,
body,

View file

@ -85,9 +85,7 @@ 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.generator || arrow.expression)
}
AstKind::ArrowExpression(arrow) => (&arrow.body, arrow.r#async || arrow.expression),
AstKind::Function(function) => {
if let Some(body) = &function.body {
(body, function.r#async || function.generator)

View file

@ -50,11 +50,7 @@ impl Rule for RequireYield {
{
func.id.as_ref().map_or_else(|| kind.span(), |ident| ident.span)
}
AstKind::ArrowExpression(arrow)
if arrow.generator && !arrow.body.statements.is_empty() =>
{
arrow.span
}
AstKind::ArrowExpression(arrow) if !arrow.body.statements.is_empty() => arrow.span,
_ => return,
};

View file

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

View file

@ -253,7 +253,6 @@ impl<'a> Parser<'a> {
Ok(self.ast.arrow_expression(
self.end_span(span),
expression,
false,
r#async,
params,
body,
@ -519,7 +518,6 @@ impl<'a> Parser<'a> {
Ok(self.ast.arrow_expression(
self.end_span(span),
expression,
false,
r#async,
params,
body,

View file

@ -127,7 +127,7 @@ impl<'a> ArrowFunctions<'a> {
FunctionType::FunctionExpression,
SPAN,
None,
arrow_expr.generator,
false,
arrow_expr.r#async,
None,
self.ast.copy(&arrow_expr.params),

View file

@ -88,7 +88,6 @@ impl<'a> ClassStaticBlock<'a> {
SPAN,
false,
false,
false,
params,
function_body,
None,

View file

@ -429,7 +429,6 @@ impl<'a> Decorators<'a> {
SPAN,
true,
false,
false,
params,
ast.function_body(
SPAN,
@ -473,7 +472,6 @@ impl<'a> Decorators<'a> {
SPAN,
true,
false,
false,
params,
ast.function_body(
SPAN,

View file

@ -535,7 +535,7 @@ impl<'a> TypeScript<'a> {
let statements = self.transform_ts_enum_members(&mut decl.body.members, &enum_name);
let body = self.ast.function_body(decl.body.span, self.ast.new_vec(), statements);
let callee = self.ast.arrow_expression(SPAN, false, false, false, params, body, None, None);
let callee = self.ast.arrow_expression(SPAN, false, false, params, body, None, None);
// })(Foo || {});
let mut arguments = self.ast.new_vec();