TypeScript/tests/baselines/reference/defineProperty(target=esnext).errors.txt
Nathan Shively-Sanders 368db997ed
ESNext+[[Define]]: reference to param props illegal (#36425)
* ESNext+[[Define]]: reference to param props illegal

When target: "esnext" and useDefineForClassFields: true, property
declaration initialisers should not be able to reference parameter
properties; class fields are initialised before the constructor runs,
but parameter properties are not:

```ts
class C {
  foo = this.bar
  constructor(public bar: string) { }
}
```

emits code that looks like this:

```js
class C {
  bar
  foo = this.bar
  constructor(bar) {
    this.bar = bar
  }
}
new C('x').foo.length // crashes; foo is undefined
```

This PR adds an error on foo's declaration with ESNext+[[Define]].

* improve test
2020-01-24 14:53:28 -08:00

43 lines
2 KiB
Plaintext

tests/cases/conformance/classes/propertyMemberDeclarations/defineProperty.ts(3,14): error TS2729: Property 'y' is used before its initialization.
tests/cases/conformance/classes/propertyMemberDeclarations/defineProperty.ts(10,14): error TS2729: Property 'y' is used before its initialization.
tests/cases/conformance/classes/propertyMemberDeclarations/defineProperty.ts(18,14): error TS2729: Property 'ka' is used before its initialization.
tests/cases/conformance/classes/propertyMemberDeclarations/defineProperty.ts(22,15): error TS2729: Property 'ka' is used before its initialization.
==== tests/cases/conformance/classes/propertyMemberDeclarations/defineProperty.ts (4 errors) ====
var x: "p" = "p"
class A {
a = this.y
~
!!! error TS2729: Property 'y' is used before its initialization.
!!! related TS2728 tests/cases/conformance/classes/propertyMemberDeclarations/defineProperty.ts:9:17: 'y' is declared here.
b
public c;
["computed"] = 13
;[x] = 14
m() { }
constructor(public readonly y: number) { }
z = this.y
~
!!! error TS2729: Property 'y' is used before its initialization.
!!! related TS2728 tests/cases/conformance/classes/propertyMemberDeclarations/defineProperty.ts:9:17: 'y' is declared here.
declare notEmitted;
}
class B {
public a;
}
class C extends B {
declare public a;
z = this.ka
~~
!!! error TS2729: Property 'ka' is used before its initialization.
!!! related TS2728 tests/cases/conformance/classes/propertyMemberDeclarations/defineProperty.ts:19:17: 'ka' is declared here.
constructor(public ka: number) {
super()
}
ki = this.ka
~~
!!! error TS2729: Property 'ka' is used before its initialization.
!!! related TS2728 tests/cases/conformance/classes/propertyMemberDeclarations/defineProperty.ts:19:17: 'ka' is declared here.
}