Throw better errors for non-iterables when Symbol doesn't exist (#11264)

This commit is contained in:
Nicolò Ribaudo
2020-03-16 16:34:33 +01:00
committed by GitHub
parent 10058901d0
commit 1ba41f2084
17 changed files with 115 additions and 26 deletions

View 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;
}

View File

@@ -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];

View File

@@ -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));

View 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/);