Skip to content

Commit ee0eca7

Browse files
RyanCavanaughjakebailey
authored andcommitted
MetaProperty is possibly nullish (microsoft#60440)
1 parent cbda51a commit ee0eca7

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39784,6 +39784,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3978439784
case SyntaxKind.AwaitExpression:
3978539785
case SyntaxKind.CallExpression:
3978639786
case SyntaxKind.ElementAccessExpression:
39787+
case SyntaxKind.MetaProperty:
3978739788
case SyntaxKind.NewExpression:
3978839789
case SyntaxKind.PropertyAccessExpression:
3978939790
case SyntaxKind.YieldExpression:

tests/baselines/reference/predicateSemantics.errors.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,11 @@ predicateSemantics.ts(52,14): error TS2869: Right operand of ?? is unreachable b
9696
~~~~~~~~~~
9797
!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
9898
}
99+
100+
// https://github.com/microsoft/TypeScript/issues/60439
101+
class X {
102+
constructor() {
103+
const p = new.target ?? 32;
104+
}
105+
}
99106

tests/baselines/reference/predicateSemantics.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ function foo(this: Object | undefined) {
5454
const e = (i++, i++) ?? true; // error
5555
const f = (maybe, i++) ?? true; // error
5656
}
57+
58+
// https://github.com/microsoft/TypeScript/issues/60439
59+
class X {
60+
constructor() {
61+
const p = new.target ?? 32;
62+
}
63+
}
5764

5865

5966
//// [predicateSemantics.js]
@@ -106,3 +113,12 @@ function foo() {
106113
var e = (_h = (i++, i++)) !== null && _h !== void 0 ? _h : true; // error
107114
var f = (_j = (maybe, i++)) !== null && _j !== void 0 ? _j : true; // error
108115
}
116+
// https://github.com/microsoft/TypeScript/issues/60439
117+
var X = /** @class */ (function () {
118+
function X() {
119+
var _newTarget = this.constructor;
120+
var _a;
121+
var p = (_a = _newTarget) !== null && _a !== void 0 ? _a : 32;
122+
}
123+
return X;
124+
}());

tests/baselines/reference/predicateSemantics.symbols

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,15 @@ function foo(this: Object | undefined) {
104104
>i : Symbol(i, Decl(predicateSemantics.ts, 48, 5))
105105
}
106106

107+
// https://github.com/microsoft/TypeScript/issues/60439
108+
class X {
109+
>X : Symbol(X, Decl(predicateSemantics.ts, 52, 1))
110+
111+
constructor() {
112+
const p = new.target ?? 32;
113+
>p : Symbol(p, Decl(predicateSemantics.ts, 57, 9))
114+
>new.target : Symbol(X, Decl(predicateSemantics.ts, 52, 1))
115+
>target : Symbol(X, Decl(predicateSemantics.ts, 52, 1))
116+
}
117+
}
118+

tests/baselines/reference/predicateSemantics.types

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,23 @@ function foo(this: Object | undefined) {
308308
> : ^^^^
309309
}
310310

311+
// https://github.com/microsoft/TypeScript/issues/60439
312+
class X {
313+
>X : X
314+
> : ^
315+
316+
constructor() {
317+
const p = new.target ?? 32;
318+
>p : 32 | typeof X
319+
> : ^^^^^^^^^^^^^
320+
>new.target ?? 32 : 32 | typeof X
321+
> : ^^^^^^^^^^^^^
322+
>new.target : typeof X
323+
> : ^^^^^^^^
324+
>target : typeof X
325+
> : ^^^^^^^^
326+
>32 : 32
327+
> : ^^
328+
}
329+
}
330+

tests/cases/compiler/predicateSemantics.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,10 @@ function foo(this: Object | undefined) {
5151
const e = (i++, i++) ?? true; // error
5252
const f = (maybe, i++) ?? true; // error
5353
}
54+
55+
// https://github.com/microsoft/TypeScript/issues/60439
56+
class X {
57+
constructor() {
58+
const p = new.target ?? 32;
59+
}
60+
}

0 commit comments

Comments
 (0)