babel/babel

[Bug]: Error parsing TypeScript generics on left-hand side

mtdavis opened this issue · 1 comments

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

REPL link

other compilers for comparison

Configuration file name

.babelrc

Configuration

{
  "presets": [
    [
      "@babel/preset-typescript",
      {
        "allowDeclareFields": true
      }
    ],
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": true
        },
        "modules": "commonjs"
      }
    ]
  ]
}

Current and expected behavior

Current behavior: Babel outputs the error "Invalid left-hand side in assignment expression."

Expected behavior: Babel does not output an error, and generates code similar to what tsc generates.

Environment

  System:
    OS: Windows 10 10.0.19045
  Binaries:
    Node: 20.11.1 - ~\.nvm\versions\node\v20.11.1\bin\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.2.4 - ~\.nvm\versions\node\v20.11.1\bin\npm.CMD
  npmPackages:
    @babel/cli: ^7.23.9 => 7.23.9
    @babel/core: ^7.24.0 => 7.24.0
    @babel/node: ^7.23.9 => 7.23.9
    @babel/polyfill: ^7.11.5 => 7.12.1
    @babel/preset-env: ^7.24.0 => 7.24.0
    @babel/preset-typescript: ^7.23.3 => 7.23.3
    eslint: ^8.57.0 => 8.57.0
    jest: ^29.7.0 => 29.7.0

Possible solution

No response

Additional context

The minimal reproduction code is a little weird, but the real use case where we encountered this issue is when initializing Sequelize model classes that extend a base class.

Hey @mtdavis! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.