Skip to content

Commit 497d627

Browse files
committed
Test: Allow ++ after non-null assertion
1 parent 55beb14 commit 497d627

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [incrementOnNullAssertion.ts]
2+
interface Dictionary<T> {
3+
[myFavouriteType: string]: T | undefined
4+
}
5+
const x = 'bar'
6+
let foo: Dictionary<number> = {}
7+
if (foo[x] === undefined) {
8+
foo[x] = 1
9+
}
10+
else {
11+
let nu = foo[x]
12+
let n = foo[x]
13+
foo[x]!++
14+
}
15+
16+
17+
//// [incrementOnNullAssertion.js]
18+
"use strict";
19+
var x = 'bar';
20+
var foo = {};
21+
if (foo[x] === undefined) {
22+
foo[x] = 1;
23+
}
24+
else {
25+
var nu = foo[x];
26+
var n = foo[x];
27+
foo[x]++;
28+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
=== tests/cases/compiler/incrementOnNullAssertion.ts ===
2+
interface Dictionary<T> {
3+
>Dictionary : Symbol(Dictionary, Decl(incrementOnNullAssertion.ts, 0, 0))
4+
>T : Symbol(T, Decl(incrementOnNullAssertion.ts, 0, 21))
5+
6+
[myFavouriteType: string]: T | undefined
7+
>myFavouriteType : Symbol(myFavouriteType, Decl(incrementOnNullAssertion.ts, 1, 5))
8+
>T : Symbol(T, Decl(incrementOnNullAssertion.ts, 0, 21))
9+
}
10+
const x = 'bar'
11+
>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5))
12+
13+
let foo: Dictionary<number> = {}
14+
>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3))
15+
>Dictionary : Symbol(Dictionary, Decl(incrementOnNullAssertion.ts, 0, 0))
16+
17+
if (foo[x] === undefined) {
18+
>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3))
19+
>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5))
20+
>undefined : Symbol(undefined)
21+
22+
foo[x] = 1
23+
>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3))
24+
>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5))
25+
}
26+
else {
27+
let nu = foo[x]
28+
>nu : Symbol(nu, Decl(incrementOnNullAssertion.ts, 9, 7))
29+
>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3))
30+
>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5))
31+
32+
let n = foo[x]
33+
>n : Symbol(n, Decl(incrementOnNullAssertion.ts, 10, 7))
34+
>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3))
35+
>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5))
36+
37+
foo[x]!++
38+
>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3))
39+
>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5))
40+
}
41+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
=== tests/cases/compiler/incrementOnNullAssertion.ts ===
2+
interface Dictionary<T> {
3+
>Dictionary : Dictionary<T>
4+
>T : T
5+
6+
[myFavouriteType: string]: T | undefined
7+
>myFavouriteType : string
8+
>T : T
9+
}
10+
const x = 'bar'
11+
>x : "bar"
12+
>'bar' : "bar"
13+
14+
let foo: Dictionary<number> = {}
15+
>foo : Dictionary<number>
16+
>Dictionary : Dictionary<T>
17+
>{} : {}
18+
19+
if (foo[x] === undefined) {
20+
>foo[x] === undefined : boolean
21+
>foo[x] : number | undefined
22+
>foo : Dictionary<number>
23+
>x : "bar"
24+
>undefined : undefined
25+
26+
foo[x] = 1
27+
>foo[x] = 1 : 1
28+
>foo[x] : number | undefined
29+
>foo : Dictionary<number>
30+
>x : "bar"
31+
>1 : 1
32+
}
33+
else {
34+
let nu = foo[x]
35+
>nu : number | undefined
36+
>foo[x] : number | undefined
37+
>foo : Dictionary<number>
38+
>x : "bar"
39+
40+
let n = foo[x]
41+
>n : number | undefined
42+
>foo[x] : number | undefined
43+
>foo : Dictionary<number>
44+
>x : "bar"
45+
46+
foo[x]!++
47+
>foo[x]!++ : number
48+
>foo[x]! : number
49+
>foo[x] : number | undefined
50+
>foo : Dictionary<number>
51+
>x : "bar"
52+
}
53+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @strict: true
2+
interface Dictionary<T> {
3+
[myFavouriteType: string]: T | undefined
4+
}
5+
const x = 'bar'
6+
let foo: Dictionary<number> = {}
7+
if (foo[x] === undefined) {
8+
foo[x] = 1
9+
}
10+
else {
11+
let nu = foo[x]
12+
let n = foo[x]
13+
foo[x]!++
14+
}

0 commit comments

Comments
 (0)