Debian Codegraph @

packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/empty-array-pattern/exec.js

raw
1 expect(() => {
2 var [] = null;
3 }).toThrow(TypeError);
4
5 expect(() => {
6 var [] = 42;
7 }).toThrow(TypeError);
8
9 expect(() => {
10 var [] = {};
11 }).toThrow(TypeError);
12
13 expect(() => {
14 var [] = { [Symbol.iterator]: () => {} };
15 }).toThrow(TypeError);
16
17 expect(() => {
18 var [] = [];
19 var [] = [0, 1, 2];
20 var [] = "foo";
21 var [] = (function*() { throw new Error("Should not throw"); })();
22 var [] = { [Symbol.iterator]: () => ({}) };
23 var [] = { [Symbol.iterator]: () => () => {} };
24 var [] = { [Symbol.iterator]: async function*() {} };
25 }).not.toThrow();
26
27 // iterator.return should be called
28 var returnCalled = false;
29 var [] = {
30 [Symbol.iterator]: () => {
31 return {
32 return: () => {
33 returnCalled = true;
34 return {};
35 },
36 };
37 },
38 };
39 expect(returnCalled).toStrictEqual(true);
40
41 // #15154
42 expect(() => {
43 var [] = { [Symbol.iterator]: () => [] };
44 }).not.toThrow();
45
46 // #15168
47 expect(() => {
48 var [] = { [Symbol.iterator]: () => async function* () {} };
49 }).not.toThrow();