No this-property assignments in TS (#40009)
* No this-property assignments in TS Even when `this` is aliased, which I mistakenly allowed in #39908. * remove errant file
This commit is contained in:
parent
57e2fe0462
commit
d371ae770d
|
@ -2487,7 +2487,7 @@ namespace ts {
|
|||
break;
|
||||
case AssignmentDeclarationKind.Property:
|
||||
const expression = ((node as BinaryExpression).left as AccessExpression).expression;
|
||||
if (isIdentifier(expression)) {
|
||||
if (isInJSFile(node) && isIdentifier(expression)) {
|
||||
const symbol = lookupSymbolForName(blockScopeContainer, expression.escapedText);
|
||||
if (isThisInitializedDeclaration(symbol?.valueDeclaration)) {
|
||||
bindThisPropertyAssignment(node as BindablePropertyAssignmentExpression);
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
//// [inferringClassMembersFromAssignments8.ts]
|
||||
// no inference in TS files, even for `this` aliases:
|
||||
|
||||
var app = function() {
|
||||
var _this = this;
|
||||
_this.swap = function() { }
|
||||
}
|
||||
var a = new app()
|
||||
a
|
||||
|
||||
|
||||
//// [inferringClassMembersFromAssignments8.js]
|
||||
// no inference in TS files, even for `this` aliases:
|
||||
var app = function () {
|
||||
var _this = this;
|
||||
_this.swap = function () { };
|
||||
};
|
||||
var a = new app();
|
||||
a;
|
|
@ -0,0 +1,19 @@
|
|||
=== tests/cases/conformance/salsa/inferringClassMembersFromAssignments8.ts ===
|
||||
// no inference in TS files, even for `this` aliases:
|
||||
|
||||
var app = function() {
|
||||
>app : Symbol(app, Decl(inferringClassMembersFromAssignments8.ts, 2, 3))
|
||||
|
||||
var _this = this;
|
||||
>_this : Symbol(_this, Decl(inferringClassMembersFromAssignments8.ts, 3, 7))
|
||||
|
||||
_this.swap = function() { }
|
||||
>_this : Symbol(_this, Decl(inferringClassMembersFromAssignments8.ts, 3, 7))
|
||||
}
|
||||
var a = new app()
|
||||
>a : Symbol(a, Decl(inferringClassMembersFromAssignments8.ts, 6, 3))
|
||||
>app : Symbol(app, Decl(inferringClassMembersFromAssignments8.ts, 2, 3))
|
||||
|
||||
a
|
||||
>a : Symbol(a, Decl(inferringClassMembersFromAssignments8.ts, 6, 3))
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
=== tests/cases/conformance/salsa/inferringClassMembersFromAssignments8.ts ===
|
||||
// no inference in TS files, even for `this` aliases:
|
||||
|
||||
var app = function() {
|
||||
>app : () => void
|
||||
>function() { var _this = this; _this.swap = function() { }} : () => void
|
||||
|
||||
var _this = this;
|
||||
>_this : any
|
||||
>this : any
|
||||
|
||||
_this.swap = function() { }
|
||||
>_this.swap = function() { } : () => void
|
||||
>_this.swap : any
|
||||
>_this : any
|
||||
>swap : any
|
||||
>function() { } : () => void
|
||||
}
|
||||
var a = new app()
|
||||
>a : any
|
||||
>new app() : any
|
||||
>app : () => void
|
||||
|
||||
a
|
||||
>a : any
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// no inference in TS files, even for `this` aliases:
|
||||
|
||||
var app = function() {
|
||||
var _this = this;
|
||||
_this.swap = function() { }
|
||||
}
|
||||
var a = new app()
|
||||
a
|
Loading…
Reference in a new issue