Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Empty body function cuase errors for several eslint rules #253

Closed
@soda0289

Description

@soda0289

There was a long standing issue with this parser and escope that caused a crash when encountering an empty body function. This is because ESTree defines that all Function/Method Declarations and Function expressions should have a body.

Escope has since been forked as eslint-scope and can now parse empty body function nodes. There are still serveral eslint rules that expect functions to have bodies.

Issues this caused are: #162 #92 #80 #78

These issue have caused the parser to change the node type of the following function nodes:

There are other cases where we do not change the node type of empty body functions. These include:

  • Declared Classes
  • Declared Functions
  • Function overloading
  • Abstract Function expression (found within an abstract method declaration)

There are two options to fix this. We can change the type of these node or modify the failing eslint rules.

I have proposed the following PRs: #166 #165 #163

All of these change the type of both the function declaration and function expression. Maybe we should just remove the function expression entierly. We can create the following new nodes:

TSAbstractMethodDefinition {
  id: Identifier;
  params: [ Parameters ];
  returnType: TypeAnnotation;
  typeParameters: [ TSTypeParameter ];
}
TSAmbientFunctionDefinition {
  id: Identifier;
  params: [ Parameters ];
  returnType: TypeAnnotation;
  typeParameters: [ TSTypeParameter ];
  declared: boolean;
}
TSOverloadFunctionDefinition {
  id: Identifier;
  params: [ Parameters ];
  returnType: TypeAnnotation;
  typeParameters: [ TSTypeParameter ];
}

Sorry about the long post but wanted to create a summary of the current situation and allow for easier discussion. If we keep keep the nodes the way they are we might want to change back the TSNamespaceFunction declaration since it is causing another issue.

@JamesHenry thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions