Skip to content

Add bugfix plugin for Safari array rest destructuring bug#17788

Merged
nicolo-ribaudo merged 6 commits intobabel:mainfrom
JLHwung:bugfix-safari-rest-destructuring-rhs-array
Mar 7, 2026
Merged

Add bugfix plugin for Safari array rest destructuring bug#17788
nicolo-ribaudo merged 6 commits intobabel:mainfrom
JLHwung:bugfix-safari-rest-destructuring-rhs-array

Conversation

@JLHwung
Copy link
Copy Markdown
Contributor

@JLHwung JLHwung commented Feb 11, 2026

Q                       A
Fixed Issues? Fixes #17773
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

In this PR we introduce a new bugfix plugin @babel/plugin-bugfix-safari-rest-destructuring-rhs-array, which detects the affected code patterns by this Safari bug and transform the affected code such that

  • The extra footprint is small (4 bytes before compression per affected array pattern)
  • The result can not be easily reverted by terser on default compress options

This plugin is also added to the preset-env. In Babel 8, the bugfixes option is always enabled, so if users ever targeted affected Safari versions from 9 to 13.1, this plugin will be enabled automatically to avoid triggering the specific Webkit bug.

This PR is currently blocked by #17787 as the CI is failing. I will rebase once that PR gets merged.

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Feb 11, 2026

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61141

@JLHwung JLHwung force-pushed the bugfix-safari-rest-destructuring-rhs-array branch from e6dc800 to 5d7ec11 Compare February 11, 2026 20:54
Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fun one.

@JLHwung JLHwung force-pushed the bugfix-safari-rest-destructuring-rhs-array branch from 5d7ec11 to c4c4d20 Compare February 16, 2026 15:07
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Feb 16, 2026

Open in StackBlitz

commit: 4326f60

@nicolo-ribaudo
Copy link
Copy Markdown
Member

I run node ./scripts/ensure-packages-exist.ts locally to prepare the new package for publishing. Restarting CI now.

@JLHwung
Copy link
Copy Markdown
Contributor Author

JLHwung commented Feb 17, 2026

I just come up with a new idea that will further shrink the extra footprint to 2 bytes, let me give it a try.

@JLHwung
Copy link
Copy Markdown
Contributor Author

JLHwung commented Feb 17, 2026

Never mind, the new approach is to unshift hole elements into both array, but that would break TSSatisfiesExpression since the array composition is changed.

However, either approach would change the completion value of an assignment expression, which would otherwise be kept by the trailling comma approach. But this approach would not survive from minifiers...

@nicolo-ribaudo nicolo-ribaudo force-pushed the bugfix-safari-rest-destructuring-rhs-array branch from 7fd51c2 to 2c1ad94 Compare March 7, 2026 22:35
@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories i: browser bug PR: Bug Fix (next major) 🐛 A type of pull request used for our changelog categories for next major release and removed PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Mar 7, 2026
@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Mar 7, 2026
@nicolo-ribaudo nicolo-ribaudo merged commit f1a708c into babel:main Mar 7, 2026
55 of 56 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the bugfix-safari-rest-destructuring-rhs-array branch March 7, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

i: browser bug PR: Bug Fix 🐛 A type of pull request used for our changelog categories PR: Bug Fix (next major) 🐛 A type of pull request used for our changelog categories for next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rest in arrays is not fully supported in Safari <= 13

4 participants