Skip to content

Commit d00a5b7

Browse files
committed
Improve test cases
Signed-off-by: Babak K. Shandiz <[email protected]>
1 parent 3f1b524 commit d00a5b7

8 files changed

+107
-2
lines changed

tests/baselines/reference/destructuringArrayBindingPatternAndAssignment5SiblingInitializer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ function f3() {
1818
const [a1, b1 = a1] = ['hi', 1];
1919
const [a2, b2 = a2 + '!'] = ['hi', 1];
2020
}
21+
22+
// Based on comment:
23+
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486
24+
declare const yadda: [number, number] | undefined
25+
function f4() {
26+
const [ a, b = a ] = yadda ?? [];
27+
}
2128

2229

2330
//// [destructuringArrayBindingPatternAndAssignment5SiblingInitializer.js]
@@ -36,3 +43,6 @@ function f3() {
3643
var _a = ['hi', 1], a1 = _a[0], _b = _a[1], b1 = _b === void 0 ? a1 : _b;
3744
var _c = ['hi', 1], a2 = _c[0], _d = _c[1], b2 = _d === void 0 ? a2 + '!' : _d;
3845
}
46+
function f4() {
47+
var _a = yadda !== null && yadda !== void 0 ? yadda : [], a = _a[0], _b = _a[1], b = _b === void 0 ? a : _b;
48+
}

tests/baselines/reference/destructuringArrayBindingPatternAndAssignment5SiblingInitializer.symbols

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,18 @@ function f3() {
4646
>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 15, 11))
4747
}
4848

49+
// Based on comment:
50+
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486
51+
declare const yadda: [number, number] | undefined
52+
>yadda : Symbol(yadda, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 20, 13))
53+
54+
function f4() {
55+
>f4 : Symbol(f4, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 20, 49))
56+
57+
const [ a, b = a ] = yadda ?? [];
58+
>a : Symbol(a, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 22, 11))
59+
>b : Symbol(b, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 22, 14))
60+
>a : Symbol(a, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 22, 11))
61+
>yadda : Symbol(yadda, Decl(destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts, 20, 13))
62+
}
63+

tests/baselines/reference/destructuringArrayBindingPatternAndAssignment5SiblingInitializer.types

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,20 @@ function f3() {
6666
>1 : 1
6767
}
6868

69+
// Based on comment:
70+
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486
71+
declare const yadda: [number, number] | undefined
72+
>yadda : [number, number]
73+
74+
function f4() {
75+
>f4 : () => void
76+
77+
const [ a, b = a ] = yadda ?? [];
78+
>a : number
79+
>b : number
80+
>a : number
81+
>yadda ?? [] : [number, number] | []
82+
>yadda : [number, number]
83+
>[] : []
84+
}
85+

tests/baselines/reference/destructuringObjectBindingPatternAndAssignment9SiblingInitializer.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ function f2() {
1717
function f3() {
1818
const { a1, b1 = a1 } = { a1: 'hi', b1: 1 };
1919
const { a2, b2 = a2 + '!' } = { a2: 'hi', b2: 1 };
20-
}
20+
}
21+
22+
// Based on comment:
23+
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486
24+
declare const yadda: { a?: number, b?: number } | undefined
25+
function f4() {
26+
const { a, b = a } = yadda ?? {};
27+
}
28+
2129

2230
//// [destructuringObjectBindingPatternAndAssignment9SiblingInitializer.js]
2331
// To be inferred as `number`
@@ -35,3 +43,6 @@ function f3() {
3543
var _a = { a1: 'hi', b1: 1 }, a1 = _a.a1, _b = _a.b1, b1 = _b === void 0 ? a1 : _b;
3644
var _c = { a2: 'hi', b2: 1 }, a2 = _c.a2, _d = _c.b2, b2 = _d === void 0 ? a2 + '!' : _d;
3745
}
46+
function f4() {
47+
var _a = yadda !== null && yadda !== void 0 ? yadda : {}, a = _a.a, _b = _a.b, b = _b === void 0 ? a : _b;
48+
}

tests/baselines/reference/destructuringObjectBindingPatternAndAssignment9SiblingInitializer.symbols

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,21 @@ function f3() {
5353
>a2 : Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts, 15, 35))
5454
>b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts, 15, 45))
5555
}
56+
57+
// Based on comment:
58+
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486
59+
declare const yadda: { a?: number, b?: number } | undefined
60+
>yadda : Symbol(yadda, Decl(destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts, 20, 13))
61+
>a : Symbol(a, Decl(destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts, 20, 22))
62+
>b : Symbol(b, Decl(destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts, 20, 34))
63+
64+
function f4() {
65+
>f4 : Symbol(f4, Decl(destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts, 20, 59))
66+
67+
const { a, b = a } = yadda ?? {};
68+
>a : Symbol(a, Decl(destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts, 22, 11))
69+
>b : Symbol(b, Decl(destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts, 22, 14))
70+
>a : Symbol(a, Decl(destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts, 22, 11))
71+
>yadda : Symbol(yadda, Decl(destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts, 20, 13))
72+
}
73+

tests/baselines/reference/destructuringObjectBindingPatternAndAssignment9SiblingInitializer.types

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,23 @@ function f3() {
7373
>b2 : number
7474
>1 : 1
7575
}
76+
77+
// Based on comment:
78+
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486
79+
declare const yadda: { a?: number, b?: number } | undefined
80+
>yadda : { a?: number; b?: number; }
81+
>a : number
82+
>b : number
83+
84+
function f4() {
85+
>f4 : () => void
86+
87+
const { a, b = a } = yadda ?? {};
88+
>a : number
89+
>b : number
90+
>a : number
91+
>yadda ?? {} : { a?: number; b?: number; }
92+
>yadda : { a?: number; b?: number; }
93+
>{} : {}
94+
}
95+

tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment5SiblingInitializer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ function f3() {
1717
const [a1, b1 = a1] = ['hi', 1];
1818
const [a2, b2 = a2 + '!'] = ['hi', 1];
1919
}
20+
21+
// Based on comment:
22+
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486
23+
declare const yadda: [number, number] | undefined
24+
function f4() {
25+
const [ a, b = a ] = yadda ?? [];
26+
}

tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment9SiblingInitializer.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@ function f2() {
1616
function f3() {
1717
const { a1, b1 = a1 } = { a1: 'hi', b1: 1 };
1818
const { a2, b2 = a2 + '!' } = { a2: 'hi', b2: 1 };
19-
}
19+
}
20+
21+
// Based on comment:
22+
// - https://github.com/microsoft/TypeScript/issues/49989#issuecomment-1852694486
23+
declare const yadda: { a?: number, b?: number } | undefined
24+
function f4() {
25+
const { a, b = a } = yadda ?? {};
26+
}

0 commit comments

Comments
 (0)