Repository navigation
Fix (@babel/plugin-transform-computed-properties): rest spread data is lost - #17150
KHZhanibek wants to merge 4 commits into
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58785 |
0e7263d to
c7c76f5
Compare
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
This is reasonable, but I'm curious to know why one would transpile computed properties without transpiling object spread.
| ...first, | ||
| a: 'a', | ||
| ['c']: 'c' | ||
| } No newline at end of file |
There was a problem hiding this comment.
Can you also add ...second after the computed property?
There was a problem hiding this comment.
like just type ...second on 10th line?
There was a problem hiding this comment.
or you mean ...first after computed property?
There was a problem hiding this comment.
...second at the end, so that there are both first and second :)
| ['c']: 'c', | ||
| } | ||
|
|
||
| const third = {...second} No newline at end of file |
There was a problem hiding this comment.
Sorry, I didn't realize you already had a second variable so I wasn't clear 😅
I meant this:
const second = {
...first,
a: 'a',
['c']: 'c',
...third
}
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
LGTM, pending #17150 (comment)
JLHwung
left a comment
There was a problem hiding this comment.
Thanks. Left a non-blocker.
|
|
||
| for (const prop of node.properties) { | ||
| if (t.isSpreadElement(prop)) { | ||
| initProps.push(prop); |
There was a problem hiding this comment.
This for loop seems a bit too verbose, could you help simplify it?
| ...first, | ||
| a: 'a', | ||
| ...third | ||
| }, 'c', 'c'); No newline at end of file |
There was a problem hiding this comment.
This is wrong: if third contains c: 1, second should contain c: 1 but with this output code it will contain c: 'c'. You should take a look at how we make sure that normal properies that come after the computer property are defined after the defineProperty call, and do the same.
* fix(plugin-transform-computed-properties): keep spread elements 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 babel#16233 Closes babel#17150 Assisted-by: Claude Fable 5.2 * address review comments 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
Uh oh!
There was an error while loading. Please reload this page.