Fix __spreadArray for non-concat-spreadables#45386
Conversation
| } | ||
| } | ||
| return to.concat(ar || from); | ||
| return to.concat(ar || Array.prototype.slice.call(from)); |
There was a problem hiding this comment.
I don't know how crazy we want to get with this one but we could also do
| return to.concat(ar || Array.prototype.slice.call(from)); | |
| return to.concat(ar || (from instanceof Array ? from : Array.prototype.slice.call(from))); |
There was a problem hiding this comment.
I considered that, including a check for isConcatSpreadable, but it just became long-winded and the performance benefits seemed negligible.
There was a problem hiding this comment.
I was originally thinking of doing this:
var __spreadArray = (this && this.__spreadArray) || (function () {
var toString = Object.prototype.toString;
var slice = Array.prototype.slice;
var isArray = typeof Array.isArray === "function" ? Array.isArray : function (obj) { return toString.call(obj) === "[object Array]"; };
var isConcatSpreadable = typeof Symbol === "function" && Symbol.isConcatSpreadable;
function canConcat(obj) { return isArray(obj) || isConcatSpreadable && obj[isConcatSpreadable]; }
return function (to, from, pack) {
if (pack || arguments.length === 2) {
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = slice.call(from, 0, i);
ar[i] = from[i];
}
}
if (ar) from = ar;
}
return to.concat(canConcat(from) ? from : slice.call(from));
}
})();|
We'll need to cherry-pick this in for release-4.4, so ping me when you're ready to merge. |
|
Also, take a look at microsoft/tslib#155 to fix this on the tslib side, since the concat-spreadable thing is a back-compat issue. |
|
@typescript-bot cherry-pick this to release-4.4 |
|
Heya @DanielRosenwasser, I've started to run the task to cherry-pick this into |
|
@typescript-bot cherry-pick this to release-4.4 and LKG |
|
Heya @DanielRosenwasser, I've started to run the task to cherry-pick this into |
|
Hey @DanielRosenwasser, I've opened #45416 for you. |
Component commits: 7c7e0eb Fix __spreadArray for non-concat-spreadables
|
Hey @DanielRosenwasser, I couldn't open a PR with the cherry-pick. (You can check the log here). You may need to squash and pick this PR into release-4.4 manually. |
Component commits: 7c7e0eb Fix __spreadArray for non-concat-spreadables
The
__spreadArrayhelper usesArray.concat, which doesn't work with DOM NodeList or HTMLCollection. This changes the__spreadArrayhelper to fall back toArray.prototype.slice.call(from)to ensure the elements offromare concatenated properly.Fixes TypeScript side of microsoft/tslib#153