| 1 |
let [x = 23] = [,]; |
| 2 |
expect(x).toEqual(23); |
| 3 |
|
| 4 |
const [y = 24, z] = [, 42]; |
| 5 |
expect(y).toEqual(24); |
| 6 |
expect(z).toEqual(42); |
| 7 |
|
| 8 |
function* foo() { |
| 9 |
yield 1; |
| 10 |
yield 2; |
| 11 |
} |
| 12 |
|
| 13 |
let bar = foo(); |
| 14 |
|
| 15 |
const [a = bar.next().value, b] = [, bar.next().value]; |
| 16 |
|
| 17 |
expect(a).toEqual(2); |
| 18 |
expect(b).toEqual(1); |
| 19 |
|
| 20 |
const arr = [c = 42] = [,]; |
| 21 |
expect(c).toEqual(42); |
| 22 |
expect(arr).toStrictEqual([,]); |
| 23 |
|
| 24 |
var iterCount = 0; |
| 25 |
|
| 26 |
for (const [x = 23] = [,]; iterCount < 1; ) { |
| 27 |
expect(x).toEqual(23); |
| 28 |
// another statement |
| 29 |
|
| 30 |
iterCount += 1; |
| 31 |
} |
| 32 |
|
| 33 |
expect(iterCount).toEqual(1); |
| 34 |
|
| 35 |
const [...d] = [,]; |
| 36 |
const [...{ 0: e }] = [,]; |
| 37 |
|
| 38 |
expect(d).toStrictEqual([,]); |
| 39 |
expect(e).toEqual(undefined); |
| 40 |
|
| 41 |
const [f] = [,]; |
| 42 |
expect(f).toEqual(undefined); |
| 43 |
|
| 44 |
let [g] = [,]; |
| 45 |
expect(g).toEqual(undefined); |
| 46 |
|
| 47 |
let thrown; |
| 48 |
try { |
| 49 |
thrown = false; |
| 50 |
[{}] = [,]; |
| 51 |
} catch (e) { |
| 52 |
thrown = true; |
| 53 |
} |
| 54 |
expect(thrown).toEqual(true); |
| 55 |
|
| 56 |
try { |
| 57 |
thrown = false; |
| 58 |
[[]] = [,]; |
| 59 |
} catch (e) { |
| 60 |
thrown = true; |
| 61 |
} |
| 62 |
expect(thrown).toEqual(true); |