Skip to content

fix(computed-properties): keep object spread elements - #18581

Merged
JLHwung merged 2 commits into
mainfrom
jlhwung/fix-computed-properties-spread
Nov 16, 2026
Merged

JLHwung merged 2 commits into
mainfrom
jlhwung/fix-computed-properties-spread

Conversation

@JLHwung

@JLHwung JLHwung commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? Fixes #16233, Closes #17150
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
Need backport? No
License MIT

In this PR we preserve the object spread element before the first computed key, and throw an error if the spread element and seen after the first computed key, which this plugin can not handled.

Assisted-by: Claude Fable 5.2

@babel-bot

babel-bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

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

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories 7.x: needs backport labels Nov 11, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

commit: 5cfb5c1

@JLHwung
JLHwung added this pull request to stack #18587 November 11, 2026 13:39
@JLHwung
JLHwung marked this pull request as ready for review November 11, 2026 13:43
@nicolo-ribaudo

Copy link
Copy Markdown
Member

I would prefer the "throw an helpful error" approach, as I cannot imagine why one would want to use the computed properties plugin without also using the spread plugin.

When an object literal had both a computed key and a spread element,
and object rest/spread was not transformed, the spread element was
dropped from the output.

Spread elements before the first computed key now stay in the initial
object literal. Those after it are applied in source order with the
objectSpread2 helper, so that they still override the properties
defined before them.

Fixes #16233
Closes #17150

Assisted-by: Claude Fable 5.2
@JLHwung
JLHwung force-pushed the jlhwung/fix-computed-properties-spread branch from a2a9966 to 693c995 Compare November 12, 2026 02:25
@liuxingbaoyu

Copy link
Copy Markdown
Member

I would prefer the "throw an helpful error" approach, as I cannot imagine why one would want to use the computed properties plugin without also using the spread plugin.

@JLHwung Has this review been addressed?

Throw an error instead of compiling spread elements that follow
a computed key.

Spread elements before the first computed key still stay in the
initial object literal.

Assisted-by: Claude Opus 5.5
@JLHwung

JLHwung commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

I would prefer the "throw an helpful error" approach, as I cannot imagine why one would want to use the computed properties plugin without also using the spread plugin.

OK, I pushed a new commit that just throws an error when we have seen spread after the computed properties, the spread before computed properties still passes through.

@JLHwung
JLHwung added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit 295a210 Nov 16, 2026
40 checks passed
@JLHwung
JLHwung deleted the jlhwung/fix-computed-properties-spread branch November 16, 2026 21:24
@babel-bot

Copy link
Copy Markdown
Collaborator

Backported to 7.x in #18642.

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

Labels

PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: rest spread data is lost when @babel/plugin-transform-computed-properties is used alone

4 participants