Skip to content

REPL: preserve env targets that have no sidebar control - #3267

Open
officialasishkumar wants to merge 1 commit into
babel:mainfrom
officialasishkumar:repl-preserve-env-targets
Open

officialasishkumar wants to merge 1 commit into
babel:mainfrom
officialasishkumar:repl-preserve-env-targets

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

The REPL only kept the browsers, electron and node keys of the preset-env targets option when syncing the config tab with the sidebar. Other valid targets such as rhino, deno, chrome or esmodules were dropped whenever the config was regenerated (toggling any sidebar option, switching the Babel version, ...). That made it impossible to compile for Rhino, which can't be expressed as a browserslist query in the "Targets" textarea.

Steps to reproduce on main: in the Config tab, set "presets": [["env", { "targets": { "rhino": "1.7.14" } }]], then toggle any env preset option. The rhino target disappears and the output falls back to the default targets.

Changes:

  • Move the targets parsing from Repl.tsx into a new applyTargetsToEnvConfig helper in replUtils.ts. Targets without a dedicated control are stored in envConfig.otherTargets and merged back in buildTransformOpts.
  • Reset the Electron/Node toggles when the config's targets object no longer contains them. Before, they stayed enabled with stale values.
  • Accept targets (and targets.browsers) given as an array of browserslist queries instead of discarding them.

I tested this by bundling replUtils.ts and running the config → sidebar state → config round trip for string, array, object and null targets. { rhino: "1.7.14" } survives a sidebar change, and the regenerated config compiles with @babel/standalone 8 for Rhino: arrow functions and default params are transformed and ** is kept.

Fixes #2843

The REPL only kept the `browsers`, `electron` and `node` keys of the
`@babel/preset-env` `targets` option when syncing the config editor with
the sidebar. Any other valid target written in the config tab, such as
`rhino`, `deno`, `chrome` or `esmodules`, was silently dropped as soon as
the config was regenerated (toggling any sidebar option, changing the
Babel version, ...), so it was effectively impossible to compile for
targets like Rhino, which cannot be expressed as a browserslist query.

Move the targets parsing into a new `applyTargetsToEnvConfig` helper in
replUtils that stores the extra targets in `envConfig.otherTargets`, and
merge them back in `buildTransformOpts`. While here:

- reset the Electron/Node toggles when the config's targets object no
  longer contains them, instead of leaving stale values enabled;
- accept `targets` (and `targets.browsers`) given as an array of
  browserslist queries, instead of discarding them.

Fixes babel#2843
@netlify

netlify Bot commented Nov 15, 2026

Copy link
Copy Markdown

👷 Deploy request for babel-v9 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit f9c080e

@netlify

netlify Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for babel-v8 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit f9c080e
🔍 Latest deploy log https://app.netlify.com/projects/babel-v8/deploys/6afa30b2d838c871a612c2d4
😎 Deploy Preview https://deploy-preview-3267--babel-v8.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

REPL: cannot specify rhino as a target

1 participant