Explicitly throw if the rest/spread items are not iterable.
This commit is contained in:
parent
4d76d5dddc
commit
eaa31b6ec3
@ -687,17 +687,21 @@ helpers.slicedToArrayLoose = () => template.program.ast`
|
|||||||
|
|
||||||
helpers.toArray = () => template.program.ast`
|
helpers.toArray = () => template.program.ast`
|
||||||
import arrayWithHoles from "arrayWithHoles";
|
import arrayWithHoles from "arrayWithHoles";
|
||||||
|
import iterableToArray from "iterableToArray";
|
||||||
|
import nonIterableRest from "nonIterableRest";
|
||||||
|
|
||||||
export default function _toConsumableArray(arr) {
|
export default function _toConsumableArray(arr) {
|
||||||
return arrayWithHoles(arr) || Array.from(arr);
|
return arrayWithHoles(arr) || iterableToArray(arr) || nonIterableRest();
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
helpers.toConsumableArray = () => template.program.ast`
|
helpers.toConsumableArray = () => template.program.ast`
|
||||||
import arrayWithoutHoles from "arrayWithoutHoles";
|
import arrayWithoutHoles from "arrayWithoutHoles";
|
||||||
|
import iterableToArray from "iterableToArray";
|
||||||
|
import nonIterableSpread from "nonIterableSpread";
|
||||||
|
|
||||||
export default function _toConsumableArray(arr) {
|
export default function _toConsumableArray(arr) {
|
||||||
return arrayWithoutHoles(arr) || Array.from(arr);
|
return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -716,6 +720,15 @@ helpers.arrayWithHoles = () => template.program.ast`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
helpers.iterableToArray = () => template.program.ast`
|
||||||
|
export default function _iterableToArray(iter) {
|
||||||
|
if (
|
||||||
|
Symbol.iterator in Object(iter) ||
|
||||||
|
Object.prototype.toString.call(iter) === "[object Arguments]"
|
||||||
|
) return Array.from(iter);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
helpers.iterableToArrayLimit = () => template.program.ast`
|
helpers.iterableToArrayLimit = () => template.program.ast`
|
||||||
export default function _iterableToArrayLimit(arr, i) {
|
export default function _iterableToArrayLimit(arr, i) {
|
||||||
// this is an expanded form of \`for...of\` that properly supports abrupt completions of
|
// this is an expanded form of \`for...of\` that properly supports abrupt completions of
|
||||||
@ -762,6 +775,12 @@ helpers.iterableToArrayLimitLoose = () => template.program.ast`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
helpers.nonIterableSpread = () => template.program.ast`
|
||||||
|
export default function _nonIterableSpread() {
|
||||||
|
throw new TypeError("Invalid attempt to spread non-iterable instance");
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
helpers.nonIterableRest = () => template.program.ast`
|
helpers.nonIterableRest = () => template.program.ast`
|
||||||
export default function _nonIterableRest() {
|
export default function _nonIterableRest() {
|
||||||
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user