Empty body function cuase errors for several eslint rules #253
Description
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:
- Abstract method declaration -
TSAbstractMethods
- Function Declarations in namespace -
TSNamespaceFunctionDeclaration
(We do this even for non empty body functions which causes another problem Namespace exported function return causing later code to be marked unreachable #127)
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?