Skip to content

Commit e968243

Browse files
committed
Accept new baselines
1 parent 290eff9 commit e968243

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//// [controlFlowDestructuringLoop.ts]
2+
// Repro from #28758
3+
4+
interface NumVal { val: number; }
5+
interface StrVal { val: string; }
6+
type Val = NumVal | StrVal;
7+
8+
function isNumVal(x: Val): x is NumVal {
9+
return typeof x.val === 'number';
10+
}
11+
12+
function foo(things: Val[]): void {
13+
for (const thing of things) {
14+
if (isNumVal(thing)) {
15+
const { val } = thing;
16+
val.toFixed(2);
17+
}
18+
else {
19+
const { val } = thing;
20+
val.length;
21+
}
22+
}
23+
}
24+
25+
//// [controlFlowDestructuringLoop.js]
26+
"use strict";
27+
// Repro from #28758
28+
function isNumVal(x) {
29+
return typeof x.val === 'number';
30+
}
31+
function foo(things) {
32+
for (var _i = 0, things_1 = things; _i < things_1.length; _i++) {
33+
var thing = things_1[_i];
34+
if (isNumVal(thing)) {
35+
var val = thing.val;
36+
val.toFixed(2);
37+
}
38+
else {
39+
var val = thing.val;
40+
val.length;
41+
}
42+
}
43+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
=== tests/cases/compiler/controlFlowDestructuringLoop.ts ===
2+
// Repro from #28758
3+
4+
interface NumVal { val: number; }
5+
>NumVal : Symbol(NumVal, Decl(controlFlowDestructuringLoop.ts, 0, 0))
6+
>val : Symbol(NumVal.val, Decl(controlFlowDestructuringLoop.ts, 2, 18))
7+
8+
interface StrVal { val: string; }
9+
>StrVal : Symbol(StrVal, Decl(controlFlowDestructuringLoop.ts, 2, 33))
10+
>val : Symbol(StrVal.val, Decl(controlFlowDestructuringLoop.ts, 3, 18))
11+
12+
type Val = NumVal | StrVal;
13+
>Val : Symbol(Val, Decl(controlFlowDestructuringLoop.ts, 3, 33))
14+
>NumVal : Symbol(NumVal, Decl(controlFlowDestructuringLoop.ts, 0, 0))
15+
>StrVal : Symbol(StrVal, Decl(controlFlowDestructuringLoop.ts, 2, 33))
16+
17+
function isNumVal(x: Val): x is NumVal {
18+
>isNumVal : Symbol(isNumVal, Decl(controlFlowDestructuringLoop.ts, 4, 27))
19+
>x : Symbol(x, Decl(controlFlowDestructuringLoop.ts, 6, 18))
20+
>Val : Symbol(Val, Decl(controlFlowDestructuringLoop.ts, 3, 33))
21+
>x : Symbol(x, Decl(controlFlowDestructuringLoop.ts, 6, 18))
22+
>NumVal : Symbol(NumVal, Decl(controlFlowDestructuringLoop.ts, 0, 0))
23+
24+
return typeof x.val === 'number';
25+
>x.val : Symbol(val, Decl(controlFlowDestructuringLoop.ts, 2, 18), Decl(controlFlowDestructuringLoop.ts, 3, 18))
26+
>x : Symbol(x, Decl(controlFlowDestructuringLoop.ts, 6, 18))
27+
>val : Symbol(val, Decl(controlFlowDestructuringLoop.ts, 2, 18), Decl(controlFlowDestructuringLoop.ts, 3, 18))
28+
}
29+
30+
function foo(things: Val[]): void {
31+
>foo : Symbol(foo, Decl(controlFlowDestructuringLoop.ts, 8, 1))
32+
>things : Symbol(things, Decl(controlFlowDestructuringLoop.ts, 10, 13))
33+
>Val : Symbol(Val, Decl(controlFlowDestructuringLoop.ts, 3, 33))
34+
35+
for (const thing of things) {
36+
>thing : Symbol(thing, Decl(controlFlowDestructuringLoop.ts, 11, 14))
37+
>things : Symbol(things, Decl(controlFlowDestructuringLoop.ts, 10, 13))
38+
39+
if (isNumVal(thing)) {
40+
>isNumVal : Symbol(isNumVal, Decl(controlFlowDestructuringLoop.ts, 4, 27))
41+
>thing : Symbol(thing, Decl(controlFlowDestructuringLoop.ts, 11, 14))
42+
43+
const { val } = thing;
44+
>val : Symbol(val, Decl(controlFlowDestructuringLoop.ts, 13, 19))
45+
>thing : Symbol(thing, Decl(controlFlowDestructuringLoop.ts, 11, 14))
46+
47+
val.toFixed(2);
48+
>val.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
49+
>val : Symbol(val, Decl(controlFlowDestructuringLoop.ts, 13, 19))
50+
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
51+
}
52+
else {
53+
const { val } = thing;
54+
>val : Symbol(val, Decl(controlFlowDestructuringLoop.ts, 17, 19))
55+
>thing : Symbol(thing, Decl(controlFlowDestructuringLoop.ts, 11, 14))
56+
57+
val.length;
58+
>val.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
59+
>val : Symbol(val, Decl(controlFlowDestructuringLoop.ts, 17, 19))
60+
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
61+
}
62+
}
63+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
=== tests/cases/compiler/controlFlowDestructuringLoop.ts ===
2+
// Repro from #28758
3+
4+
interface NumVal { val: number; }
5+
>val : number
6+
7+
interface StrVal { val: string; }
8+
>val : string
9+
10+
type Val = NumVal | StrVal;
11+
>Val : Val
12+
13+
function isNumVal(x: Val): x is NumVal {
14+
>isNumVal : (x: Val) => x is NumVal
15+
>x : Val
16+
17+
return typeof x.val === 'number';
18+
>typeof x.val === 'number' : boolean
19+
>typeof x.val : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
20+
>x.val : string | number
21+
>x : Val
22+
>val : string | number
23+
>'number' : "number"
24+
}
25+
26+
function foo(things: Val[]): void {
27+
>foo : (things: Val[]) => void
28+
>things : Val[]
29+
30+
for (const thing of things) {
31+
>thing : Val
32+
>things : Val[]
33+
34+
if (isNumVal(thing)) {
35+
>isNumVal(thing) : boolean
36+
>isNumVal : (x: Val) => x is NumVal
37+
>thing : Val
38+
39+
const { val } = thing;
40+
>val : number
41+
>thing : NumVal
42+
43+
val.toFixed(2);
44+
>val.toFixed(2) : string
45+
>val.toFixed : (fractionDigits?: number | undefined) => string
46+
>val : number
47+
>toFixed : (fractionDigits?: number | undefined) => string
48+
>2 : 2
49+
}
50+
else {
51+
const { val } = thing;
52+
>val : string
53+
>thing : StrVal
54+
55+
val.length;
56+
>val.length : number
57+
>val : string
58+
>length : number
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)