From f0315b995dcab39884d3c7cea8ac6c47297b0597 Mon Sep 17 00:00:00 2001 From: Zzzen Date: Sat, 15 Jul 2023 15:32:48 +0800 Subject: [PATCH 1/7] fix use-before-init error when targeting ES2022 --- src/compiler/checker.ts | 4 +- ...ertyToPropertyDeclarationES2022.errors.txt | 6 ++- .../initializationOrdering1(target=es2021).js | 43 +++++++++++++++++ ...ializationOrdering1(target=es2021).symbols | 42 +++++++++++++++++ ...itializationOrdering1(target=es2021).types | 46 +++++++++++++++++++ ...izationOrdering1(target=es2022).errors.txt | 22 +++++++++ .../initializationOrdering1(target=es2022).js | 34 ++++++++++++++ ...ializationOrdering1(target=es2022).symbols | 42 +++++++++++++++++ ...itializationOrdering1(target=es2022).types | 46 +++++++++++++++++++ ...izationOrdering1(target=esnext).errors.txt | 22 +++++++++ .../initializationOrdering1(target=esnext).js | 34 ++++++++++++++ ...ializationOrdering1(target=esnext).symbols | 42 +++++++++++++++++ ...itializationOrdering1(target=esnext).types | 46 +++++++++++++++++++ .../initializationOrdering2(target=es2021).js | 33 +++++++++++++ ...ializationOrdering2(target=es2021).symbols | 42 +++++++++++++++++ ...itializationOrdering2(target=es2021).types | 46 +++++++++++++++++++ .../initializationOrdering2(target=es2022).js | 33 +++++++++++++ ...ializationOrdering2(target=es2022).symbols | 42 +++++++++++++++++ ...itializationOrdering2(target=es2022).types | 46 +++++++++++++++++++ .../initializationOrdering2(target=esnext).js | 33 +++++++++++++ ...ializationOrdering2(target=esnext).symbols | 42 +++++++++++++++++ ...itializationOrdering2(target=esnext).types | 46 +++++++++++++++++++ .../initializationOrdering1.ts | 18 ++++++++ .../initializationOrdering2.ts | 18 ++++++++ 24 files changed, 825 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2021).js create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2021).symbols create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2021).types create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2022).errors.txt create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2022).js create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2022).symbols create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2022).types create mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext).errors.txt create mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext).js create mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext).symbols create mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext).types create mode 100644 tests/baselines/reference/initializationOrdering2(target=es2021).js create mode 100644 tests/baselines/reference/initializationOrdering2(target=es2021).symbols create mode 100644 tests/baselines/reference/initializationOrdering2(target=es2021).types create mode 100644 tests/baselines/reference/initializationOrdering2(target=es2022).js create mode 100644 tests/baselines/reference/initializationOrdering2(target=es2022).symbols create mode 100644 tests/baselines/reference/initializationOrdering2(target=es2022).types create mode 100644 tests/baselines/reference/initializationOrdering2(target=esnext).js create mode 100644 tests/baselines/reference/initializationOrdering2(target=esnext).symbols create mode 100644 tests/baselines/reference/initializationOrdering2(target=esnext).types create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f1324425367bb..7f68d41525eda 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2782,8 +2782,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return !isPropertyImmediatelyReferencedWithinDeclaration(declaration, usage, /*stopAtAnyPropertyDeclaration*/ false); } else if (isParameterPropertyDeclaration(declaration, declaration.parent)) { - // foo = this.bar is illegal in esnext+useDefineForClassFields when bar is a parameter property - return !(getEmitScriptTarget(compilerOptions) === ScriptTarget.ESNext && useDefineForClassFields + // foo = this.bar is illegal in es2022+useDefineForClassFields when bar is a parameter property + return !(getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2022 && useDefineForClassFields && getContainingClass(declaration) === getContainingClass(usage) && isUsedInFunctionOrInstanceProperty(usage, declaration)); } diff --git a/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationES2022.errors.txt b/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationES2022.errors.txt index 59ee9f7409d20..ac6d34a8470f6 100644 --- a/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationES2022.errors.txt +++ b/tests/baselines/reference/assignParameterPropertyToPropertyDeclarationES2022.errors.txt @@ -2,9 +2,10 @@ assignParameterPropertyToPropertyDeclarationES2022.ts(2,16): error TS2729: Prope assignParameterPropertyToPropertyDeclarationES2022.ts(3,16): error TS2729: Property 'foo' is used before its initialization. assignParameterPropertyToPropertyDeclarationES2022.ts(6,19): error TS2729: Property 'm3' is used before its initialization. assignParameterPropertyToPropertyDeclarationES2022.ts(12,17): error TS2729: Property 'baz' is used before its initialization. +assignParameterPropertyToPropertyDeclarationES2022.ts(13,16): error TS2729: Property 'foo' is used before its initialization. -==== assignParameterPropertyToPropertyDeclarationES2022.ts (4 errors) ==== +==== assignParameterPropertyToPropertyDeclarationES2022.ts (5 errors) ==== class C { qux = this.bar // should error ~~~ @@ -30,6 +31,9 @@ assignParameterPropertyToPropertyDeclarationES2022.ts(12,17): error TS2729: Prop !!! error TS2729: Property 'baz' is used before its initialization. !!! related TS2728 assignParameterPropertyToPropertyDeclarationES2022.ts:13:5: 'baz' is declared here. baz = this.foo; // should error + ~~~ +!!! error TS2729: Property 'foo' is used before its initialization. +!!! related TS2728 assignParameterPropertyToPropertyDeclarationES2022.ts:11:17: 'foo' is declared here. quid = this.baz // ok m2() { this.foo // ok diff --git a/tests/baselines/reference/initializationOrdering1(target=es2021).js b/tests/baselines/reference/initializationOrdering1(target=es2021).js new file mode 100644 index 0000000000000..88209b7c7e023 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2021).js @@ -0,0 +1,43 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +//// [initializationOrdering1.ts] +class Helper { + create(): boolean { + return true + } +} + +export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + +} + +new Broken(new Helper) + +//// [initializationOrdering1.js] +class Helper { + create() { + return true; + } +} +export class Broken { + constructor(facade) { + Object.defineProperty(this, "facade", { + enumerable: true, + configurable: true, + writable: true, + value: facade + }); + Object.defineProperty(this, "bug", { + enumerable: true, + configurable: true, + writable: true, + value: this.facade.create() + }); + console.log(this.bug); + } +} +new Broken(new Helper); diff --git a/tests/baselines/reference/initializationOrdering1(target=es2021).symbols b/tests/baselines/reference/initializationOrdering1(target=es2021).symbols new file mode 100644 index 0000000000000..be3a543112930 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2021).symbols @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + create(): boolean { +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + + return true + } +} + +export class Broken { +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) + + constructor(readonly facade: Helper) { +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + console.log(this.bug) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) + } + bug = this.facade.create() +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this.facade.create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) +>this.facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + +} + +new Broken(new Helper) +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + diff --git a/tests/baselines/reference/initializationOrdering1(target=es2021).types b/tests/baselines/reference/initializationOrdering1(target=es2021).types new file mode 100644 index 0000000000000..1444366790e82 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2021).types @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Helper + + create(): boolean { +>create : () => boolean + + return true +>true : true + } +} + +export class Broken { +>Broken : Broken + + constructor(readonly facade: Helper) { +>facade : Helper + + console.log(this.bug) +>console.log(this.bug) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.bug : boolean +>this : this +>bug : boolean + } + bug = this.facade.create() +>bug : boolean +>this.facade.create() : boolean +>this.facade.create : () => boolean +>this.facade : Helper +>this : this +>facade : Helper +>create : () => boolean + +} + +new Broken(new Helper) +>new Broken(new Helper) : Broken +>Broken : typeof Broken +>new Helper : Helper +>Helper : typeof Helper + diff --git a/tests/baselines/reference/initializationOrdering1(target=es2022).errors.txt b/tests/baselines/reference/initializationOrdering1(target=es2022).errors.txt new file mode 100644 index 0000000000000..a69a0dfb78a06 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2022).errors.txt @@ -0,0 +1,22 @@ +initializationOrdering1.ts(11,16): error TS2729: Property 'facade' is used before its initialization. + + +==== initializationOrdering1.ts (1 errors) ==== + class Helper { + create(): boolean { + return true + } + } + + export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + ~~~~~~ +!!! error TS2729: Property 'facade' is used before its initialization. +!!! related TS2728 initializationOrdering1.ts:8:17: 'facade' is declared here. + + } + + new Broken(new Helper) \ No newline at end of file diff --git a/tests/baselines/reference/initializationOrdering1(target=es2022).js b/tests/baselines/reference/initializationOrdering1(target=es2022).js new file mode 100644 index 0000000000000..205dee2520ab8 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2022).js @@ -0,0 +1,34 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +//// [initializationOrdering1.ts] +class Helper { + create(): boolean { + return true + } +} + +export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + +} + +new Broken(new Helper) + +//// [initializationOrdering1.js] +class Helper { + create() { + return true; + } +} +export class Broken { + facade; + constructor(facade) { + this.facade = facade; + console.log(this.bug); + } + bug = this.facade.create(); +} +new Broken(new Helper); diff --git a/tests/baselines/reference/initializationOrdering1(target=es2022).symbols b/tests/baselines/reference/initializationOrdering1(target=es2022).symbols new file mode 100644 index 0000000000000..be3a543112930 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2022).symbols @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + create(): boolean { +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + + return true + } +} + +export class Broken { +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) + + constructor(readonly facade: Helper) { +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + console.log(this.bug) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) + } + bug = this.facade.create() +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this.facade.create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) +>this.facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + +} + +new Broken(new Helper) +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + diff --git a/tests/baselines/reference/initializationOrdering1(target=es2022).types b/tests/baselines/reference/initializationOrdering1(target=es2022).types new file mode 100644 index 0000000000000..1444366790e82 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2022).types @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Helper + + create(): boolean { +>create : () => boolean + + return true +>true : true + } +} + +export class Broken { +>Broken : Broken + + constructor(readonly facade: Helper) { +>facade : Helper + + console.log(this.bug) +>console.log(this.bug) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.bug : boolean +>this : this +>bug : boolean + } + bug = this.facade.create() +>bug : boolean +>this.facade.create() : boolean +>this.facade.create : () => boolean +>this.facade : Helper +>this : this +>facade : Helper +>create : () => boolean + +} + +new Broken(new Helper) +>new Broken(new Helper) : Broken +>Broken : typeof Broken +>new Helper : Helper +>Helper : typeof Helper + diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext).errors.txt b/tests/baselines/reference/initializationOrdering1(target=esnext).errors.txt new file mode 100644 index 0000000000000..a69a0dfb78a06 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=esnext).errors.txt @@ -0,0 +1,22 @@ +initializationOrdering1.ts(11,16): error TS2729: Property 'facade' is used before its initialization. + + +==== initializationOrdering1.ts (1 errors) ==== + class Helper { + create(): boolean { + return true + } + } + + export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + ~~~~~~ +!!! error TS2729: Property 'facade' is used before its initialization. +!!! related TS2728 initializationOrdering1.ts:8:17: 'facade' is declared here. + + } + + new Broken(new Helper) \ No newline at end of file diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext).js b/tests/baselines/reference/initializationOrdering1(target=esnext).js new file mode 100644 index 0000000000000..205dee2520ab8 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=esnext).js @@ -0,0 +1,34 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +//// [initializationOrdering1.ts] +class Helper { + create(): boolean { + return true + } +} + +export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + +} + +new Broken(new Helper) + +//// [initializationOrdering1.js] +class Helper { + create() { + return true; + } +} +export class Broken { + facade; + constructor(facade) { + this.facade = facade; + console.log(this.bug); + } + bug = this.facade.create(); +} +new Broken(new Helper); diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext).symbols b/tests/baselines/reference/initializationOrdering1(target=esnext).symbols new file mode 100644 index 0000000000000..be3a543112930 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=esnext).symbols @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + create(): boolean { +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + + return true + } +} + +export class Broken { +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) + + constructor(readonly facade: Helper) { +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + console.log(this.bug) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) + } + bug = this.facade.create() +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this.facade.create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) +>this.facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + +} + +new Broken(new Helper) +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext).types b/tests/baselines/reference/initializationOrdering1(target=esnext).types new file mode 100644 index 0000000000000..1444366790e82 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=esnext).types @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Helper + + create(): boolean { +>create : () => boolean + + return true +>true : true + } +} + +export class Broken { +>Broken : Broken + + constructor(readonly facade: Helper) { +>facade : Helper + + console.log(this.bug) +>console.log(this.bug) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.bug : boolean +>this : this +>bug : boolean + } + bug = this.facade.create() +>bug : boolean +>this.facade.create() : boolean +>this.facade.create : () => boolean +>this.facade : Helper +>this : this +>facade : Helper +>create : () => boolean + +} + +new Broken(new Helper) +>new Broken(new Helper) : Broken +>Broken : typeof Broken +>new Helper : Helper +>Helper : typeof Helper + diff --git a/tests/baselines/reference/initializationOrdering2(target=es2021).js b/tests/baselines/reference/initializationOrdering2(target=es2021).js new file mode 100644 index 0000000000000..29737d28aae6f --- /dev/null +++ b/tests/baselines/reference/initializationOrdering2(target=es2021).js @@ -0,0 +1,33 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// + +//// [initializationOrdering2.ts] +class Helper { + create(): boolean { + return true + } +} + +export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + +} + +new Broken(new Helper) + +//// [initializationOrdering2.js] +class Helper { + create() { + return true; + } +} +export class Broken { + constructor(facade) { + this.facade = facade; + this.bug = this.facade.create(); + console.log(this.bug); + } +} +new Broken(new Helper); diff --git a/tests/baselines/reference/initializationOrdering2(target=es2021).symbols b/tests/baselines/reference/initializationOrdering2(target=es2021).symbols new file mode 100644 index 0000000000000..7088b7e56be3c --- /dev/null +++ b/tests/baselines/reference/initializationOrdering2(target=es2021).symbols @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// + +=== initializationOrdering2.ts === +class Helper { +>Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) + + create(): boolean { +>create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) + + return true + } +} + +export class Broken { +>Broken : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) + + constructor(readonly facade: Helper) { +>facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) +>Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) + + console.log(this.bug) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) +>this : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) +>bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) + } + bug = this.facade.create() +>bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) +>this.facade.create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) +>this.facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) +>this : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) +>facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) +>create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) + +} + +new Broken(new Helper) +>Broken : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) +>Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) + diff --git a/tests/baselines/reference/initializationOrdering2(target=es2021).types b/tests/baselines/reference/initializationOrdering2(target=es2021).types new file mode 100644 index 0000000000000..06fa06850ef2b --- /dev/null +++ b/tests/baselines/reference/initializationOrdering2(target=es2021).types @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// + +=== initializationOrdering2.ts === +class Helper { +>Helper : Helper + + create(): boolean { +>create : () => boolean + + return true +>true : true + } +} + +export class Broken { +>Broken : Broken + + constructor(readonly facade: Helper) { +>facade : Helper + + console.log(this.bug) +>console.log(this.bug) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.bug : boolean +>this : this +>bug : boolean + } + bug = this.facade.create() +>bug : boolean +>this.facade.create() : boolean +>this.facade.create : () => boolean +>this.facade : Helper +>this : this +>facade : Helper +>create : () => boolean + +} + +new Broken(new Helper) +>new Broken(new Helper) : Broken +>Broken : typeof Broken +>new Helper : Helper +>Helper : typeof Helper + diff --git a/tests/baselines/reference/initializationOrdering2(target=es2022).js b/tests/baselines/reference/initializationOrdering2(target=es2022).js new file mode 100644 index 0000000000000..29737d28aae6f --- /dev/null +++ b/tests/baselines/reference/initializationOrdering2(target=es2022).js @@ -0,0 +1,33 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// + +//// [initializationOrdering2.ts] +class Helper { + create(): boolean { + return true + } +} + +export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + +} + +new Broken(new Helper) + +//// [initializationOrdering2.js] +class Helper { + create() { + return true; + } +} +export class Broken { + constructor(facade) { + this.facade = facade; + this.bug = this.facade.create(); + console.log(this.bug); + } +} +new Broken(new Helper); diff --git a/tests/baselines/reference/initializationOrdering2(target=es2022).symbols b/tests/baselines/reference/initializationOrdering2(target=es2022).symbols new file mode 100644 index 0000000000000..7088b7e56be3c --- /dev/null +++ b/tests/baselines/reference/initializationOrdering2(target=es2022).symbols @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// + +=== initializationOrdering2.ts === +class Helper { +>Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) + + create(): boolean { +>create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) + + return true + } +} + +export class Broken { +>Broken : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) + + constructor(readonly facade: Helper) { +>facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) +>Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) + + console.log(this.bug) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) +>this : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) +>bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) + } + bug = this.facade.create() +>bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) +>this.facade.create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) +>this.facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) +>this : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) +>facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) +>create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) + +} + +new Broken(new Helper) +>Broken : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) +>Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) + diff --git a/tests/baselines/reference/initializationOrdering2(target=es2022).types b/tests/baselines/reference/initializationOrdering2(target=es2022).types new file mode 100644 index 0000000000000..06fa06850ef2b --- /dev/null +++ b/tests/baselines/reference/initializationOrdering2(target=es2022).types @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// + +=== initializationOrdering2.ts === +class Helper { +>Helper : Helper + + create(): boolean { +>create : () => boolean + + return true +>true : true + } +} + +export class Broken { +>Broken : Broken + + constructor(readonly facade: Helper) { +>facade : Helper + + console.log(this.bug) +>console.log(this.bug) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.bug : boolean +>this : this +>bug : boolean + } + bug = this.facade.create() +>bug : boolean +>this.facade.create() : boolean +>this.facade.create : () => boolean +>this.facade : Helper +>this : this +>facade : Helper +>create : () => boolean + +} + +new Broken(new Helper) +>new Broken(new Helper) : Broken +>Broken : typeof Broken +>new Helper : Helper +>Helper : typeof Helper + diff --git a/tests/baselines/reference/initializationOrdering2(target=esnext).js b/tests/baselines/reference/initializationOrdering2(target=esnext).js new file mode 100644 index 0000000000000..29737d28aae6f --- /dev/null +++ b/tests/baselines/reference/initializationOrdering2(target=esnext).js @@ -0,0 +1,33 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// + +//// [initializationOrdering2.ts] +class Helper { + create(): boolean { + return true + } +} + +export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + +} + +new Broken(new Helper) + +//// [initializationOrdering2.js] +class Helper { + create() { + return true; + } +} +export class Broken { + constructor(facade) { + this.facade = facade; + this.bug = this.facade.create(); + console.log(this.bug); + } +} +new Broken(new Helper); diff --git a/tests/baselines/reference/initializationOrdering2(target=esnext).symbols b/tests/baselines/reference/initializationOrdering2(target=esnext).symbols new file mode 100644 index 0000000000000..7088b7e56be3c --- /dev/null +++ b/tests/baselines/reference/initializationOrdering2(target=esnext).symbols @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// + +=== initializationOrdering2.ts === +class Helper { +>Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) + + create(): boolean { +>create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) + + return true + } +} + +export class Broken { +>Broken : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) + + constructor(readonly facade: Helper) { +>facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) +>Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) + + console.log(this.bug) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) +>this : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) +>bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) + } + bug = this.facade.create() +>bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) +>this.facade.create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) +>this.facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) +>this : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) +>facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) +>create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) + +} + +new Broken(new Helper) +>Broken : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) +>Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) + diff --git a/tests/baselines/reference/initializationOrdering2(target=esnext).types b/tests/baselines/reference/initializationOrdering2(target=esnext).types new file mode 100644 index 0000000000000..06fa06850ef2b --- /dev/null +++ b/tests/baselines/reference/initializationOrdering2(target=esnext).types @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// + +=== initializationOrdering2.ts === +class Helper { +>Helper : Helper + + create(): boolean { +>create : () => boolean + + return true +>true : true + } +} + +export class Broken { +>Broken : Broken + + constructor(readonly facade: Helper) { +>facade : Helper + + console.log(this.bug) +>console.log(this.bug) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.bug : boolean +>this : this +>bug : boolean + } + bug = this.facade.create() +>bug : boolean +>this.facade.create() : boolean +>this.facade.create : () => boolean +>this.facade : Helper +>this : this +>facade : Helper +>create : () => boolean + +} + +new Broken(new Helper) +>new Broken(new Helper) : Broken +>Broken : typeof Broken +>new Helper : Helper +>Helper : typeof Helper + diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts new file mode 100644 index 0000000000000..66df9d253beca --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts @@ -0,0 +1,18 @@ +// @target: esnext, es2021, es2022 +// @useDefineForClassFields: true + +class Helper { + create(): boolean { + return true + } +} + +export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + +} + +new Broken(new Helper) \ No newline at end of file diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts new file mode 100644 index 0000000000000..0ff2ec70cf49a --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts @@ -0,0 +1,18 @@ +// @target: esnext, es2021, es2022 +// @useDefineForClassFields: false + +class Helper { + create(): boolean { + return true + } +} + +export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + +} + +new Broken(new Helper) \ No newline at end of file From b2c1019fce4809f2697531fcf8524592533fd17f Mon Sep 17 00:00:00 2001 From: Zzzen Date: Fri, 21 Jul 2023 00:41:56 +0800 Subject: [PATCH 2/7] remove redundant check of emit target --- src/compiler/checker.ts | 20 ++++----- ...7,usedefineforclassfields=true).errors.txt | 12 ------ ...es2017,usedefineforclassfields=true).types | 4 +- .../defineProperty(target=es5).errors.txt | 43 +++++++++++++++++++ ...izationOrdering1(target=es2021).errors.txt | 22 ++++++++++ ...neForClassFields(target=es2022).errors.txt | 8 +--- 6 files changed, 78 insertions(+), 31 deletions(-) delete mode 100644 tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).errors.txt create mode 100644 tests/baselines/reference/defineProperty(target=es5).errors.txt create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2021).errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7f68d41525eda..1dce1d8fd22c4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2782,8 +2782,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return !isPropertyImmediatelyReferencedWithinDeclaration(declaration, usage, /*stopAtAnyPropertyDeclaration*/ false); } else if (isParameterPropertyDeclaration(declaration, declaration.parent)) { - // foo = this.bar is illegal in es2022+useDefineForClassFields when bar is a parameter property - return !(getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2022 && useDefineForClassFields + // foo = this.bar is illegal in useDefineForClassFields when bar is a parameter property + return !(useDefineForClassFields && getContainingClass(declaration) === getContainingClass(usage) && isUsedInFunctionOrInstanceProperty(usage, declaration)); } @@ -2814,7 +2814,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return true; } if (isUsedInFunctionOrInstanceProperty(usage, declaration)) { - if (getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2022 && useDefineForClassFields + if (useDefineForClassFields && getContainingClass(declaration) && (isPropertyDeclaration(declaration) || isParameterPropertyDeclaration(declaration, declaration.parent))) { return !isPropertyImmediatelyReferencedWithinDeclaration(declaration, usage, /*stopAtAnyPropertyDeclaration*/ true); @@ -2971,7 +2971,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.PropertyDeclaration: // static properties in classes introduce temporary variables if (hasStaticModifier(node)) { - return target < ScriptTarget.ESNext || !useDefineForClassFields; + return !useDefineForClassFields; } return requiresScopeChangeWorker((node as PropertyDeclaration).name); default: @@ -3389,10 +3389,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // 1. When result is undefined, after checking for a missing "this." // 2. When result is defined function checkAndReportErrorForInvalidInitializer() { - if (propertyWithInvalidInitializer && !(useDefineForClassFields && getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2022)) { + if (propertyWithInvalidInitializer && !useDefineForClassFields) { // We have a match, but the reference occurred within a property initializer and the identifier also binds // to a local variable in the constructor where the code will be emitted. Note that this is actually allowed - // with ESNext+useDefineForClassFields because the scope semantics are different. + // with useDefineForClassFields because the scope semantics are different. error(errorLocation, errorLocation && propertyWithInvalidInitializer.type && textRangeContainsPositionInclusive(propertyWithInvalidInitializer.type, errorLocation.pos) ? Diagnostics.Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor @@ -31739,7 +31739,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { && !(isAccessExpression(node) && isAccessExpression(node.expression)) && !isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right) && !(isMethodDeclaration(valueDeclaration) && getCombinedModifierFlagsCached(valueDeclaration) & ModifierFlags.Static) - && (compilerOptions.useDefineForClassFields || !isPropertyDeclaredInAncestorClass(prop))) { + && (useDefineForClassFields || !isPropertyDeclaredInAncestorClass(prop))) { diagnosticMessage = error(right, Diagnostics.Property_0_is_used_before_its_initialization, declarationName); } else if (valueDeclaration.kind === SyntaxKind.ClassDeclaration && @@ -38429,7 +38429,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case "length": case "caller": case "arguments": - if (compilerOptions.useDefineForClassFields) { + if (useDefineForClassFields) { break; } // fall through @@ -38634,7 +38634,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // or the containing class declares instance member variables with initializers. const superCallShouldBeRootLevel = - (getEmitScriptTarget(compilerOptions) !== ScriptTarget.ESNext || !useDefineForClassFields) && + (!useDefineForClassFields) && (some((node.parent as ClassDeclaration).members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) || some(node.parameters, p => hasSyntacticModifier(p, ModifierFlags.ParameterPropertyModifier))); @@ -42900,7 +42900,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { !legacyDecorators && languageVersion < ScriptTarget.ESNext && classOrConstructorParameterIsDecorated(/*useLegacyDecorators*/ false, node); const willTransformPrivateElementsOrClassStaticBlocks = languageVersion <= ScriptTarget.ES2022; - const willTransformInitializers = !useDefineForClassFields || languageVersion < ScriptTarget.ES2022; + const willTransformInitializers = !useDefineForClassFields; if (willTransformStaticElementsOfDecoratedClass || willTransformPrivateElementsOrClassStaticBlocks) { for (const member of node.members) { if (willTransformStaticElementsOfDecoratedClass && classElementOrClassElementParameterIsDecorated(/*useLegacyDecorators*/ false, member, node)) { diff --git a/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).errors.txt b/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).errors.txt deleted file mode 100644 index 656de0c3fb4dc..0000000000000 --- a/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -classMemberInitializerScoping2.ts(3,9): error TS2301: Initializer of instance member variable 'p' cannot reference identifier 'x' declared in the constructor. - - -==== classMemberInitializerScoping2.ts (1 errors) ==== - const x = 1 - class C { - p = x - ~ -!!! error TS2301: Initializer of instance member variable 'p' cannot reference identifier 'x' declared in the constructor. - constructor(x: string) { } - } - \ No newline at end of file diff --git a/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).types b/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).types index 85f4cf9f5d71c..55b80bfce98c1 100644 --- a/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).types +++ b/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).types @@ -9,8 +9,8 @@ class C { >C : C p = x ->p : any ->x : any +>p : number +>x : 1 constructor(x: string) { } >x : string diff --git a/tests/baselines/reference/defineProperty(target=es5).errors.txt b/tests/baselines/reference/defineProperty(target=es5).errors.txt new file mode 100644 index 0000000000000..c27c6cac01dcc --- /dev/null +++ b/tests/baselines/reference/defineProperty(target=es5).errors.txt @@ -0,0 +1,43 @@ +defineProperty.ts(3,14): error TS2729: Property 'y' is used before its initialization. +defineProperty.ts(10,14): error TS2729: Property 'y' is used before its initialization. +defineProperty.ts(18,14): error TS2729: Property 'ka' is used before its initialization. +defineProperty.ts(22,15): error TS2729: Property 'ka' is used before its initialization. + + +==== defineProperty.ts (4 errors) ==== + var x: "p" = "p" + class A { + a = this.y + ~ +!!! error TS2729: Property 'y' is used before its initialization. +!!! related TS2728 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 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 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 defineProperty.ts:19:17: 'ka' is declared here. + } + \ No newline at end of file diff --git a/tests/baselines/reference/initializationOrdering1(target=es2021).errors.txt b/tests/baselines/reference/initializationOrdering1(target=es2021).errors.txt new file mode 100644 index 0000000000000..a69a0dfb78a06 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2021).errors.txt @@ -0,0 +1,22 @@ +initializationOrdering1.ts(11,16): error TS2729: Property 'facade' is used before its initialization. + + +==== initializationOrdering1.ts (1 errors) ==== + class Helper { + create(): boolean { + return true + } + } + + export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + ~~~~~~ +!!! error TS2729: Property 'facade' is used before its initialization. +!!! related TS2728 initializationOrdering1.ts:8:17: 'facade' is declared here. + + } + + new Broken(new Helper) \ No newline at end of file diff --git a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).errors.txt b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).errors.txt index 26b3664cb6ba0..a887798812842 100644 --- a/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).errors.txt +++ b/tests/baselines/reference/privateNameBadSuperUseDefineForClassFields(target=es2022).errors.txt @@ -1,21 +1,15 @@ -privateNameBadSuperUseDefineForClassFields.ts(4,3): error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. privateNameBadSuperUseDefineForClassFields.ts(5,5): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== privateNameBadSuperUseDefineForClassFields.ts (2 errors) ==== +==== privateNameBadSuperUseDefineForClassFields.ts (1 errors) ==== class B {}; class A extends B { #x; constructor() { - ~~~~~~~~~~~~~~~ this; - ~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); - ~~~~~~~~~~~~ } - ~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers. } \ No newline at end of file From a01de8f608fb7569ec7fc72c1bd6dda66c147c2f Mon Sep 17 00:00:00 2001 From: Zzzen Date: Fri, 21 Jul 2023 22:46:46 +0800 Subject: [PATCH 3/7] add emitStandardClassFields flag --- src/compiler/checker.ts | 20 +++++---- src/compiler/utilities.ts | 5 +++ ...7,usedefineforclassfields=true).errors.txt | 12 ++++++ ...es2017,usedefineforclassfields=true).types | 4 +- .../defineProperty(target=es5).errors.txt | 43 ------------------- ...izationOrdering1(target=es2021).errors.txt | 22 ---------- 6 files changed, 30 insertions(+), 76 deletions(-) create mode 100644 tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).errors.txt delete mode 100644 tests/baselines/reference/defineProperty(target=es5).errors.txt delete mode 100644 tests/baselines/reference/initializationOrdering1(target=es2021).errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1dce1d8fd22c4..c33a9a733ba9b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -274,6 +274,7 @@ import { getEmitModuleKind, getEmitModuleResolutionKind, getEmitScriptTarget, + getEmitStandardClassFields, getEnclosingBlockScopeContainer, getEnclosingContainer, getEntityNameFromTypeNode, @@ -1434,6 +1435,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { var moduleKind = getEmitModuleKind(compilerOptions); var legacyDecorators = !!compilerOptions.experimentalDecorators; var useDefineForClassFields = getUseDefineForClassFields(compilerOptions); + var emitStandardClassFields = getEmitStandardClassFields(compilerOptions); var allowSyntheticDefaultImports = getAllowSyntheticDefaultImports(compilerOptions); var strictNullChecks = getStrictOptionValue(compilerOptions, "strictNullChecks"); var strictFunctionTypes = getStrictOptionValue(compilerOptions, "strictFunctionTypes"); @@ -2782,8 +2784,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return !isPropertyImmediatelyReferencedWithinDeclaration(declaration, usage, /*stopAtAnyPropertyDeclaration*/ false); } else if (isParameterPropertyDeclaration(declaration, declaration.parent)) { - // foo = this.bar is illegal in useDefineForClassFields when bar is a parameter property - return !(useDefineForClassFields + // foo = this.bar is illegal in emitStandardClassFields when bar is a parameter property + return !(getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2022 && emitStandardClassFields && getContainingClass(declaration) === getContainingClass(usage) && isUsedInFunctionOrInstanceProperty(usage, declaration)); } @@ -2795,7 +2797,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // 1. inside an export specifier // 2. inside a function // 3. inside an instance property initializer, a reference to a non-instance property - // (except when target: "esnext" and useDefineForClassFields: true and the reference is to a parameter property) + // (except when emitStandardClassFields: true and the reference is to a parameter property) // 4. inside a static property initializer, a reference to a static method in the same class // 5. inside a TS export= declaration (since we will move the export statement during emit to avoid TDZ) // or if usage is in a type context: @@ -2814,7 +2816,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return true; } if (isUsedInFunctionOrInstanceProperty(usage, declaration)) { - if (useDefineForClassFields + if (emitStandardClassFields && getContainingClass(declaration) && (isPropertyDeclaration(declaration) || isParameterPropertyDeclaration(declaration, declaration.parent))) { return !isPropertyImmediatelyReferencedWithinDeclaration(declaration, usage, /*stopAtAnyPropertyDeclaration*/ true); @@ -2971,7 +2973,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.PropertyDeclaration: // static properties in classes introduce temporary variables if (hasStaticModifier(node)) { - return !useDefineForClassFields; + return !emitStandardClassFields; } return requiresScopeChangeWorker((node as PropertyDeclaration).name); default: @@ -3389,10 +3391,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // 1. When result is undefined, after checking for a missing "this." // 2. When result is defined function checkAndReportErrorForInvalidInitializer() { - if (propertyWithInvalidInitializer && !useDefineForClassFields) { + if (propertyWithInvalidInitializer && !(emitStandardClassFields)) { // We have a match, but the reference occurred within a property initializer and the identifier also binds // to a local variable in the constructor where the code will be emitted. Note that this is actually allowed - // with useDefineForClassFields because the scope semantics are different. + // with emitStandardClassFields because the scope semantics are different. error(errorLocation, errorLocation && propertyWithInvalidInitializer.type && textRangeContainsPositionInclusive(propertyWithInvalidInitializer.type, errorLocation.pos) ? Diagnostics.Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor @@ -38634,7 +38636,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // or the containing class declares instance member variables with initializers. const superCallShouldBeRootLevel = - (!useDefineForClassFields) && + !emitStandardClassFields && (some((node.parent as ClassDeclaration).members, isInstancePropertyWithInitializerOrPrivateIdentifierProperty) || some(node.parameters, p => hasSyntacticModifier(p, ModifierFlags.ParameterPropertyModifier))); @@ -42900,7 +42902,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { !legacyDecorators && languageVersion < ScriptTarget.ESNext && classOrConstructorParameterIsDecorated(/*useLegacyDecorators*/ false, node); const willTransformPrivateElementsOrClassStaticBlocks = languageVersion <= ScriptTarget.ES2022; - const willTransformInitializers = !useDefineForClassFields; + const willTransformInitializers = !emitStandardClassFields; if (willTransformStaticElementsOfDecoratedClass || willTransformPrivateElementsOrClassStaticBlocks) { for (const member of node.members) { if (willTransformStaticElementsOfDecoratedClass && classElementOrClassElementParameterIsDecorated(/*useLegacyDecorators*/ false, member, node)) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 251f8a4f16306..320c5e631d860 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -8653,6 +8653,11 @@ export function getUseDefineForClassFields(compilerOptions: CompilerOptions): bo return compilerOptions.useDefineForClassFields === undefined ? getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2022 : compilerOptions.useDefineForClassFields; } +/** @internal */ +export function getEmitStandardClassFields(compilerOptions: CompilerOptions) { + return compilerOptions.useDefineForClassFields !== false && getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2022; +} + /** @internal */ export function compilerOptionsAffectSemanticDiagnostics(newOptions: CompilerOptions, oldOptions: CompilerOptions): boolean { return optionsHaveChanges(oldOptions, newOptions, semanticDiagnosticsOptionDeclarations); diff --git a/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).errors.txt b/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).errors.txt new file mode 100644 index 0000000000000..656de0c3fb4dc --- /dev/null +++ b/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).errors.txt @@ -0,0 +1,12 @@ +classMemberInitializerScoping2.ts(3,9): error TS2301: Initializer of instance member variable 'p' cannot reference identifier 'x' declared in the constructor. + + +==== classMemberInitializerScoping2.ts (1 errors) ==== + const x = 1 + class C { + p = x + ~ +!!! error TS2301: Initializer of instance member variable 'p' cannot reference identifier 'x' declared in the constructor. + constructor(x: string) { } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).types b/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).types index 55b80bfce98c1..85f4cf9f5d71c 100644 --- a/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).types +++ b/tests/baselines/reference/classMemberInitializerScoping2(target=es2017,usedefineforclassfields=true).types @@ -9,8 +9,8 @@ class C { >C : C p = x ->p : number ->x : 1 +>p : any +>x : any constructor(x: string) { } >x : string diff --git a/tests/baselines/reference/defineProperty(target=es5).errors.txt b/tests/baselines/reference/defineProperty(target=es5).errors.txt deleted file mode 100644 index c27c6cac01dcc..0000000000000 --- a/tests/baselines/reference/defineProperty(target=es5).errors.txt +++ /dev/null @@ -1,43 +0,0 @@ -defineProperty.ts(3,14): error TS2729: Property 'y' is used before its initialization. -defineProperty.ts(10,14): error TS2729: Property 'y' is used before its initialization. -defineProperty.ts(18,14): error TS2729: Property 'ka' is used before its initialization. -defineProperty.ts(22,15): error TS2729: Property 'ka' is used before its initialization. - - -==== defineProperty.ts (4 errors) ==== - var x: "p" = "p" - class A { - a = this.y - ~ -!!! error TS2729: Property 'y' is used before its initialization. -!!! related TS2728 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 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 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 defineProperty.ts:19:17: 'ka' is declared here. - } - \ No newline at end of file diff --git a/tests/baselines/reference/initializationOrdering1(target=es2021).errors.txt b/tests/baselines/reference/initializationOrdering1(target=es2021).errors.txt deleted file mode 100644 index a69a0dfb78a06..0000000000000 --- a/tests/baselines/reference/initializationOrdering1(target=es2021).errors.txt +++ /dev/null @@ -1,22 +0,0 @@ -initializationOrdering1.ts(11,16): error TS2729: Property 'facade' is used before its initialization. - - -==== initializationOrdering1.ts (1 errors) ==== - class Helper { - create(): boolean { - return true - } - } - - export class Broken { - constructor(readonly facade: Helper) { - console.log(this.bug) - } - bug = this.facade.create() - ~~~~~~ -!!! error TS2729: Property 'facade' is used before its initialization. -!!! related TS2728 initializationOrdering1.ts:8:17: 'facade' is declared here. - - } - - new Broken(new Helper) \ No newline at end of file From f6c010aee41f2001eb0aac5b18c313abab6d02c3 Mon Sep 17 00:00:00 2001 From: Zzzen Date: Fri, 21 Jul 2023 23:19:04 +0800 Subject: [PATCH 4/7] add emitStandardClassFields flag --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c33a9a733ba9b..9ab1b5eca5caf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2785,7 +2785,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } else if (isParameterPropertyDeclaration(declaration, declaration.parent)) { // foo = this.bar is illegal in emitStandardClassFields when bar is a parameter property - return !(getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2022 && emitStandardClassFields + return !(emitStandardClassFields && getContainingClass(declaration) === getContainingClass(usage) && isUsedInFunctionOrInstanceProperty(usage, declaration)); } From a2dabceba8ea78508a272a4d81ad4f9f5315aa97 Mon Sep 17 00:00:00 2001 From: Zzzen Date: Fri, 21 Jul 2023 23:55:55 +0800 Subject: [PATCH 5/7] simplify tests --- ...=es2021,usedefineforclassfields=false).js} | 6 +-- ...021,usedefineforclassfields=false).symbols | 42 +++++++++++++++++ ...2021,usedefineforclassfields=false).types} | 4 +- ...et=es2021,usedefineforclassfields=true).js | 43 +++++++++++++++++ ...2021,usedefineforclassfields=true).symbols | 42 +++++++++++++++++ ...s2021,usedefineforclassfields=true).types} | 4 +- ...=es2022,usedefineforclassfields=false).js} | 6 +-- ...022,usedefineforclassfields=false).symbols | 42 +++++++++++++++++ ...2022,usedefineforclassfields=false).types} | 4 +- ...2,usedefineforclassfields=true).errors.txt | 22 +++++++++ ...et=es2022,usedefineforclassfields=true).js | 34 ++++++++++++++ ...2022,usedefineforclassfields=true).symbols | 42 +++++++++++++++++ ...es2022,usedefineforclassfields=true).types | 46 +++++++++++++++++++ ...=esnext,usedefineforclassfields=false).js} | 6 +-- ...ext,usedefineforclassfields=false).symbols | 42 +++++++++++++++++ ...snext,usedefineforclassfields=false).types | 46 +++++++++++++++++++ ...t,usedefineforclassfields=true).errors.txt | 22 +++++++++ ...et=esnext,usedefineforclassfields=true).js | 34 ++++++++++++++ ...next,usedefineforclassfields=true).symbols | 42 +++++++++++++++++ ...esnext,usedefineforclassfields=true).types | 46 +++++++++++++++++++ ...ializationOrdering2(target=es2021).symbols | 42 ----------------- ...ializationOrdering2(target=es2022).symbols | 42 ----------------- ...ializationOrdering2(target=esnext).symbols | 42 ----------------- .../initializationOrdering1.ts | 2 +- .../initializationOrdering2.ts | 18 -------- 25 files changed, 561 insertions(+), 160 deletions(-) rename tests/baselines/reference/{initializationOrdering2(target=es2021).js => initializationOrdering1(target=es2021,usedefineforclassfields=false).js} (81%) create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=false).symbols rename tests/baselines/reference/{initializationOrdering2(target=esnext).types => initializationOrdering1(target=es2021,usedefineforclassfields=false).types} (87%) create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=true).js create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=true).symbols rename tests/baselines/reference/{initializationOrdering2(target=es2022).types => initializationOrdering1(target=es2021,usedefineforclassfields=true).types} (87%) rename tests/baselines/reference/{initializationOrdering2(target=esnext).js => initializationOrdering1(target=es2022,usedefineforclassfields=false).js} (81%) create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=false).symbols rename tests/baselines/reference/{initializationOrdering2(target=es2021).types => initializationOrdering1(target=es2022,usedefineforclassfields=false).types} (87%) create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).errors.txt create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).js create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).symbols create mode 100644 tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).types rename tests/baselines/reference/{initializationOrdering2(target=es2022).js => initializationOrdering1(target=esnext,usedefineforclassfields=false).js} (81%) create mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=false).symbols create mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=false).types create mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).errors.txt create mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).js create mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).symbols create mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).types delete mode 100644 tests/baselines/reference/initializationOrdering2(target=es2021).symbols delete mode 100644 tests/baselines/reference/initializationOrdering2(target=es2022).symbols delete mode 100644 tests/baselines/reference/initializationOrdering2(target=esnext).symbols delete mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts diff --git a/tests/baselines/reference/initializationOrdering2(target=es2021).js b/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=false).js similarity index 81% rename from tests/baselines/reference/initializationOrdering2(target=es2021).js rename to tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=false).js index 29737d28aae6f..9f2f51960ca62 100644 --- a/tests/baselines/reference/initializationOrdering2(target=es2021).js +++ b/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=false).js @@ -1,6 +1,6 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// -//// [initializationOrdering2.ts] +//// [initializationOrdering1.ts] class Helper { create(): boolean { return true @@ -17,7 +17,7 @@ export class Broken { new Broken(new Helper) -//// [initializationOrdering2.js] +//// [initializationOrdering1.js] class Helper { create() { return true; diff --git a/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=false).symbols b/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=false).symbols new file mode 100644 index 0000000000000..be3a543112930 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=false).symbols @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + create(): boolean { +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + + return true + } +} + +export class Broken { +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) + + constructor(readonly facade: Helper) { +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + console.log(this.bug) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) + } + bug = this.facade.create() +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this.facade.create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) +>this.facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + +} + +new Broken(new Helper) +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + diff --git a/tests/baselines/reference/initializationOrdering2(target=esnext).types b/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=false).types similarity index 87% rename from tests/baselines/reference/initializationOrdering2(target=esnext).types rename to tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=false).types index 06fa06850ef2b..1444366790e82 100644 --- a/tests/baselines/reference/initializationOrdering2(target=esnext).types +++ b/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=false).types @@ -1,6 +1,6 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// -=== initializationOrdering2.ts === +=== initializationOrdering1.ts === class Helper { >Helper : Helper diff --git a/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=true).js b/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=true).js new file mode 100644 index 0000000000000..88209b7c7e023 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=true).js @@ -0,0 +1,43 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +//// [initializationOrdering1.ts] +class Helper { + create(): boolean { + return true + } +} + +export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + +} + +new Broken(new Helper) + +//// [initializationOrdering1.js] +class Helper { + create() { + return true; + } +} +export class Broken { + constructor(facade) { + Object.defineProperty(this, "facade", { + enumerable: true, + configurable: true, + writable: true, + value: facade + }); + Object.defineProperty(this, "bug", { + enumerable: true, + configurable: true, + writable: true, + value: this.facade.create() + }); + console.log(this.bug); + } +} +new Broken(new Helper); diff --git a/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=true).symbols b/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=true).symbols new file mode 100644 index 0000000000000..be3a543112930 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=true).symbols @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + create(): boolean { +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + + return true + } +} + +export class Broken { +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) + + constructor(readonly facade: Helper) { +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + console.log(this.bug) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) + } + bug = this.facade.create() +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this.facade.create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) +>this.facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + +} + +new Broken(new Helper) +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + diff --git a/tests/baselines/reference/initializationOrdering2(target=es2022).types b/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=true).types similarity index 87% rename from tests/baselines/reference/initializationOrdering2(target=es2022).types rename to tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=true).types index 06fa06850ef2b..1444366790e82 100644 --- a/tests/baselines/reference/initializationOrdering2(target=es2022).types +++ b/tests/baselines/reference/initializationOrdering1(target=es2021,usedefineforclassfields=true).types @@ -1,6 +1,6 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// -=== initializationOrdering2.ts === +=== initializationOrdering1.ts === class Helper { >Helper : Helper diff --git a/tests/baselines/reference/initializationOrdering2(target=esnext).js b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=false).js similarity index 81% rename from tests/baselines/reference/initializationOrdering2(target=esnext).js rename to tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=false).js index 29737d28aae6f..9f2f51960ca62 100644 --- a/tests/baselines/reference/initializationOrdering2(target=esnext).js +++ b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=false).js @@ -1,6 +1,6 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// -//// [initializationOrdering2.ts] +//// [initializationOrdering1.ts] class Helper { create(): boolean { return true @@ -17,7 +17,7 @@ export class Broken { new Broken(new Helper) -//// [initializationOrdering2.js] +//// [initializationOrdering1.js] class Helper { create() { return true; diff --git a/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=false).symbols b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=false).symbols new file mode 100644 index 0000000000000..be3a543112930 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=false).symbols @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + create(): boolean { +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + + return true + } +} + +export class Broken { +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) + + constructor(readonly facade: Helper) { +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + console.log(this.bug) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) + } + bug = this.facade.create() +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this.facade.create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) +>this.facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + +} + +new Broken(new Helper) +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + diff --git a/tests/baselines/reference/initializationOrdering2(target=es2021).types b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=false).types similarity index 87% rename from tests/baselines/reference/initializationOrdering2(target=es2021).types rename to tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=false).types index 06fa06850ef2b..1444366790e82 100644 --- a/tests/baselines/reference/initializationOrdering2(target=es2021).types +++ b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=false).types @@ -1,6 +1,6 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// -=== initializationOrdering2.ts === +=== initializationOrdering1.ts === class Helper { >Helper : Helper diff --git a/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).errors.txt b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).errors.txt new file mode 100644 index 0000000000000..a69a0dfb78a06 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).errors.txt @@ -0,0 +1,22 @@ +initializationOrdering1.ts(11,16): error TS2729: Property 'facade' is used before its initialization. + + +==== initializationOrdering1.ts (1 errors) ==== + class Helper { + create(): boolean { + return true + } + } + + export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + ~~~~~~ +!!! error TS2729: Property 'facade' is used before its initialization. +!!! related TS2728 initializationOrdering1.ts:8:17: 'facade' is declared here. + + } + + new Broken(new Helper) \ No newline at end of file diff --git a/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).js b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).js new file mode 100644 index 0000000000000..205dee2520ab8 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).js @@ -0,0 +1,34 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +//// [initializationOrdering1.ts] +class Helper { + create(): boolean { + return true + } +} + +export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + +} + +new Broken(new Helper) + +//// [initializationOrdering1.js] +class Helper { + create() { + return true; + } +} +export class Broken { + facade; + constructor(facade) { + this.facade = facade; + console.log(this.bug); + } + bug = this.facade.create(); +} +new Broken(new Helper); diff --git a/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).symbols b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).symbols new file mode 100644 index 0000000000000..be3a543112930 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).symbols @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + create(): boolean { +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + + return true + } +} + +export class Broken { +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) + + constructor(readonly facade: Helper) { +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + console.log(this.bug) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) + } + bug = this.facade.create() +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this.facade.create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) +>this.facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + +} + +new Broken(new Helper) +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + diff --git a/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).types b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).types new file mode 100644 index 0000000000000..1444366790e82 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=es2022,usedefineforclassfields=true).types @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Helper + + create(): boolean { +>create : () => boolean + + return true +>true : true + } +} + +export class Broken { +>Broken : Broken + + constructor(readonly facade: Helper) { +>facade : Helper + + console.log(this.bug) +>console.log(this.bug) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.bug : boolean +>this : this +>bug : boolean + } + bug = this.facade.create() +>bug : boolean +>this.facade.create() : boolean +>this.facade.create : () => boolean +>this.facade : Helper +>this : this +>facade : Helper +>create : () => boolean + +} + +new Broken(new Helper) +>new Broken(new Helper) : Broken +>Broken : typeof Broken +>new Helper : Helper +>Helper : typeof Helper + diff --git a/tests/baselines/reference/initializationOrdering2(target=es2022).js b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=false).js similarity index 81% rename from tests/baselines/reference/initializationOrdering2(target=es2022).js rename to tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=false).js index 29737d28aae6f..9f2f51960ca62 100644 --- a/tests/baselines/reference/initializationOrdering2(target=es2022).js +++ b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=false).js @@ -1,6 +1,6 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// -//// [initializationOrdering2.ts] +//// [initializationOrdering1.ts] class Helper { create(): boolean { return true @@ -17,7 +17,7 @@ export class Broken { new Broken(new Helper) -//// [initializationOrdering2.js] +//// [initializationOrdering1.js] class Helper { create() { return true; diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=false).symbols b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=false).symbols new file mode 100644 index 0000000000000..be3a543112930 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=false).symbols @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + create(): boolean { +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + + return true + } +} + +export class Broken { +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) + + constructor(readonly facade: Helper) { +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + console.log(this.bug) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) + } + bug = this.facade.create() +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this.facade.create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) +>this.facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + +} + +new Broken(new Helper) +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=false).types b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=false).types new file mode 100644 index 0000000000000..1444366790e82 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=false).types @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Helper + + create(): boolean { +>create : () => boolean + + return true +>true : true + } +} + +export class Broken { +>Broken : Broken + + constructor(readonly facade: Helper) { +>facade : Helper + + console.log(this.bug) +>console.log(this.bug) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.bug : boolean +>this : this +>bug : boolean + } + bug = this.facade.create() +>bug : boolean +>this.facade.create() : boolean +>this.facade.create : () => boolean +>this.facade : Helper +>this : this +>facade : Helper +>create : () => boolean + +} + +new Broken(new Helper) +>new Broken(new Helper) : Broken +>Broken : typeof Broken +>new Helper : Helper +>Helper : typeof Helper + diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).errors.txt b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).errors.txt new file mode 100644 index 0000000000000..a69a0dfb78a06 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).errors.txt @@ -0,0 +1,22 @@ +initializationOrdering1.ts(11,16): error TS2729: Property 'facade' is used before its initialization. + + +==== initializationOrdering1.ts (1 errors) ==== + class Helper { + create(): boolean { + return true + } + } + + export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + ~~~~~~ +!!! error TS2729: Property 'facade' is used before its initialization. +!!! related TS2728 initializationOrdering1.ts:8:17: 'facade' is declared here. + + } + + new Broken(new Helper) \ No newline at end of file diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).js b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).js new file mode 100644 index 0000000000000..205dee2520ab8 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).js @@ -0,0 +1,34 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +//// [initializationOrdering1.ts] +class Helper { + create(): boolean { + return true + } +} + +export class Broken { + constructor(readonly facade: Helper) { + console.log(this.bug) + } + bug = this.facade.create() + +} + +new Broken(new Helper) + +//// [initializationOrdering1.js] +class Helper { + create() { + return true; + } +} +export class Broken { + facade; + constructor(facade) { + this.facade = facade; + console.log(this.bug); + } + bug = this.facade.create(); +} +new Broken(new Helper); diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).symbols b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).symbols new file mode 100644 index 0000000000000..be3a543112930 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).symbols @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + create(): boolean { +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + + return true + } +} + +export class Broken { +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) + + constructor(readonly facade: Helper) { +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + + console.log(this.bug) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) + } + bug = this.facade.create() +>bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) +>this.facade.create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) +>this.facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) +>create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) + +} + +new Broken(new Helper) +>Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) +>Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) + diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).types b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).types new file mode 100644 index 0000000000000..1444366790e82 --- /dev/null +++ b/tests/baselines/reference/initializationOrdering1(target=esnext,usedefineforclassfields=true).types @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// + +=== initializationOrdering1.ts === +class Helper { +>Helper : Helper + + create(): boolean { +>create : () => boolean + + return true +>true : true + } +} + +export class Broken { +>Broken : Broken + + constructor(readonly facade: Helper) { +>facade : Helper + + console.log(this.bug) +>console.log(this.bug) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.bug : boolean +>this : this +>bug : boolean + } + bug = this.facade.create() +>bug : boolean +>this.facade.create() : boolean +>this.facade.create : () => boolean +>this.facade : Helper +>this : this +>facade : Helper +>create : () => boolean + +} + +new Broken(new Helper) +>new Broken(new Helper) : Broken +>Broken : typeof Broken +>new Helper : Helper +>Helper : typeof Helper + diff --git a/tests/baselines/reference/initializationOrdering2(target=es2021).symbols b/tests/baselines/reference/initializationOrdering2(target=es2021).symbols deleted file mode 100644 index 7088b7e56be3c..0000000000000 --- a/tests/baselines/reference/initializationOrdering2(target=es2021).symbols +++ /dev/null @@ -1,42 +0,0 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// - -=== initializationOrdering2.ts === -class Helper { ->Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) - - create(): boolean { ->create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) - - return true - } -} - -export class Broken { ->Broken : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) - - constructor(readonly facade: Helper) { ->facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) ->Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) - - console.log(this.bug) ->console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) ->console : Symbol(console, Decl(lib.dom.d.ts, --, --)) ->log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) ->this.bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) ->this : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) ->bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) - } - bug = this.facade.create() ->bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) ->this.facade.create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) ->this.facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) ->this : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) ->facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) ->create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) - -} - -new Broken(new Helper) ->Broken : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) ->Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) - diff --git a/tests/baselines/reference/initializationOrdering2(target=es2022).symbols b/tests/baselines/reference/initializationOrdering2(target=es2022).symbols deleted file mode 100644 index 7088b7e56be3c..0000000000000 --- a/tests/baselines/reference/initializationOrdering2(target=es2022).symbols +++ /dev/null @@ -1,42 +0,0 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// - -=== initializationOrdering2.ts === -class Helper { ->Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) - - create(): boolean { ->create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) - - return true - } -} - -export class Broken { ->Broken : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) - - constructor(readonly facade: Helper) { ->facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) ->Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) - - console.log(this.bug) ->console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) ->console : Symbol(console, Decl(lib.dom.d.ts, --, --)) ->log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) ->this.bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) ->this : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) ->bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) - } - bug = this.facade.create() ->bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) ->this.facade.create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) ->this.facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) ->this : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) ->facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) ->create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) - -} - -new Broken(new Helper) ->Broken : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) ->Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) - diff --git a/tests/baselines/reference/initializationOrdering2(target=esnext).symbols b/tests/baselines/reference/initializationOrdering2(target=esnext).symbols deleted file mode 100644 index 7088b7e56be3c..0000000000000 --- a/tests/baselines/reference/initializationOrdering2(target=esnext).symbols +++ /dev/null @@ -1,42 +0,0 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts] //// - -=== initializationOrdering2.ts === -class Helper { ->Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) - - create(): boolean { ->create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) - - return true - } -} - -export class Broken { ->Broken : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) - - constructor(readonly facade: Helper) { ->facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) ->Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) - - console.log(this.bug) ->console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) ->console : Symbol(console, Decl(lib.dom.d.ts, --, --)) ->log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) ->this.bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) ->this : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) ->bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) - } - bug = this.facade.create() ->bug : Symbol(Broken.bug, Decl(initializationOrdering2.ts, 9, 5)) ->this.facade.create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) ->this.facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) ->this : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) ->facade : Symbol(Broken.facade, Decl(initializationOrdering2.ts, 7, 16)) ->create : Symbol(Helper.create, Decl(initializationOrdering2.ts, 0, 14)) - -} - -new Broken(new Helper) ->Broken : Symbol(Broken, Decl(initializationOrdering2.ts, 4, 1)) ->Helper : Symbol(Helper, Decl(initializationOrdering2.ts, 0, 0)) - diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts index 66df9d253beca..fe8afae2d66e2 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts @@ -1,5 +1,5 @@ // @target: esnext, es2021, es2022 -// @useDefineForClassFields: true +// @useDefineForClassFields: true, false class Helper { create(): boolean { diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts deleted file mode 100644 index 0ff2ec70cf49a..0000000000000 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering2.ts +++ /dev/null @@ -1,18 +0,0 @@ -// @target: esnext, es2021, es2022 -// @useDefineForClassFields: false - -class Helper { - create(): boolean { - return true - } -} - -export class Broken { - constructor(readonly facade: Helper) { - console.log(this.bug) - } - bug = this.facade.create() - -} - -new Broken(new Helper) \ No newline at end of file From 8a7c7530d0135672c350510d1dd78b2a681540f6 Mon Sep 17 00:00:00 2001 From: Zzzen Date: Sat, 22 Jul 2023 00:13:42 +0800 Subject: [PATCH 6/7] clean code --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9ab1b5eca5caf..b3cdf4600c67c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3391,7 +3391,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // 1. When result is undefined, after checking for a missing "this." // 2. When result is defined function checkAndReportErrorForInvalidInitializer() { - if (propertyWithInvalidInitializer && !(emitStandardClassFields)) { + if (propertyWithInvalidInitializer && !emitStandardClassFields) { // We have a match, but the reference occurred within a property initializer and the identifier also binds // to a local variable in the constructor where the code will be emitted. Note that this is actually allowed // with emitStandardClassFields because the scope semantics are different. From 66b8263b704bad32c01ac8415ea6162cd441cc7b Mon Sep 17 00:00:00 2001 From: Zzzen Date: Sat, 22 Jul 2023 00:35:44 +0800 Subject: [PATCH 7/7] remove unused baselines --- .../initializationOrdering1(target=es2021).js | 43 ----------------- ...ializationOrdering1(target=es2021).symbols | 42 ----------------- ...itializationOrdering1(target=es2021).types | 46 ------------------- ...izationOrdering1(target=es2022).errors.txt | 22 --------- .../initializationOrdering1(target=es2022).js | 34 -------------- ...ializationOrdering1(target=es2022).symbols | 42 ----------------- ...itializationOrdering1(target=es2022).types | 46 ------------------- ...izationOrdering1(target=esnext).errors.txt | 22 --------- .../initializationOrdering1(target=esnext).js | 34 -------------- ...ializationOrdering1(target=esnext).symbols | 42 ----------------- ...itializationOrdering1(target=esnext).types | 46 ------------------- 11 files changed, 419 deletions(-) delete mode 100644 tests/baselines/reference/initializationOrdering1(target=es2021).js delete mode 100644 tests/baselines/reference/initializationOrdering1(target=es2021).symbols delete mode 100644 tests/baselines/reference/initializationOrdering1(target=es2021).types delete mode 100644 tests/baselines/reference/initializationOrdering1(target=es2022).errors.txt delete mode 100644 tests/baselines/reference/initializationOrdering1(target=es2022).js delete mode 100644 tests/baselines/reference/initializationOrdering1(target=es2022).symbols delete mode 100644 tests/baselines/reference/initializationOrdering1(target=es2022).types delete mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext).errors.txt delete mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext).js delete mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext).symbols delete mode 100644 tests/baselines/reference/initializationOrdering1(target=esnext).types diff --git a/tests/baselines/reference/initializationOrdering1(target=es2021).js b/tests/baselines/reference/initializationOrdering1(target=es2021).js deleted file mode 100644 index 88209b7c7e023..0000000000000 --- a/tests/baselines/reference/initializationOrdering1(target=es2021).js +++ /dev/null @@ -1,43 +0,0 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// - -//// [initializationOrdering1.ts] -class Helper { - create(): boolean { - return true - } -} - -export class Broken { - constructor(readonly facade: Helper) { - console.log(this.bug) - } - bug = this.facade.create() - -} - -new Broken(new Helper) - -//// [initializationOrdering1.js] -class Helper { - create() { - return true; - } -} -export class Broken { - constructor(facade) { - Object.defineProperty(this, "facade", { - enumerable: true, - configurable: true, - writable: true, - value: facade - }); - Object.defineProperty(this, "bug", { - enumerable: true, - configurable: true, - writable: true, - value: this.facade.create() - }); - console.log(this.bug); - } -} -new Broken(new Helper); diff --git a/tests/baselines/reference/initializationOrdering1(target=es2021).symbols b/tests/baselines/reference/initializationOrdering1(target=es2021).symbols deleted file mode 100644 index be3a543112930..0000000000000 --- a/tests/baselines/reference/initializationOrdering1(target=es2021).symbols +++ /dev/null @@ -1,42 +0,0 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// - -=== initializationOrdering1.ts === -class Helper { ->Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) - - create(): boolean { ->create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) - - return true - } -} - -export class Broken { ->Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) - - constructor(readonly facade: Helper) { ->facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) ->Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) - - console.log(this.bug) ->console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) ->console : Symbol(console, Decl(lib.dom.d.ts, --, --)) ->log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) ->this.bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) ->this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) ->bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) - } - bug = this.facade.create() ->bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) ->this.facade.create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) ->this.facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) ->this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) ->facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) ->create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) - -} - -new Broken(new Helper) ->Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) ->Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) - diff --git a/tests/baselines/reference/initializationOrdering1(target=es2021).types b/tests/baselines/reference/initializationOrdering1(target=es2021).types deleted file mode 100644 index 1444366790e82..0000000000000 --- a/tests/baselines/reference/initializationOrdering1(target=es2021).types +++ /dev/null @@ -1,46 +0,0 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// - -=== initializationOrdering1.ts === -class Helper { ->Helper : Helper - - create(): boolean { ->create : () => boolean - - return true ->true : true - } -} - -export class Broken { ->Broken : Broken - - constructor(readonly facade: Helper) { ->facade : Helper - - console.log(this.bug) ->console.log(this.bug) : void ->console.log : (...data: any[]) => void ->console : Console ->log : (...data: any[]) => void ->this.bug : boolean ->this : this ->bug : boolean - } - bug = this.facade.create() ->bug : boolean ->this.facade.create() : boolean ->this.facade.create : () => boolean ->this.facade : Helper ->this : this ->facade : Helper ->create : () => boolean - -} - -new Broken(new Helper) ->new Broken(new Helper) : Broken ->Broken : typeof Broken ->new Helper : Helper ->Helper : typeof Helper - diff --git a/tests/baselines/reference/initializationOrdering1(target=es2022).errors.txt b/tests/baselines/reference/initializationOrdering1(target=es2022).errors.txt deleted file mode 100644 index a69a0dfb78a06..0000000000000 --- a/tests/baselines/reference/initializationOrdering1(target=es2022).errors.txt +++ /dev/null @@ -1,22 +0,0 @@ -initializationOrdering1.ts(11,16): error TS2729: Property 'facade' is used before its initialization. - - -==== initializationOrdering1.ts (1 errors) ==== - class Helper { - create(): boolean { - return true - } - } - - export class Broken { - constructor(readonly facade: Helper) { - console.log(this.bug) - } - bug = this.facade.create() - ~~~~~~ -!!! error TS2729: Property 'facade' is used before its initialization. -!!! related TS2728 initializationOrdering1.ts:8:17: 'facade' is declared here. - - } - - new Broken(new Helper) \ No newline at end of file diff --git a/tests/baselines/reference/initializationOrdering1(target=es2022).js b/tests/baselines/reference/initializationOrdering1(target=es2022).js deleted file mode 100644 index 205dee2520ab8..0000000000000 --- a/tests/baselines/reference/initializationOrdering1(target=es2022).js +++ /dev/null @@ -1,34 +0,0 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// - -//// [initializationOrdering1.ts] -class Helper { - create(): boolean { - return true - } -} - -export class Broken { - constructor(readonly facade: Helper) { - console.log(this.bug) - } - bug = this.facade.create() - -} - -new Broken(new Helper) - -//// [initializationOrdering1.js] -class Helper { - create() { - return true; - } -} -export class Broken { - facade; - constructor(facade) { - this.facade = facade; - console.log(this.bug); - } - bug = this.facade.create(); -} -new Broken(new Helper); diff --git a/tests/baselines/reference/initializationOrdering1(target=es2022).symbols b/tests/baselines/reference/initializationOrdering1(target=es2022).symbols deleted file mode 100644 index be3a543112930..0000000000000 --- a/tests/baselines/reference/initializationOrdering1(target=es2022).symbols +++ /dev/null @@ -1,42 +0,0 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// - -=== initializationOrdering1.ts === -class Helper { ->Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) - - create(): boolean { ->create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) - - return true - } -} - -export class Broken { ->Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) - - constructor(readonly facade: Helper) { ->facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) ->Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) - - console.log(this.bug) ->console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) ->console : Symbol(console, Decl(lib.dom.d.ts, --, --)) ->log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) ->this.bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) ->this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) ->bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) - } - bug = this.facade.create() ->bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) ->this.facade.create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) ->this.facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) ->this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) ->facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) ->create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) - -} - -new Broken(new Helper) ->Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) ->Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) - diff --git a/tests/baselines/reference/initializationOrdering1(target=es2022).types b/tests/baselines/reference/initializationOrdering1(target=es2022).types deleted file mode 100644 index 1444366790e82..0000000000000 --- a/tests/baselines/reference/initializationOrdering1(target=es2022).types +++ /dev/null @@ -1,46 +0,0 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// - -=== initializationOrdering1.ts === -class Helper { ->Helper : Helper - - create(): boolean { ->create : () => boolean - - return true ->true : true - } -} - -export class Broken { ->Broken : Broken - - constructor(readonly facade: Helper) { ->facade : Helper - - console.log(this.bug) ->console.log(this.bug) : void ->console.log : (...data: any[]) => void ->console : Console ->log : (...data: any[]) => void ->this.bug : boolean ->this : this ->bug : boolean - } - bug = this.facade.create() ->bug : boolean ->this.facade.create() : boolean ->this.facade.create : () => boolean ->this.facade : Helper ->this : this ->facade : Helper ->create : () => boolean - -} - -new Broken(new Helper) ->new Broken(new Helper) : Broken ->Broken : typeof Broken ->new Helper : Helper ->Helper : typeof Helper - diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext).errors.txt b/tests/baselines/reference/initializationOrdering1(target=esnext).errors.txt deleted file mode 100644 index a69a0dfb78a06..0000000000000 --- a/tests/baselines/reference/initializationOrdering1(target=esnext).errors.txt +++ /dev/null @@ -1,22 +0,0 @@ -initializationOrdering1.ts(11,16): error TS2729: Property 'facade' is used before its initialization. - - -==== initializationOrdering1.ts (1 errors) ==== - class Helper { - create(): boolean { - return true - } - } - - export class Broken { - constructor(readonly facade: Helper) { - console.log(this.bug) - } - bug = this.facade.create() - ~~~~~~ -!!! error TS2729: Property 'facade' is used before its initialization. -!!! related TS2728 initializationOrdering1.ts:8:17: 'facade' is declared here. - - } - - new Broken(new Helper) \ No newline at end of file diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext).js b/tests/baselines/reference/initializationOrdering1(target=esnext).js deleted file mode 100644 index 205dee2520ab8..0000000000000 --- a/tests/baselines/reference/initializationOrdering1(target=esnext).js +++ /dev/null @@ -1,34 +0,0 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// - -//// [initializationOrdering1.ts] -class Helper { - create(): boolean { - return true - } -} - -export class Broken { - constructor(readonly facade: Helper) { - console.log(this.bug) - } - bug = this.facade.create() - -} - -new Broken(new Helper) - -//// [initializationOrdering1.js] -class Helper { - create() { - return true; - } -} -export class Broken { - facade; - constructor(facade) { - this.facade = facade; - console.log(this.bug); - } - bug = this.facade.create(); -} -new Broken(new Helper); diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext).symbols b/tests/baselines/reference/initializationOrdering1(target=esnext).symbols deleted file mode 100644 index be3a543112930..0000000000000 --- a/tests/baselines/reference/initializationOrdering1(target=esnext).symbols +++ /dev/null @@ -1,42 +0,0 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// - -=== initializationOrdering1.ts === -class Helper { ->Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) - - create(): boolean { ->create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) - - return true - } -} - -export class Broken { ->Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) - - constructor(readonly facade: Helper) { ->facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) ->Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) - - console.log(this.bug) ->console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) ->console : Symbol(console, Decl(lib.dom.d.ts, --, --)) ->log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) ->this.bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) ->this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) ->bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) - } - bug = this.facade.create() ->bug : Symbol(Broken.bug, Decl(initializationOrdering1.ts, 9, 5)) ->this.facade.create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) ->this.facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) ->this : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) ->facade : Symbol(Broken.facade, Decl(initializationOrdering1.ts, 7, 16)) ->create : Symbol(Helper.create, Decl(initializationOrdering1.ts, 0, 14)) - -} - -new Broken(new Helper) ->Broken : Symbol(Broken, Decl(initializationOrdering1.ts, 4, 1)) ->Helper : Symbol(Helper, Decl(initializationOrdering1.ts, 0, 0)) - diff --git a/tests/baselines/reference/initializationOrdering1(target=esnext).types b/tests/baselines/reference/initializationOrdering1(target=esnext).types deleted file mode 100644 index 1444366790e82..0000000000000 --- a/tests/baselines/reference/initializationOrdering1(target=esnext).types +++ /dev/null @@ -1,46 +0,0 @@ -//// [tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts] //// - -=== initializationOrdering1.ts === -class Helper { ->Helper : Helper - - create(): boolean { ->create : () => boolean - - return true ->true : true - } -} - -export class Broken { ->Broken : Broken - - constructor(readonly facade: Helper) { ->facade : Helper - - console.log(this.bug) ->console.log(this.bug) : void ->console.log : (...data: any[]) => void ->console : Console ->log : (...data: any[]) => void ->this.bug : boolean ->this : this ->bug : boolean - } - bug = this.facade.create() ->bug : boolean ->this.facade.create() : boolean ->this.facade.create : () => boolean ->this.facade : Helper ->this : this ->facade : Helper ->create : () => boolean - -} - -new Broken(new Helper) ->new Broken(new Helper) : Broken ->Broken : typeof Broken ->new Helper : Helper ->Helper : typeof Helper -