Skip to content

[Bug]: Comparison with object literal fails to parse since 7.14.5 #14552

@lydell

Description

@lydell

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

const babelParser = require("@babel/parser");

const code = `({}<x)`;

console.log(
  babelParser.parse(code, {
    plugins: ["jsx"],
  })
);

Babel REPL – try toggling JSX!

Configuration file name

No response

Configuration

No response

Current and expected behavior

  • Babel 7.14.4 and older: The code parses like when JSX is disabled.
  • Babel 7.14.5 and newer: The code fails to parse when JSX is enabled.

Environment

  System:
    OS: macOS 12.3.1
  Binaries:
    Node: 16.14.2 - /usr/local/opt/node@16/bin/node
    Yarn: 1.22.18 - /usr/local/bin/yarn
    npm: 8.5.0 - /usr/local/opt/node@16/bin/npm
  npmPackages:
    @babel/parser: 7.14.5 => 7.14.5

Possible solution

Figure out what changed between 7.14.4 and 7.14.5. Looking at the changelog, this does not seem to be an intentional change.

Additional context

Note: I did not find this in real-world code. I found it while updating npm packages in js-tokens (a dependency of Babel, btw!). When updating @babel/parser, one of my tests failed. My test runs both js-tokens and @babel/parser and expects the results to be the same. Here’s where @babel/parser failed:

https://github.com/lydell/js-tokens/blob/6d5dba63c58d24ec982b6e859c040294f8ea2598/test/fixtures/valid/jsx1.jsx#L20

Metadata

Metadata

Assignees

Labels

i: regressionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions