TypeScript/tests/cases/conformance/salsa/thisPropertyAssignmentCircular.ts
Nathan Shively-Sanders eb105efdcd
Avoid circular reference in this-property assignments (#37827)
* Avoid circular reference in this-property assignments

To do this, don't check this-property assigments that have the
this-property of the lhs appearing somewhere on the rhs:

```js
class C {
  m() {
    this.x = 12
    this.x = this.x + this.y
  }
}
```

I tried suppressing the circularity error, but because we cache the
first type discovered for a property, this still results in an implicit
any for `x` in the previous example. It just doesn't have an error.

Fixes #35099

* Add test case + rename function

* Use isMatchingReference
2020-04-10 16:41:31 -07:00

23 lines
397 B
TypeScript

// @allowJs: true
// @checkJs: true
// @declaration: true
// @emitDeclarationOnly: true
// @filename: thisPropertyAssignmentCircular.js
export class Foo {
constructor() {
this.foo = "Hello";
}
slicey() {
this.foo = this.foo.slice();
}
m() {
this.foo
}
}
/** @class */
function C() {
this.x = 0;
this.x = function() { this.x.toString(); }
}