Fix truthiness call check for this-property access (#38163)
This commit is contained in:
parent
38ff7762ec
commit
fe140acc09
|
@ -31909,7 +31909,9 @@ namespace ts {
|
|||
let childExpression = childNode.parent;
|
||||
while (testedExpression && childExpression) {
|
||||
|
||||
if (isIdentifier(testedExpression) && isIdentifier(childExpression)) {
|
||||
if (isIdentifier(testedExpression) && isIdentifier(childExpression) ||
|
||||
testedExpression.kind === SyntaxKind.ThisKeyword && childExpression.kind === SyntaxKind.ThisKeyword
|
||||
) {
|
||||
return getSymbolAtLocation(testedExpression) === getSymbolAtLocation(childExpression);
|
||||
}
|
||||
|
||||
|
|
|
@ -80,6 +80,11 @@ tests/cases/compiler/truthinessCallExpressionCoercion1.ts(61,9): error TS2774: T
|
|||
|
||||
// ok
|
||||
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;
|
||||
|
||||
// ok
|
||||
if (this.isUser) {
|
||||
this.isUser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -63,6 +63,11 @@ class Foo {
|
|||
|
||||
// ok
|
||||
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;
|
||||
|
||||
// ok
|
||||
if (this.isUser) {
|
||||
this.isUser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,6 +122,10 @@ var Foo = /** @class */ (function () {
|
|||
this.isUser ? console.log('this.isUser') : undefined;
|
||||
// ok
|
||||
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;
|
||||
// ok
|
||||
if (this.isUser) {
|
||||
this.isUser();
|
||||
}
|
||||
};
|
||||
return Foo;
|
||||
}());
|
||||
|
|
|
@ -170,6 +170,18 @@ class Foo {
|
|||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>undefined : Symbol(undefined)
|
||||
|
||||
// ok
|
||||
if (this.isUser) {
|
||||
>this.isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 52, 32))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion1.ts, 49, 1))
|
||||
>isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 52, 32))
|
||||
|
||||
this.isUser();
|
||||
>this.isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 52, 32))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion1.ts, 49, 1))
|
||||
>isUser : Symbol(Foo.isUser, Decl(truthinessCallExpressionCoercion1.ts, 52, 32))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -223,6 +223,19 @@ class Foo {
|
|||
>log : (...data: any[]) => void
|
||||
>'this.maybeIsUser' : "this.maybeIsUser"
|
||||
>undefined : undefined
|
||||
|
||||
// ok
|
||||
if (this.isUser) {
|
||||
>this.isUser : () => boolean
|
||||
>this : this
|
||||
>isUser : () => boolean
|
||||
|
||||
this.isUser();
|
||||
>this.isUser() : boolean
|
||||
>this.isUser : () => boolean
|
||||
>this : this
|
||||
>isUser : () => boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,5 +64,10 @@ class Foo {
|
|||
|
||||
// ok
|
||||
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;
|
||||
|
||||
// ok
|
||||
if (this.isUser) {
|
||||
this.isUser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue