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;
|
let childExpression = childNode.parent;
|
||||||
while (testedExpression && childExpression) {
|
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);
|
return getSymbolAtLocation(testedExpression) === getSymbolAtLocation(childExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,11 @@ tests/cases/compiler/truthinessCallExpressionCoercion1.ts(61,9): error TS2774: T
|
||||||
|
|
||||||
// ok
|
// ok
|
||||||
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;
|
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;
|
||||||
|
|
||||||
|
// ok
|
||||||
|
if (this.isUser) {
|
||||||
|
this.isUser();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,11 @@ class Foo {
|
||||||
|
|
||||||
// ok
|
// ok
|
||||||
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;
|
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;
|
this.isUser ? console.log('this.isUser') : undefined;
|
||||||
// ok
|
// ok
|
||||||
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;
|
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;
|
||||||
|
// ok
|
||||||
|
if (this.isUser) {
|
||||||
|
this.isUser();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return Foo;
|
return Foo;
|
||||||
}());
|
}());
|
||||||
|
|
|
@ -170,6 +170,18 @@ class Foo {
|
||||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||||
>undefined : Symbol(undefined)
|
>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
|
>log : (...data: any[]) => void
|
||||||
>'this.maybeIsUser' : "this.maybeIsUser"
|
>'this.maybeIsUser' : "this.maybeIsUser"
|
||||||
>undefined : undefined
|
>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
|
// ok
|
||||||
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;
|
this.maybeIsUser ? console.log('this.maybeIsUser') : undefined;
|
||||||
|
|
||||||
|
// ok
|
||||||
|
if (this.isUser) {
|
||||||
|
this.isUser();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue