Skip to content

The JSXExpression union incorrectly includes JSXEmptyExpression #6315

@MageJohn

Description

@MageJohn

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: ast-specIssues related to @typescript-eslint/ast-spec

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy