Skip to content

Commit d99057d

Browse files
committed
add extra test case
1 parent 6f5d4a1 commit d99057d

4 files changed

Lines changed: 139 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//// [tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.ts] ////
2+
3+
//// [nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.ts]
4+
// https://github.com/microsoft/TypeScript/issues/61109
5+
6+
class Cls {
7+
#privateProp: number | undefined;
8+
9+
problem() {
10+
this.#privateProp ??= false ? neverThis() : 20;
11+
}
12+
}
13+
14+
function neverThis(): never {
15+
throw new Error("This should really really never happen!");
16+
}
17+
18+
19+
//// [nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.js]
20+
"use strict";
21+
// https://github.com/microsoft/TypeScript/issues/61109
22+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
23+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
24+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
25+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
26+
};
27+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
28+
if (kind === "m") throw new TypeError("Private method is not writable");
29+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
30+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
31+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
32+
};
33+
var _Cls_privateProp;
34+
class Cls {
35+
constructor() {
36+
_Cls_privateProp.set(this, void 0);
37+
}
38+
problem() {
39+
__classPrivateFieldSet(this, _Cls_privateProp, __classPrivateFieldGet(this, _Cls_privateProp, "f") ?? (false ? neverThis() : 20), "f");
40+
}
41+
}
42+
_Cls_privateProp = new WeakMap();
43+
function neverThis() {
44+
throw new Error("This should really really never happen!");
45+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.ts] ////
2+
3+
=== nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/61109
5+
6+
class Cls {
7+
>Cls : Symbol(Cls, Decl(nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.ts, 0, 0))
8+
9+
#privateProp: number | undefined;
10+
>#privateProp : Symbol(Cls.#privateProp, Decl(nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.ts, 2, 11))
11+
12+
problem() {
13+
>problem : Symbol(Cls.problem, Decl(nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.ts, 3, 35))
14+
15+
this.#privateProp ??= false ? neverThis() : 20;
16+
>this.#privateProp : Symbol(Cls.#privateProp, Decl(nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.ts, 2, 11))
17+
>this : Symbol(Cls, Decl(nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.ts, 0, 0))
18+
>neverThis : Symbol(neverThis, Decl(nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.ts, 8, 1))
19+
}
20+
}
21+
22+
function neverThis(): never {
23+
>neverThis : Symbol(neverThis, Decl(nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.ts, 8, 1))
24+
25+
throw new Error("This should really really never happen!");
26+
>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
27+
}
28+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//// [tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.ts] ////
2+
3+
=== nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/61109
5+
6+
class Cls {
7+
>Cls : Cls
8+
> : ^^^
9+
10+
#privateProp: number | undefined;
11+
>#privateProp : number | undefined
12+
> : ^^^^^^^^^^^^^^^^^^
13+
14+
problem() {
15+
>problem : () => void
16+
> : ^^^^^^^^^^
17+
18+
this.#privateProp ??= false ? neverThis() : 20;
19+
>this.#privateProp ??= false ? neverThis() : 20 : number
20+
> : ^^^^^^
21+
>this.#privateProp : number | undefined
22+
> : ^^^^^^^^^^^^^^^^^^
23+
>this : this
24+
> : ^^^^
25+
>false ? neverThis() : 20 : 20
26+
> : ^^
27+
>false : false
28+
> : ^^^^^
29+
>neverThis() : never
30+
> : ^^^^^
31+
>neverThis : () => never
32+
> : ^^^^^^
33+
>20 : 20
34+
> : ^^
35+
}
36+
}
37+
38+
function neverThis(): never {
39+
>neverThis : () => never
40+
> : ^^^^^^
41+
42+
throw new Error("This should really really never happen!");
43+
>new Error("This should really really never happen!") : Error
44+
> : ^^^^^
45+
>Error : ErrorConstructor
46+
> : ^^^^^^^^^^^^^^^^
47+
>"This should really really never happen!" : "This should really really never happen!"
48+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49+
}
50+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @strict: true
2+
// @target: es2021
3+
4+
// https://github.com/microsoft/TypeScript/issues/61109
5+
6+
class Cls {
7+
#privateProp: number | undefined;
8+
9+
problem() {
10+
this.#privateProp ??= false ? neverThis() : 20;
11+
}
12+
}
13+
14+
function neverThis(): never {
15+
throw new Error("This should really really never happen!");
16+
}

0 commit comments

Comments
 (0)