TypeScript/tests/cases/compiler/classUsedBeforeInitializedVariables.ts
Josh Goldberg cd88f6a319 Added error for class properties used within their own declaration
Fixes #5987.

Usages of a class property in a preceding property already gave an error, but the following doesn't yet:

```ts
class Test {
    x: number = this.x;
}
```

As with other use-before-declare checking, IIFEs are not treated as invalid uses.
2019-01-13 13:30:58 -05:00

41 lines
1,011 B
TypeScript

// @target: es5
class Test {
p1 = 0;
p2 = this.p1;
p3 = this.p4;
p4 = 0;
directlyAssigned: any = this.directlyAssigned;
withinArrowFunction: any = () => this.withinArrowFunction;
withinFunction: any = function () {
return this.withinFunction;
};
withinObjectLiteral: any = {
[this.withinObjectLiteral]: true,
};
withinObjectLiteralGetterName: any = {
get [this.withinObjectLiteralGetterName]() {
return true;
}
};
withinObjectLiteralSetterName: any = {
set [this.withinObjectLiteralSetterName](_: any) {}
};
withinClassDeclarationExtension: any = (class extends this.withinClassDeclarationExtension { });
// These error cases are ignored (not checked by control flow analysis)
assignedByArrowFunction: any = (() => this.assignedByFunction)();
assignedByFunction: any = (function () {
return this.assignedByFunction;
})();
}