Throw better errors for non-iterables when Symbol doesn't exist (#11264)
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
var a = (() => [1, 2, 3])();
|
||||
|
||||
// Simulate old environment
|
||||
let _Symbol = Symbol;
|
||||
Symbol = void 0;
|
||||
try {
|
||||
var [first, ...rest] = a;
|
||||
|
||||
expect(first).toBe(1);
|
||||
expect(rest).toEqual([2, 3]);
|
||||
} finally {
|
||||
Symbol = _Symbol;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
var a = (() => [1, 2, 3])();
|
||||
|
||||
// !!! In order to run this test, this shouldn't be optimized using type inference
|
||||
// If it's optimized and doesn't call toArray, please modify this test
|
||||
// and exec.js
|
||||
var [first, ...rest] = a;
|
||||
@@ -0,0 +1,8 @@
|
||||
var a = (() => [1, 2, 3])(); // !!! In order to run this test, this shouldn't be optimized using type inference
|
||||
// If it's optimized and doesn't call toArray, please modify this test
|
||||
// and exec.js
|
||||
|
||||
|
||||
var _a = babelHelpers.toArray(a),
|
||||
first = _a[0],
|
||||
rest = _a.slice(1);
|
||||
@@ -1,9 +1,22 @@
|
||||
expect(
|
||||
() => {
|
||||
var [foo, bar] = undefined;
|
||||
}).toThrow("Invalid attempt to destructure non-iterable instance");
|
||||
var foo, bar;
|
||||
|
||||
expect(
|
||||
() => {
|
||||
var foo = [ ...undefined ];
|
||||
}).toThrow("Invalid attempt to spread non-iterable instance");
|
||||
() => [foo, bar] = undefined
|
||||
).toThrow(/destructure non-iterable/);
|
||||
|
||||
expect(
|
||||
() => [foo, bar] = {}
|
||||
).toThrow(/destructure non-iterable/);
|
||||
|
||||
// Simulate old browser
|
||||
let _Symbol = Symbol;
|
||||
Symbol = void 0;
|
||||
try {
|
||||
|
||||
expect(
|
||||
() => [foo, bar] = {}
|
||||
).toThrow(/destructure non-iterable/);
|
||||
|
||||
} finally {
|
||||
Symbol = _Symbol;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"plugins": [
|
||||
"transform-destructuring"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user