Add regression test

This commit is contained in:
Anders Hejlsberg
2016-06-03 17:31:28 -07:00
parent a5e9071a2f
commit 87ee72b25a
4 changed files with 107 additions and 0 deletions
@@ -0,0 +1,32 @@
//// [classStaticPropertyTypeGuard.ts]
// Repro from #8923
class A {
private static _a: string | undefined;
public get a(): string {
if (A._a) {
return A._a; // is possibly null or undefined.
}
return A._a = 'helloworld';
}
}
//// [classStaticPropertyTypeGuard.js]
// Repro from #8923
var A = (function () {
function A() {
}
Object.defineProperty(A.prototype, "a", {
get: function () {
if (A._a) {
return A._a; // is possibly null or undefined.
}
return A._a = 'helloworld';
},
enumerable: true,
configurable: true
});
return A;
}());
@@ -0,0 +1,29 @@
=== tests/cases/compiler/classStaticPropertyTypeGuard.ts ===
// Repro from #8923
class A {
>A : Symbol(A, Decl(classStaticPropertyTypeGuard.ts, 0, 0))
private static _a: string | undefined;
>_a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
public get a(): string {
>a : Symbol(A.a, Decl(classStaticPropertyTypeGuard.ts, 4, 42))
if (A._a) {
>A._a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
>A : Symbol(A, Decl(classStaticPropertyTypeGuard.ts, 0, 0))
>_a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
return A._a; // is possibly null or undefined.
>A._a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
>A : Symbol(A, Decl(classStaticPropertyTypeGuard.ts, 0, 0))
>_a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
}
return A._a = 'helloworld';
>A._a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
>A : Symbol(A, Decl(classStaticPropertyTypeGuard.ts, 0, 0))
>_a : Symbol(A._a, Decl(classStaticPropertyTypeGuard.ts, 3, 9))
}
}
@@ -0,0 +1,31 @@
=== tests/cases/compiler/classStaticPropertyTypeGuard.ts ===
// Repro from #8923
class A {
>A : A
private static _a: string | undefined;
>_a : string | undefined
public get a(): string {
>a : string
if (A._a) {
>A._a : string | undefined
>A : typeof A
>_a : string | undefined
return A._a; // is possibly null or undefined.
>A._a : string
>A : typeof A
>_a : string
}
return A._a = 'helloworld';
>A._a = 'helloworld' : string
>A._a : string | undefined
>A : typeof A
>_a : string | undefined
>'helloworld' : string
}
}
@@ -0,0 +1,15 @@
// @strictNullChecks: true
// @target: ES5
// Repro from #8923
class A {
private static _a: string | undefined;
public get a(): string {
if (A._a) {
return A._a; // is possibly null or undefined.
}
return A._a = 'helloworld';
}
}