Set parent pointers on manufactured reference for property initialization check (#27246)

This commit is contained in:
Wesley Wigham 2018-09-20 16:54:01 -07:00 committed by Wesley Wigham
parent 9103191527
commit 93f6b73c8c
No known key found for this signature in database
GPG Key ID: D59F87F60C5400C9
5 changed files with 55 additions and 0 deletions

View File

@ -26176,6 +26176,8 @@ namespace ts {
function isPropertyInitializedInConstructor(propName: Identifier, propType: Type, constructor: ConstructorDeclaration) {
const reference = createPropertyAccess(createThis(), propName);
reference.expression.parent = reference;
reference.parent = constructor;
reference.flowNode = constructor.returnFlowNode;
const flowType = getFlowTypeOfReference(reference, propType, getOptionalType(propType));
return !(getFalsyFlags(flowType) & TypeFlags.Undefined);

View File

@ -0,0 +1,16 @@
//// [strictBooleanMemberAssignability.ts]
class Abc {
def: boolean
constructor() {
this.def = true
}
}
//// [strictBooleanMemberAssignability.js]
"use strict";
var Abc = /** @class */ (function () {
function Abc() {
this.def = true;
}
return Abc;
}());

View File

@ -0,0 +1,14 @@
=== tests/cases/compiler/strictBooleanMemberAssignability.ts ===
class Abc {
>Abc : Symbol(Abc, Decl(strictBooleanMemberAssignability.ts, 0, 0))
def: boolean
>def : Symbol(Abc.def, Decl(strictBooleanMemberAssignability.ts, 0, 11))
constructor() {
this.def = true
>this.def : Symbol(Abc.def, Decl(strictBooleanMemberAssignability.ts, 0, 11))
>this : Symbol(Abc, Decl(strictBooleanMemberAssignability.ts, 0, 0))
>def : Symbol(Abc.def, Decl(strictBooleanMemberAssignability.ts, 0, 11))
}
}

View File

@ -0,0 +1,16 @@
=== tests/cases/compiler/strictBooleanMemberAssignability.ts ===
class Abc {
>Abc : Abc
def: boolean
>def : boolean
constructor() {
this.def = true
>this.def = true : true
>this.def : boolean
>this : this
>def : boolean
>true : true
}
}

View File

@ -0,0 +1,7 @@
// @strict: true
class Abc {
def: boolean
constructor() {
this.def = true
}
}