Skip to content

Commit b56854a

Browse files
authored
Set parent pointers on manufactured reference for property initialization check (#27246)
1 parent 5f563c9 commit b56854a

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26185,6 +26185,8 @@ namespace ts {
2618526185

2618626186
function isPropertyInitializedInConstructor(propName: Identifier, propType: Type, constructor: ConstructorDeclaration) {
2618726187
const reference = createPropertyAccess(createThis(), propName);
26188+
reference.expression.parent = reference;
26189+
reference.parent = constructor;
2618826190
reference.flowNode = constructor.returnFlowNode;
2618926191
const flowType = getFlowTypeOfReference(reference, propType, getOptionalType(propType));
2619026192
return !(getFalsyFlags(flowType) & TypeFlags.Undefined);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [strictBooleanMemberAssignability.ts]
2+
class Abc {
3+
def: boolean
4+
constructor() {
5+
this.def = true
6+
}
7+
}
8+
9+
//// [strictBooleanMemberAssignability.js]
10+
"use strict";
11+
var Abc = /** @class */ (function () {
12+
function Abc() {
13+
this.def = true;
14+
}
15+
return Abc;
16+
}());
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/strictBooleanMemberAssignability.ts ===
2+
class Abc {
3+
>Abc : Symbol(Abc, Decl(strictBooleanMemberAssignability.ts, 0, 0))
4+
5+
def: boolean
6+
>def : Symbol(Abc.def, Decl(strictBooleanMemberAssignability.ts, 0, 11))
7+
8+
constructor() {
9+
this.def = true
10+
>this.def : Symbol(Abc.def, Decl(strictBooleanMemberAssignability.ts, 0, 11))
11+
>this : Symbol(Abc, Decl(strictBooleanMemberAssignability.ts, 0, 0))
12+
>def : Symbol(Abc.def, Decl(strictBooleanMemberAssignability.ts, 0, 11))
13+
}
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/strictBooleanMemberAssignability.ts ===
2+
class Abc {
3+
>Abc : Abc
4+
5+
def: boolean
6+
>def : boolean
7+
8+
constructor() {
9+
this.def = true
10+
>this.def = true : true
11+
>this.def : boolean
12+
>this : this
13+
>def : boolean
14+
>true : true
15+
}
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @strict: true
2+
class Abc {
3+
def: boolean
4+
constructor() {
5+
this.def = true
6+
}
7+
}

0 commit comments

Comments
 (0)