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:
Nathan Shively-Sanders 2020-08-11 15:46:49 -07:00 committed by GitHub
parent 57e2fe0462
commit d371ae770d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 1 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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))

View file

@ -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

View file

@ -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