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

The JSXExpression union incorrectly includes JSXEmptyExpression #6315

Closed
4 tasks done
MageJohn opened this issue Jan 9, 2023 · 1 comment · Fixed by #6321
Closed
4 tasks done

The JSXExpression union incorrectly includes JSXEmptyExpression #6315

MageJohn opened this issue Jan 9, 2023 · 1 comment · Fixed by #6321
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: ast-spec Issues related to @typescript-eslint/ast-spec

Comments

@MageJohn
Copy link
Contributor

MageJohn commented Jan 9, 2023

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Relevant Package

ast-spec

Playground Link

https://typescript-eslint.io/play/#ts=4.3.5&jsx=true&sourceType=module&showAST=es&code=DwQwfA3gvsD04G4g&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

// This parses as a JSXExpressionContainer node whose expression is a JSXEmptyExpression node.
<a>{}</a>;

ESLint Config

No response

tsconfig

No response

Expected Result

I expect that when using the AST_NODE_TYPES.JSXExpression type the AST_NODE_TYPES.JSXEmptyExpression won't be a member of the union.

Actual Result

What I see is that the definition of the union is:

export type JSXExpression =
  | JSXEmptyExpression
  | JSXExpressionContainer
  | JSXSpreadChild;

Additional Info

Code like <a>{}</a> is parsed by typescript as a JsxExpression node who's expression value is undefined. As part of converting the JsxExpression node to an ESLint compatible AST, the typescript-estree package replaces the undefined with a JSXEmptyExpression node (relevant code).

However, in the ast-spec package the JSXEmptyExpression type is a part of the JSXExpression union (defined here). As explained above, this is incorrect as the JSXEmptyExpression node is only created as the child of a JSXExpression.

Versions

package version
@typescript-eslint/ast-spec 5.48.0
@typescript-eslint/typescript-estree 5.48.0
@MageJohn MageJohn added bug Something isn't working triage Waiting for maintainers to take a look labels Jan 9, 2023
@bradzacher
Copy link
Member

From the looks of our snapshots, yeah I think that JSXEmptyExpression should only be valid as a child. Of JSXExpressionContainer.

I thought there was a case that you could have an empty expression by itself, but I can't seem to find it.

@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue package: ast-spec Issues related to @typescript-eslint/ast-spec and removed triage Waiting for maintainers to take a look labels Jan 9, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: ast-spec Issues related to @typescript-eslint/ast-spec
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants