Skip to content

Commit 9d246a2

Browse files
committed
Fix leaking top level logical assignment
1 parent b48757c commit 9d246a2

10 files changed

+261
-4
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [logicalAssignment11.ts]
2+
let x: string | undefined;
3+
4+
let d: string | undefined;
5+
d ?? (d = x ?? "x")
6+
d.length;
7+
8+
let e: string | undefined;
9+
e ??= x ?? "x"
10+
e.length
11+
12+
//// [logicalAssignment11.js]
13+
"use strict";
14+
let x;
15+
let d;
16+
d !== null && d !== void 0 ? d : (d = x !== null && x !== void 0 ? x : "x");
17+
d.length;
18+
let e;
19+
e !== null && e !== void 0 ? e : (e = x !== null && x !== void 0 ? x : "x");
20+
e.length;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts ===
2+
let x: string | undefined;
3+
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3))
4+
5+
let d: string | undefined;
6+
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3))
7+
8+
d ?? (d = x ?? "x")
9+
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3))
10+
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3))
11+
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3))
12+
13+
d.length;
14+
>d.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
15+
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3))
16+
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
17+
18+
let e: string | undefined;
19+
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3))
20+
21+
e ??= x ?? "x"
22+
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3))
23+
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3))
24+
25+
e.length
26+
>e.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
27+
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3))
28+
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
29+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts ===
2+
let x: string | undefined;
3+
>x : string | undefined
4+
5+
let d: string | undefined;
6+
>d : string | undefined
7+
8+
d ?? (d = x ?? "x")
9+
>d ?? (d = x ?? "x") : string
10+
>d : string | undefined
11+
>(d = x ?? "x") : string
12+
>d = x ?? "x" : string
13+
>d : string | undefined
14+
>x ?? "x" : string
15+
>x : string | undefined
16+
>"x" : "x"
17+
18+
d.length;
19+
>d.length : number
20+
>d : string
21+
>length : number
22+
23+
let e: string | undefined;
24+
>e : string | undefined
25+
26+
e ??= x ?? "x"
27+
>e ??= x ?? "x" : string
28+
>e : string | undefined
29+
>x ?? "x" : string
30+
>x : string | undefined
31+
>"x" : "x"
32+
33+
e.length
34+
>e.length : number
35+
>e : string
36+
>length : number
37+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [logicalAssignment11.ts]
2+
let x: string | undefined;
3+
4+
let d: string | undefined;
5+
d ?? (d = x ?? "x")
6+
d.length;
7+
8+
let e: string | undefined;
9+
e ??= x ?? "x"
10+
e.length
11+
12+
//// [logicalAssignment11.js]
13+
"use strict";
14+
let x;
15+
let d;
16+
d ?? (d = x ?? "x");
17+
d.length;
18+
let e;
19+
e ?? (e = x ?? "x");
20+
e.length;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts ===
2+
let x: string | undefined;
3+
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3))
4+
5+
let d: string | undefined;
6+
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3))
7+
8+
d ?? (d = x ?? "x")
9+
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3))
10+
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3))
11+
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3))
12+
13+
d.length;
14+
>d.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
15+
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3))
16+
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
17+
18+
let e: string | undefined;
19+
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3))
20+
21+
e ??= x ?? "x"
22+
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3))
23+
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3))
24+
25+
e.length
26+
>e.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
27+
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3))
28+
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
29+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts ===
2+
let x: string | undefined;
3+
>x : string | undefined
4+
5+
let d: string | undefined;
6+
>d : string | undefined
7+
8+
d ?? (d = x ?? "x")
9+
>d ?? (d = x ?? "x") : string
10+
>d : string | undefined
11+
>(d = x ?? "x") : string
12+
>d = x ?? "x" : string
13+
>d : string | undefined
14+
>x ?? "x" : string
15+
>x : string | undefined
16+
>"x" : "x"
17+
18+
d.length;
19+
>d.length : number
20+
>d : string
21+
>length : number
22+
23+
let e: string | undefined;
24+
>e : string | undefined
25+
26+
e ??= x ?? "x"
27+
>e ??= x ?? "x" : string
28+
>e : string | undefined
29+
>x ?? "x" : string
30+
>x : string | undefined
31+
>"x" : "x"
32+
33+
e.length
34+
>e.length : number
35+
>e : string
36+
>length : number
37+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [logicalAssignment11.ts]
2+
let x: string | undefined;
3+
4+
let d: string | undefined;
5+
d ?? (d = x ?? "x")
6+
d.length;
7+
8+
let e: string | undefined;
9+
e ??= x ?? "x"
10+
e.length
11+
12+
//// [logicalAssignment11.js]
13+
"use strict";
14+
let x;
15+
let d;
16+
d ?? (d = x ?? "x");
17+
d.length;
18+
let e;
19+
e ??= x ?? "x";
20+
e.length;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts ===
2+
let x: string | undefined;
3+
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3))
4+
5+
let d: string | undefined;
6+
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3))
7+
8+
d ?? (d = x ?? "x")
9+
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3))
10+
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3))
11+
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3))
12+
13+
d.length;
14+
>d.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
15+
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3))
16+
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
17+
18+
let e: string | undefined;
19+
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3))
20+
21+
e ??= x ?? "x"
22+
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3))
23+
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3))
24+
25+
e.length
26+
>e.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
27+
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3))
28+
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
29+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts ===
2+
let x: string | undefined;
3+
>x : string | undefined
4+
5+
let d: string | undefined;
6+
>d : string | undefined
7+
8+
d ?? (d = x ?? "x")
9+
>d ?? (d = x ?? "x") : string
10+
>d : string | undefined
11+
>(d = x ?? "x") : string
12+
>d = x ?? "x" : string
13+
>d : string | undefined
14+
>x ?? "x" : string
15+
>x : string | undefined
16+
>"x" : "x"
17+
18+
d.length;
19+
>d.length : number
20+
>d : string
21+
>length : number
22+
23+
let e: string | undefined;
24+
>e : string | undefined
25+
26+
e ??= x ?? "x"
27+
>e ??= x ?? "x" : string
28+
>e : string | undefined
29+
>x ?? "x" : string
30+
>x : string | undefined
31+
>"x" : "x"
32+
33+
e.length
34+
>e.length : number
35+
>e : string
36+
>length : number
37+

tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
let x: string | undefined;
55

6-
// let d: string | undefined;
7-
// d ?? (d = x ?? "x")
8-
// d.length;
9-
6+
let d: string | undefined;
7+
d ?? (d = x ?? "x")
8+
d.length;
109

1110
let e: string | undefined;
1211
e ??= x ?? "x"

0 commit comments

Comments
 (0)