Repository navigation
fix(transform-spread): copy constant array when later elements have side effects - #18613
Open
hoanle0126 wants to merge 2 commits into
Open
hoanle0126 wants to merge 2 commits into
hoanle0126 wants to merge 2 commits into
Conversation
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63286 |
|
commit: |
JLHwung
reviewed
Nov 13, 2026
| let lastImpureIndex = -1; | ||
|
|
||
| for (const prop of props) { | ||
| if (!iterableIsArray) { |
Contributor
There was a problem hiding this comment.
The lastImpureIndex is computed only when iterableIsArray is false, so under iterableIsArray assumption, the #18531 is still not fixed.
Given the input [...a, a.push(3)], under this assumption, we can emit
[].concat(a.slice(), [a.push(3)])so it still outputs [1, 2, 3]. Could you implement it and add a new test case for the iterableIsArray assumption case?
Contributor
Author
There was a problem hiding this comment.
Good catch, updated to emit .slice() under iterableIsArray when a later element has side effects and added a test fixture for it.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an array is spread before impure elements (such as
[...a, a.push(3)]), passingadirectly to.concat(...)evaluates the later arguments before readinga. Clone the spread argument whenever a subsequent element may have side effects (toConsumableArrayfor constantArraybindings by default, or.slice()under theiterableIsArrayassumption).