Throw better errors for non-iterables when Symbol doesn't exist (#11264)
This commit is contained in:
10
packages/babel-plugin-transform-spread/test/fixtures/spread/array-symbol-unsupported/exec.js
vendored
Normal file
10
packages/babel-plugin-transform-spread/test/fixtures/spread/array-symbol-unsupported/exec.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
var a = (() => [2, 3])();
|
||||
|
||||
// Simulate old environment
|
||||
let _Symbol = Symbol;
|
||||
Symbol = void 0;
|
||||
try {
|
||||
expect([1, ...a]).toEqual([1, 2, 3]);
|
||||
} finally {
|
||||
Symbol = _Symbol;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
var a = (() => [2, 3])();
|
||||
|
||||
// !!! In order to run this test, this shouldn't be optimized using type inference
|
||||
// If it's optimized and doesn't call toConsumableArray, please modify this test
|
||||
// and exec.js
|
||||
[1, ...a];
|
||||
@@ -0,0 +1,6 @@
|
||||
var a = (() => [2, 3])(); // !!! In order to run this test, this shouldn't be optimized using type inference
|
||||
// If it's optimized and doesn't call toConsumableArray, please modify this test
|
||||
// and exec.js
|
||||
|
||||
|
||||
[1].concat(babelHelpers.toConsumableArray(a));
|
||||
10
packages/babel-plugin-transform-spread/test/fixtures/spread/non-iterable/exec.js
vendored
Normal file
10
packages/babel-plugin-transform-spread/test/fixtures/spread/non-iterable/exec.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
var o = {};
|
||||
|
||||
expect(() => [...undefined]).toThrow(/spread non-iterable/);
|
||||
|
||||
expect(() => [...o]).toThrow(/spread non-iterable/);
|
||||
|
||||
// Simulate old browser
|
||||
Symbol = void 0;
|
||||
|
||||
expect(() => [...o]).toThrow(/spread non-iterable/);
|
||||
Reference in New Issue
Block a user