Skip to content

Commit f97d5fa

Browse files
committed
Update tests with improved spread-falsy-union rules
1 parent 9c6f651 commit f97d5fa

28 files changed

+707
-372
lines changed

tests/baselines/reference/objectSpread.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,42 @@ getter.a = 12;
3838
// functions result in { }
3939
let spreadFunc = { ...(function () { }) };
4040

41-
// boolean && T results in Partial<T>
42-
function conditionalSpreadBoolean(b: boolean) : { x?: number | undefined, y?: number | undefined } {
43-
return { ...b && { x: 1, y: 2 } };
41+
type Header = { head: string, body: string, authToken: string }
42+
function from16326(this: { header: Header }, header: Header, authToken: string): Header {
43+
return {
44+
...this.header,
45+
...header,
46+
...authToken && { authToken }
47+
}
4448
}
45-
function conditionalSpreadNumber(nt: number): { x?: number | undefined, y: number } {
49+
// boolean && T results in Partial<T>
50+
function conditionalSpreadBoolean(b: boolean) : { x: number, y: number } {
4651
let o = { x: 12, y: 13 }
52+
o = {
53+
...o,
54+
...b && { x: 14 }
55+
}
56+
let o2 = { ...b && { x: 21 }}
57+
return o;
58+
}
59+
function conditionalSpreadNumber(nt: number): { x: number, y: number } {
60+
let o = { x: 15, y: 16 }
4761
o = {
4862
...o,
4963
...nt && { x: nt }
5064
}
5165
let o2 = { ...nt && { x: nt }}
5266
return o;
5367
}
54-
function conditionalSpreadString(st: string): { x?: string | undefined, y: number } {
55-
let o = { x: 'hi', y: 13 }
68+
function conditionalSpreadString(st: string): { x: string, y: number } {
69+
let o = { x: 'hi', y: 17 }
5670
o = {
5771
...o,
5872
...st && { x: st }
5973
}
6074
let o2 = { ...st && { x: st }}
6175
return o;
6276
}
63-
// other booleans result in { }
64-
let spreadBool = { ... true }
6577

6678
// any results in any
6779
let anything: any;
@@ -141,24 +153,28 @@ var getter = __assign({}, op, { c: 7 });
141153
getter.a = 12;
142154
// functions result in { }
143155
var spreadFunc = __assign({}, (function () { }));
156+
function from16326(header, authToken) {
157+
return __assign({}, this.header, header, authToken && { authToken: authToken });
158+
}
144159
// boolean && T results in Partial<T>
145160
function conditionalSpreadBoolean(b) {
146-
return __assign({}, b && { x: 1, y: 2 });
161+
var o = { x: 12, y: 13 };
162+
o = __assign({}, o, b && { x: 14 });
163+
var o2 = __assign({}, b && { x: 21 });
164+
return o;
147165
}
148166
function conditionalSpreadNumber(nt) {
149-
var o = { x: 12, y: 13 };
167+
var o = { x: 15, y: 16 };
150168
o = __assign({}, o, nt && { x: nt });
151169
var o2 = __assign({}, nt && { x: nt });
152170
return o;
153171
}
154172
function conditionalSpreadString(st) {
155-
var o = { x: 'hi', y: 13 };
173+
var o = { x: 'hi', y: 17 };
156174
o = __assign({}, o, st && { x: st });
157175
var o2 = __assign({}, st && { x: st });
158176
return o;
159177
}
160-
// other booleans result in { }
161-
var spreadBool = __assign({}, true);
162178
// any results in any
163179
var anything;
164180
var spreadAny = __assign({}, anything);

0 commit comments

Comments
 (0)