With preset-env, still need to manually add plugin-transform-classes for (...args) => super(...args)
- Dominant language
- TypeScript
- Stars
- 44k
- Forks
- 6k
- Avg merge
- 5d 15h
- Merged PRs (30d)
- 23
Description
### 💻
- [ ] Would you like to work on a fix?
### How are you using Babel?
@babel/cli
### Input code
```js
class Foo {
constructor() {}
}
class Bar extends Foo {
constructor(...args) {
let f = (...args) => super(...args);
f();
}
}
```
### Configuration file name
babel.config.json
### Configuration
```json
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"esmodules": true
}
}
]
]
}
```
### Current and expected behavior
It would fail with an error.
```
SyntaxError: ...: When using '@babel/plugin-transform-parameters', it's not possible to compile `super()` in an arrow function with default or rest parameters without compiling classes.
Please add '@babel/plugin-transform-classes' to your Babel configuration.
5 | class Bar extends Foo {
6 | constructor(...args) {
> 7 | let f = (...args) => super(...args);
| ^^^^^^^^^^^^^^
8 | f();
9 | }
10 | }
...
{
code: 'BABEL_TRANSFORM_ERROR'
}
```
### Environment
```
System:
OS: Linux 5.15 Ubuntu 24.04 LTS 24.04 LTS (Noble Numbat)
Binaries:
Node: 22.9.0 - ~/.nvm/versions/node/v22.9.0/bin/node
npm: 10.8.3 - ~/.nvm/versions/node/v22.9.0/bin/npm
npmPackages:
@babel/cli: ^7.26.4 => 7.26.4
@babel/core: ^7.26.10 => 7.26.10
@babel/plugin-transform-classes: ^7.25.9 => 7.25.9
@babel/preset-env: ^7.26.9 => 7.26.9
```
### Possible solution
Manually add `@babel/plugin-transform-classes` to `babel.config.json/plugins`.
### Additional context
Maybe related to #15148.
[Compat data](https://github.com/babel/babel/blob/main/packages/babel-compat-data/data/plugins.json) says `@babel/plugin-transform-classes` is not needed for Safari >= 10, which may not be true as this bug repro.
#### Working configuration for `@babel/preset-env`
```json
{}
```
```json
{
"forceAllTransforms": true,
"targets": {
"esmodules": true
}
}
```
```json
{
"targets": {
"safari": "9"
}
}
```
(Newly added below)
```json
{
"bugfixes": true,
"targets": {
"esmodules": true
}
}
```
```json
{
"bugfixes": true,
"targets": {
"esmodules": true,
"safari": "10"
}
}
```
#### Not working configuration for `@babel/preset-env`
(Same error)
```json
{
"targets": {
"esmodules": true,
"safari": "10"
}
}
```
```json
{
"targets": {
"safari": "10"
}
}
```
Contributor guide
Research direction
Start by reproducing the example with @babel/cli and babel.config.json using @babel/preset-env and the esmodules target. Compare the failing configurations with the working bugfixes and forceAllTransforms cases, then inspect packages/babel-compat-data/data/plugins.json; done means the reported input compiles without manually adding @babel/plugin-transform-classes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100