-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correctly transform spreads of arrays with holes #13439
Correctly transform spreads of arrays with holes #13439
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit c685177:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/46747/ |
cd73f2e
to
f604e84
Compare
|
||
if (t.isArrayExpression(spreadLiteral) && hasHole(spreadLiteral)) { | ||
spreadLiteral = t.callExpression( | ||
file.addHelper("arrayWithoutHoles"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can call arrayLikeToArray
since we know for sure spreadLiteral
is an array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arrayLikeToArray
isn't available in every Babel 7 version, I went for the easy route. I'll add a switch to use arrayLikeToArray
in Babel 8.
@@ -0,0 +1,2 @@ | |||
let arr = ['a', ...['b',,'c']]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this isn't statically analyzable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It uses toConsumableArray(spreadArgument)
, which does all the necessary checks to ensure that it's correct. arrayWithoutHoles
is part of those checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
443bc8d
to
c685177
Compare
This is #9146 rebased. I couldn't push to the original PR because the fork has been deleted.