Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrowFunctionExpression fails to check arrow functions without body and the type is also wrong #676

Open
danielo515 opened this issue Dec 1, 2021 · 3 comments

Comments

@danielo515
Copy link

danielo515 commented Dec 1, 2021

There are arrow functions whose body is a JSXExpression, like this:

const bla = (name: string) => <div>hello {name}</div>

That function will return false if you run ArrowFunctionExpression.check(path) and also the body type is wrongly defined here:

body: K.BlockStatementKind | K.ExpressionKind;

Because the type of that body is JSXElement, which doesn't have a nested body, which the other two does. This can lead to uncaught bugs.

@danielo515
Copy link
Author

Ok, found an error on my code, I was passing down the wrapper path to the check function rather than the actual node, doing ArrowFunctionExpression.check(path.value) yields true. However te body type is still wrong

@benjamn
Copy link
Owner

benjamn commented Dec 3, 2021

@danielo515 I think JSXElement should be a subtype of Expression?

export interface JSXElement extends Omit<Expression, "type"> {

In your case, both JSXElement.check(arrowFunExpr.body) and Expression.check(arrowFunExpr.body) should return true, so I think the body type might be okay?

@danielo515
Copy link
Author

@benjamn the thing is that JSXElement can be a the only body of an arrow function:
image

All the other two types have a nested body but the JSXElement does not so you can mistakenly try to access it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants