Test: Allow ++ after non-null assertion

This commit is contained in:
Nathan Shively-Sanders 2017-06-12 14:41:10 -07:00
parent 55beb14bca
commit 497d627a02
4 changed files with 136 additions and 0 deletions

View file

@ -0,0 +1,28 @@
//// [incrementOnNullAssertion.ts]
interface Dictionary<T> {
[myFavouriteType: string]: T | undefined
}
const x = 'bar'
let foo: Dictionary<number> = {}
if (foo[x] === undefined) {
foo[x] = 1
}
else {
let nu = foo[x]
let n = foo[x]
foo[x]!++
}
//// [incrementOnNullAssertion.js]
"use strict";
var x = 'bar';
var foo = {};
if (foo[x] === undefined) {
foo[x] = 1;
}
else {
var nu = foo[x];
var n = foo[x];
foo[x]++;
}

View file

@ -0,0 +1,41 @@
=== tests/cases/compiler/incrementOnNullAssertion.ts ===
interface Dictionary<T> {
>Dictionary : Symbol(Dictionary, Decl(incrementOnNullAssertion.ts, 0, 0))
>T : Symbol(T, Decl(incrementOnNullAssertion.ts, 0, 21))
[myFavouriteType: string]: T | undefined
>myFavouriteType : Symbol(myFavouriteType, Decl(incrementOnNullAssertion.ts, 1, 5))
>T : Symbol(T, Decl(incrementOnNullAssertion.ts, 0, 21))
}
const x = 'bar'
>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5))
let foo: Dictionary<number> = {}
>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3))
>Dictionary : Symbol(Dictionary, Decl(incrementOnNullAssertion.ts, 0, 0))
if (foo[x] === undefined) {
>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3))
>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5))
>undefined : Symbol(undefined)
foo[x] = 1
>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3))
>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5))
}
else {
let nu = foo[x]
>nu : Symbol(nu, Decl(incrementOnNullAssertion.ts, 9, 7))
>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3))
>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5))
let n = foo[x]
>n : Symbol(n, Decl(incrementOnNullAssertion.ts, 10, 7))
>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3))
>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5))
foo[x]!++
>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3))
>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5))
}

View file

@ -0,0 +1,53 @@
=== tests/cases/compiler/incrementOnNullAssertion.ts ===
interface Dictionary<T> {
>Dictionary : Dictionary<T>
>T : T
[myFavouriteType: string]: T | undefined
>myFavouriteType : string
>T : T
}
const x = 'bar'
>x : "bar"
>'bar' : "bar"
let foo: Dictionary<number> = {}
>foo : Dictionary<number>
>Dictionary : Dictionary<T>
>{} : {}
if (foo[x] === undefined) {
>foo[x] === undefined : boolean
>foo[x] : number | undefined
>foo : Dictionary<number>
>x : "bar"
>undefined : undefined
foo[x] = 1
>foo[x] = 1 : 1
>foo[x] : number | undefined
>foo : Dictionary<number>
>x : "bar"
>1 : 1
}
else {
let nu = foo[x]
>nu : number | undefined
>foo[x] : number | undefined
>foo : Dictionary<number>
>x : "bar"
let n = foo[x]
>n : number | undefined
>foo[x] : number | undefined
>foo : Dictionary<number>
>x : "bar"
foo[x]!++
>foo[x]!++ : number
>foo[x]! : number
>foo[x] : number | undefined
>foo : Dictionary<number>
>x : "bar"
}

View file

@ -0,0 +1,14 @@
// @strict: true
interface Dictionary<T> {
[myFavouriteType: string]: T | undefined
}
const x = 'bar'
let foo: Dictionary<number> = {}
if (foo[x] === undefined) {
foo[x] = 1
}
else {
let nu = foo[x]
let n = foo[x]
foo[x]!++
}