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.
nit: we can call arrayLikeToArray since we know for sure spreadLiteral is an array.
There was a problem hiding this comment.
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.
What happens if this isn't statically analyzable?
There was a problem hiding this comment.
It uses toConsumableArray(spreadArgument), which does all the necessary checks to ensure that it's correct. arrayWithoutHoles is part of those checks.
443bc8d to
c685177
Compare
This is #9146 rebased. I couldn't push to the original PR because the fork has been deleted.