Repository navigation
Improve rest spread output - #17023
liuxingbaoyu wants to merge 5 commits into
Conversation
liuxingbaoyu
commented
Dec 14, 2024
| Q | A |
|---|---|
| Fixed Issues? | Fixes #16969 |
| Patch: Bug Fix? | |
| Major: Breaking Change? | |
| Minor: New Feature? | |
| Tests Added + Pass? | Yes |
| Documentation PR Link | |
| Any Dependency Changes? | |
| License | MIT |
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58949 |
| ({ | ||
| _c = c2, { | ||
| a2 | ||
| } = _c); | ||
| b2 = babelHelpers.objectWithoutProperties(_c, ["a2"]); | ||
| _c; | ||
| } = _c, b2 = babelHelpers.objectWithoutProperties(_c, ["a2"]); |
There was a problem hiding this comment.
In all these cases, could we generate _c = { a2 } = c2, b2 = babelHelpers.objectWithoutProperties(_c, ["a2"]) instead? It can also be done as a separate PR, this one looks good already.
There was a problem hiding this comment.
In cases where the value c2 is not read, then we could make it even smaller:
b2 = babelHelpers.objectWithoutProperties({ a2 } = c2, ["a2"])with no temp variable.
| ]), | ||
| ); | ||
| let refName; | ||
| if (t.isIdentifier(right) && path.scope.hasBinding(right.name)) { |
There was a problem hiding this comment.
Should we also check if the binding is constant? A getter in the destructured object could reassign it.
let a = { get x() { a = { z: 2 } }, y: 2 };
let x, rest;
({ x, ...rest } = a);There was a problem hiding this comment.
(add this as an exec test)
| (pureGetters || | ||
| path.scope.getBinding(right.name)?.constantViolations.every( | ||
| // declared in loop | ||
| p => p.isVariableDeclarator(), |
There was a problem hiding this comment.
Why do we need to check this?
There was a problem hiding this comment.
for(var x of y)
x will be registered as constantViolations.
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
One minor comment, but the implementation looks good
Co-authored-by: Nicolò Ribaudo <[email protected]>