From f76e01fbd98f3c847d5ee84e949c88b45893ee5c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 12 Sep 2019 15:04:36 -0700 Subject: [PATCH 01/44] Disallow property/accessor overrides Unless the base property or accessor is abstract --- src/compiler/checker.ts | 23 ++++-- src/compiler/diagnosticMessages.json | 9 +++ src/compiler/utilities.ts | 1 - .../accessorsOverrideProperty.errors.txt | 24 ++++++ .../reference/accessorsOverrideProperty.js | 39 ++++++++++ .../accessorsOverrideProperty.symbols | 42 +++++++++++ .../reference/accessorsOverrideProperty.types | 47 ++++++++++++ .../accessorsOverrideProperty2.errors.txt | 18 +++++ .../reference/accessorsOverrideProperty2.js | 26 +++++++ .../accessorsOverrideProperty2.symbols | 36 +++++++++ .../accessorsOverrideProperty2.types | 42 +++++++++++ .../accessorsOverrideProperty3.errors.txt | 15 ++++ .../reference/accessorsOverrideProperty3.js | 20 +++++ .../accessorsOverrideProperty3.symbols | 29 ++++++++ .../accessorsOverrideProperty3.types | 31 ++++++++ .../accessorsOverrideProperty4.errors.txt | 15 ++++ .../reference/accessorsOverrideProperty4.js | 20 +++++ .../accessorsOverrideProperty4.symbols | 29 ++++++++ .../accessorsOverrideProperty4.types | 31 ++++++++ ...emberAccessorOverridingProperty.errors.txt | 5 +- ...emberPropertyOverridingAccessor.errors.txt | 5 +- .../propertyOverridesAccessors.errors.txt | 24 ++++++ .../reference/propertyOverridesAccessors.js | 40 ++++++++++ .../propertyOverridesAccessors.symbols | 42 +++++++++++ .../propertyOverridesAccessors.types | 47 ++++++++++++ .../propertyOverridesAccessors2.errors.txt | 18 +++++ .../reference/propertyOverridesAccessors2.js | 27 +++++++ .../propertyOverridesAccessors2.symbols | 36 +++++++++ .../propertyOverridesAccessors2.types | 42 +++++++++++ .../propertyOverridesAccessors3.errors.txt | 30 ++++++++ .../reference/propertyOverridesAccessors3.js | 50 +++++++++++++ .../propertyOverridesAccessors3.symbols | 65 +++++++++++++++++ .../propertyOverridesAccessors3.types | 73 +++++++++++++++++++ .../propertyOverridesAccessors4.errors.txt | 14 ++++ .../reference/propertyOverridesAccessors4.js | 33 +++++++++ .../propertyOverridesAccessors4.symbols | 19 +++++ .../propertyOverridesAccessors4.types | 20 +++++ .../accessorsOverrideProperty.ts | 15 ++++ .../accessorsOverrideProperty2.ts | 12 +++ .../accessorsOverrideProperty3.ts | 9 +++ .../accessorsOverrideProperty4.ts | 9 +++ .../propertyOverridesAccessors.ts | 15 ++++ .../propertyOverridesAccessors2.ts | 12 +++ .../propertyOverridesAccessors3.ts | 24 ++++++ .../propertyOverridesAccessors4.ts | 7 ++ 45 files changed, 1182 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/accessorsOverrideProperty.errors.txt create mode 100644 tests/baselines/reference/accessorsOverrideProperty.js create mode 100644 tests/baselines/reference/accessorsOverrideProperty.symbols create mode 100644 tests/baselines/reference/accessorsOverrideProperty.types create mode 100644 tests/baselines/reference/accessorsOverrideProperty2.errors.txt create mode 100644 tests/baselines/reference/accessorsOverrideProperty2.js create mode 100644 tests/baselines/reference/accessorsOverrideProperty2.symbols create mode 100644 tests/baselines/reference/accessorsOverrideProperty2.types create mode 100644 tests/baselines/reference/accessorsOverrideProperty3.errors.txt create mode 100644 tests/baselines/reference/accessorsOverrideProperty3.js create mode 100644 tests/baselines/reference/accessorsOverrideProperty3.symbols create mode 100644 tests/baselines/reference/accessorsOverrideProperty3.types create mode 100644 tests/baselines/reference/accessorsOverrideProperty4.errors.txt create mode 100644 tests/baselines/reference/accessorsOverrideProperty4.js create mode 100644 tests/baselines/reference/accessorsOverrideProperty4.symbols create mode 100644 tests/baselines/reference/accessorsOverrideProperty4.types create mode 100644 tests/baselines/reference/propertyOverridesAccessors.errors.txt create mode 100644 tests/baselines/reference/propertyOverridesAccessors.js create mode 100644 tests/baselines/reference/propertyOverridesAccessors.symbols create mode 100644 tests/baselines/reference/propertyOverridesAccessors.types create mode 100644 tests/baselines/reference/propertyOverridesAccessors2.errors.txt create mode 100644 tests/baselines/reference/propertyOverridesAccessors2.js create mode 100644 tests/baselines/reference/propertyOverridesAccessors2.symbols create mode 100644 tests/baselines/reference/propertyOverridesAccessors2.types create mode 100644 tests/baselines/reference/propertyOverridesAccessors3.errors.txt create mode 100644 tests/baselines/reference/propertyOverridesAccessors3.js create mode 100644 tests/baselines/reference/propertyOverridesAccessors3.symbols create mode 100644 tests/baselines/reference/propertyOverridesAccessors3.types create mode 100644 tests/baselines/reference/propertyOverridesAccessors4.errors.txt create mode 100644 tests/baselines/reference/propertyOverridesAccessors4.js create mode 100644 tests/baselines/reference/propertyOverridesAccessors4.symbols create mode 100644 tests/baselines/reference/propertyOverridesAccessors4.types create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty4.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors2.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors3.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors4.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f8c8817888591..b6d7723c6cab1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29513,14 +29513,27 @@ namespace ts { // either base or derived property is private - not override, skip it continue; } - - if (isPrototypeProperty(base) || base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) { - // method is overridden with method or property/accessor is overridden with property/accessor - correct case + if (isPrototypeProperty(base)) { + // method is overridden with method - correct case continue; } - let errorMessage: DiagnosticMessage; - if (isPrototypeProperty(base)) { + const basePropertyFlags = base.flags & SymbolFlags.PropertyOrAccessor; + const derivedPropertyFlags = derived.flags & SymbolFlags.PropertyOrAccessor; + if (basePropertyFlags && derivedPropertyFlags) { + // property/accessor is overridden with property/accessor + if (!(baseDeclarationFlags & ModifierFlags.Abstract) && basePropertyFlags !== SymbolFlags.Property && derivedPropertyFlags === SymbolFlags.Property) { + errorMessage = Diagnostics.Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_property; + } + else if (!(baseDeclarationFlags & ModifierFlags.Abstract) && basePropertyFlags === SymbolFlags.Property && derivedPropertyFlags !== SymbolFlags.Property) { + errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_but_extended_class_2_defines_it_as_instance_member_accessor; + } + else { + // correct case + continue; + } + } + else if (isPrototypeProperty(base)) { if (derived.flags & SymbolFlags.Accessor) { errorMessage = Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 86686cb9f6c1b..24e1df77649c2 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2204,6 +2204,15 @@ "category": "Error", "code": 2609 }, + "Class '{0}' defines instance member accessor '{1}', but extended class '{2}' defines it as instance member property.": { + "category": "Error", + "code": 2610 + }, + "Class '{0}' defines instance member property '{1}', but extended class '{2}' defines it as instance member accessor.": { + "category": "Error", + "code": 2611 + }, + "Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": { "category": "Error", "code": 2649 diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b338d3ba657cd..ed7bdff0fc97e 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3972,7 +3972,6 @@ namespace ts { } export function getModifierFlagsNoCache(node: Node): ModifierFlags { - let flags = ModifierFlags.None; if (node.modifiers) { for (const modifier of node.modifiers) { diff --git a/tests/baselines/reference/accessorsOverrideProperty.errors.txt b/tests/baselines/reference/accessorsOverrideProperty.errors.txt new file mode 100644 index 0000000000000..cda030610b543 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts(5,9): error TS2611: Class 'A' defines instance member property 'p', but extended class 'B' defines it as instance member accessor. +tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts(12,9): error TS2611: Class 'C' defines instance member property 'p', but extended class 'D' defines it as instance member accessor. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts (2 errors) ==== + class A { + p = 'yep' + } + class B extends A { + get p() { return 'oh no' } // error + ~ +!!! error TS2611: Class 'A' defines instance member property 'p', but extended class 'B' defines it as instance member accessor. + } + class C { + p = 101 + } + class D extends C { + _secret = 11 + get p() { return this._secret } // error + ~ +!!! error TS2611: Class 'C' defines instance member property 'p', but extended class 'D' defines it as instance member accessor. + set p(value) { this._secret = value } // error + } + \ No newline at end of file diff --git a/tests/baselines/reference/accessorsOverrideProperty.js b/tests/baselines/reference/accessorsOverrideProperty.js new file mode 100644 index 0000000000000..3a19b0f7fff33 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty.js @@ -0,0 +1,39 @@ +//// [accessorsOverrideProperty.ts] +class A { + p = 'yep' +} +class B extends A { + get p() { return 'oh no' } // error +} +class C { + p = 101 +} +class D extends C { + _secret = 11 + get p() { return this._secret } // error + set p(value) { this._secret = value } // error +} + + +//// [accessorsOverrideProperty.js] +class A { + constructor() { + this.p = 'yep'; + } +} +class B extends A { + get p() { return 'oh no'; } // error +} +class C { + constructor() { + this.p = 101; + } +} +class D extends C { + constructor() { + super(...arguments); + this._secret = 11; + } + get p() { return this._secret; } // error + set p(value) { this._secret = value; } // error +} diff --git a/tests/baselines/reference/accessorsOverrideProperty.symbols b/tests/baselines/reference/accessorsOverrideProperty.symbols new file mode 100644 index 0000000000000..702417679a316 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty.symbols @@ -0,0 +1,42 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts === +class A { +>A : Symbol(A, Decl(accessorsOverrideProperty.ts, 0, 0)) + + p = 'yep' +>p : Symbol(A.p, Decl(accessorsOverrideProperty.ts, 0, 9)) +} +class B extends A { +>B : Symbol(B, Decl(accessorsOverrideProperty.ts, 2, 1)) +>A : Symbol(A, Decl(accessorsOverrideProperty.ts, 0, 0)) + + get p() { return 'oh no' } // error +>p : Symbol(B.p, Decl(accessorsOverrideProperty.ts, 3, 19)) +} +class C { +>C : Symbol(C, Decl(accessorsOverrideProperty.ts, 5, 1)) + + p = 101 +>p : Symbol(C.p, Decl(accessorsOverrideProperty.ts, 6, 9)) +} +class D extends C { +>D : Symbol(D, Decl(accessorsOverrideProperty.ts, 8, 1)) +>C : Symbol(C, Decl(accessorsOverrideProperty.ts, 5, 1)) + + _secret = 11 +>_secret : Symbol(D._secret, Decl(accessorsOverrideProperty.ts, 9, 19)) + + get p() { return this._secret } // error +>p : Symbol(D.p, Decl(accessorsOverrideProperty.ts, 10, 17), Decl(accessorsOverrideProperty.ts, 11, 35)) +>this._secret : Symbol(D._secret, Decl(accessorsOverrideProperty.ts, 9, 19)) +>this : Symbol(D, Decl(accessorsOverrideProperty.ts, 8, 1)) +>_secret : Symbol(D._secret, Decl(accessorsOverrideProperty.ts, 9, 19)) + + set p(value) { this._secret = value } // error +>p : Symbol(D.p, Decl(accessorsOverrideProperty.ts, 10, 17), Decl(accessorsOverrideProperty.ts, 11, 35)) +>value : Symbol(value, Decl(accessorsOverrideProperty.ts, 12, 10)) +>this._secret : Symbol(D._secret, Decl(accessorsOverrideProperty.ts, 9, 19)) +>this : Symbol(D, Decl(accessorsOverrideProperty.ts, 8, 1)) +>_secret : Symbol(D._secret, Decl(accessorsOverrideProperty.ts, 9, 19)) +>value : Symbol(value, Decl(accessorsOverrideProperty.ts, 12, 10)) +} + diff --git a/tests/baselines/reference/accessorsOverrideProperty.types b/tests/baselines/reference/accessorsOverrideProperty.types new file mode 100644 index 0000000000000..4e3021e70243f --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty.types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts === +class A { +>A : A + + p = 'yep' +>p : string +>'yep' : "yep" +} +class B extends A { +>B : B +>A : A + + get p() { return 'oh no' } // error +>p : string +>'oh no' : "oh no" +} +class C { +>C : C + + p = 101 +>p : number +>101 : 101 +} +class D extends C { +>D : D +>C : C + + _secret = 11 +>_secret : number +>11 : 11 + + get p() { return this._secret } // error +>p : number +>this._secret : number +>this : this +>_secret : number + + set p(value) { this._secret = value } // error +>p : number +>value : number +>this._secret = value : number +>this._secret : number +>this : this +>_secret : number +>value : number +} + diff --git a/tests/baselines/reference/accessorsOverrideProperty2.errors.txt b/tests/baselines/reference/accessorsOverrideProperty2.errors.txt new file mode 100644 index 0000000000000..ee26b16f7c906 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty2.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts(6,7): error TS2611: Class 'Base' defines instance member property 'x', but extended class 'Derived' defines it as instance member accessor. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts (1 errors) ==== + class Base { + x = 1; + } + + class Derived extends Base { + get x() { return 2; } // should be an error + ~ +!!! error TS2611: Class 'Base' defines instance member property 'x', but extended class 'Derived' defines it as instance member accessor. + set x(value) { console.log(`x was set to ${value}`); } + } + + const obj = new Derived(); // nothing printed + console.log(obj.x); // 1 + \ No newline at end of file diff --git a/tests/baselines/reference/accessorsOverrideProperty2.js b/tests/baselines/reference/accessorsOverrideProperty2.js new file mode 100644 index 0000000000000..dcdb2308253a4 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty2.js @@ -0,0 +1,26 @@ +//// [accessorsOverrideProperty2.ts] +class Base { + x = 1; +} + +class Derived extends Base { + get x() { return 2; } // should be an error + set x(value) { console.log(`x was set to ${value}`); } +} + +const obj = new Derived(); // nothing printed +console.log(obj.x); // 1 + + +//// [accessorsOverrideProperty2.js] +class Base { + constructor() { + this.x = 1; + } +} +class Derived extends Base { + get x() { return 2; } // should be an error + set x(value) { console.log(`x was set to ${value}`); } +} +const obj = new Derived(); // nothing printed +console.log(obj.x); // 1 diff --git a/tests/baselines/reference/accessorsOverrideProperty2.symbols b/tests/baselines/reference/accessorsOverrideProperty2.symbols new file mode 100644 index 0000000000000..eab967402566b --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty2.symbols @@ -0,0 +1,36 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts === +class Base { +>Base : Symbol(Base, Decl(accessorsOverrideProperty2.ts, 0, 0)) + + x = 1; +>x : Symbol(Base.x, Decl(accessorsOverrideProperty2.ts, 0, 12)) +} + +class Derived extends Base { +>Derived : Symbol(Derived, Decl(accessorsOverrideProperty2.ts, 2, 1)) +>Base : Symbol(Base, Decl(accessorsOverrideProperty2.ts, 0, 0)) + + get x() { return 2; } // should be an error +>x : Symbol(Derived.x, Decl(accessorsOverrideProperty2.ts, 4, 28), Decl(accessorsOverrideProperty2.ts, 5, 23)) + + set x(value) { console.log(`x was set to ${value}`); } +>x : Symbol(Derived.x, Decl(accessorsOverrideProperty2.ts, 4, 28), Decl(accessorsOverrideProperty2.ts, 5, 23)) +>value : Symbol(value, Decl(accessorsOverrideProperty2.ts, 6, 8)) +>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, --, --)) +>value : Symbol(value, Decl(accessorsOverrideProperty2.ts, 6, 8)) +} + +const obj = new Derived(); // nothing printed +>obj : Symbol(obj, Decl(accessorsOverrideProperty2.ts, 9, 5)) +>Derived : Symbol(Derived, Decl(accessorsOverrideProperty2.ts, 2, 1)) + +console.log(obj.x); // 1 +>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, --, --)) +>obj.x : Symbol(Derived.x, Decl(accessorsOverrideProperty2.ts, 4, 28), Decl(accessorsOverrideProperty2.ts, 5, 23)) +>obj : Symbol(obj, Decl(accessorsOverrideProperty2.ts, 9, 5)) +>x : Symbol(Derived.x, Decl(accessorsOverrideProperty2.ts, 4, 28), Decl(accessorsOverrideProperty2.ts, 5, 23)) + diff --git a/tests/baselines/reference/accessorsOverrideProperty2.types b/tests/baselines/reference/accessorsOverrideProperty2.types new file mode 100644 index 0000000000000..f094ab56040e0 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty2.types @@ -0,0 +1,42 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts === +class Base { +>Base : Base + + x = 1; +>x : number +>1 : 1 +} + +class Derived extends Base { +>Derived : Derived +>Base : Base + + get x() { return 2; } // should be an error +>x : number +>2 : 2 + + set x(value) { console.log(`x was set to ${value}`); } +>x : number +>value : number +>console.log(`x was set to ${value}`) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>`x was set to ${value}` : string +>value : number +} + +const obj = new Derived(); // nothing printed +>obj : Derived +>new Derived() : Derived +>Derived : typeof Derived + +console.log(obj.x); // 1 +>console.log(obj.x) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>obj.x : number +>obj : Derived +>x : number + diff --git a/tests/baselines/reference/accessorsOverrideProperty3.errors.txt b/tests/baselines/reference/accessorsOverrideProperty3.errors.txt new file mode 100644 index 0000000000000..129af97f9b573 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty3.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts(6,9): error TS2611: Class 'Animal' defines instance member property 'sound', but extended class 'Lion' defines it as instance member accessor. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts (1 errors) ==== + declare class Animal { + sound: string + } + class Lion extends Animal { + _sound = 'grrr' + get sound() { return this._sound } // error here + ~~~~~ +!!! error TS2611: Class 'Animal' defines instance member property 'sound', but extended class 'Lion' defines it as instance member accessor. + set sound(val) { this._sound = val } + } + \ No newline at end of file diff --git a/tests/baselines/reference/accessorsOverrideProperty3.js b/tests/baselines/reference/accessorsOverrideProperty3.js new file mode 100644 index 0000000000000..1f1b69ed6eece --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty3.js @@ -0,0 +1,20 @@ +//// [accessorsOverrideProperty3.ts] +declare class Animal { + sound: string +} +class Lion extends Animal { + _sound = 'grrr' + get sound() { return this._sound } // error here + set sound(val) { this._sound = val } +} + + +//// [accessorsOverrideProperty3.js] +class Lion extends Animal { + constructor() { + super(...arguments); + this._sound = 'grrr'; + } + get sound() { return this._sound; } // error here + set sound(val) { this._sound = val; } +} diff --git a/tests/baselines/reference/accessorsOverrideProperty3.symbols b/tests/baselines/reference/accessorsOverrideProperty3.symbols new file mode 100644 index 0000000000000..f34923d36aad3 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty3.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts === +declare class Animal { +>Animal : Symbol(Animal, Decl(accessorsOverrideProperty3.ts, 0, 0)) + + sound: string +>sound : Symbol(Animal.sound, Decl(accessorsOverrideProperty3.ts, 0, 22)) +} +class Lion extends Animal { +>Lion : Symbol(Lion, Decl(accessorsOverrideProperty3.ts, 2, 1)) +>Animal : Symbol(Animal, Decl(accessorsOverrideProperty3.ts, 0, 0)) + + _sound = 'grrr' +>_sound : Symbol(Lion._sound, Decl(accessorsOverrideProperty3.ts, 3, 27)) + + get sound() { return this._sound } // error here +>sound : Symbol(Lion.sound, Decl(accessorsOverrideProperty3.ts, 4, 19), Decl(accessorsOverrideProperty3.ts, 5, 38)) +>this._sound : Symbol(Lion._sound, Decl(accessorsOverrideProperty3.ts, 3, 27)) +>this : Symbol(Lion, Decl(accessorsOverrideProperty3.ts, 2, 1)) +>_sound : Symbol(Lion._sound, Decl(accessorsOverrideProperty3.ts, 3, 27)) + + set sound(val) { this._sound = val } +>sound : Symbol(Lion.sound, Decl(accessorsOverrideProperty3.ts, 4, 19), Decl(accessorsOverrideProperty3.ts, 5, 38)) +>val : Symbol(val, Decl(accessorsOverrideProperty3.ts, 6, 14)) +>this._sound : Symbol(Lion._sound, Decl(accessorsOverrideProperty3.ts, 3, 27)) +>this : Symbol(Lion, Decl(accessorsOverrideProperty3.ts, 2, 1)) +>_sound : Symbol(Lion._sound, Decl(accessorsOverrideProperty3.ts, 3, 27)) +>val : Symbol(val, Decl(accessorsOverrideProperty3.ts, 6, 14)) +} + diff --git a/tests/baselines/reference/accessorsOverrideProperty3.types b/tests/baselines/reference/accessorsOverrideProperty3.types new file mode 100644 index 0000000000000..6fa0efd42f5a6 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty3.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts === +declare class Animal { +>Animal : Animal + + sound: string +>sound : string +} +class Lion extends Animal { +>Lion : Lion +>Animal : Animal + + _sound = 'grrr' +>_sound : string +>'grrr' : "grrr" + + get sound() { return this._sound } // error here +>sound : string +>this._sound : string +>this : this +>_sound : string + + set sound(val) { this._sound = val } +>sound : string +>val : string +>this._sound = val : string +>this._sound : string +>this : this +>_sound : string +>val : string +} + diff --git a/tests/baselines/reference/accessorsOverrideProperty4.errors.txt b/tests/baselines/reference/accessorsOverrideProperty4.errors.txt new file mode 100644 index 0000000000000..ca69ba6074425 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty4.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty4.ts(6,9): error TS2611: Class 'Animal' defines instance member property 'sound', but extended class 'Lion' defines it as instance member accessor. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty4.ts (1 errors) ==== + declare class Animal { + sound: string; + } + class Lion extends Animal { + _sound = 'roar' + get sound(): string { return this._sound } + ~~~~~ +!!! error TS2611: Class 'Animal' defines instance member property 'sound', but extended class 'Lion' defines it as instance member accessor. + set sound(val: string) { this._sound = val } + } + \ No newline at end of file diff --git a/tests/baselines/reference/accessorsOverrideProperty4.js b/tests/baselines/reference/accessorsOverrideProperty4.js new file mode 100644 index 0000000000000..43c07e0c3657c --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty4.js @@ -0,0 +1,20 @@ +//// [accessorsOverrideProperty4.ts] +declare class Animal { + sound: string; +} +class Lion extends Animal { + _sound = 'roar' + get sound(): string { return this._sound } + set sound(val: string) { this._sound = val } +} + + +//// [accessorsOverrideProperty4.js] +class Lion extends Animal { + constructor() { + super(...arguments); + this._sound = 'roar'; + } + get sound() { return this._sound; } + set sound(val) { this._sound = val; } +} diff --git a/tests/baselines/reference/accessorsOverrideProperty4.symbols b/tests/baselines/reference/accessorsOverrideProperty4.symbols new file mode 100644 index 0000000000000..d51646d1ce558 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty4.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty4.ts === +declare class Animal { +>Animal : Symbol(Animal, Decl(accessorsOverrideProperty4.ts, 0, 0)) + + sound: string; +>sound : Symbol(Animal.sound, Decl(accessorsOverrideProperty4.ts, 0, 22)) +} +class Lion extends Animal { +>Lion : Symbol(Lion, Decl(accessorsOverrideProperty4.ts, 2, 1)) +>Animal : Symbol(Animal, Decl(accessorsOverrideProperty4.ts, 0, 0)) + + _sound = 'roar' +>_sound : Symbol(Lion._sound, Decl(accessorsOverrideProperty4.ts, 3, 27)) + + get sound(): string { return this._sound } +>sound : Symbol(Lion.sound, Decl(accessorsOverrideProperty4.ts, 4, 19), Decl(accessorsOverrideProperty4.ts, 5, 46)) +>this._sound : Symbol(Lion._sound, Decl(accessorsOverrideProperty4.ts, 3, 27)) +>this : Symbol(Lion, Decl(accessorsOverrideProperty4.ts, 2, 1)) +>_sound : Symbol(Lion._sound, Decl(accessorsOverrideProperty4.ts, 3, 27)) + + set sound(val: string) { this._sound = val } +>sound : Symbol(Lion.sound, Decl(accessorsOverrideProperty4.ts, 4, 19), Decl(accessorsOverrideProperty4.ts, 5, 46)) +>val : Symbol(val, Decl(accessorsOverrideProperty4.ts, 6, 14)) +>this._sound : Symbol(Lion._sound, Decl(accessorsOverrideProperty4.ts, 3, 27)) +>this : Symbol(Lion, Decl(accessorsOverrideProperty4.ts, 2, 1)) +>_sound : Symbol(Lion._sound, Decl(accessorsOverrideProperty4.ts, 3, 27)) +>val : Symbol(val, Decl(accessorsOverrideProperty4.ts, 6, 14)) +} + diff --git a/tests/baselines/reference/accessorsOverrideProperty4.types b/tests/baselines/reference/accessorsOverrideProperty4.types new file mode 100644 index 0000000000000..e553e5f37f05d --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty4.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty4.ts === +declare class Animal { +>Animal : Animal + + sound: string; +>sound : string +} +class Lion extends Animal { +>Lion : Lion +>Animal : Animal + + _sound = 'roar' +>_sound : string +>'roar' : "roar" + + get sound(): string { return this._sound } +>sound : string +>this._sound : string +>this : this +>_sound : string + + set sound(val: string) { this._sound = val } +>sound : string +>val : string +>this._sound = val : string +>this._sound : string +>this : this +>_sound : string +>val : string +} + diff --git a/tests/baselines/reference/inheritanceMemberAccessorOverridingProperty.errors.txt b/tests/baselines/reference/inheritanceMemberAccessorOverridingProperty.errors.txt index 98b9d349d64fe..fd71a37a6875d 100644 --- a/tests/baselines/reference/inheritanceMemberAccessorOverridingProperty.errors.txt +++ b/tests/baselines/reference/inheritanceMemberAccessorOverridingProperty.errors.txt @@ -1,8 +1,9 @@ tests/cases/compiler/inheritanceMemberAccessorOverridingProperty.ts(6,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/inheritanceMemberAccessorOverridingProperty.ts(6,9): error TS2611: Class 'a' defines instance member property 'x', but extended class 'b' defines it as instance member accessor. tests/cases/compiler/inheritanceMemberAccessorOverridingProperty.ts(9,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -==== tests/cases/compiler/inheritanceMemberAccessorOverridingProperty.ts (2 errors) ==== +==== tests/cases/compiler/inheritanceMemberAccessorOverridingProperty.ts (3 errors) ==== class a { x: string; } @@ -11,6 +12,8 @@ tests/cases/compiler/inheritanceMemberAccessorOverridingProperty.ts(9,9): error get x() { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~ +!!! error TS2611: Class 'a' defines instance member property 'x', but extended class 'b' defines it as instance member accessor. return "20"; } set x(aValue: string) { diff --git a/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt b/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt index ec8ec05a8aeb5..4b468181f96a3 100644 --- a/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt +++ b/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt @@ -1,8 +1,9 @@ tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(6,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(12,5): error TS2610: Class 'a' defines instance member accessor 'x', but extended class 'b' defines it as instance member property. -==== tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts (2 errors) ==== +==== tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts (3 errors) ==== class a { private __x: () => string; get x() { @@ -19,4 +20,6 @@ tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(6,9): error class b extends a { x: () => string; + ~ +!!! error TS2610: Class 'a' defines instance member accessor 'x', but extended class 'b' defines it as instance member property. } \ No newline at end of file diff --git a/tests/baselines/reference/propertyOverridesAccessors.errors.txt b/tests/baselines/reference/propertyOverridesAccessors.errors.txt new file mode 100644 index 0000000000000..dcacf16696d48 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts(5,5): error TS2610: Class 'A' defines instance member accessor 'p', but extended class 'B' defines it as instance member property. +tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts(13,5): error TS2610: Class 'C' defines instance member accessor 'p', but extended class 'D' defines it as instance member property. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts (2 errors) ==== + class A { + get p() { return 'oh no' } + } + class B extends A { + p = 'yep' // error + ~ +!!! error TS2610: Class 'A' defines instance member accessor 'p', but extended class 'B' defines it as instance member property. + } + class C { + _secret = 11 + get p() { return this._secret } + set p(value) { this._secret = value } + } + class D extends C { + p = 101 // error + ~ +!!! error TS2610: Class 'C' defines instance member accessor 'p', but extended class 'D' defines it as instance member property. + } + \ No newline at end of file diff --git a/tests/baselines/reference/propertyOverridesAccessors.js b/tests/baselines/reference/propertyOverridesAccessors.js new file mode 100644 index 0000000000000..bc69da6705a36 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors.js @@ -0,0 +1,40 @@ +//// [propertyOverridesAccessors.ts] +class A { + get p() { return 'oh no' } +} +class B extends A { + p = 'yep' // error +} +class C { + _secret = 11 + get p() { return this._secret } + set p(value) { this._secret = value } +} +class D extends C { + p = 101 // error +} + + +//// [propertyOverridesAccessors.js] +class A { + get p() { return 'oh no'; } +} +class B extends A { + constructor() { + super(...arguments); + this.p = 'yep'; // error + } +} +class C { + constructor() { + this._secret = 11; + } + get p() { return this._secret; } + set p(value) { this._secret = value; } +} +class D extends C { + constructor() { + super(...arguments); + this.p = 101; // error + } +} diff --git a/tests/baselines/reference/propertyOverridesAccessors.symbols b/tests/baselines/reference/propertyOverridesAccessors.symbols new file mode 100644 index 0000000000000..e365fedad0a2e --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors.symbols @@ -0,0 +1,42 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts === +class A { +>A : Symbol(A, Decl(propertyOverridesAccessors.ts, 0, 0)) + + get p() { return 'oh no' } +>p : Symbol(A.p, Decl(propertyOverridesAccessors.ts, 0, 9)) +} +class B extends A { +>B : Symbol(B, Decl(propertyOverridesAccessors.ts, 2, 1)) +>A : Symbol(A, Decl(propertyOverridesAccessors.ts, 0, 0)) + + p = 'yep' // error +>p : Symbol(B.p, Decl(propertyOverridesAccessors.ts, 3, 19)) +} +class C { +>C : Symbol(C, Decl(propertyOverridesAccessors.ts, 5, 1)) + + _secret = 11 +>_secret : Symbol(C._secret, Decl(propertyOverridesAccessors.ts, 6, 9)) + + get p() { return this._secret } +>p : Symbol(C.p, Decl(propertyOverridesAccessors.ts, 7, 16), Decl(propertyOverridesAccessors.ts, 8, 35)) +>this._secret : Symbol(C._secret, Decl(propertyOverridesAccessors.ts, 6, 9)) +>this : Symbol(C, Decl(propertyOverridesAccessors.ts, 5, 1)) +>_secret : Symbol(C._secret, Decl(propertyOverridesAccessors.ts, 6, 9)) + + set p(value) { this._secret = value } +>p : Symbol(C.p, Decl(propertyOverridesAccessors.ts, 7, 16), Decl(propertyOverridesAccessors.ts, 8, 35)) +>value : Symbol(value, Decl(propertyOverridesAccessors.ts, 9, 10)) +>this._secret : Symbol(C._secret, Decl(propertyOverridesAccessors.ts, 6, 9)) +>this : Symbol(C, Decl(propertyOverridesAccessors.ts, 5, 1)) +>_secret : Symbol(C._secret, Decl(propertyOverridesAccessors.ts, 6, 9)) +>value : Symbol(value, Decl(propertyOverridesAccessors.ts, 9, 10)) +} +class D extends C { +>D : Symbol(D, Decl(propertyOverridesAccessors.ts, 10, 1)) +>C : Symbol(C, Decl(propertyOverridesAccessors.ts, 5, 1)) + + p = 101 // error +>p : Symbol(D.p, Decl(propertyOverridesAccessors.ts, 11, 19)) +} + diff --git a/tests/baselines/reference/propertyOverridesAccessors.types b/tests/baselines/reference/propertyOverridesAccessors.types new file mode 100644 index 0000000000000..9ffec6e8fe68d --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors.types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts === +class A { +>A : A + + get p() { return 'oh no' } +>p : string +>'oh no' : "oh no" +} +class B extends A { +>B : B +>A : A + + p = 'yep' // error +>p : string +>'yep' : "yep" +} +class C { +>C : C + + _secret = 11 +>_secret : number +>11 : 11 + + get p() { return this._secret } +>p : number +>this._secret : number +>this : this +>_secret : number + + set p(value) { this._secret = value } +>p : number +>value : number +>this._secret = value : number +>this._secret : number +>this : this +>_secret : number +>value : number +} +class D extends C { +>D : D +>C : C + + p = 101 // error +>p : number +>101 : 101 +} + diff --git a/tests/baselines/reference/propertyOverridesAccessors2.errors.txt b/tests/baselines/reference/propertyOverridesAccessors2.errors.txt new file mode 100644 index 0000000000000..0c91d3b9f7f7a --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors2.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors2.ts(7,3): error TS2610: Class 'Base' defines instance member accessor 'x', but extended class 'Derived' defines it as instance member property. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors2.ts (1 errors) ==== + class Base { + get x() { return 2; } + set x(value) { console.log(`x was set to ${value}`); } + } + + class Derived extends Base { + x = 1; + ~ +!!! error TS2610: Class 'Base' defines instance member accessor 'x', but extended class 'Derived' defines it as instance member property. + } + + const obj = new Derived(); // prints 'x was set to 1' + console.log(obj.x); // 2 + \ No newline at end of file diff --git a/tests/baselines/reference/propertyOverridesAccessors2.js b/tests/baselines/reference/propertyOverridesAccessors2.js new file mode 100644 index 0000000000000..bf5825771ff06 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors2.js @@ -0,0 +1,27 @@ +//// [propertyOverridesAccessors2.ts] +class Base { + get x() { return 2; } + set x(value) { console.log(`x was set to ${value}`); } +} + +class Derived extends Base { + x = 1; +} + +const obj = new Derived(); // prints 'x was set to 1' +console.log(obj.x); // 2 + + +//// [propertyOverridesAccessors2.js] +class Base { + get x() { return 2; } + set x(value) { console.log(`x was set to ${value}`); } +} +class Derived extends Base { + constructor() { + super(...arguments); + this.x = 1; + } +} +const obj = new Derived(); // prints 'x was set to 1' +console.log(obj.x); // 2 diff --git a/tests/baselines/reference/propertyOverridesAccessors2.symbols b/tests/baselines/reference/propertyOverridesAccessors2.symbols new file mode 100644 index 0000000000000..fd26e67e69bf0 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors2.symbols @@ -0,0 +1,36 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors2.ts === +class Base { +>Base : Symbol(Base, Decl(propertyOverridesAccessors2.ts, 0, 0)) + + get x() { return 2; } +>x : Symbol(Base.x, Decl(propertyOverridesAccessors2.ts, 0, 12), Decl(propertyOverridesAccessors2.ts, 1, 23)) + + set x(value) { console.log(`x was set to ${value}`); } +>x : Symbol(Base.x, Decl(propertyOverridesAccessors2.ts, 0, 12), Decl(propertyOverridesAccessors2.ts, 1, 23)) +>value : Symbol(value, Decl(propertyOverridesAccessors2.ts, 2, 8)) +>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, --, --)) +>value : Symbol(value, Decl(propertyOverridesAccessors2.ts, 2, 8)) +} + +class Derived extends Base { +>Derived : Symbol(Derived, Decl(propertyOverridesAccessors2.ts, 3, 1)) +>Base : Symbol(Base, Decl(propertyOverridesAccessors2.ts, 0, 0)) + + x = 1; +>x : Symbol(Derived.x, Decl(propertyOverridesAccessors2.ts, 5, 28)) +} + +const obj = new Derived(); // prints 'x was set to 1' +>obj : Symbol(obj, Decl(propertyOverridesAccessors2.ts, 9, 5)) +>Derived : Symbol(Derived, Decl(propertyOverridesAccessors2.ts, 3, 1)) + +console.log(obj.x); // 2 +>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, --, --)) +>obj.x : Symbol(Derived.x, Decl(propertyOverridesAccessors2.ts, 5, 28)) +>obj : Symbol(obj, Decl(propertyOverridesAccessors2.ts, 9, 5)) +>x : Symbol(Derived.x, Decl(propertyOverridesAccessors2.ts, 5, 28)) + diff --git a/tests/baselines/reference/propertyOverridesAccessors2.types b/tests/baselines/reference/propertyOverridesAccessors2.types new file mode 100644 index 0000000000000..5db511e968184 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors2.types @@ -0,0 +1,42 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors2.ts === +class Base { +>Base : Base + + get x() { return 2; } +>x : number +>2 : 2 + + set x(value) { console.log(`x was set to ${value}`); } +>x : number +>value : number +>console.log(`x was set to ${value}`) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>`x was set to ${value}` : string +>value : number +} + +class Derived extends Base { +>Derived : Derived +>Base : Base + + x = 1; +>x : number +>1 : 1 +} + +const obj = new Derived(); // prints 'x was set to 1' +>obj : Derived +>new Derived() : Derived +>Derived : typeof Derived + +console.log(obj.x); // 2 +>console.log(obj.x) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>obj.x : number +>obj : Derived +>x : number + diff --git a/tests/baselines/reference/propertyOverridesAccessors3.errors.txt b/tests/baselines/reference/propertyOverridesAccessors3.errors.txt new file mode 100644 index 0000000000000..523a0f6db3d08 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors3.errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors3.ts(19,5): error TS2610: Class 'Animal' defines instance member accessor 'sound', but extended class 'Lion' defines it as instance member property. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors3.ts (1 errors) ==== + class Animal { + _sound = 'rustling noise in the bushes' + + get sound() { return this._sound } + set sound(val) { + this._sound = val; + /* some important code here, perhaps tracking known sounds, etc */ + } + + makeSound() { + console.log(this._sound) + } + } + + const a = new Animal + a.makeSound() // 'rustling noise in the bushes' + + class Lion extends Animal { + sound = 'RAWR!' // error here + ~~~~~ +!!! error TS2610: Class 'Animal' defines instance member accessor 'sound', but extended class 'Lion' defines it as instance member property. + } + + const lion = new Lion + lion.makeSound() // with [[Define]]: Expected "RAWR!" but got "rustling noise in the bushes" + \ No newline at end of file diff --git a/tests/baselines/reference/propertyOverridesAccessors3.js b/tests/baselines/reference/propertyOverridesAccessors3.js new file mode 100644 index 0000000000000..3df81827bc97f --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors3.js @@ -0,0 +1,50 @@ +//// [propertyOverridesAccessors3.ts] +class Animal { + _sound = 'rustling noise in the bushes' + + get sound() { return this._sound } + set sound(val) { + this._sound = val; + /* some important code here, perhaps tracking known sounds, etc */ + } + + makeSound() { + console.log(this._sound) + } +} + +const a = new Animal +a.makeSound() // 'rustling noise in the bushes' + +class Lion extends Animal { + sound = 'RAWR!' // error here +} + +const lion = new Lion +lion.makeSound() // with [[Define]]: Expected "RAWR!" but got "rustling noise in the bushes" + + +//// [propertyOverridesAccessors3.js] +class Animal { + constructor() { + this._sound = 'rustling noise in the bushes'; + } + get sound() { return this._sound; } + set sound(val) { + this._sound = val; + /* some important code here, perhaps tracking known sounds, etc */ + } + makeSound() { + console.log(this._sound); + } +} +const a = new Animal; +a.makeSound(); // 'rustling noise in the bushes' +class Lion extends Animal { + constructor() { + super(...arguments); + this.sound = 'RAWR!'; // error here + } +} +const lion = new Lion; +lion.makeSound(); // with [[Define]]: Expected "RAWR!" but got "rustling noise in the bushes" diff --git a/tests/baselines/reference/propertyOverridesAccessors3.symbols b/tests/baselines/reference/propertyOverridesAccessors3.symbols new file mode 100644 index 0000000000000..801b6ca3c9810 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors3.symbols @@ -0,0 +1,65 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors3.ts === +class Animal { +>Animal : Symbol(Animal, Decl(propertyOverridesAccessors3.ts, 0, 0)) + + _sound = 'rustling noise in the bushes' +>_sound : Symbol(Animal._sound, Decl(propertyOverridesAccessors3.ts, 0, 14)) + + get sound() { return this._sound } +>sound : Symbol(Animal.sound, Decl(propertyOverridesAccessors3.ts, 1, 43), Decl(propertyOverridesAccessors3.ts, 3, 38)) +>this._sound : Symbol(Animal._sound, Decl(propertyOverridesAccessors3.ts, 0, 14)) +>this : Symbol(Animal, Decl(propertyOverridesAccessors3.ts, 0, 0)) +>_sound : Symbol(Animal._sound, Decl(propertyOverridesAccessors3.ts, 0, 14)) + + set sound(val) { +>sound : Symbol(Animal.sound, Decl(propertyOverridesAccessors3.ts, 1, 43), Decl(propertyOverridesAccessors3.ts, 3, 38)) +>val : Symbol(val, Decl(propertyOverridesAccessors3.ts, 4, 14)) + + this._sound = val; +>this._sound : Symbol(Animal._sound, Decl(propertyOverridesAccessors3.ts, 0, 14)) +>this : Symbol(Animal, Decl(propertyOverridesAccessors3.ts, 0, 0)) +>_sound : Symbol(Animal._sound, Decl(propertyOverridesAccessors3.ts, 0, 14)) +>val : Symbol(val, Decl(propertyOverridesAccessors3.ts, 4, 14)) + + /* some important code here, perhaps tracking known sounds, etc */ + } + + makeSound() { +>makeSound : Symbol(Animal.makeSound, Decl(propertyOverridesAccessors3.ts, 7, 5)) + + console.log(this._sound) +>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._sound : Symbol(Animal._sound, Decl(propertyOverridesAccessors3.ts, 0, 14)) +>this : Symbol(Animal, Decl(propertyOverridesAccessors3.ts, 0, 0)) +>_sound : Symbol(Animal._sound, Decl(propertyOverridesAccessors3.ts, 0, 14)) + } +} + +const a = new Animal +>a : Symbol(a, Decl(propertyOverridesAccessors3.ts, 14, 5)) +>Animal : Symbol(Animal, Decl(propertyOverridesAccessors3.ts, 0, 0)) + +a.makeSound() // 'rustling noise in the bushes' +>a.makeSound : Symbol(Animal.makeSound, Decl(propertyOverridesAccessors3.ts, 7, 5)) +>a : Symbol(a, Decl(propertyOverridesAccessors3.ts, 14, 5)) +>makeSound : Symbol(Animal.makeSound, Decl(propertyOverridesAccessors3.ts, 7, 5)) + +class Lion extends Animal { +>Lion : Symbol(Lion, Decl(propertyOverridesAccessors3.ts, 15, 13)) +>Animal : Symbol(Animal, Decl(propertyOverridesAccessors3.ts, 0, 0)) + + sound = 'RAWR!' // error here +>sound : Symbol(Lion.sound, Decl(propertyOverridesAccessors3.ts, 17, 27)) +} + +const lion = new Lion +>lion : Symbol(lion, Decl(propertyOverridesAccessors3.ts, 21, 5)) +>Lion : Symbol(Lion, Decl(propertyOverridesAccessors3.ts, 15, 13)) + +lion.makeSound() // with [[Define]]: Expected "RAWR!" but got "rustling noise in the bushes" +>lion.makeSound : Symbol(Animal.makeSound, Decl(propertyOverridesAccessors3.ts, 7, 5)) +>lion : Symbol(lion, Decl(propertyOverridesAccessors3.ts, 21, 5)) +>makeSound : Symbol(Animal.makeSound, Decl(propertyOverridesAccessors3.ts, 7, 5)) + diff --git a/tests/baselines/reference/propertyOverridesAccessors3.types b/tests/baselines/reference/propertyOverridesAccessors3.types new file mode 100644 index 0000000000000..b7ea64087c7a8 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors3.types @@ -0,0 +1,73 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors3.ts === +class Animal { +>Animal : Animal + + _sound = 'rustling noise in the bushes' +>_sound : string +>'rustling noise in the bushes' : "rustling noise in the bushes" + + get sound() { return this._sound } +>sound : string +>this._sound : string +>this : this +>_sound : string + + set sound(val) { +>sound : string +>val : string + + this._sound = val; +>this._sound = val : string +>this._sound : string +>this : this +>_sound : string +>val : string + + /* some important code here, perhaps tracking known sounds, etc */ + } + + makeSound() { +>makeSound : () => void + + console.log(this._sound) +>console.log(this._sound) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>this._sound : string +>this : this +>_sound : string + } +} + +const a = new Animal +>a : Animal +>new Animal : Animal +>Animal : typeof Animal + +a.makeSound() // 'rustling noise in the bushes' +>a.makeSound() : void +>a.makeSound : () => void +>a : Animal +>makeSound : () => void + +class Lion extends Animal { +>Lion : Lion +>Animal : Animal + + sound = 'RAWR!' // error here +>sound : string +>'RAWR!' : "RAWR!" +} + +const lion = new Lion +>lion : Lion +>new Lion : Lion +>Lion : typeof Lion + +lion.makeSound() // with [[Define]]: Expected "RAWR!" but got "rustling noise in the bushes" +>lion.makeSound() : void +>lion.makeSound : () => void +>lion : Lion +>makeSound : () => void + diff --git a/tests/baselines/reference/propertyOverridesAccessors4.errors.txt b/tests/baselines/reference/propertyOverridesAccessors4.errors.txt new file mode 100644 index 0000000000000..c437e05b28280 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors4.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors4.ts(6,5): error TS2610: Class 'Animal' defines instance member accessor 'sound', but extended class 'Lion' defines it as instance member property. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors4.ts (1 errors) ==== + declare class Animal { + get sound(): string + set sound(val: string) + } + class Lion extends Animal { + sound = 'RAWR!' // error here + ~~~~~ +!!! error TS2610: Class 'Animal' defines instance member accessor 'sound', but extended class 'Lion' defines it as instance member property. + } + \ No newline at end of file diff --git a/tests/baselines/reference/propertyOverridesAccessors4.js b/tests/baselines/reference/propertyOverridesAccessors4.js new file mode 100644 index 0000000000000..0b0330de05668 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors4.js @@ -0,0 +1,33 @@ +//// [propertyOverridesAccessors4.ts] +declare class Animal { + get sound(): string + set sound(val: string) +} +class Lion extends Animal { + sound = 'RAWR!' // error here +} + + +//// [propertyOverridesAccessors4.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var Lion = /** @class */ (function (_super) { + __extends(Lion, _super); + function Lion() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.sound = 'RAWR!'; // error here + return _this; + } + return Lion; +}(Animal)); diff --git a/tests/baselines/reference/propertyOverridesAccessors4.symbols b/tests/baselines/reference/propertyOverridesAccessors4.symbols new file mode 100644 index 0000000000000..d7097e1d528cd --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors4.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors4.ts === +declare class Animal { +>Animal : Symbol(Animal, Decl(propertyOverridesAccessors4.ts, 0, 0)) + + get sound(): string +>sound : Symbol(Animal.sound, Decl(propertyOverridesAccessors4.ts, 0, 22), Decl(propertyOverridesAccessors4.ts, 1, 23)) + + set sound(val: string) +>sound : Symbol(Animal.sound, Decl(propertyOverridesAccessors4.ts, 0, 22), Decl(propertyOverridesAccessors4.ts, 1, 23)) +>val : Symbol(val, Decl(propertyOverridesAccessors4.ts, 2, 14)) +} +class Lion extends Animal { +>Lion : Symbol(Lion, Decl(propertyOverridesAccessors4.ts, 3, 1)) +>Animal : Symbol(Animal, Decl(propertyOverridesAccessors4.ts, 0, 0)) + + sound = 'RAWR!' // error here +>sound : Symbol(Lion.sound, Decl(propertyOverridesAccessors4.ts, 4, 27)) +} + diff --git a/tests/baselines/reference/propertyOverridesAccessors4.types b/tests/baselines/reference/propertyOverridesAccessors4.types new file mode 100644 index 0000000000000..5701f76127bd6 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors4.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors4.ts === +declare class Animal { +>Animal : Animal + + get sound(): string +>sound : string + + set sound(val: string) +>sound : string +>val : string +} +class Lion extends Animal { +>Lion : Lion +>Animal : Animal + + sound = 'RAWR!' // error here +>sound : string +>'RAWR!' : "RAWR!" +} + diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts new file mode 100644 index 0000000000000..9365ea6bf9467 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts @@ -0,0 +1,15 @@ +// @target: esnext +class A { + p = 'yep' +} +class B extends A { + get p() { return 'oh no' } // error +} +class C { + p = 101 +} +class D extends C { + _secret = 11 + get p() { return this._secret } // error + set p(value) { this._secret = value } // error +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts new file mode 100644 index 0000000000000..18a51bb1c11ab --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts @@ -0,0 +1,12 @@ +// @target: esnext +class Base { + x = 1; +} + +class Derived extends Base { + get x() { return 2; } // should be an error + set x(value) { console.log(`x was set to ${value}`); } +} + +const obj = new Derived(); // nothing printed +console.log(obj.x); // 1 diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts new file mode 100644 index 0000000000000..204286d2463d6 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts @@ -0,0 +1,9 @@ +// @target: esnext +declare class Animal { + sound: string +} +class Lion extends Animal { + _sound = 'grrr' + get sound() { return this._sound } // error here + set sound(val) { this._sound = val } +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty4.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty4.ts new file mode 100644 index 0000000000000..4712b9c6f8d38 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty4.ts @@ -0,0 +1,9 @@ +// @target: esnext +declare class Animal { + sound: string; +} +class Lion extends Animal { + _sound = 'roar' + get sound(): string { return this._sound } + set sound(val: string) { this._sound = val } +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts new file mode 100644 index 0000000000000..b9dc49c574005 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts @@ -0,0 +1,15 @@ +// @target: esnext +class A { + get p() { return 'oh no' } +} +class B extends A { + p = 'yep' // error +} +class C { + _secret = 11 + get p() { return this._secret } + set p(value) { this._secret = value } +} +class D extends C { + p = 101 // error +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors2.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors2.ts new file mode 100644 index 0000000000000..760658238a5ec --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors2.ts @@ -0,0 +1,12 @@ +// @target: esnext +class Base { + get x() { return 2; } + set x(value) { console.log(`x was set to ${value}`); } +} + +class Derived extends Base { + x = 1; +} + +const obj = new Derived(); // prints 'x was set to 1' +console.log(obj.x); // 2 diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors3.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors3.ts new file mode 100644 index 0000000000000..5d61108fc99b7 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors3.ts @@ -0,0 +1,24 @@ +// @target: esnext +class Animal { + _sound = 'rustling noise in the bushes' + + get sound() { return this._sound } + set sound(val) { + this._sound = val; + /* some important code here, perhaps tracking known sounds, etc */ + } + + makeSound() { + console.log(this._sound) + } +} + +const a = new Animal +a.makeSound() // 'rustling noise in the bushes' + +class Lion extends Animal { + sound = 'RAWR!' // error here +} + +const lion = new Lion +lion.makeSound() // with [[Define]]: Expected "RAWR!" but got "rustling noise in the bushes" diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors4.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors4.ts new file mode 100644 index 0000000000000..e34b08a9bbd77 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors4.ts @@ -0,0 +1,7 @@ +declare class Animal { + get sound(): string + set sound(val: string) +} +class Lion extends Animal { + sound = 'RAWR!' // error here +} From ac9673977758afb864137da021f728afc30f7139 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 13 Sep 2019 14:38:09 -0700 Subject: [PATCH 02/44] Disallow uninitialised property overrides This causes quite a few test breaks. We'll probably want to revert many of them by switching to the upcoming `declare x: number` syntax. --- src/compiler/checker.ts | 43 ++-- src/compiler/diagnosticMessages.json | 4 + .../apparentTypeSubtyping.errors.txt | 8 +- .../apparentTypeSupertype.errors.txt | 5 +- ...baseClassImprovedMismatchErrors.errors.txt | 5 +- .../classIsSubtypeOfBaseType.errors.txt | 8 +- ...declarationEmitProtectedMembers.errors.txt | 55 +++++ ...dClassOverridesProtectedMembers.errors.txt | 44 ++++ ...ClassOverridesProtectedMembers2.errors.txt | 72 +++++++ ...ClassOverridesProtectedMembers3.errors.txt | 8 +- ...ClassOverridesProtectedMembers4.errors.txt | 8 +- ...ivedClassOverridesPublicMembers.errors.txt | 8 +- ...vedClassOverridesWithoutSubtype.errors.txt | 29 +++ .../reference/derivedClassWithAny.errors.txt | 8 +- .../derivedGenericClassWithAny.errors.txt | 8 +- ...ninitializedPropertyDeclaration.errors.txt | 22 ++ ...derivedUninitializedPropertyDeclaration.js | 54 +++++ ...edUninitializedPropertyDeclaration.symbols | 28 +++ ...ivedUninitializedPropertyDeclaration.types | 29 +++ .../genericPrototypeProperty2.errors.txt | 24 +++ .../genericPrototypeProperty3.errors.txt | 23 +++ ...aceExtendingClassWithProtecteds.errors.txt | 5 +- .../reference/inheritance.errors.txt | 5 +- ...emberPropertyOverridingAccessor.errors.txt | 5 +- ...emberPropertyOverridingProperty.errors.txt | 13 ++ .../instanceSubtypeCheck2.errors.txt | 5 +- ...erfaceExtendsObjectIntersection.errors.txt | 78 +++++++ ...ExtendsObjectIntersectionErrors.errors.txt | 17 +- .../reference/multipleInheritance.errors.txt | 5 +- .../mutuallyRecursiveInference.errors.txt | 24 +++ .../reference/protectedMembers.errors.txt | 11 +- .../baselines/reference/scopeTests.errors.txt | 5 +- .../subtypesOfTypeParameter.errors.txt | 5 +- ...OfTypeParameterWithConstraints4.errors.txt | 29 ++- ...rameterWithRecursiveConstraints.errors.txt | 56 +++++- .../subtypingTransitivity.errors.txt | 28 +++ .../subtypingWithObjectMembers.errors.txt | 38 +++- .../tsxGenericAttributesType5.errors.txt | 19 ++ .../tsxGenericAttributesType6.errors.txt | 19 ++ .../undefinedIsSubtypeOfEverything.errors.txt | 190 ++++++++++++++++++ ...derivedUninitializedPropertyDeclaration.ts | 12 ++ tests/cases/fourslash/incompatibleOverride.ts | 6 +- .../squiggleIllegalSubclassOverride.ts | 4 +- 43 files changed, 1030 insertions(+), 42 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitProtectedMembers.errors.txt create mode 100644 tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt create mode 100644 tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt create mode 100644 tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt create mode 100644 tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt create mode 100644 tests/baselines/reference/derivedUninitializedPropertyDeclaration.js create mode 100644 tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols create mode 100644 tests/baselines/reference/derivedUninitializedPropertyDeclaration.types create mode 100644 tests/baselines/reference/genericPrototypeProperty2.errors.txt create mode 100644 tests/baselines/reference/genericPrototypeProperty3.errors.txt create mode 100644 tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt create mode 100644 tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt create mode 100644 tests/baselines/reference/mutuallyRecursiveInference.errors.txt create mode 100644 tests/baselines/reference/subtypingTransitivity.errors.txt create mode 100644 tests/baselines/reference/tsxGenericAttributesType5.errors.txt create mode 100644 tests/baselines/reference/tsxGenericAttributesType6.errors.txt create mode 100644 tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f8c8817888591..311b57d1c1701 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29442,22 +29442,22 @@ namespace ts { d.kind === SyntaxKind.ClassDeclaration || d.kind === SyntaxKind.InterfaceDeclaration); } + /** + * TypeScript 1.0 spec (April 2014): 8.2.3 + * A derived class inherits all members from its base class it doesn't override. + * Inheritance means that a derived class implicitly contains all non - overridden members of the base class. + * Both public and private property members are inherited, but only public property members can be overridden. + * A property member in a derived class is said to override a property member in a base class + * when the derived class property member has the same name and kind(instance or static) + * as the base class property member. + * The type of an overriding property member must be assignable(section 3.8.4) + * to the type of the overridden property member, or otherwise a compile - time error occurs. + * Base class instance member functions can be overridden by derived class instance member functions, + * but not by other kinds of members. + * Base class instance member variables and accessors can be overridden by + * derived class instance member variables and accessors, but not by other kinds of members. + */ function checkKindsOfPropertyMemberOverrides(type: InterfaceType, baseType: BaseType): void { - - // TypeScript 1.0 spec (April 2014): 8.2.3 - // A derived class inherits all members from its base class it doesn't override. - // Inheritance means that a derived class implicitly contains all non - overridden members of the base class. - // Both public and private property members are inherited, but only public property members can be overridden. - // A property member in a derived class is said to override a property member in a base class - // when the derived class property member has the same name and kind(instance or static) - // as the base class property member. - // The type of an overriding property member must be assignable(section 3.8.4) - // to the type of the overridden property member, or otherwise a compile - time error occurs. - // Base class instance member functions can be overridden by derived class instance member functions, - // but not by other kinds of members. - // Base class instance member variables and accessors can be overridden by - // derived class instance member variables and accessors, but not by other kinds of members. - // NOTE: assignability is checked in checkClassDeclaration const baseProperties = getPropertiesOfType(baseType); basePropertyCheck: for (const baseProperty of baseProperties) { @@ -29514,10 +29514,21 @@ namespace ts { continue; } - if (isPrototypeProperty(base) || base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) { + if (isPrototypeProperty(base)) { // method is overridden with method or property/accessor is overridden with property/accessor - correct case continue; } + if (base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) { + if (derived.flags & SymbolFlags.Property + && !(derived.flags & SymbolFlags.Transient) + && !(baseDeclarationFlags & ModifierFlags.Abstract) + && !derived.declarations.some(d => d.flags & NodeFlags.Ambient) + && derived.declarations.some(d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer)) { + const errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_so_extended_class_2_must_provide_an_initializer_with_this_override; + error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type)); + } + continue; + } let errorMessage: DiagnosticMessage; if (isPrototypeProperty(base)) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 86686cb9f6c1b..0200bf4b1b3d4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2204,6 +2204,10 @@ "category": "Error", "code": 2609 }, + "Class '{0}' defines instance member property '{1}', so extended class '{2}' must provide an initializer with this override.": { + "category": "Error", + "code": 2610 + }, "Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": { "category": "Error", "code": 2649 diff --git a/tests/baselines/reference/apparentTypeSubtyping.errors.txt b/tests/baselines/reference/apparentTypeSubtyping.errors.txt index ca2f0765d6211..92ce3a37c3c35 100644 --- a/tests/baselines/reference/apparentTypeSubtyping.errors.txt +++ b/tests/baselines/reference/apparentTypeSubtyping.errors.txt @@ -1,9 +1,11 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'Base'. Type 'String' is not assignable to type 'string'. 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. +tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(20,5): error TS2610: Class 'Base2' defines instance member property 'x', so extended class 'Derived2' must provide an initializer with this override. -==== tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts (3 errors) ==== // subtype checks use the apparent type of the target type // S is a subtype of a type T, and T is a supertype of S, if one of the following is true, where S' denotes the apparent type (section 3.8.1) of S: @@ -18,6 +20,8 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtypi !!! error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'String' is not assignable to type 'string'. !!! error TS2416: 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. + ~ +!!! error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must provide an initializer with this override. } class Base2 { @@ -28,4 +32,6 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtypi // is U extends String (S) a subtype of String (T)? Apparent type of U is String so it succeeds class Derived2 extends Base2 { // error because of the prototype's not matching, not because of the instance side x: U; + ~ +!!! error TS2610: Class 'Base2' defines instance member property 'x', so extended class 'Derived2' must provide an initializer with this override. } \ No newline at end of file diff --git a/tests/baselines/reference/apparentTypeSupertype.errors.txt b/tests/baselines/reference/apparentTypeSupertype.errors.txt index a4a8ccc0a8bdd..23e4ee3cb3512 100644 --- a/tests/baselines/reference/apparentTypeSupertype.errors.txt +++ b/tests/baselines/reference/apparentTypeSupertype.errors.txt @@ -2,9 +2,10 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSuperty Type 'U' is not assignable to type 'string'. Type 'String' is not assignable to type 'string'. 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. +tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts(10,5): error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must provide an initializer with this override. -==== tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts (2 errors) ==== // subtype checks use the apparent type of the target type // S is a subtype of a type T, and T is a supertype of S, if one of the following is true, where S' denotes the apparent type (section 3.8.1) of S: @@ -20,4 +21,6 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSuperty !!! error TS2416: Type 'U' is not assignable to type 'string'. !!! error TS2416: Type 'String' is not assignable to type 'string'. !!! error TS2416: 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. + ~ +!!! error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must provide an initializer with this override. } \ No newline at end of file diff --git a/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt b/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt index 5f46ee70d2aaa..9a097955fde14 100644 --- a/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt +++ b/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt @@ -5,6 +5,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2416: Prop Types of property 'n' are incompatible. Type 'string | Derived' is not assignable to type 'string | Base'. Type 'Derived' is not assignable to type 'string | Base'. +tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2610: Class 'Base' defines instance member property 'n', so extended class 'Derived' must provide an initializer with this override. tests/cases/compiler/baseClassImprovedMismatchErrors.ts(9,5): error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'. Type '() => string | number' is not assignable to type '() => number'. Type 'string | number' is not assignable to type 'number'. @@ -22,7 +23,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro Type 'string' is not assignable to type 'number'. -==== tests/cases/compiler/baseClassImprovedMismatchErrors.ts (4 errors) ==== +==== tests/cases/compiler/baseClassImprovedMismatchErrors.ts (5 errors) ==== class Base { n: Base | string; fn() { @@ -39,6 +40,8 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro !!! error TS2416: Types of property 'n' are incompatible. !!! error TS2416: Type 'string | Derived' is not assignable to type 'string | Base'. !!! error TS2416: Type 'Derived' is not assignable to type 'string | Base'. + ~ +!!! error TS2610: Class 'Base' defines instance member property 'n', so extended class 'Derived' must provide an initializer with this override. fn() { ~~ !!! error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'. diff --git a/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt b/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt index 8b84602b807c5..f59f03763efa0 100644 --- a/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt +++ b/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt @@ -1,15 +1,19 @@ +tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(6,5): error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived' must provide an initializer with this override. tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type 'Base<{ bar: string; }>'. Type '{ bar?: string; }' is not assignable to type '{ bar: string; }'. Property 'bar' is optional in type '{ bar?: string; }' but required in type '{ bar: string; }'. +tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived2' must provide an initializer with this override. -==== tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts (1 errors) ==== +==== tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts (3 errors) ==== class Base { foo: T; } class Derived extends Base<{ bar: string; }> { foo: { + ~~~ +!!! error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived' must provide an initializer with this override. bar: string; baz: number; // ok } } @@ -20,6 +24,8 @@ tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/cla !!! error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type 'Base<{ bar: string; }>'. !!! error TS2416: Type '{ bar?: string; }' is not assignable to type '{ bar: string; }'. !!! error TS2416: Property 'bar' is optional in type '{ bar?: string; }' but required in type '{ bar: string; }'. + ~~~ +!!! error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived2' must provide an initializer with this override. bar?: string; // error } } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt b/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt new file mode 100644 index 0000000000000..ee19970f04d14 --- /dev/null +++ b/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt @@ -0,0 +1,55 @@ +tests/cases/compiler/declarationEmitProtectedMembers.ts(34,5): error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must provide an initializer with this override. + + +==== tests/cases/compiler/declarationEmitProtectedMembers.ts (1 errors) ==== + // Class with protected members + class C1 { + protected x: number; + + protected f() { + return this.x; + } + + protected set accessor(a: number) { } + protected get accessor() { return 0; } + + protected static sx: number; + + protected static sf() { + return this.sx; + } + + protected static set staticSetter(a: number) { } + protected static get staticGetter() { return 0; } + } + + // Derived class overriding protected members + class C2 extends C1 { + protected f() { + return super.f() + this.x; + } + protected static sf() { + return super.sf() + this.sx; + } + } + + // Derived class making protected members public + class C3 extends C2 { + x: number; + ~ +!!! error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must provide an initializer with this override. + static sx: number; + f() { + return super.f(); + } + static sf() { + return super.sf(); + } + + static get staticGetter() { return 1; } + } + + // Protected properties in constructors + class C4 { + constructor(protected a: number, protected b) { } + } \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt new file mode 100644 index 0000000000000..645abc21fc0f1 --- /dev/null +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts(21,15): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts(25,15): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must provide an initializer with this override. + + +==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts (2 errors) ==== + var x: { foo: string; } + var y: { foo: string; bar: string; } + + class Base { + protected a: typeof x; + protected b(a: typeof x) { } + protected get c() { return x; } + protected set c(v: typeof x) { } + protected d: (a: typeof x) => void; + + protected static r: typeof x; + protected static s(a: typeof x) { } + protected static get t() { return x; } + protected static set t(v: typeof x) { } + protected static u: (a: typeof x) => void; + + constructor(a: typeof x) { } + } + + class Derived extends Base { + protected a: typeof y; + ~ +!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must provide an initializer with this override. + protected b(a: typeof y) { } + protected get c() { return y; } + protected set c(v: typeof y) { } + protected d: (a: typeof y) => void; + ~ +!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must provide an initializer with this override. + + protected static r: typeof y; + protected static s(a: typeof y) { } + protected static get t() { return y; } + protected static set t(a: typeof y) { } + protected static u: (a: typeof y) => void; + + constructor(a: typeof y) { super(x) } + } + \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt new file mode 100644 index 0000000000000..51677922dccda --- /dev/null +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt @@ -0,0 +1,72 @@ +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts(22,5): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts(26,5): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must provide an initializer with this override. + + +==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts (2 errors) ==== + var x: { foo: string; } + var y: { foo: string; bar: string; } + + class Base { + protected a: typeof x; + protected b(a: typeof x) { } + protected get c() { return x; } + protected set c(v: typeof x) { } + protected d: (a: typeof x) => void ; + + protected static r: typeof x; + protected static s(a: typeof x) { } + protected static get t() { return x; } + protected static set t(v: typeof x) { } + protected static u: (a: typeof x) => void ; + + constructor(a: typeof x) { } + } + + // Increase visibility of all protected members to public + class Derived extends Base { + a: typeof y; + ~ +!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must provide an initializer with this override. + b(a: typeof y) { } + get c() { return y; } + set c(v: typeof y) { } + d: (a: typeof y) => void; + ~ +!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must provide an initializer with this override. + + static r: typeof y; + static s(a: typeof y) { } + static get t() { return y; } + static set t(a: typeof y) { } + static u: (a: typeof y) => void; + + constructor(a: typeof y) { super(a); } + } + + var d: Derived = new Derived(y); + var r1 = d.a; + var r2 = d.b(y); + var r3 = d.c; + var r3a = d.d; + d.c = y; + var r4 = Derived.r; + var r5 = Derived.s(y); + var r6 = Derived.t; + var r6a = Derived.u; + Derived.t = y; + + class Base2 { + [i: string]: Object; + [i: number]: typeof x; + } + + class Derived2 extends Base2 { + [i: string]: typeof x; + [i: number]: typeof y; + } + + var d2: Derived2; + var r7 = d2['']; + var r8 = d2[1]; + + \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt index faf228e8d55c2..6fdb020e366c4 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt @@ -1,5 +1,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(22,7): error TS2415: Class 'Derived1' incorrectly extends base class 'Base'. Property 'a' is protected in type 'Derived1' but public in type 'Base'. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(23,15): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must provide an initializer with this override. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(27,7): error TS2415: Class 'Derived2' incorrectly extends base class 'Base'. Property 'b' is protected in type 'Derived2' but public in type 'Base'. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(32,7): error TS2415: Class 'Derived3' incorrectly extends base class 'Base'. @@ -8,6 +9,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve Property 'c' is protected in type 'Derived4' but public in type 'Base'. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(42,7): error TS2415: Class 'Derived5' incorrectly extends base class 'Base'. Property 'd' is protected in type 'Derived5' but public in type 'Base'. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(43,15): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived5' must provide an initializer with this override. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(47,7): error TS2417: Class static side 'typeof Derived6' incorrectly extends base class static side 'typeof Base'. Property 'r' is protected in type 'typeof Derived6' but public in type 'typeof Base'. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(52,7): error TS2417: Class static side 'typeof Derived7' incorrectly extends base class static side 'typeof Base'. @@ -20,7 +22,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve Property 'u' is protected in type 'typeof Derived10' but public in type 'typeof Base'. -==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts (10 errors) ==== +==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts (12 errors) ==== var x: { foo: string; } var y: { foo: string; bar: string; } @@ -47,6 +49,8 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS2415: Class 'Derived1' incorrectly extends base class 'Base'. !!! error TS2415: Property 'a' is protected in type 'Derived1' but public in type 'Base'. protected a: typeof x; + ~ +!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must provide an initializer with this override. constructor(a: typeof x) { super(a); } } @@ -79,6 +83,8 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS2415: Class 'Derived5' incorrectly extends base class 'Base'. !!! error TS2415: Property 'd' is protected in type 'Derived5' but public in type 'Base'. protected d: (a: typeof x) => void ; + ~ +!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived5' must provide an initializer with this override. constructor(a: typeof x) { super(a); } } diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt index 064e2e8d43c2f..00eecd17d899a 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt @@ -1,8 +1,10 @@ +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(9,12): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must provide an initializer with this override. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(12,7): error TS2415: Class 'Derived2' incorrectly extends base class 'Derived1'. Property 'a' is protected in type 'Derived2' but public in type 'Derived1'. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(13,15): error TS2610: Class 'Derived1' defines instance member property 'a', so extended class 'Derived2' must provide an initializer with this override. -==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts (1 errors) ==== +==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts (3 errors) ==== var x: { foo: string; } var y: { foo: string; bar: string; } @@ -12,6 +14,8 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived1 extends Base { public a: typeof x; + ~ +!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must provide an initializer with this override. } class Derived2 extends Derived1 { @@ -19,4 +23,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS2415: Class 'Derived2' incorrectly extends base class 'Derived1'. !!! error TS2415: Property 'a' is protected in type 'Derived2' but public in type 'Derived1'. protected a: typeof x; // Error, parent was public + ~ +!!! error TS2610: Class 'Derived1' defines instance member property 'a', so extended class 'Derived2' must provide an initializer with this override. } \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt b/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt index 9292ff64411d5..19273eebe347d 100644 --- a/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt @@ -2,13 +2,15 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(13,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(14,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(21,5): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must provide an initializer with this override. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(23,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(24,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(25,5): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must provide an initializer with this override. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(29,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(30,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts (8 errors) ==== +==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts (10 errors) ==== var x: { foo: string; } var y: { foo: string; bar: string; } @@ -38,6 +40,8 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived extends Base { a: typeof y; + ~ +!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must provide an initializer with this override. b(a: typeof y) { } get c() { return y; } ~ @@ -46,6 +50,8 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. d: (a: typeof y) => void; + ~ +!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must provide an initializer with this override. static r: typeof y; static s(a: typeof y) { } diff --git a/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt b/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt new file mode 100644 index 0000000000000..46e01f242e299 --- /dev/null +++ b/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt @@ -0,0 +1,29 @@ +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype.ts(8,5): error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must provide an initializer with this override. + + +==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype.ts (1 errors) ==== + class Base { + x: { + foo: string; + } + } + + class Derived extends Base { + x: { + ~ +!!! error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must provide an initializer with this override. + foo: any; + } + } + + class Base2 { + static y: { + foo: string; + } + } + + class Derived2 extends Base2 { + static y: { + foo: any; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassWithAny.errors.txt b/tests/baselines/reference/derivedClassWithAny.errors.txt index aa91979706b51..37cb69218f432 100644 --- a/tests/baselines/reference/derivedClassWithAny.errors.txt +++ b/tests/baselines/reference/derivedClassWithAny.errors.txt @@ -1,7 +1,9 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(9,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(18,5): error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must provide an initializer with this override. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(19,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(27,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(37,5): error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must provide an initializer with this override. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(38,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(44,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(57,1): error TS2322: Type 'E' is not assignable to type 'C'. @@ -9,7 +11,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWit Type 'string' is not assignable to type 'number'. -==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts (7 errors) ==== +==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts (9 errors) ==== class C { x: number; get X(): number { return 1; } @@ -32,6 +34,8 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWit class D extends C { x: any; + ~ +!!! error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must provide an initializer with this override. get X(): any { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -55,6 +59,8 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWit // if D is a valid class definition than E is now not safe tranisitively through C class E extends D { x: string; + ~ +!!! error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must provide an initializer with this override. get X(): string{ return ''; } ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. diff --git a/tests/baselines/reference/derivedGenericClassWithAny.errors.txt b/tests/baselines/reference/derivedGenericClassWithAny.errors.txt index e63849e4aa887..d7d4167c342e3 100644 --- a/tests/baselines/reference/derivedGenericClassWithAny.errors.txt +++ b/tests/baselines/reference/derivedGenericClassWithAny.errors.txt @@ -1,6 +1,8 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(10,5): error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must provide an initializer with this override. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(11,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(19,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(29,5): error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must provide an initializer with this override. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,18): error TS2322: Type '""' is not assignable to type 'T'. '""' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'. @@ -11,7 +13,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC Type 'string' is not assignable to type 'number'. -==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts (7 errors) ==== +==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts (9 errors) ==== class C { x: T; get X(): T { return null; } @@ -24,6 +26,8 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC class D extends C { x: any; + ~ +!!! error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must provide an initializer with this override. get X(): any { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -47,6 +51,8 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC // if D is a valid class definition than E is now not safe tranisitively through C class E extends D { x: T; + ~ +!!! error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must provide an initializer with this override. get X(): T { return ''; } // error ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt new file mode 100644 index 0000000000000..0dcdfbee74c89 --- /dev/null +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(5,5): error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must provide an initializer with this override. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(11,5): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (2 errors) ==== + class A { + property = 'x'; + } + class B extends A { + property; // should be an error + ~~~~~~~~ +!!! error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must provide an initializer with this override. + } + class C { + p: string; + } + class D extends C { + p: 'hi'; // should also be an error? + ~ +!!! error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. + } + \ No newline at end of file diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js new file mode 100644 index 0000000000000..fbd2f1cdf8ecd --- /dev/null +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js @@ -0,0 +1,54 @@ +//// [derivedUninitializedPropertyDeclaration.ts] +class A { + property = 'x'; +} +class B extends A { + property; // should be an error +} +class C { + p: string; +} +class D extends C { + p: 'hi'; // should also be an error? +} + + +//// [derivedUninitializedPropertyDeclaration.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var A = /** @class */ (function () { + function A() { + this.property = 'x'; + } + return A; +}()); +var B = /** @class */ (function (_super) { + __extends(B, _super); + function B() { + return _super !== null && _super.apply(this, arguments) || this; + } + return B; +}(A)); +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D() { + return _super !== null && _super.apply(this, arguments) || this; + } + return D; +}(C)); diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols new file mode 100644 index 0000000000000..aad484889bbbd --- /dev/null +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts === +class A { +>A : Symbol(A, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 0)) + + property = 'x'; +>property : Symbol(A.property, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 9)) +} +class B extends A { +>B : Symbol(B, Decl(derivedUninitializedPropertyDeclaration.ts, 2, 1)) +>A : Symbol(A, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 0)) + + property; // should be an error +>property : Symbol(B.property, Decl(derivedUninitializedPropertyDeclaration.ts, 3, 19)) +} +class C { +>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 5, 1)) + + p: string; +>p : Symbol(C.p, Decl(derivedUninitializedPropertyDeclaration.ts, 6, 9)) +} +class D extends C { +>D : Symbol(D, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1)) +>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 5, 1)) + + p: 'hi'; // should also be an error? +>p : Symbol(D.p, Decl(derivedUninitializedPropertyDeclaration.ts, 9, 19)) +} + diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types new file mode 100644 index 0000000000000..60d8502fb552d --- /dev/null +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts === +class A { +>A : A + + property = 'x'; +>property : string +>'x' : "x" +} +class B extends A { +>B : B +>A : A + + property; // should be an error +>property : any +} +class C { +>C : C + + p: string; +>p : string +} +class D extends C { +>D : D +>C : C + + p: 'hi'; // should also be an error? +>p : "hi" +} + diff --git a/tests/baselines/reference/genericPrototypeProperty2.errors.txt b/tests/baselines/reference/genericPrototypeProperty2.errors.txt new file mode 100644 index 0000000000000..212abb8d79552 --- /dev/null +++ b/tests/baselines/reference/genericPrototypeProperty2.errors.txt @@ -0,0 +1,24 @@ +tests/cases/compiler/genericPrototypeProperty2.ts(7,5): error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must provide an initializer with this override. +tests/cases/compiler/genericPrototypeProperty2.ts(14,5): error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must provide an initializer with this override. + + +==== tests/cases/compiler/genericPrototypeProperty2.ts (2 errors) ==== + interface EventTarget { x } + class BaseEvent { + target: EventTarget; + } + + class MyEvent extends BaseEvent { + target: T; + ~~~~~~ +!!! error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must provide an initializer with this override. + } + class BaseEventWrapper { + t: BaseEvent; + } + + class MyEventWrapper extends BaseEventWrapper { + t: MyEvent; // any satisfies constraint and passes assignability check between 'target' properties + ~ +!!! error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must provide an initializer with this override. + } \ No newline at end of file diff --git a/tests/baselines/reference/genericPrototypeProperty3.errors.txt b/tests/baselines/reference/genericPrototypeProperty3.errors.txt new file mode 100644 index 0000000000000..d13518f48135e --- /dev/null +++ b/tests/baselines/reference/genericPrototypeProperty3.errors.txt @@ -0,0 +1,23 @@ +tests/cases/compiler/genericPrototypeProperty3.ts(6,5): error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must provide an initializer with this override. +tests/cases/compiler/genericPrototypeProperty3.ts(13,5): error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must provide an initializer with this override. + + +==== tests/cases/compiler/genericPrototypeProperty3.ts (2 errors) ==== + class BaseEvent { + target: {}; + } + + class MyEvent extends BaseEvent { // T is instantiated to any in the prototype, which is assignable to {} + target: T; + ~~~~~~ +!!! error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must provide an initializer with this override. + } + class BaseEventWrapper { + t: BaseEvent; + } + + class MyEventWrapper extends BaseEventWrapper { + t: MyEvent; + ~ +!!! error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must provide an initializer with this override. + } \ No newline at end of file diff --git a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt index ecb3e4664a470..b4ca2536ac5bd 100644 --- a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt +++ b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt @@ -10,9 +10,10 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInte Property 'y' is missing in type 'Bar5' but required in type 'I'. tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(29,7): error TS2420: Class 'Bar6' incorrectly implements interface 'I'. Property 'y' is protected in type 'Bar6' but public in type 'I'. +tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(38,5): error TS2610: Class 'Foo' defines instance member property 'x', so extended class 'Bar8' must provide an initializer with this override. -==== tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts (6 errors) ==== +==== tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts (7 errors) ==== class Foo { protected x: string; } @@ -71,6 +72,8 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInte class Bar8 extends Foo implements I { x: string; + ~ +!!! error TS2610: Class 'Foo' defines instance member property 'x', so extended class 'Bar8' must provide an initializer with this override. y: number; } \ No newline at end of file diff --git a/tests/baselines/reference/inheritance.errors.txt b/tests/baselines/reference/inheritance.errors.txt index b476f1399b445..12994b1c87665 100644 --- a/tests/baselines/reference/inheritance.errors.txt +++ b/tests/baselines/reference/inheritance.errors.txt @@ -1,9 +1,10 @@ +tests/cases/compiler/inheritance.ts(22,12): error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must provide an initializer with this override. tests/cases/compiler/inheritance.ts(31,12): error TS2425: Class 'Good' defines instance member property 'f', but extended class 'Baad' defines it as instance member function. tests/cases/compiler/inheritance.ts(32,12): error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type 'Good'. Type '(n: number) => number' is not assignable to type '() => number'. -==== tests/cases/compiler/inheritance.ts (2 errors) ==== +==== tests/cases/compiler/inheritance.ts (3 errors) ==== class B1 { public x; } @@ -26,6 +27,8 @@ tests/cases/compiler/inheritance.ts(32,12): error TS2416: Property 'g' in type ' class ND extends N { // any is assignable to number public y; + ~ +!!! error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must provide an initializer with this override. } class Good { diff --git a/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt b/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt index ec8ec05a8aeb5..9491f47ff133b 100644 --- a/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt +++ b/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt @@ -1,8 +1,9 @@ tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(6,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(12,5): error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must provide an initializer with this override. -==== tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts (2 errors) ==== +==== tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts (3 errors) ==== class a { private __x: () => string; get x() { @@ -19,4 +20,6 @@ tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(6,9): error class b extends a { x: () => string; + ~ +!!! error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must provide an initializer with this override. } \ No newline at end of file diff --git a/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt b/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt new file mode 100644 index 0000000000000..ed604c5260725 --- /dev/null +++ b/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/inheritanceMemberPropertyOverridingProperty.ts(6,5): error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must provide an initializer with this override. + + +==== tests/cases/compiler/inheritanceMemberPropertyOverridingProperty.ts (1 errors) ==== + class a { + x: () => string; + } + + class b extends a { + x: () => string; + ~ +!!! error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must provide an initializer with this override. + } \ No newline at end of file diff --git a/tests/baselines/reference/instanceSubtypeCheck2.errors.txt b/tests/baselines/reference/instanceSubtypeCheck2.errors.txt index 84b454d7ea0a6..cd53a1304c246 100644 --- a/tests/baselines/reference/instanceSubtypeCheck2.errors.txt +++ b/tests/baselines/reference/instanceSubtypeCheck2.errors.txt @@ -1,8 +1,9 @@ tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2416: Property 'x' in type 'C2' is not assignable to the same property in base type 'C1'. Type 'string' is not assignable to type 'C2'. +tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2610: Class 'C1' defines instance member property 'x', so extended class 'C2' must provide an initializer with this override. -==== tests/cases/compiler/instanceSubtypeCheck2.ts (1 errors) ==== +==== tests/cases/compiler/instanceSubtypeCheck2.ts (2 errors) ==== class C1 { x: C2; } @@ -12,4 +13,6 @@ tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2416: Property 'x' i ~ !!! error TS2416: Property 'x' in type 'C2' is not assignable to the same property in base type 'C1'. !!! error TS2416: Type 'string' is not assignable to type 'C2'. + ~ +!!! error TS2610: Class 'C1' defines instance member property 'x', so extended class 'C2' must provide an initializer with this override. } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt b/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt new file mode 100644 index 0000000000000..a200f3bffe1e4 --- /dev/null +++ b/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt @@ -0,0 +1,78 @@ +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(20,38): error TS2610: Class 'I1' defines instance member property 'x', so extended class 'C1' must provide an initializer with this override. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(21,38): error TS2610: Class 'I2' defines instance member property 'x', so extended class 'C2' must provide an initializer with this override. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(22,38): error TS2610: Class 'I3' defines instance member property 'x', so extended class 'C3' must provide an initializer with this override. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(23,38): error TS2610: Class 'I4' defines instance member property 'x', so extended class 'C4' must provide an initializer with this override. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(24,38): error TS2610: Class 'I5' defines instance member property 'x', so extended class 'C5' must provide an initializer with this override. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(25,38): error TS2610: Class 'I6' defines instance member property 'x', so extended class 'C6' must provide an initializer with this override. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(26,38): error TS2610: Class 'I7' defines instance member property 'x', so extended class 'C7' must provide an initializer with this override. + + +==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts (7 errors) ==== + type T1 = { a: number }; + type T2 = T1 & { b: number }; + type T3 = () => void; + type T4 = new () => { a: number }; + type T5 = number[]; + type T6 = [string, number]; + type T7 = { [P in 'a' | 'b' | 'c']: string }; + + interface I1 extends T1 { x: string } + interface I2 extends T2 { x: string } + interface I3 extends T3 { x: string } + interface I4 extends T4 { x: string } + interface I5 extends T5 { x: string } + interface I6 extends T6 { x: string } + interface I7 extends T7 { x: string } + + type Constructor = new () => T; + declare function Constructor(): Constructor; + + class C1 extends Constructor() { x: string } + ~ +!!! error TS2610: Class 'I1' defines instance member property 'x', so extended class 'C1' must provide an initializer with this override. + class C2 extends Constructor() { x: string } + ~ +!!! error TS2610: Class 'I2' defines instance member property 'x', so extended class 'C2' must provide an initializer with this override. + class C3 extends Constructor() { x: string } + ~ +!!! error TS2610: Class 'I3' defines instance member property 'x', so extended class 'C3' must provide an initializer with this override. + class C4 extends Constructor() { x: string } + ~ +!!! error TS2610: Class 'I4' defines instance member property 'x', so extended class 'C4' must provide an initializer with this override. + class C5 extends Constructor() { x: string } + ~ +!!! error TS2610: Class 'I5' defines instance member property 'x', so extended class 'C5' must provide an initializer with this override. + class C6 extends Constructor() { x: string } + ~ +!!! error TS2610: Class 'I6' defines instance member property 'x', so extended class 'C6' must provide an initializer with this override. + class C7 extends Constructor() { x: string } + ~ +!!! error TS2610: Class 'I7' defines instance member property 'x', so extended class 'C7' must provide an initializer with this override. + + declare function fx(x: string): string; + declare class CX { a: number } + declare enum EX { A, B, C } + declare namespace NX { export const a = 1 } + + type T10 = typeof fx; + type T11 = typeof CX; + type T12 = typeof EX; + type T13 = typeof NX; + + interface I10 extends T10 { x: string } + interface I11 extends T11 { x: string } + interface I12 extends T12 { x: string } + interface I13 extends T13 { x: string } + + type Identifiable = { _id: string } & T; + + interface I20 extends Partial { x: string } + interface I21 extends Readonly { x: string } + interface I22 extends Identifiable { x: string } + interface I23 extends Identifiable { x: string } + + class C20 extends Constructor>() { x: string } + class C21 extends Constructor>() { x: string } + class C22 extends Constructor>() { x: string } + class C23 extends Constructor>() { x: string } + \ No newline at end of file diff --git a/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt b/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt index 17cb5585cf87e..9acd77695b67d 100644 --- a/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt +++ b/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt @@ -16,14 +16,19 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI Type 'number' is not assignable to type 'string'. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(16,38): error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'T1'. Type 'string' is not assignable to type 'number'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(16,38): error TS2610: Class 'T1' defines instance member property 'a', so extended class 'C1' must provide an initializer with this override. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'T2'. Type 'string' is not assignable to type 'number'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2610: Class 'T2' defines instance member property 'b', so extended class 'C2' must provide an initializer with this override. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'. Type 'string' is not assignable to type 'number'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2610: Class 'number[]' defines instance member property 'length', so extended class 'C3' must provide an initializer with this override. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'. Type 'number' is not assignable to type 'string'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2610: Class '[string, number]' defines instance member property '0', so extended class 'C4' must provide an initializer with this override. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(20,38): error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'T5'. Type 'number' is not assignable to type 'string'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(20,38): error TS2610: Class 'T5' defines instance member property 'c', so extended class 'C5' must provide an initializer with this override. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(30,11): error TS2430: Interface 'I10' incorrectly extends interface 'typeof CX'. Types of property 'a' are incompatible. Type 'number' is not assignable to type 'string'. @@ -55,7 +60,7 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(47,26): error TS2312: An interface can only extend an object type or intersection of object types with statically known members. -==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts (23 errors) ==== +==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts (28 errors) ==== type T1 = { a: number }; type T2 = T1 & { b: number }; type T3 = number[]; @@ -96,22 +101,32 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI ~ !!! error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'T1'. !!! error TS2416: Type 'string' is not assignable to type 'number'. + ~ +!!! error TS2610: Class 'T1' defines instance member property 'a', so extended class 'C1' must provide an initializer with this override. class C2 extends Constructor() { b: string } ~ !!! error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'T2'. !!! error TS2416: Type 'string' is not assignable to type 'number'. + ~ +!!! error TS2610: Class 'T2' defines instance member property 'b', so extended class 'C2' must provide an initializer with this override. class C3 extends Constructor() { length: string } ~~~~~~ !!! error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'. !!! error TS2416: Type 'string' is not assignable to type 'number'. + ~~~~~~ +!!! error TS2610: Class 'number[]' defines instance member property 'length', so extended class 'C3' must provide an initializer with this override. class C4 extends Constructor() { 0: number } ~ !!! error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'. !!! error TS2416: Type 'number' is not assignable to type 'string'. + ~ +!!! error TS2610: Class '[string, number]' defines instance member property '0', so extended class 'C4' must provide an initializer with this override. class C5 extends Constructor() { c: number } ~ !!! error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'T5'. !!! error TS2416: Type 'number' is not assignable to type 'string'. + ~ +!!! error TS2610: Class 'T5' defines instance member property 'c', so extended class 'C5' must provide an initializer with this override. declare class CX { static a: string } declare enum EX { A, B, C } diff --git a/tests/baselines/reference/multipleInheritance.errors.txt b/tests/baselines/reference/multipleInheritance.errors.txt index c4a440d9a0ea5..b3e6a02c72942 100644 --- a/tests/baselines/reference/multipleInheritance.errors.txt +++ b/tests/baselines/reference/multipleInheritance.errors.txt @@ -1,11 +1,12 @@ tests/cases/compiler/multipleInheritance.ts(9,21): error TS1174: Classes can only extend a single class. tests/cases/compiler/multipleInheritance.ts(18,21): error TS1174: Classes can only extend a single class. +tests/cases/compiler/multipleInheritance.ts(26,12): error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must provide an initializer with this override. tests/cases/compiler/multipleInheritance.ts(35,12): error TS2425: Class 'Good' defines instance member property 'f', but extended class 'Baad' defines it as instance member function. tests/cases/compiler/multipleInheritance.ts(36,12): error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type 'Good'. Type '(n: number) => number' is not assignable to type '() => number'. -==== tests/cases/compiler/multipleInheritance.ts (4 errors) ==== +==== tests/cases/compiler/multipleInheritance.ts (5 errors) ==== class B1 { public x; } @@ -36,6 +37,8 @@ tests/cases/compiler/multipleInheritance.ts(36,12): error TS2416: Property 'g' i class ND extends N { // any is assignable to number public y; + ~ +!!! error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must provide an initializer with this override. } class Good { diff --git a/tests/baselines/reference/mutuallyRecursiveInference.errors.txt b/tests/baselines/reference/mutuallyRecursiveInference.errors.txt new file mode 100644 index 0000000000000..9f5b1852c7c47 --- /dev/null +++ b/tests/baselines/reference/mutuallyRecursiveInference.errors.txt @@ -0,0 +1,24 @@ +tests/cases/compiler/mutuallyRecursiveInference.ts(9,5): error TS2610: Class 'L' defines instance member property 'a', so extended class 'X' must provide an initializer with this override. +tests/cases/compiler/mutuallyRecursiveInference.ts(10,5): error TS2610: Class 'L' defines instance member property 'b', so extended class 'X' must provide an initializer with this override. + + +==== tests/cases/compiler/mutuallyRecursiveInference.ts (2 errors) ==== + class T { + a: A; + b: any + } + class L extends T { + m() { this.a } + } + class X extends L { + a: 'a' | 'b' + ~ +!!! error TS2610: Class 'L' defines instance member property 'a', so extended class 'X' must provide an initializer with this override. + b: number + ~ +!!! error TS2610: Class 'L' defines instance member property 'b', so extended class 'X' must provide an initializer with this override. + m2() { + this.a + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/protectedMembers.errors.txt b/tests/baselines/reference/protectedMembers.errors.txt index 9171df2a485b6..5a1fc2bfeb351 100644 --- a/tests/baselines/reference/protectedMembers.errors.txt +++ b/tests/baselines/reference/protectedMembers.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/protectedMembers.ts(25,5): error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must provide an initializer with this override. tests/cases/compiler/protectedMembers.ts(40,4): error TS2445: Property 'x' is protected and only accessible within class 'C1' and its subclasses. tests/cases/compiler/protectedMembers.ts(41,4): error TS2445: Property 'f' is protected and only accessible within class 'C1' and its subclasses. tests/cases/compiler/protectedMembers.ts(42,4): error TS2445: Property 'sx' is protected and only accessible within class 'C1' and its subclasses. @@ -12,11 +13,13 @@ tests/cases/compiler/protectedMembers.ts(97,1): error TS2322: Type 'B1' is not a Property 'x' is protected but type 'B1' is not a class derived from 'A1'. tests/cases/compiler/protectedMembers.ts(98,1): error TS2322: Type 'A1' is not assignable to type 'B1'. Property 'x' is protected in type 'A1' but public in type 'B1'. +tests/cases/compiler/protectedMembers.ts(104,5): error TS2610: Class 'A2' defines instance member property 'x', so extended class 'B2' must provide an initializer with this override. tests/cases/compiler/protectedMembers.ts(111,7): error TS2415: Class 'B3' incorrectly extends base class 'A3'. Property 'x' is protected in type 'B3' but public in type 'A3'. +tests/cases/compiler/protectedMembers.ts(112,15): error TS2610: Class 'A3' defines instance member property 'x', so extended class 'B3' must provide an initializer with this override. -==== tests/cases/compiler/protectedMembers.ts (13 errors) ==== +==== tests/cases/compiler/protectedMembers.ts (16 errors) ==== // Class with protected members class C1 { protected x: number; @@ -42,6 +45,8 @@ tests/cases/compiler/protectedMembers.ts(111,7): error TS2415: Class 'B3' incorr // Derived class making protected members public class C3 extends C2 { x: number; + ~ +!!! error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must provide an initializer with this override. static sx: number; f() { return super.f(); @@ -147,6 +152,8 @@ tests/cases/compiler/protectedMembers.ts(111,7): error TS2415: Class 'B3' incorr } class B2 extends A2 { x; + ~ +!!! error TS2610: Class 'A2' defines instance member property 'x', so extended class 'B2' must provide an initializer with this override. } class A3 { @@ -158,6 +165,8 @@ tests/cases/compiler/protectedMembers.ts(111,7): error TS2415: Class 'B3' incorr !!! error TS2415: Class 'B3' incorrectly extends base class 'A3'. !!! error TS2415: Property 'x' is protected in type 'B3' but public in type 'A3'. protected x; + ~ +!!! error TS2610: Class 'A3' defines instance member property 'x', so extended class 'B3' must provide an initializer with this override. } \ No newline at end of file diff --git a/tests/baselines/reference/scopeTests.errors.txt b/tests/baselines/reference/scopeTests.errors.txt index ce24301efc2bf..2457ba3912a61 100644 --- a/tests/baselines/reference/scopeTests.errors.txt +++ b/tests/baselines/reference/scopeTests.errors.txt @@ -1,8 +1,9 @@ tests/cases/compiler/scopeTests.ts(2,7): error TS2415: Class 'D' incorrectly extends base class 'C'. Property 'v' is private in type 'C' but not in type 'D'. +tests/cases/compiler/scopeTests.ts(4,10): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. -==== tests/cases/compiler/scopeTests.ts (1 errors) ==== +==== tests/cases/compiler/scopeTests.ts (2 errors) ==== class C { private v; public p; static s; } class D extends C { ~ @@ -10,6 +11,8 @@ tests/cases/compiler/scopeTests.ts(2,7): error TS2415: Class 'D' incorrectly ext !!! error TS2415: Property 'v' is private in type 'C' but not in type 'D'. public v: number; public p: number + ~ +!!! error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. constructor() { super() this.v = 1; diff --git a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt index 0ec8951fe9391..4541037baae14 100644 --- a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt @@ -1,9 +1,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(8,5): error TS2416: Property 'foo' in type 'D1' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(8,5): error TS2610: Class 'C3' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts (2 errors) ==== // checking whether other types are subtypes of type parameters class C3 { @@ -16,6 +17,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D1' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. + ~~~ +!!! error TS2610: Class 'C3' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. } function f1(x: T, y: U) { diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt index 03656c08c4ef2..e952bf31059ee 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt @@ -1,27 +1,36 @@ +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(37,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(42,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'Foo'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'Foo'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(52,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2416: Property 'foo' in type 'D5' is not assignable to the same property in base type 'B1'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. Type 'Foo' is not assignable to type 'T'. 'Foo' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'B1'. Type 'T' is not assignable to type 'U'. 'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. Type 'Foo' is not assignable to type 'U'. 'Foo' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(72,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2416: Property 'foo' in type 'D9' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts (10 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts (19 errors) ==== // checking whether other types are subtypes of type parameters with constraints class Foo { foo: number; } @@ -59,11 +68,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D1 extends B1 { [x: string]: Foo; foo: T; // ok + ~~~ +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. } class D2 extends B1 { [x: string]: Foo; foo: U; // ok + ~~~ +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. } class D3 extends B1 { @@ -74,11 +87,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~ !!! error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'Foo'. + ~~~ +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. } class D4 extends B1 { [x: string]: T; foo: T; // ok + ~~~ +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. } class D5 extends B1 { @@ -92,6 +109,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. !!! error TS2416: 'Foo' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. + ~~~ +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. } class D6 extends B1 { @@ -102,6 +121,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~ !!! error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'T'. + ~~~ +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. } class D7 extends B1 { @@ -115,11 +136,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: 'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. !!! error TS2416: 'Foo' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. + ~~~ +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. } class D8 extends B1 { [x: string]: U; foo: U; // ok + ~~~ +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. } class D9 extends B1 { @@ -130,4 +155,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~ !!! error TS2416: Property 'foo' in type 'D9' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'U'. + ~~~ +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. } \ No newline at end of file diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt index 700076db4d190..4247c68cb876a 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt @@ -1,66 +1,84 @@ +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(63,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2416: Property 'foo' in type 'D2' is not assignable to the same property in base type 'Base'. Type 'U' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base'. Type 'V' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2416: Property 'foo' in type 'D4' is not assignable to the same property in base type 'Base'. Type 'T' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(83,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base'. Type 'V' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base'. Type 'T' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base'. Type 'U' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(103,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(115,9): error TS2416: Property 'foo' in type 'D1' is not assignable to the same property in base type 'Base2'. Type 'T' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'U' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(115,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(120,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(120,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base2'. Type 'V' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'V' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(130,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(130,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(135,9): error TS2416: Property 'foo' in type 'D5' is not assignable to the same property in base type 'Base2'. Type 'U' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'T' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(135,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base2'. Type 'V' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'V' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base2'. Type 'T' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'U' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base2'. Type 'U' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'T' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(155,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts (24 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts (42 errors) ==== // checking whether other types are subtypes of type parameters with constraints class Foo { foo: T; } @@ -124,6 +142,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D1, U extends Foo, V extends Foo> extends Base { [x: string]: T; foo: T + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. } class D2, U extends Foo, V extends Foo> extends Base { @@ -135,6 +155,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D2' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. } class D3, U extends Foo, V extends Foo> extends Base { @@ -146,6 +168,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. } class D4, U extends Foo, V extends Foo> extends Base { @@ -157,11 +181,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D4' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'T' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. } class D5, U extends Foo, V extends Foo> extends Base { [x: string]: U; foo: U + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. } class D6, U extends Foo, V extends Foo> extends Base { @@ -173,6 +201,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'V' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. } class D7, U extends Foo, V extends Foo> extends Base { @@ -184,6 +214,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'T' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. } class D8, U extends Foo, V extends Foo> extends Base { @@ -195,11 +227,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'U' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. } class D9, U extends Foo, V extends Foo> extends Base { [x: string]: V; foo: V + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. } } @@ -218,6 +254,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'Foo'. !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. + ~~~ +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. } class D2, U extends Foo, V extends Foo> extends Base2 { @@ -225,6 +263,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf foo: U ~~~ !!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. + ~~~ +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. } class D3, U extends Foo, V extends Foo> extends Base2 { @@ -238,6 +278,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'Foo'. !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. + ~~~ +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. } class D4, U extends Foo, V extends Foo> extends Base2 { @@ -245,6 +287,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf foo: T ~~~ !!! error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. + ~~~ +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. } class D5, U extends Foo, V extends Foo> extends Base2 { @@ -256,6 +300,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'Foo'. !!! error TS2416: Type 'T' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. + ~~~ +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. } class D6, U extends Foo, V extends Foo> extends Base2 { @@ -269,6 +315,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'Foo'. !!! error TS2416: Type 'V' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. + ~~~ +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. } class D7, U extends Foo, V extends Foo> extends Base2 { @@ -282,6 +330,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'Foo'. !!! error TS2416: Type 'U' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. + ~~~ +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. } class D8, U extends Foo, V extends Foo> extends Base2 { @@ -295,10 +345,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'Foo'. !!! error TS2416: Type 'T' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. + ~~~ +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. } class D9, U extends Foo, V extends Foo> extends Base2 { [x: string]: V; foo: V + ~~~ +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. } } \ No newline at end of file diff --git a/tests/baselines/reference/subtypingTransitivity.errors.txt b/tests/baselines/reference/subtypingTransitivity.errors.txt new file mode 100644 index 0000000000000..1284422452565 --- /dev/null +++ b/tests/baselines/reference/subtypingTransitivity.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/subtypingTransitivity.ts(6,12): error TS2610: Class 'B' defines instance member property 'x', so extended class 'D' must provide an initializer with this override. +tests/cases/compiler/subtypingTransitivity.ts(9,12): error TS2610: Class 'B' defines instance member property 'x', so extended class 'D2' must provide an initializer with this override. + + +==== tests/cases/compiler/subtypingTransitivity.ts (2 errors) ==== + class B { + x: Object; + } + + class D extends B { + public x: string; + ~ +!!! error TS2610: Class 'B' defines instance member property 'x', so extended class 'D' must provide an initializer with this override. + } + class D2 extends B { + public x: number; + ~ +!!! error TS2610: Class 'B' defines instance member property 'x', so extended class 'D2' must provide an initializer with this override. + } + + var b: B; + var d: D; + var d2: D2; + + d.x = ''; + b = d; + b.x = 1; // assigned number to string + \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithObjectMembers.errors.txt b/tests/baselines/reference/subtypingWithObjectMembers.errors.txt index 1e2f7bc9114f1..6690c442c81a7 100644 --- a/tests/baselines/reference/subtypingWithObjectMembers.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembers.errors.txt @@ -1,18 +1,30 @@ +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(13,5): error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(14,5): error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. Type 'string' is not assignable to type 'Base'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(14,5): error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(23,5): error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(24,5): error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. Type 'string' is not assignable to type 'Base'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(24,5): error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(33,5): error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(34,5): error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. Type 'string' is not assignable to type 'Base'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(34,5): error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(44,9): error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(45,9): error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. Type 'string' is not assignable to type 'Base'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(45,9): error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(54,9): error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(55,9): error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. Type 'string' is not assignable to type 'Base'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(55,9): error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(64,9): error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must provide an initializer with this override. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(65,9): error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. Type 'string' is not assignable to type 'Base'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(65,9): error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must provide an initializer with this override. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts (6 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts (18 errors) ==== class Base { foo: string; } class Derived extends Base { bar: string; } class Derived2 extends Derived { baz: string; } @@ -26,10 +38,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { foo: Derived; // ok + ~~~ +!!! error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must provide an initializer with this override. bar: string; // error ~~~ !!! error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. + ~~~ +!!! error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must provide an initializer with this override. } class A2 { @@ -39,10 +55,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B2 extends A2 { 1: Derived; // ok + ~ +!!! error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must provide an initializer with this override. 2: string; // error ~ !!! error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. + ~ +!!! error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must provide an initializer with this override. } class A3 { @@ -52,10 +72,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A3 { '1': Derived; // ok + ~~~ +!!! error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must provide an initializer with this override. '2.0': string; // error ~~~~~ !!! error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. + ~~~~~ +!!! error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must provide an initializer with this override. } module TwoLevels { @@ -66,10 +90,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { foo: Derived2; // ok + ~~~ +!!! error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must provide an initializer with this override. bar: string; // error ~~~ !!! error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. + ~~~ +!!! error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must provide an initializer with this override. } class A2 { @@ -79,10 +107,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B2 extends A2 { 1: Derived2; // ok + ~ +!!! error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must provide an initializer with this override. 2: string; // error ~ !!! error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. + ~ +!!! error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must provide an initializer with this override. } class A3 { @@ -92,9 +124,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A3 { '1': Derived2; // ok + ~~~ +!!! error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must provide an initializer with this override. '2.0': string; // error ~~~~~ !!! error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. + ~~~~~ +!!! error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must provide an initializer with this override. } } \ No newline at end of file diff --git a/tests/baselines/reference/tsxGenericAttributesType5.errors.txt b/tests/baselines/reference/tsxGenericAttributesType5.errors.txt new file mode 100644 index 0000000000000..42f10f91f7fa2 --- /dev/null +++ b/tests/baselines/reference/tsxGenericAttributesType5.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must provide an initializer with this override. + + +==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== + import React = require('react'); + + class B1 extends React.Component { + render() { + return
hi
; + } + } + class B extends React.Component { + props: U; + ~~~~~ +!!! error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must provide an initializer with this override. + render() { + return ; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/tsxGenericAttributesType6.errors.txt b/tests/baselines/reference/tsxGenericAttributesType6.errors.txt new file mode 100644 index 0000000000000..af26e4a25b933 --- /dev/null +++ b/tests/baselines/reference/tsxGenericAttributesType6.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must provide an initializer with this override. + + +==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== + import React = require('react'); + + class B1 extends React.Component { + render() { + return
hi
; + } + } + class B extends React.Component { + props: U; + ~~~~~ +!!! error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must provide an initializer with this override. + render() { + return ; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt b/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt new file mode 100644 index 0000000000000..2bba64a42e2c6 --- /dev/null +++ b/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt @@ -0,0 +1,190 @@ +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(8,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D0' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(12,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'DA' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(16,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(20,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1A' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(25,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(29,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2A' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(34,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(38,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3A' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(43,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(47,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(52,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(56,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(61,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(68,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(73,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D10' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(78,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D11' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(86,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D12' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(95,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D13' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(100,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D14' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(105,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D15' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(114,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D16' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(119,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D17' must provide an initializer with this override. + + +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts (22 errors) ==== + // undefined is a subtype of every other types, no errors expected below + + class Base { + foo: typeof undefined; + } + + class D0 extends Base { + foo: any; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D0' must provide an initializer with this override. + } + + class DA extends Base { + foo: typeof undefined; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'DA' must provide an initializer with this override. + } + + class D1 extends Base { + foo: string; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. + } + + class D1A extends Base { + foo: String; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1A' must provide an initializer with this override. + } + + + class D2 extends Base { + foo: number; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. + } + + class D2A extends Base { + foo: Number; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2A' must provide an initializer with this override. + } + + + class D3 extends Base { + foo: boolean; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. + } + + class D3A extends Base { + foo: Boolean; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3A' must provide an initializer with this override. + } + + + class D4 extends Base { + foo: RegExp; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. + } + + class D5 extends Base { + foo: Date; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. + } + + + class D6 extends Base { + foo: number[]; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. + } + + class D7 extends Base { + foo: { bar: number }; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. + } + + + class D8 extends Base { + foo: D7; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. + } + + interface I1 { + bar: string; + } + class D9 extends Base { + foo: I1; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. + } + + + class D10 extends Base { + foo: () => number; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D10' must provide an initializer with this override. + } + + enum E { A } + class D11 extends Base { + foo: E; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D11' must provide an initializer with this override. + } + + function f() { } + module f { + export var bar = 1; + } + class D12 extends Base { + foo: typeof f; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D12' must provide an initializer with this override. + } + + + class c { baz: string } + module c { + export var bar = 1; + } + class D13 extends Base { + foo: typeof c; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D13' must provide an initializer with this override. + } + + + class D14 extends Base { + foo: T; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D14' must provide an initializer with this override. + } + + + class D15 extends Base { + foo: U; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D15' must provide an initializer with this override. + } + + //class D15 extends Base { + // foo: U; + //} + + + class D16 extends Base { + foo: Object; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D16' must provide an initializer with this override. + } + + + class D17 extends Base { + foo: {}; + ~~~ +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D17' must provide an initializer with this override. + } + \ No newline at end of file diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts new file mode 100644 index 0000000000000..8dbaed41b10de --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts @@ -0,0 +1,12 @@ +class A { + property = 'x'; +} +class B extends A { + property; // should be an error +} +class C { + p: string; +} +class D extends C { + p: 'hi'; // should also be an error? +} diff --git a/tests/cases/fourslash/incompatibleOverride.ts b/tests/cases/fourslash/incompatibleOverride.ts index 0b3dd3230154c..1ce0b07def189 100644 --- a/tests/cases/fourslash/incompatibleOverride.ts +++ b/tests/cases/fourslash/incompatibleOverride.ts @@ -3,8 +3,8 @@ // Squiggle for implementing a derived class with an incompatible override is too large //// class Foo { xyz: string; } -//// class Bar extends Foo { /*1*/xyz/*2*/: number; } -//// class Baz extends Foo { public /*3*/xyz/*4*/: number; } +//// class Bar extends Foo { /*1*/xyz/*2*/: number = 1; } +//// class Baz extends Foo { public /*3*/xyz/*4*/: number = 2; } //// class /*5*/Baf/*6*/ extends Foo { //// constructor(public xyz: number) { //// super(); @@ -14,4 +14,4 @@ verify.errorExistsBetweenMarkers('1', '2'); verify.errorExistsBetweenMarkers('3', '4'); verify.errorExistsBetweenMarkers('5', '6'); -verify.numberOfErrorsInCurrentFile(3); \ No newline at end of file +verify.numberOfErrorsInCurrentFile(3); diff --git a/tests/cases/fourslash/squiggleIllegalSubclassOverride.ts b/tests/cases/fourslash/squiggleIllegalSubclassOverride.ts index 955d461b9f13a..c97c6c75fcf5b 100644 --- a/tests/cases/fourslash/squiggleIllegalSubclassOverride.ts +++ b/tests/cases/fourslash/squiggleIllegalSubclassOverride.ts @@ -5,8 +5,8 @@ ////} //// ////class Bar extends Foo { -//// public /*1*/x/*2*/: string; +//// public /*1*/x/*2*/: string = 'hi'; ////} verify.errorExistsBetweenMarkers("1", "2"); -verify.numberOfErrorsInCurrentFile(1); \ No newline at end of file +verify.numberOfErrorsInCurrentFile(1); From c4f334a7be6f813fe8510685f5af64dddb0281f0 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 13 Sep 2019 15:49:16 -0700 Subject: [PATCH 03/44] Updates from design review + fix ancient bug 1. Don't error when overriding properties from interfaces. 2. Fix error when overriding methods with other things. This had no tests so I assume that the code was always dead and never worked. --- src/compiler/checker.ts | 19 ++++--- .../accessorsOverrideMethod.errors.txt | 13 +++++ .../reference/accessorsOverrideMethod.js | 16 ++++++ .../reference/accessorsOverrideMethod.symbols | 15 ++++++ .../reference/accessorsOverrideMethod.types | 17 +++++++ .../checkJsFiles_noErrorLocation.errors.txt | 25 ++++++++++ ...eMemberAccessorOverridingMethod.errors.txt | 20 ++++++++ ...eMemberPropertyOverridingMethod.errors.txt | 15 ++++++ .../reference/overrideInterfaceProperty.js | 31 ++++++++++++ .../overrideInterfaceProperty.symbols | 49 +++++++++++++++++++ .../reference/overrideInterfaceProperty.types | 36 ++++++++++++++ .../propertyOverridesMethod.errors.txt | 13 +++++ .../reference/propertyOverridesMethod.js | 19 +++++++ .../reference/propertyOverridesMethod.symbols | 15 ++++++ .../reference/propertyOverridesMethod.types | 17 +++++++ .../propertyOverridingPrototype.errors.txt | 16 ++++++ .../accessorsOverrideMethod.ts | 7 +++ .../overrideInterfaceProperty.ts | 18 +++++++ .../propertyOverridesMethod.ts | 7 +++ 19 files changed, 361 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/accessorsOverrideMethod.errors.txt create mode 100644 tests/baselines/reference/accessorsOverrideMethod.js create mode 100644 tests/baselines/reference/accessorsOverrideMethod.symbols create mode 100644 tests/baselines/reference/accessorsOverrideMethod.types create mode 100644 tests/baselines/reference/checkJsFiles_noErrorLocation.errors.txt create mode 100644 tests/baselines/reference/inheritanceMemberAccessorOverridingMethod.errors.txt create mode 100644 tests/baselines/reference/inheritanceMemberPropertyOverridingMethod.errors.txt create mode 100644 tests/baselines/reference/overrideInterfaceProperty.js create mode 100644 tests/baselines/reference/overrideInterfaceProperty.symbols create mode 100644 tests/baselines/reference/overrideInterfaceProperty.types create mode 100644 tests/baselines/reference/propertyOverridesMethod.errors.txt create mode 100644 tests/baselines/reference/propertyOverridesMethod.js create mode 100644 tests/baselines/reference/propertyOverridesMethod.symbols create mode 100644 tests/baselines/reference/propertyOverridesMethod.types create mode 100644 tests/baselines/reference/propertyOverridingPrototype.errors.txt create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideMethod.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/overrideInterfaceProperty.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b6d7723c6cab1..e38b631df4f9c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29513,19 +29513,20 @@ namespace ts { // either base or derived property is private - not override, skip it continue; } - if (isPrototypeProperty(base)) { - // method is overridden with method - correct case - continue; - } let errorMessage: DiagnosticMessage; const basePropertyFlags = base.flags & SymbolFlags.PropertyOrAccessor; const derivedPropertyFlags = derived.flags & SymbolFlags.PropertyOrAccessor; if (basePropertyFlags && derivedPropertyFlags) { // property/accessor is overridden with property/accessor - if (!(baseDeclarationFlags & ModifierFlags.Abstract) && basePropertyFlags !== SymbolFlags.Property && derivedPropertyFlags === SymbolFlags.Property) { + if (baseDeclarationFlags & ModifierFlags.Abstract + || getObjectFlags(getTargetType(baseType)) & ObjectFlags.Interface) { + // when the base property is abstract or from an interface, base/derived flags don't need to match + continue; + } + if (basePropertyFlags !== SymbolFlags.Property && derivedPropertyFlags === SymbolFlags.Property) { errorMessage = Diagnostics.Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_property; } - else if (!(baseDeclarationFlags & ModifierFlags.Abstract) && basePropertyFlags === SymbolFlags.Property && derivedPropertyFlags !== SymbolFlags.Property) { + else if (basePropertyFlags === SymbolFlags.Property && derivedPropertyFlags !== SymbolFlags.Property) { errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_but_extended_class_2_defines_it_as_instance_member_accessor; } else { @@ -29534,7 +29535,11 @@ namespace ts { } } else if (isPrototypeProperty(base)) { - if (derived.flags & SymbolFlags.Accessor) { + if (isPrototypeProperty(derived)) { + // method is overridden with method -- correct case + continue; + } + else if (derived.flags & SymbolFlags.Accessor) { errorMessage = Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor; } else { diff --git a/tests/baselines/reference/accessorsOverrideMethod.errors.txt b/tests/baselines/reference/accessorsOverrideMethod.errors.txt new file mode 100644 index 0000000000000..2ff047d49be36 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideMethod.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideMethod.ts(5,9): error TS2423: Class 'A' defines instance member function 'm', but extended class 'B' defines it as instance member accessor. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideMethod.ts (1 errors) ==== + class A { + m() { } + } + class B extends A { + get m() { return () => 1 } + ~ +!!! error TS2423: Class 'A' defines instance member function 'm', but extended class 'B' defines it as instance member accessor. + } + \ No newline at end of file diff --git a/tests/baselines/reference/accessorsOverrideMethod.js b/tests/baselines/reference/accessorsOverrideMethod.js new file mode 100644 index 0000000000000..0b7d62391909b --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideMethod.js @@ -0,0 +1,16 @@ +//// [accessorsOverrideMethod.ts] +class A { + m() { } +} +class B extends A { + get m() { return () => 1 } +} + + +//// [accessorsOverrideMethod.js] +class A { + m() { } +} +class B extends A { + get m() { return () => 1; } +} diff --git a/tests/baselines/reference/accessorsOverrideMethod.symbols b/tests/baselines/reference/accessorsOverrideMethod.symbols new file mode 100644 index 0000000000000..d447c137acff4 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideMethod.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideMethod.ts === +class A { +>A : Symbol(A, Decl(accessorsOverrideMethod.ts, 0, 0)) + + m() { } +>m : Symbol(A.m, Decl(accessorsOverrideMethod.ts, 0, 9)) +} +class B extends A { +>B : Symbol(B, Decl(accessorsOverrideMethod.ts, 2, 1)) +>A : Symbol(A, Decl(accessorsOverrideMethod.ts, 0, 0)) + + get m() { return () => 1 } +>m : Symbol(B.m, Decl(accessorsOverrideMethod.ts, 3, 19)) +} + diff --git a/tests/baselines/reference/accessorsOverrideMethod.types b/tests/baselines/reference/accessorsOverrideMethod.types new file mode 100644 index 0000000000000..a8781ae41a99b --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideMethod.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideMethod.ts === +class A { +>A : A + + m() { } +>m : () => void +} +class B extends A { +>B : B +>A : A + + get m() { return () => 1 } +>m : () => number +>() => 1 : () => number +>1 : 1 +} + diff --git a/tests/baselines/reference/checkJsFiles_noErrorLocation.errors.txt b/tests/baselines/reference/checkJsFiles_noErrorLocation.errors.txt new file mode 100644 index 0000000000000..d9104608284a9 --- /dev/null +++ b/tests/baselines/reference/checkJsFiles_noErrorLocation.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/a.js(14,10): error TS2424: Class 'A' defines instance member function 'foo', but extended class 'B' defines it as instance member property. + + +==== tests/cases/compiler/a.js (1 errors) ==== + // @ts-check + class A { + constructor() { + + } + foo() { + return 4; + } + } + + class B extends A { + constructor() { + super(); + this.foo = () => 3; + ~~~ +!!! error TS2424: Class 'A' defines instance member function 'foo', but extended class 'B' defines it as instance member property. + } + } + + const i = new B(); + i.foo(); \ No newline at end of file diff --git a/tests/baselines/reference/inheritanceMemberAccessorOverridingMethod.errors.txt b/tests/baselines/reference/inheritanceMemberAccessorOverridingMethod.errors.txt new file mode 100644 index 0000000000000..52ae20032e628 --- /dev/null +++ b/tests/baselines/reference/inheritanceMemberAccessorOverridingMethod.errors.txt @@ -0,0 +1,20 @@ +tests/cases/compiler/inheritanceMemberAccessorOverridingMethod.ts(8,9): error TS2423: Class 'a' defines instance member function 'x', but extended class 'b' defines it as instance member accessor. + + +==== tests/cases/compiler/inheritanceMemberAccessorOverridingMethod.ts (1 errors) ==== + class a { + x() { + return "20"; + } + } + + class b extends a { + get x() { + ~ +!!! error TS2423: Class 'a' defines instance member function 'x', but extended class 'b' defines it as instance member accessor. + return () => "20"; + } + set x(aValue) { + + } + } \ No newline at end of file diff --git a/tests/baselines/reference/inheritanceMemberPropertyOverridingMethod.errors.txt b/tests/baselines/reference/inheritanceMemberPropertyOverridingMethod.errors.txt new file mode 100644 index 0000000000000..2b56866b22b33 --- /dev/null +++ b/tests/baselines/reference/inheritanceMemberPropertyOverridingMethod.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/inheritanceMemberPropertyOverridingMethod.ts(8,5): error TS2424: Class 'a' defines instance member function 'x', but extended class 'b' defines it as instance member property. + + +==== tests/cases/compiler/inheritanceMemberPropertyOverridingMethod.ts (1 errors) ==== + class a { + x() { + return "20"; + } + } + + class b extends a { + x: () => string; + ~ +!!! error TS2424: Class 'a' defines instance member function 'x', but extended class 'b' defines it as instance member property. + } \ No newline at end of file diff --git a/tests/baselines/reference/overrideInterfaceProperty.js b/tests/baselines/reference/overrideInterfaceProperty.js new file mode 100644 index 0000000000000..0c1029b0c1129 --- /dev/null +++ b/tests/baselines/reference/overrideInterfaceProperty.js @@ -0,0 +1,31 @@ +//// [overrideInterfaceProperty.ts] +interface Mup { + readonly size: number; +} +interface MupConstructor { + new(): Mup; + new(entries?: readonly (readonly [K, V])[] | null): Mup; + readonly prototype: Mup; +} +declare var Mup: MupConstructor; + +class Sizz extends Mup { + // ok, because Mup is an interface + get size() { return 0 } +} +class Kasizz extends Mup { + size = -1 +} + + +//// [overrideInterfaceProperty.js] +class Sizz extends Mup { + // ok, because Mup is an interface + get size() { return 0; } +} +class Kasizz extends Mup { + constructor() { + super(...arguments); + this.size = -1; + } +} diff --git a/tests/baselines/reference/overrideInterfaceProperty.symbols b/tests/baselines/reference/overrideInterfaceProperty.symbols new file mode 100644 index 0000000000000..37f0f99a1070a --- /dev/null +++ b/tests/baselines/reference/overrideInterfaceProperty.symbols @@ -0,0 +1,49 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/overrideInterfaceProperty.ts === +interface Mup { +>Mup : Symbol(Mup, Decl(overrideInterfaceProperty.ts, 0, 0), Decl(overrideInterfaceProperty.ts, 8, 11)) +>K : Symbol(K, Decl(overrideInterfaceProperty.ts, 0, 14)) +>V : Symbol(V, Decl(overrideInterfaceProperty.ts, 0, 16)) + + readonly size: number; +>size : Symbol(Mup.size, Decl(overrideInterfaceProperty.ts, 0, 21)) +} +interface MupConstructor { +>MupConstructor : Symbol(MupConstructor, Decl(overrideInterfaceProperty.ts, 2, 1)) + + new(): Mup; +>Mup : Symbol(Mup, Decl(overrideInterfaceProperty.ts, 0, 0), Decl(overrideInterfaceProperty.ts, 8, 11)) + + new(entries?: readonly (readonly [K, V])[] | null): Mup; +>K : Symbol(K, Decl(overrideInterfaceProperty.ts, 5, 8)) +>V : Symbol(V, Decl(overrideInterfaceProperty.ts, 5, 10)) +>entries : Symbol(entries, Decl(overrideInterfaceProperty.ts, 5, 14)) +>K : Symbol(K, Decl(overrideInterfaceProperty.ts, 5, 8)) +>V : Symbol(V, Decl(overrideInterfaceProperty.ts, 5, 10)) +>Mup : Symbol(Mup, Decl(overrideInterfaceProperty.ts, 0, 0), Decl(overrideInterfaceProperty.ts, 8, 11)) +>K : Symbol(K, Decl(overrideInterfaceProperty.ts, 5, 8)) +>V : Symbol(V, Decl(overrideInterfaceProperty.ts, 5, 10)) + + readonly prototype: Mup; +>prototype : Symbol(MupConstructor.prototype, Decl(overrideInterfaceProperty.ts, 5, 72)) +>Mup : Symbol(Mup, Decl(overrideInterfaceProperty.ts, 0, 0), Decl(overrideInterfaceProperty.ts, 8, 11)) +} +declare var Mup: MupConstructor; +>Mup : Symbol(Mup, Decl(overrideInterfaceProperty.ts, 0, 0), Decl(overrideInterfaceProperty.ts, 8, 11)) +>MupConstructor : Symbol(MupConstructor, Decl(overrideInterfaceProperty.ts, 2, 1)) + +class Sizz extends Mup { +>Sizz : Symbol(Sizz, Decl(overrideInterfaceProperty.ts, 8, 32)) +>Mup : Symbol(Mup, Decl(overrideInterfaceProperty.ts, 0, 0), Decl(overrideInterfaceProperty.ts, 8, 11)) + + // ok, because Mup is an interface + get size() { return 0 } +>size : Symbol(Sizz.size, Decl(overrideInterfaceProperty.ts, 10, 24)) +} +class Kasizz extends Mup { +>Kasizz : Symbol(Kasizz, Decl(overrideInterfaceProperty.ts, 13, 1)) +>Mup : Symbol(Mup, Decl(overrideInterfaceProperty.ts, 0, 0), Decl(overrideInterfaceProperty.ts, 8, 11)) + + size = -1 +>size : Symbol(Kasizz.size, Decl(overrideInterfaceProperty.ts, 14, 26)) +} + diff --git a/tests/baselines/reference/overrideInterfaceProperty.types b/tests/baselines/reference/overrideInterfaceProperty.types new file mode 100644 index 0000000000000..69bf70e7358d5 --- /dev/null +++ b/tests/baselines/reference/overrideInterfaceProperty.types @@ -0,0 +1,36 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/overrideInterfaceProperty.ts === +interface Mup { + readonly size: number; +>size : number +} +interface MupConstructor { + new(): Mup; + new(entries?: readonly (readonly [K, V])[] | null): Mup; +>entries : readonly (readonly [K, V])[] +>null : null + + readonly prototype: Mup; +>prototype : Mup +} +declare var Mup: MupConstructor; +>Mup : MupConstructor + +class Sizz extends Mup { +>Sizz : Sizz +>Mup : Mup + + // ok, because Mup is an interface + get size() { return 0 } +>size : number +>0 : 0 +} +class Kasizz extends Mup { +>Kasizz : Kasizz +>Mup : Mup + + size = -1 +>size : number +>-1 : -1 +>1 : 1 +} + diff --git a/tests/baselines/reference/propertyOverridesMethod.errors.txt b/tests/baselines/reference/propertyOverridesMethod.errors.txt new file mode 100644 index 0000000000000..aaee2d48cf658 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesMethod.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts(5,5): error TS2424: Class 'A' defines instance member function 'm', but extended class 'B' defines it as instance member property. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts (1 errors) ==== + class A { + m() { } + } + class B extends A { + m = () => 1 + ~ +!!! error TS2424: Class 'A' defines instance member function 'm', but extended class 'B' defines it as instance member property. + } + \ No newline at end of file diff --git a/tests/baselines/reference/propertyOverridesMethod.js b/tests/baselines/reference/propertyOverridesMethod.js new file mode 100644 index 0000000000000..f51fb16653527 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesMethod.js @@ -0,0 +1,19 @@ +//// [propertyOverridesMethod.ts] +class A { + m() { } +} +class B extends A { + m = () => 1 +} + + +//// [propertyOverridesMethod.js] +class A { + m() { } +} +class B extends A { + constructor() { + super(...arguments); + this.m = () => 1; + } +} diff --git a/tests/baselines/reference/propertyOverridesMethod.symbols b/tests/baselines/reference/propertyOverridesMethod.symbols new file mode 100644 index 0000000000000..960aab6cb5612 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesMethod.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts === +class A { +>A : Symbol(A, Decl(propertyOverridesMethod.ts, 0, 0)) + + m() { } +>m : Symbol(A.m, Decl(propertyOverridesMethod.ts, 0, 9)) +} +class B extends A { +>B : Symbol(B, Decl(propertyOverridesMethod.ts, 2, 1)) +>A : Symbol(A, Decl(propertyOverridesMethod.ts, 0, 0)) + + m = () => 1 +>m : Symbol(B.m, Decl(propertyOverridesMethod.ts, 3, 19)) +} + diff --git a/tests/baselines/reference/propertyOverridesMethod.types b/tests/baselines/reference/propertyOverridesMethod.types new file mode 100644 index 0000000000000..13fcda01a853d --- /dev/null +++ b/tests/baselines/reference/propertyOverridesMethod.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts === +class A { +>A : A + + m() { } +>m : () => void +} +class B extends A { +>B : B +>A : A + + m = () => 1 +>m : () => number +>() => 1 : () => number +>1 : 1 +} + diff --git a/tests/baselines/reference/propertyOverridingPrototype.errors.txt b/tests/baselines/reference/propertyOverridingPrototype.errors.txt new file mode 100644 index 0000000000000..a585f7999f603 --- /dev/null +++ b/tests/baselines/reference/propertyOverridingPrototype.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/propertyOverridingPrototype.ts(7,5): error TS2424: Class 'Base' defines instance member function 'foo', but extended class 'Derived' defines it as instance member property. + + +==== tests/cases/compiler/propertyOverridingPrototype.ts (1 errors) ==== + class Base { + foo() { + } + } + + class Derived extends Base { + foo: () => { }; + ~~~ +!!! error TS2424: Class 'Base' defines instance member function 'foo', but extended class 'Derived' defines it as instance member property. + } + + \ No newline at end of file diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideMethod.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideMethod.ts new file mode 100644 index 0000000000000..c06dd5d91a970 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideMethod.ts @@ -0,0 +1,7 @@ +// @target: esnext +class A { + m() { } +} +class B extends A { + get m() { return () => 1 } +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/overrideInterfaceProperty.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/overrideInterfaceProperty.ts new file mode 100644 index 0000000000000..8b70357515cd2 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/overrideInterfaceProperty.ts @@ -0,0 +1,18 @@ +// @target: esnext +interface Mup { + readonly size: number; +} +interface MupConstructor { + new(): Mup; + new(entries?: readonly (readonly [K, V])[] | null): Mup; + readonly prototype: Mup; +} +declare var Mup: MupConstructor; + +class Sizz extends Mup { + // ok, because Mup is an interface + get size() { return 0 } +} +class Kasizz extends Mup { + size = -1 +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts new file mode 100644 index 0000000000000..9700f838663ec --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts @@ -0,0 +1,7 @@ +// @target: esnext +class A { + m() { } +} +class B extends A { + m = () => 1 +} From 70a15bdeeb432e77bc62ee9e2ffd378922da3c3f Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 16 Sep 2019 10:56:30 -0700 Subject: [PATCH 04/44] Need to add a couple of errors and squash one Will update after checking out other branch for a minute --- src/compiler/checker.ts | 11 ++++++-- ...ninitializedPropertyDeclaration.errors.txt | 12 ++++++-- ...derivedUninitializedPropertyDeclaration.js | 24 ++++++++++++++-- ...edUninitializedPropertyDeclaration.symbols | 28 ++++++++++++++----- ...ivedUninitializedPropertyDeclaration.types | 18 ++++++++++-- ...derivedUninitializedPropertyDeclaration.ts | 21 ++++++++++++-- 6 files changed, 95 insertions(+), 19 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 311b57d1c1701..84b34fcd84a57 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29477,7 +29477,6 @@ namespace ts { // type declaration, derived and base resolve to the same symbol even in the case of generic classes. if (derived === base) { // derived class inherits base without override/redeclaration - const derivedClassDecl = getClassLikeDeclarationOfSymbol(type.symbol)!; // It is an error to inherit an abstract member without implementing it or being declared abstract. @@ -29522,6 +29521,7 @@ namespace ts { if (derived.flags & SymbolFlags.Property && !(derived.flags & SymbolFlags.Transient) && !(baseDeclarationFlags & ModifierFlags.Abstract) + && !(derivedDeclarationFlags & ModifierFlags.Ambient) && !derived.declarations.some(d => d.flags & NodeFlags.Ambient) && derived.declarations.some(d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer)) { const errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_so_extended_class_2_must_provide_an_initializer_with_this_override; @@ -29529,6 +29529,11 @@ namespace ts { } continue; } + if (derivedDeclarationFlags & ModifiersFlags.Ambient) { + const errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_so_extended_class_2_must_provide_an_initializer_with_this_override; + error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type)); + continue; + } let errorMessage: DiagnosticMessage; if (isPrototypeProperty(base)) { @@ -32518,7 +32523,7 @@ namespace ts { else if (flags & ModifierFlags.Async) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } - else if (isClassLike(node.parent)) { + else if (isClassLike(node.parent) && !isPropertyDeclaration(node)) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); } else if (node.kind === SyntaxKind.Parameter) { @@ -33627,7 +33632,7 @@ namespace ts { } } - if (node.flags & NodeFlags.Ambient) { + if (node.flags & NodeFlags.Ambient || getModifierFlags(node) & ModifierFlags.Ambient) { checkAmbientInitializer(node); } diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt index 0dcdfbee74c89..7da5e3b68acce 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(5,5): error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must provide an initializer with this override. -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(11,5): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(14,5): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. ==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (2 errors) ==== @@ -7,16 +7,22 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP property = 'x'; } class B extends A { - property; // should be an error + property; // error ~~~~~~~~ !!! error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must provide an initializer with this override. } + class BD extends A { + declare property; // still has implicit any + } class C { p: string; } class D extends C { - p: 'hi'; // should also be an error? + p: 'hi'; // error ~ !!! error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. } + class DD extends C { + declare p: 'bye'; // ok + } \ No newline at end of file diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js index fbd2f1cdf8ecd..748c143279e34 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js @@ -3,13 +3,19 @@ class A { property = 'x'; } class B extends A { - property; // should be an error + property; // error +} +class BD extends A { + declare property; // still has implicit any } class C { p: string; } class D extends C { - p: 'hi'; // should also be an error? + p: 'hi'; // error +} +class DD extends C { + declare p: 'bye'; // ok } @@ -40,6 +46,13 @@ var B = /** @class */ (function (_super) { } return B; }(A)); +var BD = /** @class */ (function (_super) { + __extends(BD, _super); + function BD() { + return _super !== null && _super.apply(this, arguments) || this; + } + return BD; +}(A)); var C = /** @class */ (function () { function C() { } @@ -52,3 +65,10 @@ var D = /** @class */ (function (_super) { } return D; }(C)); +var DD = /** @class */ (function (_super) { + __extends(DD, _super); + function DD() { + return _super !== null && _super.apply(this, arguments) || this; + } + return DD; +}(C)); diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols index aad484889bbbd..f18c1602880d6 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols @@ -9,20 +9,34 @@ class B extends A { >B : Symbol(B, Decl(derivedUninitializedPropertyDeclaration.ts, 2, 1)) >A : Symbol(A, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 0)) - property; // should be an error + property; // error >property : Symbol(B.property, Decl(derivedUninitializedPropertyDeclaration.ts, 3, 19)) } +class BD extends A { +>BD : Symbol(BD, Decl(derivedUninitializedPropertyDeclaration.ts, 5, 1)) +>A : Symbol(A, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 0)) + + declare property; // still has implicit any +>property : Symbol(BD.property, Decl(derivedUninitializedPropertyDeclaration.ts, 6, 20)) +} class C { ->C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 5, 1)) +>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1)) p: string; ->p : Symbol(C.p, Decl(derivedUninitializedPropertyDeclaration.ts, 6, 9)) +>p : Symbol(C.p, Decl(derivedUninitializedPropertyDeclaration.ts, 9, 9)) } class D extends C { ->D : Symbol(D, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1)) ->C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 5, 1)) +>D : Symbol(D, Decl(derivedUninitializedPropertyDeclaration.ts, 11, 1)) +>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1)) + + p: 'hi'; // error +>p : Symbol(D.p, Decl(derivedUninitializedPropertyDeclaration.ts, 12, 19)) +} +class DD extends C { +>DD : Symbol(DD, Decl(derivedUninitializedPropertyDeclaration.ts, 14, 1)) +>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1)) - p: 'hi'; // should also be an error? ->p : Symbol(D.p, Decl(derivedUninitializedPropertyDeclaration.ts, 9, 19)) + declare p: 'bye'; // ok +>p : Symbol(DD.p, Decl(derivedUninitializedPropertyDeclaration.ts, 15, 20)) } diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types index 60d8502fb552d..693cc0dcd288e 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types @@ -10,7 +10,14 @@ class B extends A { >B : B >A : A - property; // should be an error + property; // error +>property : any +} +class BD extends A { +>BD : BD +>A : A + + declare property; // still has implicit any >property : any } class C { @@ -23,7 +30,14 @@ class D extends C { >D : D >C : C - p: 'hi'; // should also be an error? + p: 'hi'; // error >p : "hi" } +class DD extends C { +>DD : DD +>C : C + + declare p: 'bye'; // ok +>p : "bye" +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts index 8dbaed41b10de..8988576b4f3e5 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts @@ -1,12 +1,29 @@ +// @strict: true class A { property = 'x'; + m() { return 1 } } class B extends A { - property; // should be an error + property; // error } +class BD extends A { + declare property; // still has implicit any, but is implicitly initialised +} +class BDBang extends A { + declare property!; // still has implicit any, doesn't need !, but has it anyway +} +class BOther extends A { + declare m() { return 2 } // not allowed on methods + declare nonce; // only allowed when exists in base + declare property = 'y' // initialiser not allowed with declare +} + class C { p: string; } class D extends C { - p: 'hi'; // should also be an error? + p: 'hi'; // error +} +class DD extends C { + declare p: 'bye'; // ok } From feb0fb6dc4c3e4b93af9f07f1f57275f80fe61cc Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 16 Sep 2019 13:36:04 -0700 Subject: [PATCH 05/44] Everything works so far Need to test properties initialised in constructor --- src/compiler/checker.ts | 36 ++++++--- src/compiler/diagnosticMessages.json | 4 + ...lassExpressionPropertyModifiers.errors.txt | 11 ++- ...ninitializedPropertyDeclaration.errors.txt | 54 +++++++++++-- ...derivedUninitializedPropertyDeclaration.js | 58 +++++++++++++- ...edUninitializedPropertyDeclaration.symbols | 79 +++++++++++++++---- ...ivedUninitializedPropertyDeclaration.types | 58 +++++++++++++- ...illegalModifiersOnClassElements.errors.txt | 11 ++- ...rserMemberAccessorDeclaration11.errors.txt | 5 +- ...arserMemberFunctionDeclaration5.errors.txt | 5 +- ...arserMemberVariableDeclaration5.errors.txt | 6 +- ...derivedUninitializedPropertyDeclaration.ts | 21 ++++- 12 files changed, 297 insertions(+), 51 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 84b34fcd84a57..bf614c2068568 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29206,6 +29206,11 @@ namespace ts { } } + function getClassOrInterfaceDeclarationsOfSymbol(symbol: Symbol) { + return filter(symbol.declarations, (d: Declaration): d is ClassDeclaration | InterfaceDeclaration => + d.kind === SyntaxKind.ClassDeclaration || d.kind === SyntaxKind.InterfaceDeclaration); + } + function areTypeParametersIdentical(declarations: readonly (ClassDeclaration | InterfaceDeclaration)[], targetParameters: TypeParameter[]) { const maxTypeArgumentCount = length(targetParameters); const minTypeArgumentCount = getMinTypeArgumentCount(targetParameters); @@ -29299,6 +29304,7 @@ namespace ts { checkClassForStaticPropertyNameConflicts(node); } + let baseType: BaseType | undefined; const baseTypeNode = getEffectiveBaseTypeNode(node); if (baseTypeNode) { if (languageVersion < ScriptTarget.ES2015) { @@ -29312,7 +29318,7 @@ namespace ts { const baseTypes = getBaseTypes(type); if (baseTypes.length && produceDiagnostics) { - const baseType = baseTypes[0]; + baseType = baseTypes[0]; const baseConstructorType = getBaseConstructorTypeOfClass(type); const staticBaseType = getApparentType(baseConstructorType); checkBaseTypeAccessibility(staticBaseType, baseTypeNode); @@ -29352,6 +29358,7 @@ namespace ts { checkKindsOfPropertyMemberOverrides(type, baseType); } } + checkAmbientPropertyMemberOverrides(type, baseType); const implementedTypeNodes = getClassImplementsHeritageClauseElements(node); if (implementedTypeNodes) { @@ -29437,11 +29444,6 @@ namespace ts { return getCheckFlags(s) & CheckFlags.Instantiated ? (s).target! : s; } - function getClassOrInterfaceDeclarationsOfSymbol(symbol: Symbol) { - return filter(symbol.declarations, (d: Declaration): d is ClassDeclaration | InterfaceDeclaration => - d.kind === SyntaxKind.ClassDeclaration || d.kind === SyntaxKind.InterfaceDeclaration); - } - /** * TypeScript 1.0 spec (April 2014): 8.2.3 * A derived class inherits all members from its base class it doesn't override. @@ -29529,11 +29531,6 @@ namespace ts { } continue; } - if (derivedDeclarationFlags & ModifiersFlags.Ambient) { - const errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_so_extended_class_2_must_provide_an_initializer_with_this_override; - error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type)); - continue; - } let errorMessage: DiagnosticMessage; if (isPrototypeProperty(base)) { @@ -29556,6 +29553,20 @@ namespace ts { } } + function checkAmbientPropertyMemberOverrides(type: Type, baseType?: Type) { + for (const derivedProperty of getPropertiesOfType(type)) { + const derived = getTargetSymbol(derivedProperty); + if (derived.flags & SymbolFlags.Prototype) { + continue; + } + const base = baseType && getPropertyOfObjectType(baseType, derived.escapedName); + if (!base && getDeclarationModifierFlagsFromSymbol(derived) & ModifierFlags.Ambient) { + const errorMessage = Diagnostics.Ambient_property_declarations_must_override_a_property_in_a_base_class; + error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage); + } + } + } + function checkInheritedPropertiesAreIdentical(type: InterfaceType, typeNode: Node): boolean { const baseTypes = getBaseTypes(type); if (baseTypes.length < 2) { @@ -29599,6 +29610,9 @@ namespace ts { } const constructor = findConstructorDeclaration(node); for (const member of node.members) { + if (getModifierFlags(member) & ModifierFlags.Ambient) { + continue; + } if (isInstancePropertyWithoutInitializer(member)) { const propName = (member).name; if (isIdentifier(propName)) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0200bf4b1b3d4..db471650a5cec 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2208,6 +2208,10 @@ "category": "Error", "code": 2610 }, + "Ambient property declarations must override a property in a base class.": { + "category": "Error", + "code": 2611 + }, "Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": { "category": "Error", "code": 2649 diff --git a/tests/baselines/reference/classExpressionPropertyModifiers.errors.txt b/tests/baselines/reference/classExpressionPropertyModifiers.errors.txt index f4b3fed7e5458..94f55b688b19b 100644 --- a/tests/baselines/reference/classExpressionPropertyModifiers.errors.txt +++ b/tests/baselines/reference/classExpressionPropertyModifiers.errors.txt @@ -1,12 +1,15 @@ -tests/cases/compiler/classExpressionPropertyModifiers.ts(2,5): error TS1031: 'declare' modifier cannot appear on a class element. +tests/cases/compiler/classExpressionPropertyModifiers.ts(2,13): error TS2611: Ambient property declarations must override a property in a base class. +tests/cases/compiler/classExpressionPropertyModifiers.ts(2,36): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/compiler/classExpressionPropertyModifiers.ts(3,5): error TS1031: 'export' modifier cannot appear on a class element. -==== tests/cases/compiler/classExpressionPropertyModifiers.ts (2 errors) ==== +==== tests/cases/compiler/classExpressionPropertyModifiers.ts (3 errors) ==== const a = class Cat { declare [Symbol.toStringTag] = "uh"; - ~~~~~~~ -!!! error TS1031: 'declare' modifier cannot appear on a class element. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2611: Ambient property declarations must override a property in a base class. + ~~~~ +!!! error TS1039: Initializers are not allowed in ambient contexts. export foo = 1; ~~~~~~ !!! error TS1031: 'export' modifier cannot appear on a class element. diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt index 7da5e3b68acce..2ab7155769834 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt @@ -1,28 +1,72 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(5,5): error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must provide an initializer with this override. -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(14,5): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(6,5): error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must provide an initializer with this override. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(15,5): error TS1031: 'declare' modifier cannot appear on a class element. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(16,13): error TS2611: Ambient property declarations must override a property in a base class. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(17,24): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(20,13): error TS2611: Ambient property declarations must override a property in a base class. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(24,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(39,5): error TS2610: Class 'E' defines instance member property 'p1', so extended class 'F' must provide an initializer with this override. -==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (2 errors) ==== +==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (9 errors) ==== class A { property = 'x'; + m() { return 1 } } class B extends A { - property; // error + property: any; // error ~~~~~~~~ !!! error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must provide an initializer with this override. } class BD extends A { - declare property; // still has implicit any + declare property: any; // ok because it's implicitly initialised } + class BDBang extends A { + declare property!: any; // doesn't need !, but is still allowed + } + class BOther extends A { + declare m() { return 2 } // not allowed on methods + ~~~~~~~ +!!! error TS1031: 'declare' modifier cannot appear on a class element. + declare nonce: any; // only allowed when exists in base + ~~~~~ +!!! error TS2611: Ambient property declarations must override a property in a base class. + declare property = 'y' // initialiser not allowed with declare + ~~~ +!!! error TS1039: Initializers are not allowed in ambient contexts. + } + class U { + declare nonce: any; // ambient declaration only allowed when an override + ~~~~~ +!!! error TS2611: Ambient property declarations must override a property in a base class. + } + class C { p: string; + ~ +!!! error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. } class D extends C { p: 'hi'; // error ~ +!!! error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. + ~ !!! error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. } class DD extends C { declare p: 'bye'; // ok } + + + declare class E { + p1: string + p2: string + } + class F extends E { + p1!: 'z' + ~~ +!!! error TS2610: Class 'E' defines instance member property 'p1', so extended class 'F' must provide an initializer with this override. + declare p2: 'alpha' + } \ No newline at end of file diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js index 748c143279e34..53e0dbb87f2cc 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js @@ -1,13 +1,26 @@ //// [derivedUninitializedPropertyDeclaration.ts] class A { property = 'x'; + m() { return 1 } } class B extends A { - property; // error + property: any; // error } class BD extends A { - declare property; // still has implicit any + declare property: any; // ok because it's implicitly initialised } +class BDBang extends A { + declare property!: any; // doesn't need !, but is still allowed +} +class BOther extends A { + declare m() { return 2 } // not allowed on methods + declare nonce: any; // only allowed when exists in base + declare property = 'y' // initialiser not allowed with declare +} +class U { + declare nonce: any; // ambient declaration only allowed when an override +} + class C { p: string; } @@ -17,9 +30,20 @@ class D extends C { class DD extends C { declare p: 'bye'; // ok } + + +declare class E { + p1: string + p2: string +} +class F extends E { + p1!: 'z' + declare p2: 'alpha' +} //// [derivedUninitializedPropertyDeclaration.js] +"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || @@ -37,6 +61,7 @@ var A = /** @class */ (function () { function A() { this.property = 'x'; } + A.prototype.m = function () { return 1; }; return A; }()); var B = /** @class */ (function (_super) { @@ -53,6 +78,28 @@ var BD = /** @class */ (function (_super) { } return BD; }(A)); +var BDBang = /** @class */ (function (_super) { + __extends(BDBang, _super); + function BDBang() { + return _super !== null && _super.apply(this, arguments) || this; + } + return BDBang; +}(A)); +var BOther = /** @class */ (function (_super) { + __extends(BOther, _super); + function BOther() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.property = 'y'; // initialiser not allowed with declare + return _this; + } + BOther.prototype.m = function () { return 2; }; // not allowed on methods + return BOther; +}(A)); +var U = /** @class */ (function () { + function U() { + } + return U; +}()); var C = /** @class */ (function () { function C() { } @@ -72,3 +119,10 @@ var DD = /** @class */ (function (_super) { } return DD; }(C)); +var F = /** @class */ (function (_super) { + __extends(F, _super); + function F() { + return _super !== null && _super.apply(this, arguments) || this; + } + return F; +}(E)); diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols index f18c1602880d6..78cc94074200b 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols @@ -4,39 +4,90 @@ class A { property = 'x'; >property : Symbol(A.property, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 9)) + + m() { return 1 } +>m : Symbol(A.m, Decl(derivedUninitializedPropertyDeclaration.ts, 1, 19)) } class B extends A { ->B : Symbol(B, Decl(derivedUninitializedPropertyDeclaration.ts, 2, 1)) +>B : Symbol(B, Decl(derivedUninitializedPropertyDeclaration.ts, 3, 1)) >A : Symbol(A, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 0)) - property; // error ->property : Symbol(B.property, Decl(derivedUninitializedPropertyDeclaration.ts, 3, 19)) + property: any; // error +>property : Symbol(B.property, Decl(derivedUninitializedPropertyDeclaration.ts, 4, 19)) } class BD extends A { ->BD : Symbol(BD, Decl(derivedUninitializedPropertyDeclaration.ts, 5, 1)) +>BD : Symbol(BD, Decl(derivedUninitializedPropertyDeclaration.ts, 6, 1)) +>A : Symbol(A, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 0)) + + declare property: any; // ok because it's implicitly initialised +>property : Symbol(BD.property, Decl(derivedUninitializedPropertyDeclaration.ts, 7, 20)) +} +class BDBang extends A { +>BDBang : Symbol(BDBang, Decl(derivedUninitializedPropertyDeclaration.ts, 9, 1)) +>A : Symbol(A, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 0)) + + declare property!: any; // doesn't need !, but is still allowed +>property : Symbol(BDBang.property, Decl(derivedUninitializedPropertyDeclaration.ts, 10, 24)) +} +class BOther extends A { +>BOther : Symbol(BOther, Decl(derivedUninitializedPropertyDeclaration.ts, 12, 1)) >A : Symbol(A, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 0)) - declare property; // still has implicit any ->property : Symbol(BD.property, Decl(derivedUninitializedPropertyDeclaration.ts, 6, 20)) + declare m() { return 2 } // not allowed on methods +>m : Symbol(BOther.m, Decl(derivedUninitializedPropertyDeclaration.ts, 13, 24)) + + declare nonce: any; // only allowed when exists in base +>nonce : Symbol(BOther.nonce, Decl(derivedUninitializedPropertyDeclaration.ts, 14, 28)) + + declare property = 'y' // initialiser not allowed with declare +>property : Symbol(BOther.property, Decl(derivedUninitializedPropertyDeclaration.ts, 15, 23)) +} +class U { +>U : Symbol(U, Decl(derivedUninitializedPropertyDeclaration.ts, 17, 1)) + + declare nonce: any; // ambient declaration only allowed when an override +>nonce : Symbol(U.nonce, Decl(derivedUninitializedPropertyDeclaration.ts, 18, 9)) } + class C { ->C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1)) +>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 20, 1)) p: string; ->p : Symbol(C.p, Decl(derivedUninitializedPropertyDeclaration.ts, 9, 9)) +>p : Symbol(C.p, Decl(derivedUninitializedPropertyDeclaration.ts, 22, 9)) } class D extends C { ->D : Symbol(D, Decl(derivedUninitializedPropertyDeclaration.ts, 11, 1)) ->C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1)) +>D : Symbol(D, Decl(derivedUninitializedPropertyDeclaration.ts, 24, 1)) +>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 20, 1)) p: 'hi'; // error ->p : Symbol(D.p, Decl(derivedUninitializedPropertyDeclaration.ts, 12, 19)) +>p : Symbol(D.p, Decl(derivedUninitializedPropertyDeclaration.ts, 25, 19)) } class DD extends C { ->DD : Symbol(DD, Decl(derivedUninitializedPropertyDeclaration.ts, 14, 1)) ->C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 8, 1)) +>DD : Symbol(DD, Decl(derivedUninitializedPropertyDeclaration.ts, 27, 1)) +>C : Symbol(C, Decl(derivedUninitializedPropertyDeclaration.ts, 20, 1)) declare p: 'bye'; // ok ->p : Symbol(DD.p, Decl(derivedUninitializedPropertyDeclaration.ts, 15, 20)) +>p : Symbol(DD.p, Decl(derivedUninitializedPropertyDeclaration.ts, 28, 20)) +} + + +declare class E { +>E : Symbol(E, Decl(derivedUninitializedPropertyDeclaration.ts, 30, 1)) + + p1: string +>p1 : Symbol(E.p1, Decl(derivedUninitializedPropertyDeclaration.ts, 33, 17)) + + p2: string +>p2 : Symbol(E.p2, Decl(derivedUninitializedPropertyDeclaration.ts, 34, 14)) +} +class F extends E { +>F : Symbol(F, Decl(derivedUninitializedPropertyDeclaration.ts, 36, 1)) +>E : Symbol(E, Decl(derivedUninitializedPropertyDeclaration.ts, 30, 1)) + + p1!: 'z' +>p1 : Symbol(F.p1, Decl(derivedUninitializedPropertyDeclaration.ts, 37, 19)) + + declare p2: 'alpha' +>p2 : Symbol(F.p2, Decl(derivedUninitializedPropertyDeclaration.ts, 38, 12)) } diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types index 693cc0dcd288e..0c284a704aec5 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types @@ -5,21 +5,54 @@ class A { property = 'x'; >property : string >'x' : "x" + + m() { return 1 } +>m : () => number +>1 : 1 } class B extends A { >B : B >A : A - property; // error + property: any; // error >property : any } class BD extends A { >BD : BD >A : A - declare property; // still has implicit any + declare property: any; // ok because it's implicitly initialised +>property : any +} +class BDBang extends A { +>BDBang : BDBang +>A : A + + declare property!: any; // doesn't need !, but is still allowed >property : any } +class BOther extends A { +>BOther : BOther +>A : A + + declare m() { return 2 } // not allowed on methods +>m : () => number +>2 : 2 + + declare nonce: any; // only allowed when exists in base +>nonce : any + + declare property = 'y' // initialiser not allowed with declare +>property : string +>'y' : "y" +} +class U { +>U : U + + declare nonce: any; // ambient declaration only allowed when an override +>nonce : any +} + class C { >C : C @@ -41,3 +74,24 @@ class DD extends C { >p : "bye" } + +declare class E { +>E : E + + p1: string +>p1 : string + + p2: string +>p2 : string +} +class F extends E { +>F : F +>E : E + + p1!: 'z' +>p1 : "z" + + declare p2: 'alpha' +>p2 : "alpha" +} + diff --git a/tests/baselines/reference/illegalModifiersOnClassElements.errors.txt b/tests/baselines/reference/illegalModifiersOnClassElements.errors.txt index eb373ad2fae07..d8e6e10158f54 100644 --- a/tests/baselines/reference/illegalModifiersOnClassElements.errors.txt +++ b/tests/baselines/reference/illegalModifiersOnClassElements.errors.txt @@ -1,12 +1,15 @@ -tests/cases/compiler/illegalModifiersOnClassElements.ts(2,5): error TS1031: 'declare' modifier cannot appear on a class element. +tests/cases/compiler/illegalModifiersOnClassElements.ts(2,13): error TS2611: Ambient property declarations must override a property in a base class. +tests/cases/compiler/illegalModifiersOnClassElements.ts(2,19): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/compiler/illegalModifiersOnClassElements.ts(3,5): error TS1031: 'export' modifier cannot appear on a class element. -==== tests/cases/compiler/illegalModifiersOnClassElements.ts (2 errors) ==== +==== tests/cases/compiler/illegalModifiersOnClassElements.ts (3 errors) ==== class C { declare foo = 1; - ~~~~~~~ -!!! error TS1031: 'declare' modifier cannot appear on a class element. + ~~~ +!!! error TS2611: Ambient property declarations must override a property in a base class. + ~ +!!! error TS1039: Initializers are not allowed in ambient contexts. export bar = 1; ~~~~~~ !!! error TS1031: 'export' modifier cannot appear on a class element. diff --git a/tests/baselines/reference/parserMemberAccessorDeclaration11.errors.txt b/tests/baselines/reference/parserMemberAccessorDeclaration11.errors.txt index 3a04bfbbd0296..47a9e27f73e2d 100644 --- a/tests/baselines/reference/parserMemberAccessorDeclaration11.errors.txt +++ b/tests/baselines/reference/parserMemberAccessorDeclaration11.errors.txt @@ -1,12 +1,15 @@ tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration11.ts(2,5): error TS1031: 'declare' modifier cannot appear on a class element. tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration11.ts(2,17): error TS2378: A 'get' accessor must return a value. +tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration11.ts(2,17): error TS2611: Ambient property declarations must override a property in a base class. -==== tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration11.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration11.ts (3 errors) ==== class C { declare get Foo() { } ~~~~~~~ !!! error TS1031: 'declare' modifier cannot appear on a class element. ~~~ !!! error TS2378: A 'get' accessor must return a value. + ~~~ +!!! error TS2611: Ambient property declarations must override a property in a base class. } \ No newline at end of file diff --git a/tests/baselines/reference/parserMemberFunctionDeclaration5.errors.txt b/tests/baselines/reference/parserMemberFunctionDeclaration5.errors.txt index dc19cb0f8550a..25544ddeda5c4 100644 --- a/tests/baselines/reference/parserMemberFunctionDeclaration5.errors.txt +++ b/tests/baselines/reference/parserMemberFunctionDeclaration5.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration5.ts(2,5): error TS1031: 'declare' modifier cannot appear on a class element. +tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration5.ts(2,13): error TS2611: Ambient property declarations must override a property in a base class. -==== tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration5.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration5.ts (2 errors) ==== class C { declare Foo() { } ~~~~~~~ !!! error TS1031: 'declare' modifier cannot appear on a class element. + ~~~ +!!! error TS2611: Ambient property declarations must override a property in a base class. } \ No newline at end of file diff --git a/tests/baselines/reference/parserMemberVariableDeclaration5.errors.txt b/tests/baselines/reference/parserMemberVariableDeclaration5.errors.txt index 2b2ea9664ceb4..9ad6081cdf6d9 100644 --- a/tests/baselines/reference/parserMemberVariableDeclaration5.errors.txt +++ b/tests/baselines/reference/parserMemberVariableDeclaration5.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration5.ts(2,3): error TS1031: 'declare' modifier cannot appear on a class element. +tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration5.ts(2,11): error TS2611: Ambient property declarations must override a property in a base class. ==== tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration5.ts (1 errors) ==== class C { declare Foo; - ~~~~~~~ -!!! error TS1031: 'declare' modifier cannot appear on a class element. + ~~~ +!!! error TS2611: Ambient property declarations must override a property in a base class. } \ No newline at end of file diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts index 8988576b4f3e5..e57aa91ed6f35 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts @@ -4,19 +4,22 @@ class A { m() { return 1 } } class B extends A { - property; // error + property: any; // error } class BD extends A { - declare property; // still has implicit any, but is implicitly initialised + declare property: any; // ok because it's implicitly initialised } class BDBang extends A { - declare property!; // still has implicit any, doesn't need !, but has it anyway + declare property!: any; // doesn't need !, but is still allowed } class BOther extends A { declare m() { return 2 } // not allowed on methods - declare nonce; // only allowed when exists in base + declare nonce: any; // only allowed when exists in base declare property = 'y' // initialiser not allowed with declare } +class U { + declare nonce: any; // ambient declaration only allowed when an override +} class C { p: string; @@ -27,3 +30,13 @@ class D extends C { class DD extends C { declare p: 'bye'; // ok } + + +declare class E { + p1: string + p2: string +} +class F extends E { + p1!: 'z' + declare p2: 'alpha' +} From 868624293d156985e08eae49ab7a834b30c255ad Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 16 Sep 2019 15:06:53 -0700 Subject: [PATCH 06/44] Check for constructor initialisation --- src/compiler/checker.ts | 21 ++++++++---- ...ninitializedPropertyDeclaration.errors.txt | 13 ++++++++ ...derivedUninitializedPropertyDeclaration.js | 29 +++++++++++++++++ ...edUninitializedPropertyDeclaration.symbols | 29 +++++++++++++++++ ...ivedUninitializedPropertyDeclaration.types | 32 +++++++++++++++++++ ...derivedUninitializedPropertyDeclaration.ts | 13 ++++++++ ...erivedTypeIndexerWithGenericConstraints.ts | 2 +- 7 files changed, 132 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bf614c2068568..5c2c382c82759 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29520,14 +29520,23 @@ namespace ts { continue; } if (base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) { - if (derived.flags & SymbolFlags.Property + const uninitialized = find(derived.declarations, d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer); + if (uninitialized + && derived.flags & SymbolFlags.Property && !(derived.flags & SymbolFlags.Transient) && !(baseDeclarationFlags & ModifierFlags.Abstract) - && !(derivedDeclarationFlags & ModifierFlags.Ambient) - && !derived.declarations.some(d => d.flags & NodeFlags.Ambient) - && derived.declarations.some(d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer)) { - const errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_so_extended_class_2_must_provide_an_initializer_with_this_override; - error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type)); + && !(derivedDeclarationFlags & (ModifierFlags.Ambient | ModifierFlags.Abstract)) + && !derived.declarations.some(d => d.flags & NodeFlags.Ambient)) { + const constructor = findConstructorDeclaration(getClassLikeDeclarationOfSymbol(type.symbol)!); + const propName = (uninitialized as PropertyDeclaration).name; + if ((uninitialized as PropertyDeclaration).exclamationToken + || !constructor + || !isIdentifier(propName) + || !strictNullChecks + || !isPropertyInitializedInConstructor(propName, type, constructor)) { + const errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_so_extended_class_2_must_provide_an_initializer_with_this_override; + error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type)); + } } continue; } diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt index 2ab7155769834..bcdc550758420 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt @@ -69,4 +69,17 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP !!! error TS2610: Class 'E' defines instance member property 'p1', so extended class 'F' must provide an initializer with this override. declare p2: 'alpha' } + + class G extends E { + p1: 'z' + constructor() { + super() + this.p1 = 'z' + } + } + + abstract class H extends E { + abstract p1: 'a' | 'b' | 'c' + declare abstract p2: 'a' | 'b' | 'c' + } \ No newline at end of file diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js index 53e0dbb87f2cc..a07c27531cfd5 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js @@ -40,6 +40,19 @@ class F extends E { p1!: 'z' declare p2: 'alpha' } + +class G extends E { + p1: 'z' + constructor() { + super() + this.p1 = 'z' + } +} + +abstract class H extends E { + abstract p1: 'a' | 'b' | 'c' + declare abstract p2: 'a' | 'b' | 'c' +} //// [derivedUninitializedPropertyDeclaration.js] @@ -126,3 +139,19 @@ var F = /** @class */ (function (_super) { } return F; }(E)); +var G = /** @class */ (function (_super) { + __extends(G, _super); + function G() { + var _this = _super.call(this) || this; + _this.p1 = 'z'; + return _this; + } + return G; +}(E)); +var H = /** @class */ (function (_super) { + __extends(H, _super); + function H() { + return _super !== null && _super.apply(this, arguments) || this; + } + return H; +}(E)); diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols index 78cc94074200b..298022d3c2fd1 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols @@ -91,3 +91,32 @@ class F extends E { >p2 : Symbol(F.p2, Decl(derivedUninitializedPropertyDeclaration.ts, 38, 12)) } +class G extends E { +>G : Symbol(G, Decl(derivedUninitializedPropertyDeclaration.ts, 40, 1)) +>E : Symbol(E, Decl(derivedUninitializedPropertyDeclaration.ts, 30, 1)) + + p1: 'z' +>p1 : Symbol(G.p1, Decl(derivedUninitializedPropertyDeclaration.ts, 42, 19)) + + constructor() { + super() +>super : Symbol(E, Decl(derivedUninitializedPropertyDeclaration.ts, 30, 1)) + + this.p1 = 'z' +>this.p1 : Symbol(G.p1, Decl(derivedUninitializedPropertyDeclaration.ts, 42, 19)) +>this : Symbol(G, Decl(derivedUninitializedPropertyDeclaration.ts, 40, 1)) +>p1 : Symbol(G.p1, Decl(derivedUninitializedPropertyDeclaration.ts, 42, 19)) + } +} + +abstract class H extends E { +>H : Symbol(H, Decl(derivedUninitializedPropertyDeclaration.ts, 48, 1)) +>E : Symbol(E, Decl(derivedUninitializedPropertyDeclaration.ts, 30, 1)) + + abstract p1: 'a' | 'b' | 'c' +>p1 : Symbol(H.p1, Decl(derivedUninitializedPropertyDeclaration.ts, 50, 28)) + + declare abstract p2: 'a' | 'b' | 'c' +>p2 : Symbol(H.p2, Decl(derivedUninitializedPropertyDeclaration.ts, 51, 32)) +} + diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types index 0c284a704aec5..44d839492b5eb 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types @@ -95,3 +95,35 @@ class F extends E { >p2 : "alpha" } +class G extends E { +>G : G +>E : E + + p1: 'z' +>p1 : "z" + + constructor() { + super() +>super() : void +>super : typeof E + + this.p1 = 'z' +>this.p1 = 'z' : "z" +>this.p1 : "z" +>this : this +>p1 : "z" +>'z' : "z" + } +} + +abstract class H extends E { +>H : H +>E : E + + abstract p1: 'a' | 'b' | 'c' +>p1 : "a" | "b" | "c" + + declare abstract p2: 'a' | 'b' | 'c' +>p2 : "a" | "b" | "c" +} + diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts index e57aa91ed6f35..fa4fd86f01e85 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts @@ -40,3 +40,16 @@ class F extends E { p1!: 'z' declare p2: 'alpha' } + +class G extends E { + p1: 'z' + constructor() { + super() + this.p1 = 'z' + } +} + +abstract class H extends E { + abstract p1: 'a' | 'b' | 'c' + declare abstract p2: 'a' | 'b' | 'c' +} diff --git a/tests/cases/fourslash/derivedTypeIndexerWithGenericConstraints.ts b/tests/cases/fourslash/derivedTypeIndexerWithGenericConstraints.ts index 21489b5d8aa9b..82dfe9429e1b2 100644 --- a/tests/cases/fourslash/derivedTypeIndexerWithGenericConstraints.ts +++ b/tests/cases/fourslash/derivedTypeIndexerWithGenericConstraints.ts @@ -13,7 +13,7 @@ ////} ////class DbSet extends BaseCollection { // error -//// _itemsByKey: { [key: string]: TEntity; }; +//// _itemsByKey: { [key: string]: TEntity; } = {}; ////} ////var a: BaseCollection; From 2916c29204de34bb7dbbef93a18b18d9c4dd8ec4 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 16 Sep 2019 15:48:27 -0700 Subject: [PATCH 07/44] change error wording --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- .../apparentTypeSubtyping.errors.txt | 8 +- .../apparentTypeSupertype.errors.txt | 4 +- ...baseClassImprovedMismatchErrors.errors.txt | 4 +- .../classIsSubtypeOfBaseType.errors.txt | 8 +- ...declarationEmitProtectedMembers.errors.txt | 4 +- ...dClassOverridesProtectedMembers.errors.txt | 8 +- ...ClassOverridesProtectedMembers2.errors.txt | 8 +- ...ClassOverridesProtectedMembers3.errors.txt | 8 +- ...ClassOverridesProtectedMembers4.errors.txt | 8 +- ...ivedClassOverridesPublicMembers.errors.txt | 8 +- ...vedClassOverridesWithoutSubtype.errors.txt | 4 +- .../reference/derivedClassWithAny.errors.txt | 8 +- .../derivedGenericClassWithAny.errors.txt | 8 +- ...ninitializedPropertyDeclaration.errors.txt | 12 +-- .../genericPrototypeProperty2.errors.txt | 8 +- .../genericPrototypeProperty3.errors.txt | 8 +- ...aceExtendingClassWithProtecteds.errors.txt | 4 +- .../reference/inheritance.errors.txt | 4 +- ...emberPropertyOverridingAccessor.errors.txt | 4 +- ...emberPropertyOverridingProperty.errors.txt | 4 +- .../instanceSubtypeCheck2.errors.txt | 4 +- ...erfaceExtendsObjectIntersection.errors.txt | 28 +++--- ...ExtendsObjectIntersectionErrors.errors.txt | 20 ++--- .../reference/multipleInheritance.errors.txt | 4 +- .../mutuallyRecursiveInference.errors.txt | 8 +- .../reference/protectedMembers.errors.txt | 12 +-- .../baselines/reference/scopeTests.errors.txt | 4 +- .../subtypesOfTypeParameter.errors.txt | 4 +- ...OfTypeParameterWithConstraints4.errors.txt | 36 ++++---- ...rameterWithRecursiveConstraints.errors.txt | 72 +++++++-------- .../subtypingTransitivity.errors.txt | 8 +- .../subtypingWithObjectMembers.errors.txt | 48 +++++----- .../tsxGenericAttributesType5.errors.txt | 4 +- .../tsxGenericAttributesType6.errors.txt | 4 +- .../undefinedIsSubtypeOfEverything.errors.txt | 88 +++++++++---------- 37 files changed, 240 insertions(+), 240 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5c2c382c82759..1a26abaaa4abf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29534,7 +29534,7 @@ namespace ts { || !isIdentifier(propName) || !strictNullChecks || !isPropertyInitializedInConstructor(propName, type, constructor)) { - const errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_so_extended_class_2_must_provide_an_initializer_with_this_override; + const errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_so_extended_class_2_must_use_declare_to_make_it_ambient; error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type)); } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index db471650a5cec..b0f8ca8e24ed2 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2204,7 +2204,7 @@ "category": "Error", "code": 2609 }, - "Class '{0}' defines instance member property '{1}', so extended class '{2}' must provide an initializer with this override.": { + "Class '{0}' defines instance member property '{1}', so extended class '{2}' must use 'declare' to make it ambient.": { "category": "Error", "code": 2610 }, diff --git a/tests/baselines/reference/apparentTypeSubtyping.errors.txt b/tests/baselines/reference/apparentTypeSubtyping.errors.txt index 92ce3a37c3c35..e4088efe246a7 100644 --- a/tests/baselines/reference/apparentTypeSubtyping.errors.txt +++ b/tests/baselines/reference/apparentTypeSubtyping.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'Base'. Type 'String' is not assignable to type 'string'. 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. -tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(20,5): error TS2610: Class 'Base2' defines instance member property 'x', so extended class 'Derived2' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(20,5): error TS2610: Class 'Base2' defines instance member property 'x', so extended class 'Derived2' must use 'declare' to make it ambient. ==== tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts (3 errors) ==== @@ -21,7 +21,7 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtypi !!! error TS2416: Type 'String' is not assignable to type 'string'. !!! error TS2416: 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. ~ -!!! error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must use 'declare' to make it ambient. } class Base2 { @@ -33,5 +33,5 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtypi class Derived2 extends Base2 { // error because of the prototype's not matching, not because of the instance side x: U; ~ -!!! error TS2610: Class 'Base2' defines instance member property 'x', so extended class 'Derived2' must provide an initializer with this override. +!!! error TS2610: Class 'Base2' defines instance member property 'x', so extended class 'Derived2' must use 'declare' to make it ambient. } \ No newline at end of file diff --git a/tests/baselines/reference/apparentTypeSupertype.errors.txt b/tests/baselines/reference/apparentTypeSupertype.errors.txt index 23e4ee3cb3512..5d13848277882 100644 --- a/tests/baselines/reference/apparentTypeSupertype.errors.txt +++ b/tests/baselines/reference/apparentTypeSupertype.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSuperty Type 'U' is not assignable to type 'string'. Type 'String' is not assignable to type 'string'. 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. -tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts(10,5): error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts(10,5): error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must use 'declare' to make it ambient. ==== tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts (2 errors) ==== @@ -22,5 +22,5 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSuperty !!! error TS2416: Type 'String' is not assignable to type 'string'. !!! error TS2416: 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. ~ -!!! error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must use 'declare' to make it ambient. } \ No newline at end of file diff --git a/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt b/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt index 9a097955fde14..b654bfa37d072 100644 --- a/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt +++ b/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2416: Prop Types of property 'n' are incompatible. Type 'string | Derived' is not assignable to type 'string | Base'. Type 'Derived' is not assignable to type 'string | Base'. -tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2610: Class 'Base' defines instance member property 'n', so extended class 'Derived' must provide an initializer with this override. +tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2610: Class 'Base' defines instance member property 'n', so extended class 'Derived' must use 'declare' to make it ambient. tests/cases/compiler/baseClassImprovedMismatchErrors.ts(9,5): error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'. Type '() => string | number' is not assignable to type '() => number'. Type 'string | number' is not assignable to type 'number'. @@ -41,7 +41,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro !!! error TS2416: Type 'string | Derived' is not assignable to type 'string | Base'. !!! error TS2416: Type 'Derived' is not assignable to type 'string | Base'. ~ -!!! error TS2610: Class 'Base' defines instance member property 'n', so extended class 'Derived' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'n', so extended class 'Derived' must use 'declare' to make it ambient. fn() { ~~ !!! error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'. diff --git a/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt b/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt index f59f03763efa0..86370198f2c6e 100644 --- a/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt +++ b/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(6,5): error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived' must provide an initializer with this override. +tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(6,5): error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived' must use 'declare' to make it ambient. tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type 'Base<{ bar: string; }>'. Type '{ bar?: string; }' is not assignable to type '{ bar: string; }'. Property 'bar' is optional in type '{ bar?: string; }' but required in type '{ bar: string; }'. -tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived2' must provide an initializer with this override. +tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived2' must use 'declare' to make it ambient. ==== tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts (3 errors) ==== @@ -13,7 +13,7 @@ tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/cla class Derived extends Base<{ bar: string; }> { foo: { ~~~ -!!! error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived' must provide an initializer with this override. +!!! error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived' must use 'declare' to make it ambient. bar: string; baz: number; // ok } } @@ -25,7 +25,7 @@ tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/cla !!! error TS2416: Type '{ bar?: string; }' is not assignable to type '{ bar: string; }'. !!! error TS2416: Property 'bar' is optional in type '{ bar?: string; }' but required in type '{ bar: string; }'. ~~~ -!!! error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived2' must provide an initializer with this override. +!!! error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived2' must use 'declare' to make it ambient. bar?: string; // error } } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt b/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt index ee19970f04d14..803f761654333 100644 --- a/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt +++ b/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/declarationEmitProtectedMembers.ts(34,5): error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must provide an initializer with this override. +tests/cases/compiler/declarationEmitProtectedMembers.ts(34,5): error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must use 'declare' to make it ambient. ==== tests/cases/compiler/declarationEmitProtectedMembers.ts (1 errors) ==== @@ -37,7 +37,7 @@ tests/cases/compiler/declarationEmitProtectedMembers.ts(34,5): error TS2610: Cla class C3 extends C2 { x: number; ~ -!!! error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must provide an initializer with this override. +!!! error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must use 'declare' to make it ambient. static sx: number; f() { return super.f(); diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt index 645abc21fc0f1..cbf6d7f53c228 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts(21,15): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must provide an initializer with this override. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts(25,15): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts(21,15): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts(25,15): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must use 'declare' to make it ambient. ==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts (2 errors) ==== @@ -25,13 +25,13 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived extends Base { protected a: typeof y; ~ -!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must use 'declare' to make it ambient. protected b(a: typeof y) { } protected get c() { return y; } protected set c(v: typeof y) { } protected d: (a: typeof y) => void; ~ -!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must use 'declare' to make it ambient. protected static r: typeof y; protected static s(a: typeof y) { } diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt index 51677922dccda..b739769498fbf 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts(22,5): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must provide an initializer with this override. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts(26,5): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts(22,5): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts(26,5): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must use 'declare' to make it ambient. ==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts (2 errors) ==== @@ -26,13 +26,13 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived extends Base { a: typeof y; ~ -!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must use 'declare' to make it ambient. b(a: typeof y) { } get c() { return y; } set c(v: typeof y) { } d: (a: typeof y) => void; ~ -!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must use 'declare' to make it ambient. static r: typeof y; static s(a: typeof y) { } diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt index 6fdb020e366c4..4c74d97f040a9 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(22,7): error TS2415: Class 'Derived1' incorrectly extends base class 'Base'. Property 'a' is protected in type 'Derived1' but public in type 'Base'. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(23,15): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(23,15): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must use 'declare' to make it ambient. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(27,7): error TS2415: Class 'Derived2' incorrectly extends base class 'Base'. Property 'b' is protected in type 'Derived2' but public in type 'Base'. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(32,7): error TS2415: Class 'Derived3' incorrectly extends base class 'Base'. @@ -9,7 +9,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve Property 'c' is protected in type 'Derived4' but public in type 'Base'. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(42,7): error TS2415: Class 'Derived5' incorrectly extends base class 'Base'. Property 'd' is protected in type 'Derived5' but public in type 'Base'. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(43,15): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived5' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(43,15): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived5' must use 'declare' to make it ambient. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(47,7): error TS2417: Class static side 'typeof Derived6' incorrectly extends base class static side 'typeof Base'. Property 'r' is protected in type 'typeof Derived6' but public in type 'typeof Base'. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(52,7): error TS2417: Class static side 'typeof Derived7' incorrectly extends base class static side 'typeof Base'. @@ -50,7 +50,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS2415: Property 'a' is protected in type 'Derived1' but public in type 'Base'. protected a: typeof x; ~ -!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must use 'declare' to make it ambient. constructor(a: typeof x) { super(a); } } @@ -84,7 +84,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS2415: Property 'd' is protected in type 'Derived5' but public in type 'Base'. protected d: (a: typeof x) => void ; ~ -!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived5' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived5' must use 'declare' to make it ambient. constructor(a: typeof x) { super(a); } } diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt index 00eecd17d899a..9f401ea1e5668 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(9,12): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(9,12): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must use 'declare' to make it ambient. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(12,7): error TS2415: Class 'Derived2' incorrectly extends base class 'Derived1'. Property 'a' is protected in type 'Derived2' but public in type 'Derived1'. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(13,15): error TS2610: Class 'Derived1' defines instance member property 'a', so extended class 'Derived2' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(13,15): error TS2610: Class 'Derived1' defines instance member property 'a', so extended class 'Derived2' must use 'declare' to make it ambient. ==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts (3 errors) ==== @@ -15,7 +15,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived1 extends Base { public a: typeof x; ~ -!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must use 'declare' to make it ambient. } class Derived2 extends Derived1 { @@ -24,5 +24,5 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS2415: Property 'a' is protected in type 'Derived2' but public in type 'Derived1'. protected a: typeof x; // Error, parent was public ~ -!!! error TS2610: Class 'Derived1' defines instance member property 'a', so extended class 'Derived2' must provide an initializer with this override. +!!! error TS2610: Class 'Derived1' defines instance member property 'a', so extended class 'Derived2' must use 'declare' to make it ambient. } \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt b/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt index 19273eebe347d..145350ee604f9 100644 --- a/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt @@ -2,10 +2,10 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(13,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(14,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(21,5): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(21,5): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must use 'declare' to make it ambient. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(23,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(24,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(25,5): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(25,5): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must use 'declare' to make it ambient. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(29,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(30,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -41,7 +41,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived extends Base { a: typeof y; ~ -!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must use 'declare' to make it ambient. b(a: typeof y) { } get c() { return y; } ~ @@ -51,7 +51,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. d: (a: typeof y) => void; ~ -!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must use 'declare' to make it ambient. static r: typeof y; static s(a: typeof y) { } diff --git a/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt b/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt index 46e01f242e299..7a7633d461c6e 100644 --- a/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype.ts(8,5): error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype.ts(8,5): error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must use 'declare' to make it ambient. ==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype.ts (1 errors) ==== @@ -11,7 +11,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived extends Base { x: { ~ -!!! error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must use 'declare' to make it ambient. foo: any; } } diff --git a/tests/baselines/reference/derivedClassWithAny.errors.txt b/tests/baselines/reference/derivedClassWithAny.errors.txt index 37cb69218f432..c2037c529cfb0 100644 --- a/tests/baselines/reference/derivedClassWithAny.errors.txt +++ b/tests/baselines/reference/derivedClassWithAny.errors.txt @@ -1,9 +1,9 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(9,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(18,5): error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(18,5): error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must use 'declare' to make it ambient. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(19,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(27,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(37,5): error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(37,5): error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must use 'declare' to make it ambient. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(38,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(44,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(57,1): error TS2322: Type 'E' is not assignable to type 'C'. @@ -35,7 +35,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWit class D extends C { x: any; ~ -!!! error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must provide an initializer with this override. +!!! error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must use 'declare' to make it ambient. get X(): any { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -60,7 +60,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWit class E extends D { x: string; ~ -!!! error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must provide an initializer with this override. +!!! error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must use 'declare' to make it ambient. get X(): string{ return ''; } ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. diff --git a/tests/baselines/reference/derivedGenericClassWithAny.errors.txt b/tests/baselines/reference/derivedGenericClassWithAny.errors.txt index d7d4167c342e3..d5dc9585271d2 100644 --- a/tests/baselines/reference/derivedGenericClassWithAny.errors.txt +++ b/tests/baselines/reference/derivedGenericClassWithAny.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(10,5): error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(10,5): error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must use 'declare' to make it ambient. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(11,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(19,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(29,5): error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must provide an initializer with this override. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(29,5): error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must use 'declare' to make it ambient. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,18): error TS2322: Type '""' is not assignable to type 'T'. '""' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'. @@ -27,7 +27,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC class D extends C { x: any; ~ -!!! error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must provide an initializer with this override. +!!! error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must use 'declare' to make it ambient. get X(): any { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -52,7 +52,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC class E extends D { x: T; ~ -!!! error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must provide an initializer with this override. +!!! error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must use 'declare' to make it ambient. get X(): T { return ''; } // error ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt index bcdc550758420..aa9f4b955938d 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt @@ -1,12 +1,12 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(6,5): error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must provide an initializer with this override. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(6,5): error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must use 'declare' to make it ambient. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(15,5): error TS1031: 'declare' modifier cannot appear on a class element. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(16,13): error TS2611: Ambient property declarations must override a property in a base class. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(17,24): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(20,13): error TS2611: Ambient property declarations must override a property in a base class. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(24,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(39,5): error TS2610: Class 'E' defines instance member property 'p1', so extended class 'F' must provide an initializer with this override. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must use 'declare' to make it ambient. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(39,5): error TS2610: Class 'E' defines instance member property 'p1', so extended class 'F' must use 'declare' to make it ambient. ==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (9 errors) ==== @@ -17,7 +17,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP class B extends A { property: any; // error ~~~~~~~~ -!!! error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must provide an initializer with this override. +!!! error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must use 'declare' to make it ambient. } class BD extends A { declare property: any; // ok because it's implicitly initialised @@ -52,7 +52,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP ~ !!! error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. ~ -!!! error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. +!!! error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must use 'declare' to make it ambient. } class DD extends C { declare p: 'bye'; // ok @@ -66,7 +66,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP class F extends E { p1!: 'z' ~~ -!!! error TS2610: Class 'E' defines instance member property 'p1', so extended class 'F' must provide an initializer with this override. +!!! error TS2610: Class 'E' defines instance member property 'p1', so extended class 'F' must use 'declare' to make it ambient. declare p2: 'alpha' } diff --git a/tests/baselines/reference/genericPrototypeProperty2.errors.txt b/tests/baselines/reference/genericPrototypeProperty2.errors.txt index 212abb8d79552..117cc90b99fae 100644 --- a/tests/baselines/reference/genericPrototypeProperty2.errors.txt +++ b/tests/baselines/reference/genericPrototypeProperty2.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/genericPrototypeProperty2.ts(7,5): error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must provide an initializer with this override. -tests/cases/compiler/genericPrototypeProperty2.ts(14,5): error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must provide an initializer with this override. +tests/cases/compiler/genericPrototypeProperty2.ts(7,5): error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must use 'declare' to make it ambient. +tests/cases/compiler/genericPrototypeProperty2.ts(14,5): error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must use 'declare' to make it ambient. ==== tests/cases/compiler/genericPrototypeProperty2.ts (2 errors) ==== @@ -11,7 +11,7 @@ tests/cases/compiler/genericPrototypeProperty2.ts(14,5): error TS2610: Class 'Ba class MyEvent extends BaseEvent { target: T; ~~~~~~ -!!! error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must provide an initializer with this override. +!!! error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must use 'declare' to make it ambient. } class BaseEventWrapper { t: BaseEvent; @@ -20,5 +20,5 @@ tests/cases/compiler/genericPrototypeProperty2.ts(14,5): error TS2610: Class 'Ba class MyEventWrapper extends BaseEventWrapper { t: MyEvent; // any satisfies constraint and passes assignability check between 'target' properties ~ -!!! error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must provide an initializer with this override. +!!! error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must use 'declare' to make it ambient. } \ No newline at end of file diff --git a/tests/baselines/reference/genericPrototypeProperty3.errors.txt b/tests/baselines/reference/genericPrototypeProperty3.errors.txt index d13518f48135e..ca3398d6722d3 100644 --- a/tests/baselines/reference/genericPrototypeProperty3.errors.txt +++ b/tests/baselines/reference/genericPrototypeProperty3.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/genericPrototypeProperty3.ts(6,5): error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must provide an initializer with this override. -tests/cases/compiler/genericPrototypeProperty3.ts(13,5): error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must provide an initializer with this override. +tests/cases/compiler/genericPrototypeProperty3.ts(6,5): error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must use 'declare' to make it ambient. +tests/cases/compiler/genericPrototypeProperty3.ts(13,5): error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must use 'declare' to make it ambient. ==== tests/cases/compiler/genericPrototypeProperty3.ts (2 errors) ==== @@ -10,7 +10,7 @@ tests/cases/compiler/genericPrototypeProperty3.ts(13,5): error TS2610: Class 'Ba class MyEvent extends BaseEvent { // T is instantiated to any in the prototype, which is assignable to {} target: T; ~~~~~~ -!!! error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must provide an initializer with this override. +!!! error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must use 'declare' to make it ambient. } class BaseEventWrapper { t: BaseEvent; @@ -19,5 +19,5 @@ tests/cases/compiler/genericPrototypeProperty3.ts(13,5): error TS2610: Class 'Ba class MyEventWrapper extends BaseEventWrapper { t: MyEvent; ~ -!!! error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must provide an initializer with this override. +!!! error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must use 'declare' to make it ambient. } \ No newline at end of file diff --git a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt index b4ca2536ac5bd..98aee8dd231f7 100644 --- a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt +++ b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt @@ -10,7 +10,7 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInte Property 'y' is missing in type 'Bar5' but required in type 'I'. tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(29,7): error TS2420: Class 'Bar6' incorrectly implements interface 'I'. Property 'y' is protected in type 'Bar6' but public in type 'I'. -tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(38,5): error TS2610: Class 'Foo' defines instance member property 'x', so extended class 'Bar8' must provide an initializer with this override. +tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(38,5): error TS2610: Class 'Foo' defines instance member property 'x', so extended class 'Bar8' must use 'declare' to make it ambient. ==== tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts (7 errors) ==== @@ -73,7 +73,7 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInte class Bar8 extends Foo implements I { x: string; ~ -!!! error TS2610: Class 'Foo' defines instance member property 'x', so extended class 'Bar8' must provide an initializer with this override. +!!! error TS2610: Class 'Foo' defines instance member property 'x', so extended class 'Bar8' must use 'declare' to make it ambient. y: number; } \ No newline at end of file diff --git a/tests/baselines/reference/inheritance.errors.txt b/tests/baselines/reference/inheritance.errors.txt index 12994b1c87665..9b589f51a0b0e 100644 --- a/tests/baselines/reference/inheritance.errors.txt +++ b/tests/baselines/reference/inheritance.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/inheritance.ts(22,12): error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must provide an initializer with this override. +tests/cases/compiler/inheritance.ts(22,12): error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must use 'declare' to make it ambient. tests/cases/compiler/inheritance.ts(31,12): error TS2425: Class 'Good' defines instance member property 'f', but extended class 'Baad' defines it as instance member function. tests/cases/compiler/inheritance.ts(32,12): error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type 'Good'. Type '(n: number) => number' is not assignable to type '() => number'. @@ -28,7 +28,7 @@ tests/cases/compiler/inheritance.ts(32,12): error TS2416: Property 'g' in type ' class ND extends N { // any is assignable to number public y; ~ -!!! error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must provide an initializer with this override. +!!! error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must use 'declare' to make it ambient. } class Good { diff --git a/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt b/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt index 9491f47ff133b..18f70505450b4 100644 --- a/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt +++ b/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(6,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(12,5): error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must provide an initializer with this override. +tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(12,5): error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must use 'declare' to make it ambient. ==== tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts (3 errors) ==== @@ -21,5 +21,5 @@ tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(12,5): error class b extends a { x: () => string; ~ -!!! error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must provide an initializer with this override. +!!! error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must use 'declare' to make it ambient. } \ No newline at end of file diff --git a/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt b/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt index ed604c5260725..ee3da3f95a37d 100644 --- a/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt +++ b/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/inheritanceMemberPropertyOverridingProperty.ts(6,5): error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must provide an initializer with this override. +tests/cases/compiler/inheritanceMemberPropertyOverridingProperty.ts(6,5): error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must use 'declare' to make it ambient. ==== tests/cases/compiler/inheritanceMemberPropertyOverridingProperty.ts (1 errors) ==== @@ -9,5 +9,5 @@ tests/cases/compiler/inheritanceMemberPropertyOverridingProperty.ts(6,5): error class b extends a { x: () => string; ~ -!!! error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must provide an initializer with this override. +!!! error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must use 'declare' to make it ambient. } \ No newline at end of file diff --git a/tests/baselines/reference/instanceSubtypeCheck2.errors.txt b/tests/baselines/reference/instanceSubtypeCheck2.errors.txt index cd53a1304c246..4640ae46fc29f 100644 --- a/tests/baselines/reference/instanceSubtypeCheck2.errors.txt +++ b/tests/baselines/reference/instanceSubtypeCheck2.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2416: Property 'x' in type 'C2' is not assignable to the same property in base type 'C1'. Type 'string' is not assignable to type 'C2'. -tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2610: Class 'C1' defines instance member property 'x', so extended class 'C2' must provide an initializer with this override. +tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2610: Class 'C1' defines instance member property 'x', so extended class 'C2' must use 'declare' to make it ambient. ==== tests/cases/compiler/instanceSubtypeCheck2.ts (2 errors) ==== @@ -14,5 +14,5 @@ tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2610: Class 'C1' !!! error TS2416: Property 'x' in type 'C2' is not assignable to the same property in base type 'C1'. !!! error TS2416: Type 'string' is not assignable to type 'C2'. ~ -!!! error TS2610: Class 'C1' defines instance member property 'x', so extended class 'C2' must provide an initializer with this override. +!!! error TS2610: Class 'C1' defines instance member property 'x', so extended class 'C2' must use 'declare' to make it ambient. } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt b/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt index a200f3bffe1e4..4778cd7e0f2f2 100644 --- a/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt +++ b/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(20,38): error TS2610: Class 'I1' defines instance member property 'x', so extended class 'C1' must provide an initializer with this override. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(21,38): error TS2610: Class 'I2' defines instance member property 'x', so extended class 'C2' must provide an initializer with this override. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(22,38): error TS2610: Class 'I3' defines instance member property 'x', so extended class 'C3' must provide an initializer with this override. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(23,38): error TS2610: Class 'I4' defines instance member property 'x', so extended class 'C4' must provide an initializer with this override. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(24,38): error TS2610: Class 'I5' defines instance member property 'x', so extended class 'C5' must provide an initializer with this override. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(25,38): error TS2610: Class 'I6' defines instance member property 'x', so extended class 'C6' must provide an initializer with this override. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(26,38): error TS2610: Class 'I7' defines instance member property 'x', so extended class 'C7' must provide an initializer with this override. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(20,38): error TS2610: Class 'I1' defines instance member property 'x', so extended class 'C1' must use 'declare' to make it ambient. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(21,38): error TS2610: Class 'I2' defines instance member property 'x', so extended class 'C2' must use 'declare' to make it ambient. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(22,38): error TS2610: Class 'I3' defines instance member property 'x', so extended class 'C3' must use 'declare' to make it ambient. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(23,38): error TS2610: Class 'I4' defines instance member property 'x', so extended class 'C4' must use 'declare' to make it ambient. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(24,38): error TS2610: Class 'I5' defines instance member property 'x', so extended class 'C5' must use 'declare' to make it ambient. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(25,38): error TS2610: Class 'I6' defines instance member property 'x', so extended class 'C6' must use 'declare' to make it ambient. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(26,38): error TS2610: Class 'I7' defines instance member property 'x', so extended class 'C7' must use 'declare' to make it ambient. ==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts (7 errors) ==== @@ -29,25 +29,25 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI class C1 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I1' defines instance member property 'x', so extended class 'C1' must provide an initializer with this override. +!!! error TS2610: Class 'I1' defines instance member property 'x', so extended class 'C1' must use 'declare' to make it ambient. class C2 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I2' defines instance member property 'x', so extended class 'C2' must provide an initializer with this override. +!!! error TS2610: Class 'I2' defines instance member property 'x', so extended class 'C2' must use 'declare' to make it ambient. class C3 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I3' defines instance member property 'x', so extended class 'C3' must provide an initializer with this override. +!!! error TS2610: Class 'I3' defines instance member property 'x', so extended class 'C3' must use 'declare' to make it ambient. class C4 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I4' defines instance member property 'x', so extended class 'C4' must provide an initializer with this override. +!!! error TS2610: Class 'I4' defines instance member property 'x', so extended class 'C4' must use 'declare' to make it ambient. class C5 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I5' defines instance member property 'x', so extended class 'C5' must provide an initializer with this override. +!!! error TS2610: Class 'I5' defines instance member property 'x', so extended class 'C5' must use 'declare' to make it ambient. class C6 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I6' defines instance member property 'x', so extended class 'C6' must provide an initializer with this override. +!!! error TS2610: Class 'I6' defines instance member property 'x', so extended class 'C6' must use 'declare' to make it ambient. class C7 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I7' defines instance member property 'x', so extended class 'C7' must provide an initializer with this override. +!!! error TS2610: Class 'I7' defines instance member property 'x', so extended class 'C7' must use 'declare' to make it ambient. declare function fx(x: string): string; declare class CX { a: number } diff --git a/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt b/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt index 9acd77695b67d..0f4a62fd786ac 100644 --- a/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt +++ b/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt @@ -16,19 +16,19 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI Type 'number' is not assignable to type 'string'. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(16,38): error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'T1'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(16,38): error TS2610: Class 'T1' defines instance member property 'a', so extended class 'C1' must provide an initializer with this override. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(16,38): error TS2610: Class 'T1' defines instance member property 'a', so extended class 'C1' must use 'declare' to make it ambient. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'T2'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2610: Class 'T2' defines instance member property 'b', so extended class 'C2' must provide an initializer with this override. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2610: Class 'T2' defines instance member property 'b', so extended class 'C2' must use 'declare' to make it ambient. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2610: Class 'number[]' defines instance member property 'length', so extended class 'C3' must provide an initializer with this override. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2610: Class 'number[]' defines instance member property 'length', so extended class 'C3' must use 'declare' to make it ambient. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2610: Class '[string, number]' defines instance member property '0', so extended class 'C4' must provide an initializer with this override. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2610: Class '[string, number]' defines instance member property '0', so extended class 'C4' must use 'declare' to make it ambient. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(20,38): error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'T5'. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(20,38): error TS2610: Class 'T5' defines instance member property 'c', so extended class 'C5' must provide an initializer with this override. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(20,38): error TS2610: Class 'T5' defines instance member property 'c', so extended class 'C5' must use 'declare' to make it ambient. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(30,11): error TS2430: Interface 'I10' incorrectly extends interface 'typeof CX'. Types of property 'a' are incompatible. Type 'number' is not assignable to type 'string'. @@ -102,31 +102,31 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI !!! error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'T1'. !!! error TS2416: Type 'string' is not assignable to type 'number'. ~ -!!! error TS2610: Class 'T1' defines instance member property 'a', so extended class 'C1' must provide an initializer with this override. +!!! error TS2610: Class 'T1' defines instance member property 'a', so extended class 'C1' must use 'declare' to make it ambient. class C2 extends Constructor() { b: string } ~ !!! error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'T2'. !!! error TS2416: Type 'string' is not assignable to type 'number'. ~ -!!! error TS2610: Class 'T2' defines instance member property 'b', so extended class 'C2' must provide an initializer with this override. +!!! error TS2610: Class 'T2' defines instance member property 'b', so extended class 'C2' must use 'declare' to make it ambient. class C3 extends Constructor() { length: string } ~~~~~~ !!! error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'. !!! error TS2416: Type 'string' is not assignable to type 'number'. ~~~~~~ -!!! error TS2610: Class 'number[]' defines instance member property 'length', so extended class 'C3' must provide an initializer with this override. +!!! error TS2610: Class 'number[]' defines instance member property 'length', so extended class 'C3' must use 'declare' to make it ambient. class C4 extends Constructor() { 0: number } ~ !!! error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'. !!! error TS2416: Type 'number' is not assignable to type 'string'. ~ -!!! error TS2610: Class '[string, number]' defines instance member property '0', so extended class 'C4' must provide an initializer with this override. +!!! error TS2610: Class '[string, number]' defines instance member property '0', so extended class 'C4' must use 'declare' to make it ambient. class C5 extends Constructor() { c: number } ~ !!! error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'T5'. !!! error TS2416: Type 'number' is not assignable to type 'string'. ~ -!!! error TS2610: Class 'T5' defines instance member property 'c', so extended class 'C5' must provide an initializer with this override. +!!! error TS2610: Class 'T5' defines instance member property 'c', so extended class 'C5' must use 'declare' to make it ambient. declare class CX { static a: string } declare enum EX { A, B, C } diff --git a/tests/baselines/reference/multipleInheritance.errors.txt b/tests/baselines/reference/multipleInheritance.errors.txt index b3e6a02c72942..0f4e79738e9e6 100644 --- a/tests/baselines/reference/multipleInheritance.errors.txt +++ b/tests/baselines/reference/multipleInheritance.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/multipleInheritance.ts(9,21): error TS1174: Classes can only extend a single class. tests/cases/compiler/multipleInheritance.ts(18,21): error TS1174: Classes can only extend a single class. -tests/cases/compiler/multipleInheritance.ts(26,12): error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must provide an initializer with this override. +tests/cases/compiler/multipleInheritance.ts(26,12): error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must use 'declare' to make it ambient. tests/cases/compiler/multipleInheritance.ts(35,12): error TS2425: Class 'Good' defines instance member property 'f', but extended class 'Baad' defines it as instance member function. tests/cases/compiler/multipleInheritance.ts(36,12): error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type 'Good'. Type '(n: number) => number' is not assignable to type '() => number'. @@ -38,7 +38,7 @@ tests/cases/compiler/multipleInheritance.ts(36,12): error TS2416: Property 'g' i class ND extends N { // any is assignable to number public y; ~ -!!! error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must provide an initializer with this override. +!!! error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must use 'declare' to make it ambient. } class Good { diff --git a/tests/baselines/reference/mutuallyRecursiveInference.errors.txt b/tests/baselines/reference/mutuallyRecursiveInference.errors.txt index 9f5b1852c7c47..f6b5d58430f4b 100644 --- a/tests/baselines/reference/mutuallyRecursiveInference.errors.txt +++ b/tests/baselines/reference/mutuallyRecursiveInference.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/mutuallyRecursiveInference.ts(9,5): error TS2610: Class 'L' defines instance member property 'a', so extended class 'X' must provide an initializer with this override. -tests/cases/compiler/mutuallyRecursiveInference.ts(10,5): error TS2610: Class 'L' defines instance member property 'b', so extended class 'X' must provide an initializer with this override. +tests/cases/compiler/mutuallyRecursiveInference.ts(9,5): error TS2610: Class 'L' defines instance member property 'a', so extended class 'X' must use 'declare' to make it ambient. +tests/cases/compiler/mutuallyRecursiveInference.ts(10,5): error TS2610: Class 'L' defines instance member property 'b', so extended class 'X' must use 'declare' to make it ambient. ==== tests/cases/compiler/mutuallyRecursiveInference.ts (2 errors) ==== @@ -13,10 +13,10 @@ tests/cases/compiler/mutuallyRecursiveInference.ts(10,5): error TS2610: Class 'L class X extends L { a: 'a' | 'b' ~ -!!! error TS2610: Class 'L' defines instance member property 'a', so extended class 'X' must provide an initializer with this override. +!!! error TS2610: Class 'L' defines instance member property 'a', so extended class 'X' must use 'declare' to make it ambient. b: number ~ -!!! error TS2610: Class 'L' defines instance member property 'b', so extended class 'X' must provide an initializer with this override. +!!! error TS2610: Class 'L' defines instance member property 'b', so extended class 'X' must use 'declare' to make it ambient. m2() { this.a } diff --git a/tests/baselines/reference/protectedMembers.errors.txt b/tests/baselines/reference/protectedMembers.errors.txt index 5a1fc2bfeb351..da2be41e9488e 100644 --- a/tests/baselines/reference/protectedMembers.errors.txt +++ b/tests/baselines/reference/protectedMembers.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/protectedMembers.ts(25,5): error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must provide an initializer with this override. +tests/cases/compiler/protectedMembers.ts(25,5): error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must use 'declare' to make it ambient. tests/cases/compiler/protectedMembers.ts(40,4): error TS2445: Property 'x' is protected and only accessible within class 'C1' and its subclasses. tests/cases/compiler/protectedMembers.ts(41,4): error TS2445: Property 'f' is protected and only accessible within class 'C1' and its subclasses. tests/cases/compiler/protectedMembers.ts(42,4): error TS2445: Property 'sx' is protected and only accessible within class 'C1' and its subclasses. @@ -13,10 +13,10 @@ tests/cases/compiler/protectedMembers.ts(97,1): error TS2322: Type 'B1' is not a Property 'x' is protected but type 'B1' is not a class derived from 'A1'. tests/cases/compiler/protectedMembers.ts(98,1): error TS2322: Type 'A1' is not assignable to type 'B1'. Property 'x' is protected in type 'A1' but public in type 'B1'. -tests/cases/compiler/protectedMembers.ts(104,5): error TS2610: Class 'A2' defines instance member property 'x', so extended class 'B2' must provide an initializer with this override. +tests/cases/compiler/protectedMembers.ts(104,5): error TS2610: Class 'A2' defines instance member property 'x', so extended class 'B2' must use 'declare' to make it ambient. tests/cases/compiler/protectedMembers.ts(111,7): error TS2415: Class 'B3' incorrectly extends base class 'A3'. Property 'x' is protected in type 'B3' but public in type 'A3'. -tests/cases/compiler/protectedMembers.ts(112,15): error TS2610: Class 'A3' defines instance member property 'x', so extended class 'B3' must provide an initializer with this override. +tests/cases/compiler/protectedMembers.ts(112,15): error TS2610: Class 'A3' defines instance member property 'x', so extended class 'B3' must use 'declare' to make it ambient. ==== tests/cases/compiler/protectedMembers.ts (16 errors) ==== @@ -46,7 +46,7 @@ tests/cases/compiler/protectedMembers.ts(112,15): error TS2610: Class 'A3' defin class C3 extends C2 { x: number; ~ -!!! error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must provide an initializer with this override. +!!! error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must use 'declare' to make it ambient. static sx: number; f() { return super.f(); @@ -153,7 +153,7 @@ tests/cases/compiler/protectedMembers.ts(112,15): error TS2610: Class 'A3' defin class B2 extends A2 { x; ~ -!!! error TS2610: Class 'A2' defines instance member property 'x', so extended class 'B2' must provide an initializer with this override. +!!! error TS2610: Class 'A2' defines instance member property 'x', so extended class 'B2' must use 'declare' to make it ambient. } class A3 { @@ -166,7 +166,7 @@ tests/cases/compiler/protectedMembers.ts(112,15): error TS2610: Class 'A3' defin !!! error TS2415: Property 'x' is protected in type 'B3' but public in type 'A3'. protected x; ~ -!!! error TS2610: Class 'A3' defines instance member property 'x', so extended class 'B3' must provide an initializer with this override. +!!! error TS2610: Class 'A3' defines instance member property 'x', so extended class 'B3' must use 'declare' to make it ambient. } \ No newline at end of file diff --git a/tests/baselines/reference/scopeTests.errors.txt b/tests/baselines/reference/scopeTests.errors.txt index 2457ba3912a61..cfafac1e1cada 100644 --- a/tests/baselines/reference/scopeTests.errors.txt +++ b/tests/baselines/reference/scopeTests.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/scopeTests.ts(2,7): error TS2415: Class 'D' incorrectly extends base class 'C'. Property 'v' is private in type 'C' but not in type 'D'. -tests/cases/compiler/scopeTests.ts(4,10): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. +tests/cases/compiler/scopeTests.ts(4,10): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must use 'declare' to make it ambient. ==== tests/cases/compiler/scopeTests.ts (2 errors) ==== @@ -12,7 +12,7 @@ tests/cases/compiler/scopeTests.ts(4,10): error TS2610: Class 'C' defines instan public v: number; public p: number ~ -!!! error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must provide an initializer with this override. +!!! error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must use 'declare' to make it ambient. constructor() { super() this.v = 1; diff --git a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt index 4541037baae14..44c8e7ba6a51d 100644 --- a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(8,5): error TS2416: Property 'foo' in type 'D1' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(8,5): error TS2610: Class 'C3' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(8,5): error TS2610: Class 'C3' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts (2 errors) ==== @@ -18,7 +18,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. ~~~ -!!! error TS2610: Class 'C3' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. +!!! error TS2610: Class 'C3' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. } function f1(x: T, y: U) { diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt index e952bf31059ee..d1b6e7efe3aef 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt @@ -1,33 +1,33 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(37,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(42,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(37,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(42,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'Foo'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(52,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(52,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2416: Property 'foo' in type 'D5' is not assignable to the same property in base type 'B1'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. Type 'Foo' is not assignable to type 'T'. 'Foo' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'B1'. Type 'T' is not assignable to type 'U'. 'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. Type 'Foo' is not assignable to type 'U'. 'Foo' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(72,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(72,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2416: Property 'foo' in type 'D9' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts (19 errors) ==== @@ -69,14 +69,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: Foo; foo: T; // ok ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. } class D2 extends B1 { [x: string]: Foo; foo: U; // ok ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. } class D3 extends B1 { @@ -88,14 +88,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'Foo'. ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. } class D4 extends B1 { [x: string]: T; foo: T; // ok ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. } class D5 extends B1 { @@ -110,7 +110,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'T'. !!! error TS2416: 'Foo' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. } class D6 extends B1 { @@ -122,7 +122,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'T'. ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. } class D7 extends B1 { @@ -137,14 +137,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'U'. !!! error TS2416: 'Foo' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. } class D8 extends B1 { [x: string]: U; foo: U; // ok ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. } class D9 extends B1 { @@ -156,5 +156,5 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D9' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'U'. ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. +!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. } \ No newline at end of file diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt index 4247c68cb876a..5ef5c6aa184ed 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt @@ -1,81 +1,81 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(63,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(63,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2416: Property 'foo' in type 'D2' is not assignable to the same property in base type 'Base'. Type 'U' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base'. Type 'V' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2416: Property 'foo' in type 'D4' is not assignable to the same property in base type 'Base'. Type 'T' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(83,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(83,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base'. Type 'V' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base'. Type 'T' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base'. Type 'U' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(103,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(103,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(115,9): error TS2416: Property 'foo' in type 'D1' is not assignable to the same property in base type 'Base2'. Type 'T' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'U' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(115,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(115,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(120,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(120,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(120,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base2'. Type 'V' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'V' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(130,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(130,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(130,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(135,9): error TS2416: Property 'foo' in type 'D5' is not assignable to the same property in base type 'Base2'. Type 'U' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'T' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(135,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(135,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base2'. Type 'V' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'V' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base2'. Type 'T' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'U' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base2'. Type 'U' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'T' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(155,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(155,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts (42 errors) ==== @@ -143,7 +143,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: T ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. } class D2, U extends Foo, V extends Foo> extends Base { @@ -156,7 +156,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. } class D3, U extends Foo, V extends Foo> extends Base { @@ -169,7 +169,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. } class D4, U extends Foo, V extends Foo> extends Base { @@ -182,14 +182,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'T' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. } class D5, U extends Foo, V extends Foo> extends Base { [x: string]: U; foo: U ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. } class D6, U extends Foo, V extends Foo> extends Base { @@ -202,7 +202,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'V' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. } class D7, U extends Foo, V extends Foo> extends Base { @@ -215,7 +215,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'T' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. } class D8, U extends Foo, V extends Foo> extends Base { @@ -228,14 +228,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'U' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. } class D9, U extends Foo, V extends Foo> extends Base { [x: string]: V; foo: V ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. } } @@ -255,7 +255,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. } class D2, U extends Foo, V extends Foo> extends Base2 { @@ -264,7 +264,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~ !!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. } class D3, U extends Foo, V extends Foo> extends Base2 { @@ -279,7 +279,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. } class D4, U extends Foo, V extends Foo> extends Base2 { @@ -288,7 +288,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~ !!! error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. } class D5, U extends Foo, V extends Foo> extends Base2 { @@ -301,7 +301,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'T' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. } class D6, U extends Foo, V extends Foo> extends Base2 { @@ -316,7 +316,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'V' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. } class D7, U extends Foo, V extends Foo> extends Base2 { @@ -331,7 +331,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'U' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. } class D8, U extends Foo, V extends Foo> extends Base2 { @@ -346,13 +346,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'T' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. } class D9, U extends Foo, V extends Foo> extends Base2 { [x: string]: V; foo: V ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. +!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. } } \ No newline at end of file diff --git a/tests/baselines/reference/subtypingTransitivity.errors.txt b/tests/baselines/reference/subtypingTransitivity.errors.txt index 1284422452565..c2ca02697cdd4 100644 --- a/tests/baselines/reference/subtypingTransitivity.errors.txt +++ b/tests/baselines/reference/subtypingTransitivity.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/subtypingTransitivity.ts(6,12): error TS2610: Class 'B' defines instance member property 'x', so extended class 'D' must provide an initializer with this override. -tests/cases/compiler/subtypingTransitivity.ts(9,12): error TS2610: Class 'B' defines instance member property 'x', so extended class 'D2' must provide an initializer with this override. +tests/cases/compiler/subtypingTransitivity.ts(6,12): error TS2610: Class 'B' defines instance member property 'x', so extended class 'D' must use 'declare' to make it ambient. +tests/cases/compiler/subtypingTransitivity.ts(9,12): error TS2610: Class 'B' defines instance member property 'x', so extended class 'D2' must use 'declare' to make it ambient. ==== tests/cases/compiler/subtypingTransitivity.ts (2 errors) ==== @@ -10,12 +10,12 @@ tests/cases/compiler/subtypingTransitivity.ts(9,12): error TS2610: Class 'B' def class D extends B { public x: string; ~ -!!! error TS2610: Class 'B' defines instance member property 'x', so extended class 'D' must provide an initializer with this override. +!!! error TS2610: Class 'B' defines instance member property 'x', so extended class 'D' must use 'declare' to make it ambient. } class D2 extends B { public x: number; ~ -!!! error TS2610: Class 'B' defines instance member property 'x', so extended class 'D2' must provide an initializer with this override. +!!! error TS2610: Class 'B' defines instance member property 'x', so extended class 'D2' must use 'declare' to make it ambient. } var b: B; diff --git a/tests/baselines/reference/subtypingWithObjectMembers.errors.txt b/tests/baselines/reference/subtypingWithObjectMembers.errors.txt index 6690c442c81a7..b748602a82bf1 100644 --- a/tests/baselines/reference/subtypingWithObjectMembers.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembers.errors.txt @@ -1,27 +1,27 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(13,5): error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(13,5): error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(14,5): error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(14,5): error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(23,5): error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(14,5): error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(23,5): error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(24,5): error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(24,5): error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(33,5): error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(24,5): error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(33,5): error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(34,5): error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(34,5): error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(44,9): error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(34,5): error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(44,9): error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(45,9): error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(45,9): error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(54,9): error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(45,9): error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(54,9): error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(55,9): error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(55,9): error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(64,9): error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(55,9): error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(64,9): error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must use 'declare' to make it ambient. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(65,9): error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(65,9): error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(65,9): error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must use 'declare' to make it ambient. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts (18 errors) ==== @@ -39,13 +39,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { foo: Derived; // ok ~~~ -!!! error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must provide an initializer with this override. +!!! error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must use 'declare' to make it ambient. bar: string; // error ~~~ !!! error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. ~~~ -!!! error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must provide an initializer with this override. +!!! error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must use 'declare' to make it ambient. } class A2 { @@ -56,13 +56,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B2 extends A2 { 1: Derived; // ok ~ -!!! error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must provide an initializer with this override. +!!! error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must use 'declare' to make it ambient. 2: string; // error ~ !!! error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. ~ -!!! error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must provide an initializer with this override. +!!! error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must use 'declare' to make it ambient. } class A3 { @@ -73,13 +73,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A3 { '1': Derived; // ok ~~~ -!!! error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must provide an initializer with this override. +!!! error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must use 'declare' to make it ambient. '2.0': string; // error ~~~~~ !!! error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. ~~~~~ -!!! error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must provide an initializer with this override. +!!! error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must use 'declare' to make it ambient. } module TwoLevels { @@ -91,13 +91,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { foo: Derived2; // ok ~~~ -!!! error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must provide an initializer with this override. +!!! error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must use 'declare' to make it ambient. bar: string; // error ~~~ !!! error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. ~~~ -!!! error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must provide an initializer with this override. +!!! error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must use 'declare' to make it ambient. } class A2 { @@ -108,13 +108,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B2 extends A2 { 1: Derived2; // ok ~ -!!! error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must provide an initializer with this override. +!!! error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must use 'declare' to make it ambient. 2: string; // error ~ !!! error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. ~ -!!! error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must provide an initializer with this override. +!!! error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must use 'declare' to make it ambient. } class A3 { @@ -125,12 +125,12 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A3 { '1': Derived2; // ok ~~~ -!!! error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must provide an initializer with this override. +!!! error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must use 'declare' to make it ambient. '2.0': string; // error ~~~~~ !!! error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. ~~~~~ -!!! error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must provide an initializer with this override. +!!! error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must use 'declare' to make it ambient. } } \ No newline at end of file diff --git a/tests/baselines/reference/tsxGenericAttributesType5.errors.txt b/tests/baselines/reference/tsxGenericAttributesType5.errors.txt index 42f10f91f7fa2..5143478df0c47 100644 --- a/tests/baselines/reference/tsxGenericAttributesType5.errors.txt +++ b/tests/baselines/reference/tsxGenericAttributesType5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must provide an initializer with this override. +tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must use 'declare' to make it ambient. ==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== @@ -12,7 +12,7 @@ tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Class 'Component class B extends React.Component { props: U; ~~~~~ -!!! error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must provide an initializer with this override. +!!! error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must use 'declare' to make it ambient. render() { return ; } diff --git a/tests/baselines/reference/tsxGenericAttributesType6.errors.txt b/tests/baselines/reference/tsxGenericAttributesType6.errors.txt index af26e4a25b933..e1933e9a5c670 100644 --- a/tests/baselines/reference/tsxGenericAttributesType6.errors.txt +++ b/tests/baselines/reference/tsxGenericAttributesType6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must provide an initializer with this override. +tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must use 'declare' to make it ambient. ==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== @@ -12,7 +12,7 @@ tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Class 'Component class B extends React.Component { props: U; ~~~~~ -!!! error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must provide an initializer with this override. +!!! error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must use 'declare' to make it ambient. render() { return ; } diff --git a/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt b/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt index 2bba64a42e2c6..eb283445e2327 100644 --- a/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt +++ b/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt @@ -1,25 +1,25 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(8,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D0' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(12,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'DA' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(16,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(20,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1A' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(25,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(29,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2A' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(34,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(38,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3A' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(43,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(47,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(52,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(56,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(61,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(68,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(73,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D10' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(78,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D11' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(86,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D12' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(95,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D13' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(100,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D14' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(105,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D15' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(114,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D16' must provide an initializer with this override. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(119,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D17' must provide an initializer with this override. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(8,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D0' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(12,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'DA' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(16,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(20,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1A' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(25,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(29,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2A' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(34,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(38,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3A' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(43,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(47,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(52,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(56,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(61,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(68,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(73,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D10' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(78,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D11' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(86,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D12' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(95,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D13' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(100,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D14' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(105,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D15' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(114,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D16' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(119,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D17' must use 'declare' to make it ambient. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts (22 errors) ==== @@ -32,84 +32,84 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedI class D0 extends Base { foo: any; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D0' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D0' must use 'declare' to make it ambient. } class DA extends Base { foo: typeof undefined; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'DA' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'DA' must use 'declare' to make it ambient. } class D1 extends Base { foo: string; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. } class D1A extends Base { foo: String; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1A' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1A' must use 'declare' to make it ambient. } class D2 extends Base { foo: number; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. } class D2A extends Base { foo: Number; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2A' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2A' must use 'declare' to make it ambient. } class D3 extends Base { foo: boolean; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. } class D3A extends Base { foo: Boolean; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3A' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3A' must use 'declare' to make it ambient. } class D4 extends Base { foo: RegExp; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. } class D5 extends Base { foo: Date; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. } class D6 extends Base { foo: number[]; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. } class D7 extends Base { foo: { bar: number }; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. } class D8 extends Base { foo: D7; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. } interface I1 { @@ -118,21 +118,21 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedI class D9 extends Base { foo: I1; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. } class D10 extends Base { foo: () => number; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D10' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D10' must use 'declare' to make it ambient. } enum E { A } class D11 extends Base { foo: E; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D11' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D11' must use 'declare' to make it ambient. } function f() { } @@ -142,7 +142,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedI class D12 extends Base { foo: typeof f; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D12' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D12' must use 'declare' to make it ambient. } @@ -153,21 +153,21 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedI class D13 extends Base { foo: typeof c; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D13' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D13' must use 'declare' to make it ambient. } class D14 extends Base { foo: T; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D14' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D14' must use 'declare' to make it ambient. } class D15 extends Base { foo: U; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D15' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D15' must use 'declare' to make it ambient. } //class D15 extends Base { @@ -178,13 +178,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedI class D16 extends Base { foo: Object; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D16' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D16' must use 'declare' to make it ambient. } class D17 extends Base { foo: {}; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D17' must provide an initializer with this override. +!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D17' must use 'declare' to make it ambient. } \ No newline at end of file From 2e5f57ce2b94bb08c29f58bde252c858a9e753f4 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 16 Sep 2019 16:18:52 -0700 Subject: [PATCH 08/44] Improve error wording --- src/compiler/checker.ts | 4 +- src/compiler/diagnosticMessages.json | 2 +- .../apparentTypeSubtyping.errors.txt | 8 +- .../apparentTypeSupertype.errors.txt | 4 +- ...baseClassImprovedMismatchErrors.errors.txt | 4 +- .../classIsSubtypeOfBaseType.errors.txt | 8 +- ...declarationEmitProtectedMembers.errors.txt | 4 +- ...dClassOverridesProtectedMembers.errors.txt | 8 +- ...ClassOverridesProtectedMembers2.errors.txt | 8 +- ...ClassOverridesProtectedMembers3.errors.txt | 8 +- ...ClassOverridesProtectedMembers4.errors.txt | 8 +- ...ivedClassOverridesPublicMembers.errors.txt | 8 +- ...vedClassOverridesWithoutSubtype.errors.txt | 4 +- .../reference/derivedClassWithAny.errors.txt | 8 +- .../derivedGenericClassWithAny.errors.txt | 8 +- ...ninitializedPropertyDeclaration.errors.txt | 12 +-- .../genericPrototypeProperty2.errors.txt | 8 +- .../genericPrototypeProperty3.errors.txt | 8 +- ...aceExtendingClassWithProtecteds.errors.txt | 4 +- .../reference/inheritance.errors.txt | 4 +- ...emberPropertyOverridingAccessor.errors.txt | 4 +- ...emberPropertyOverridingProperty.errors.txt | 4 +- .../instanceSubtypeCheck2.errors.txt | 4 +- ...erfaceExtendsObjectIntersection.errors.txt | 28 +++--- ...ExtendsObjectIntersectionErrors.errors.txt | 20 ++--- .../reference/multipleInheritance.errors.txt | 4 +- .../mutuallyRecursiveInference.errors.txt | 8 +- .../reference/protectedMembers.errors.txt | 12 +-- .../baselines/reference/scopeTests.errors.txt | 4 +- .../subtypesOfTypeParameter.errors.txt | 4 +- ...OfTypeParameterWithConstraints4.errors.txt | 36 ++++---- ...rameterWithRecursiveConstraints.errors.txt | 72 +++++++-------- .../subtypingTransitivity.errors.txt | 8 +- .../subtypingWithObjectMembers.errors.txt | 48 +++++----- .../tsxGenericAttributesType5.errors.txt | 4 +- .../tsxGenericAttributesType6.errors.txt | 4 +- .../undefinedIsSubtypeOfEverything.errors.txt | 88 +++++++++---------- 37 files changed, 241 insertions(+), 241 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1a26abaaa4abf..0b1e43dc205ba 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29534,8 +29534,8 @@ namespace ts { || !isIdentifier(propName) || !strictNullChecks || !isPropertyInitializedInConstructor(propName, type, constructor)) { - const errorMessage = Diagnostics.Class_0_defines_instance_member_property_1_so_extended_class_2_must_use_declare_to_make_it_ambient; - error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type)); + const errorMessage = Diagnostics.Property_0_will_overwrite_the_base_property_in_1_Add_a_declare_modifier_or_an_initializer_to_avoid_this; + error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, symbolToString(base), typeToString(baseType)); } } continue; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b0f8ca8e24ed2..baa77494e818b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2204,7 +2204,7 @@ "category": "Error", "code": 2609 }, - "Class '{0}' defines instance member property '{1}', so extended class '{2}' must use 'declare' to make it ambient.": { + "Property '{0}' will overwrite the base property in '{1}'. Add a 'declare' modifier or an initializer to avoid this.": { "category": "Error", "code": 2610 }, diff --git a/tests/baselines/reference/apparentTypeSubtyping.errors.txt b/tests/baselines/reference/apparentTypeSubtyping.errors.txt index e4088efe246a7..9f43225eb1594 100644 --- a/tests/baselines/reference/apparentTypeSubtyping.errors.txt +++ b/tests/baselines/reference/apparentTypeSubtyping.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'Base'. Type 'String' is not assignable to type 'string'. 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. -tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(20,5): error TS2610: Class 'Base2' defines instance member property 'x', so extended class 'Derived2' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2610: Property 'x' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(20,5): error TS2610: Property 'x' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts (3 errors) ==== @@ -21,7 +21,7 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtypi !!! error TS2416: Type 'String' is not assignable to type 'string'. !!! error TS2416: 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. ~ -!!! error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class Base2 { @@ -33,5 +33,5 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtypi class Derived2 extends Base2 { // error because of the prototype's not matching, not because of the instance side x: U; ~ -!!! error TS2610: Class 'Base2' defines instance member property 'x', so extended class 'Derived2' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/apparentTypeSupertype.errors.txt b/tests/baselines/reference/apparentTypeSupertype.errors.txt index 5d13848277882..1dde3b891f812 100644 --- a/tests/baselines/reference/apparentTypeSupertype.errors.txt +++ b/tests/baselines/reference/apparentTypeSupertype.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSuperty Type 'U' is not assignable to type 'string'. Type 'String' is not assignable to type 'string'. 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. -tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts(10,5): error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts(10,5): error TS2610: Property 'x' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts (2 errors) ==== @@ -22,5 +22,5 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSuperty !!! error TS2416: Type 'String' is not assignable to type 'string'. !!! error TS2416: 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. ~ -!!! error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt b/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt index b654bfa37d072..4bdf83b31c789 100644 --- a/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt +++ b/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2416: Prop Types of property 'n' are incompatible. Type 'string | Derived' is not assignable to type 'string | Base'. Type 'Derived' is not assignable to type 'string | Base'. -tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2610: Class 'Base' defines instance member property 'n', so extended class 'Derived' must use 'declare' to make it ambient. +tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2610: Property 'n' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/compiler/baseClassImprovedMismatchErrors.ts(9,5): error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'. Type '() => string | number' is not assignable to type '() => number'. Type 'string | number' is not assignable to type 'number'. @@ -41,7 +41,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro !!! error TS2416: Type 'string | Derived' is not assignable to type 'string | Base'. !!! error TS2416: Type 'Derived' is not assignable to type 'string | Base'. ~ -!!! error TS2610: Class 'Base' defines instance member property 'n', so extended class 'Derived' must use 'declare' to make it ambient. +!!! error TS2610: Property 'n' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. fn() { ~~ !!! error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'. diff --git a/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt b/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt index 86370198f2c6e..f8369af4ad403 100644 --- a/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt +++ b/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(6,5): error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived' must use 'declare' to make it ambient. +tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(6,5): error TS2610: Property 'foo' will overwrite the base property in 'Base<{ bar: string; }>'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type 'Base<{ bar: string; }>'. Type '{ bar?: string; }' is not assignable to type '{ bar: string; }'. Property 'bar' is optional in type '{ bar?: string; }' but required in type '{ bar: string; }'. -tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived2' must use 'declare' to make it ambient. +tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2610: Property 'foo' will overwrite the base property in 'Base<{ bar: string; }>'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts (3 errors) ==== @@ -13,7 +13,7 @@ tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/cla class Derived extends Base<{ bar: string; }> { foo: { ~~~ -!!! error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base<{ bar: string; }>'. Add a 'declare' modifier or an initializer to avoid this. bar: string; baz: number; // ok } } @@ -25,7 +25,7 @@ tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/cla !!! error TS2416: Type '{ bar?: string; }' is not assignable to type '{ bar: string; }'. !!! error TS2416: Property 'bar' is optional in type '{ bar?: string; }' but required in type '{ bar: string; }'. ~~~ -!!! error TS2610: Class 'Base<{ bar: string; }>' defines instance member property 'foo', so extended class 'Derived2' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base<{ bar: string; }>'. Add a 'declare' modifier or an initializer to avoid this. bar?: string; // error } } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt b/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt index 803f761654333..5adfa76f4f627 100644 --- a/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt +++ b/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/declarationEmitProtectedMembers.ts(34,5): error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must use 'declare' to make it ambient. +tests/cases/compiler/declarationEmitProtectedMembers.ts(34,5): error TS2610: Property 'x' will overwrite the base property in 'C2'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/compiler/declarationEmitProtectedMembers.ts (1 errors) ==== @@ -37,7 +37,7 @@ tests/cases/compiler/declarationEmitProtectedMembers.ts(34,5): error TS2610: Cla class C3 extends C2 { x: number; ~ -!!! error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'C2'. Add a 'declare' modifier or an initializer to avoid this. static sx: number; f() { return super.f(); diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt index cbf6d7f53c228..a7c03264131bb 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts(21,15): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must use 'declare' to make it ambient. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts(25,15): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts(21,15): error TS2610: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts(25,15): error TS2610: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts (2 errors) ==== @@ -25,13 +25,13 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived extends Base { protected a: typeof y; ~ -!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must use 'declare' to make it ambient. +!!! error TS2610: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. protected b(a: typeof y) { } protected get c() { return y; } protected set c(v: typeof y) { } protected d: (a: typeof y) => void; ~ -!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must use 'declare' to make it ambient. +!!! error TS2610: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. protected static r: typeof y; protected static s(a: typeof y) { } diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt index b739769498fbf..816f3b4df5d25 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts(22,5): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must use 'declare' to make it ambient. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts(26,5): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts(22,5): error TS2610: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts(26,5): error TS2610: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts (2 errors) ==== @@ -26,13 +26,13 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived extends Base { a: typeof y; ~ -!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must use 'declare' to make it ambient. +!!! error TS2610: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. b(a: typeof y) { } get c() { return y; } set c(v: typeof y) { } d: (a: typeof y) => void; ~ -!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must use 'declare' to make it ambient. +!!! error TS2610: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. static r: typeof y; static s(a: typeof y) { } diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt index 4c74d97f040a9..1be0509e6524d 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(22,7): error TS2415: Class 'Derived1' incorrectly extends base class 'Base'. Property 'a' is protected in type 'Derived1' but public in type 'Base'. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(23,15): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(23,15): error TS2610: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(27,7): error TS2415: Class 'Derived2' incorrectly extends base class 'Base'. Property 'b' is protected in type 'Derived2' but public in type 'Base'. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(32,7): error TS2415: Class 'Derived3' incorrectly extends base class 'Base'. @@ -9,7 +9,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve Property 'c' is protected in type 'Derived4' but public in type 'Base'. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(42,7): error TS2415: Class 'Derived5' incorrectly extends base class 'Base'. Property 'd' is protected in type 'Derived5' but public in type 'Base'. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(43,15): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived5' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(43,15): error TS2610: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(47,7): error TS2417: Class static side 'typeof Derived6' incorrectly extends base class static side 'typeof Base'. Property 'r' is protected in type 'typeof Derived6' but public in type 'typeof Base'. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(52,7): error TS2417: Class static side 'typeof Derived7' incorrectly extends base class static side 'typeof Base'. @@ -50,7 +50,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS2415: Property 'a' is protected in type 'Derived1' but public in type 'Base'. protected a: typeof x; ~ -!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must use 'declare' to make it ambient. +!!! error TS2610: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. constructor(a: typeof x) { super(a); } } @@ -84,7 +84,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS2415: Property 'd' is protected in type 'Derived5' but public in type 'Base'. protected d: (a: typeof x) => void ; ~ -!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived5' must use 'declare' to make it ambient. +!!! error TS2610: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. constructor(a: typeof x) { super(a); } } diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt index 9f401ea1e5668..2d11066559826 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(9,12): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(9,12): error TS2610: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(12,7): error TS2415: Class 'Derived2' incorrectly extends base class 'Derived1'. Property 'a' is protected in type 'Derived2' but public in type 'Derived1'. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(13,15): error TS2610: Class 'Derived1' defines instance member property 'a', so extended class 'Derived2' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(13,15): error TS2610: Property 'a' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts (3 errors) ==== @@ -15,7 +15,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived1 extends Base { public a: typeof x; ~ -!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived1' must use 'declare' to make it ambient. +!!! error TS2610: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class Derived2 extends Derived1 { @@ -24,5 +24,5 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS2415: Property 'a' is protected in type 'Derived2' but public in type 'Derived1'. protected a: typeof x; // Error, parent was public ~ -!!! error TS2610: Class 'Derived1' defines instance member property 'a', so extended class 'Derived2' must use 'declare' to make it ambient. +!!! error TS2610: Property 'a' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt b/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt index 145350ee604f9..45511c1a2c013 100644 --- a/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt @@ -2,10 +2,10 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(13,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(14,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(21,5): error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(21,5): error TS2610: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(23,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(24,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(25,5): error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(25,5): error TS2610: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(29,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(30,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -41,7 +41,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived extends Base { a: typeof y; ~ -!!! error TS2610: Class 'Base' defines instance member property 'a', so extended class 'Derived' must use 'declare' to make it ambient. +!!! error TS2610: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. b(a: typeof y) { } get c() { return y; } ~ @@ -51,7 +51,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. d: (a: typeof y) => void; ~ -!!! error TS2610: Class 'Base' defines instance member property 'd', so extended class 'Derived' must use 'declare' to make it ambient. +!!! error TS2610: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. static r: typeof y; static s(a: typeof y) { } diff --git a/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt b/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt index 7a7633d461c6e..8f65f436dcac8 100644 --- a/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype.ts(8,5): error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype.ts(8,5): error TS2610: Property 'x' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype.ts (1 errors) ==== @@ -11,7 +11,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived extends Base { x: { ~ -!!! error TS2610: Class 'Base' defines instance member property 'x', so extended class 'Derived' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. foo: any; } } diff --git a/tests/baselines/reference/derivedClassWithAny.errors.txt b/tests/baselines/reference/derivedClassWithAny.errors.txt index c2037c529cfb0..5f8a219b58eb2 100644 --- a/tests/baselines/reference/derivedClassWithAny.errors.txt +++ b/tests/baselines/reference/derivedClassWithAny.errors.txt @@ -1,9 +1,9 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(9,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(18,5): error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(18,5): error TS2610: Property 'x' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(19,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(27,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(37,5): error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(37,5): error TS2610: Property 'x' will overwrite the base property in 'D'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(38,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(44,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(57,1): error TS2322: Type 'E' is not assignable to type 'C'. @@ -35,7 +35,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWit class D extends C { x: any; ~ -!!! error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. get X(): any { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -60,7 +60,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWit class E extends D { x: string; ~ -!!! error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'D'. Add a 'declare' modifier or an initializer to avoid this. get X(): string{ return ''; } ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. diff --git a/tests/baselines/reference/derivedGenericClassWithAny.errors.txt b/tests/baselines/reference/derivedGenericClassWithAny.errors.txt index d5dc9585271d2..6d32d3f814739 100644 --- a/tests/baselines/reference/derivedGenericClassWithAny.errors.txt +++ b/tests/baselines/reference/derivedGenericClassWithAny.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(10,5): error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(10,5): error TS2610: Property 'x' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(11,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(19,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(29,5): error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must use 'declare' to make it ambient. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(29,5): error TS2610: Property 'x' will overwrite the base property in 'D'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,18): error TS2322: Type '""' is not assignable to type 'T'. '""' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'. @@ -27,7 +27,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC class D extends C { x: any; ~ -!!! error TS2610: Class 'C' defines instance member property 'x', so extended class 'D' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. get X(): any { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -52,7 +52,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC class E extends D { x: T; ~ -!!! error TS2610: Class 'D' defines instance member property 'x', so extended class 'E' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'D'. Add a 'declare' modifier or an initializer to avoid this. get X(): T { return ''; } // error ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt index aa9f4b955938d..737c83bd0ce8c 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt @@ -1,12 +1,12 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(6,5): error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must use 'declare' to make it ambient. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(6,5): error TS2610: Property 'property' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(15,5): error TS1031: 'declare' modifier cannot appear on a class element. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(16,13): error TS2611: Ambient property declarations must override a property in a base class. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(17,24): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(20,13): error TS2611: Ambient property declarations must override a property in a base class. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(24,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must use 'declare' to make it ambient. -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(39,5): error TS2610: Class 'E' defines instance member property 'p1', so extended class 'F' must use 'declare' to make it ambient. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2610: Property 'p' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(39,5): error TS2610: Property 'p1' will overwrite the base property in 'E'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (9 errors) ==== @@ -17,7 +17,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP class B extends A { property: any; // error ~~~~~~~~ -!!! error TS2610: Class 'A' defines instance member property 'property', so extended class 'B' must use 'declare' to make it ambient. +!!! error TS2610: Property 'property' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. } class BD extends A { declare property: any; // ok because it's implicitly initialised @@ -52,7 +52,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP ~ !!! error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. ~ -!!! error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must use 'declare' to make it ambient. +!!! error TS2610: Property 'p' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. } class DD extends C { declare p: 'bye'; // ok @@ -66,7 +66,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP class F extends E { p1!: 'z' ~~ -!!! error TS2610: Class 'E' defines instance member property 'p1', so extended class 'F' must use 'declare' to make it ambient. +!!! error TS2610: Property 'p1' will overwrite the base property in 'E'. Add a 'declare' modifier or an initializer to avoid this. declare p2: 'alpha' } diff --git a/tests/baselines/reference/genericPrototypeProperty2.errors.txt b/tests/baselines/reference/genericPrototypeProperty2.errors.txt index 117cc90b99fae..2d27cf0fc4e72 100644 --- a/tests/baselines/reference/genericPrototypeProperty2.errors.txt +++ b/tests/baselines/reference/genericPrototypeProperty2.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/genericPrototypeProperty2.ts(7,5): error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must use 'declare' to make it ambient. -tests/cases/compiler/genericPrototypeProperty2.ts(14,5): error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must use 'declare' to make it ambient. +tests/cases/compiler/genericPrototypeProperty2.ts(7,5): error TS2610: Property 'target' will overwrite the base property in 'BaseEvent'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/compiler/genericPrototypeProperty2.ts(14,5): error TS2610: Property 't' will overwrite the base property in 'BaseEventWrapper'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/compiler/genericPrototypeProperty2.ts (2 errors) ==== @@ -11,7 +11,7 @@ tests/cases/compiler/genericPrototypeProperty2.ts(14,5): error TS2610: Class 'Ba class MyEvent extends BaseEvent { target: T; ~~~~~~ -!!! error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must use 'declare' to make it ambient. +!!! error TS2610: Property 'target' will overwrite the base property in 'BaseEvent'. Add a 'declare' modifier or an initializer to avoid this. } class BaseEventWrapper { t: BaseEvent; @@ -20,5 +20,5 @@ tests/cases/compiler/genericPrototypeProperty2.ts(14,5): error TS2610: Class 'Ba class MyEventWrapper extends BaseEventWrapper { t: MyEvent; // any satisfies constraint and passes assignability check between 'target' properties ~ -!!! error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must use 'declare' to make it ambient. +!!! error TS2610: Property 't' will overwrite the base property in 'BaseEventWrapper'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/genericPrototypeProperty3.errors.txt b/tests/baselines/reference/genericPrototypeProperty3.errors.txt index ca3398d6722d3..c12e29d3da0cc 100644 --- a/tests/baselines/reference/genericPrototypeProperty3.errors.txt +++ b/tests/baselines/reference/genericPrototypeProperty3.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/genericPrototypeProperty3.ts(6,5): error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must use 'declare' to make it ambient. -tests/cases/compiler/genericPrototypeProperty3.ts(13,5): error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must use 'declare' to make it ambient. +tests/cases/compiler/genericPrototypeProperty3.ts(6,5): error TS2610: Property 'target' will overwrite the base property in 'BaseEvent'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/compiler/genericPrototypeProperty3.ts(13,5): error TS2610: Property 't' will overwrite the base property in 'BaseEventWrapper'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/compiler/genericPrototypeProperty3.ts (2 errors) ==== @@ -10,7 +10,7 @@ tests/cases/compiler/genericPrototypeProperty3.ts(13,5): error TS2610: Class 'Ba class MyEvent extends BaseEvent { // T is instantiated to any in the prototype, which is assignable to {} target: T; ~~~~~~ -!!! error TS2610: Class 'BaseEvent' defines instance member property 'target', so extended class 'MyEvent' must use 'declare' to make it ambient. +!!! error TS2610: Property 'target' will overwrite the base property in 'BaseEvent'. Add a 'declare' modifier or an initializer to avoid this. } class BaseEventWrapper { t: BaseEvent; @@ -19,5 +19,5 @@ tests/cases/compiler/genericPrototypeProperty3.ts(13,5): error TS2610: Class 'Ba class MyEventWrapper extends BaseEventWrapper { t: MyEvent; ~ -!!! error TS2610: Class 'BaseEventWrapper' defines instance member property 't', so extended class 'MyEventWrapper' must use 'declare' to make it ambient. +!!! error TS2610: Property 't' will overwrite the base property in 'BaseEventWrapper'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt index 98aee8dd231f7..d8cb657aa4305 100644 --- a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt +++ b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt @@ -10,7 +10,7 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInte Property 'y' is missing in type 'Bar5' but required in type 'I'. tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(29,7): error TS2420: Class 'Bar6' incorrectly implements interface 'I'. Property 'y' is protected in type 'Bar6' but public in type 'I'. -tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(38,5): error TS2610: Class 'Foo' defines instance member property 'x', so extended class 'Bar8' must use 'declare' to make it ambient. +tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(38,5): error TS2610: Property 'x' will overwrite the base property in 'Foo'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts (7 errors) ==== @@ -73,7 +73,7 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInte class Bar8 extends Foo implements I { x: string; ~ -!!! error TS2610: Class 'Foo' defines instance member property 'x', so extended class 'Bar8' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'Foo'. Add a 'declare' modifier or an initializer to avoid this. y: number; } \ No newline at end of file diff --git a/tests/baselines/reference/inheritance.errors.txt b/tests/baselines/reference/inheritance.errors.txt index 9b589f51a0b0e..45a1dbfc5666e 100644 --- a/tests/baselines/reference/inheritance.errors.txt +++ b/tests/baselines/reference/inheritance.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/inheritance.ts(22,12): error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must use 'declare' to make it ambient. +tests/cases/compiler/inheritance.ts(22,12): error TS2610: Property 'y' will overwrite the base property in 'N'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/compiler/inheritance.ts(31,12): error TS2425: Class 'Good' defines instance member property 'f', but extended class 'Baad' defines it as instance member function. tests/cases/compiler/inheritance.ts(32,12): error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type 'Good'. Type '(n: number) => number' is not assignable to type '() => number'. @@ -28,7 +28,7 @@ tests/cases/compiler/inheritance.ts(32,12): error TS2416: Property 'g' in type ' class ND extends N { // any is assignable to number public y; ~ -!!! error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must use 'declare' to make it ambient. +!!! error TS2610: Property 'y' will overwrite the base property in 'N'. Add a 'declare' modifier or an initializer to avoid this. } class Good { diff --git a/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt b/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt index 18f70505450b4..3996eaf15c34b 100644 --- a/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt +++ b/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(6,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(12,5): error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must use 'declare' to make it ambient. +tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(12,5): error TS2610: Property 'x' will overwrite the base property in 'a'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts (3 errors) ==== @@ -21,5 +21,5 @@ tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(12,5): error class b extends a { x: () => string; ~ -!!! error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'a'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt b/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt index ee3da3f95a37d..79b3e6a8f1ea8 100644 --- a/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt +++ b/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/inheritanceMemberPropertyOverridingProperty.ts(6,5): error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must use 'declare' to make it ambient. +tests/cases/compiler/inheritanceMemberPropertyOverridingProperty.ts(6,5): error TS2610: Property 'x' will overwrite the base property in 'a'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/compiler/inheritanceMemberPropertyOverridingProperty.ts (1 errors) ==== @@ -9,5 +9,5 @@ tests/cases/compiler/inheritanceMemberPropertyOverridingProperty.ts(6,5): error class b extends a { x: () => string; ~ -!!! error TS2610: Class 'a' defines instance member property 'x', so extended class 'b' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'a'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/instanceSubtypeCheck2.errors.txt b/tests/baselines/reference/instanceSubtypeCheck2.errors.txt index 4640ae46fc29f..1d3622f49e79f 100644 --- a/tests/baselines/reference/instanceSubtypeCheck2.errors.txt +++ b/tests/baselines/reference/instanceSubtypeCheck2.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2416: Property 'x' in type 'C2' is not assignable to the same property in base type 'C1'. Type 'string' is not assignable to type 'C2'. -tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2610: Class 'C1' defines instance member property 'x', so extended class 'C2' must use 'declare' to make it ambient. +tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2610: Property 'x' will overwrite the base property in 'C1'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/compiler/instanceSubtypeCheck2.ts (2 errors) ==== @@ -14,5 +14,5 @@ tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2610: Class 'C1' !!! error TS2416: Property 'x' in type 'C2' is not assignable to the same property in base type 'C1'. !!! error TS2416: Type 'string' is not assignable to type 'C2'. ~ -!!! error TS2610: Class 'C1' defines instance member property 'x', so extended class 'C2' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'C1'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt b/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt index 4778cd7e0f2f2..f23383cda97cc 100644 --- a/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt +++ b/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(20,38): error TS2610: Class 'I1' defines instance member property 'x', so extended class 'C1' must use 'declare' to make it ambient. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(21,38): error TS2610: Class 'I2' defines instance member property 'x', so extended class 'C2' must use 'declare' to make it ambient. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(22,38): error TS2610: Class 'I3' defines instance member property 'x', so extended class 'C3' must use 'declare' to make it ambient. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(23,38): error TS2610: Class 'I4' defines instance member property 'x', so extended class 'C4' must use 'declare' to make it ambient. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(24,38): error TS2610: Class 'I5' defines instance member property 'x', so extended class 'C5' must use 'declare' to make it ambient. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(25,38): error TS2610: Class 'I6' defines instance member property 'x', so extended class 'C6' must use 'declare' to make it ambient. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(26,38): error TS2610: Class 'I7' defines instance member property 'x', so extended class 'C7' must use 'declare' to make it ambient. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(20,38): error TS2610: Property 'x' will overwrite the base property in 'I1'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(21,38): error TS2610: Property 'x' will overwrite the base property in 'I2'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(22,38): error TS2610: Property 'x' will overwrite the base property in 'I3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(23,38): error TS2610: Property 'x' will overwrite the base property in 'I4'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(24,38): error TS2610: Property 'x' will overwrite the base property in 'I5'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(25,38): error TS2610: Property 'x' will overwrite the base property in 'I6'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(26,38): error TS2610: Property 'x' will overwrite the base property in 'I7'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts (7 errors) ==== @@ -29,25 +29,25 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI class C1 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I1' defines instance member property 'x', so extended class 'C1' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'I1'. Add a 'declare' modifier or an initializer to avoid this. class C2 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I2' defines instance member property 'x', so extended class 'C2' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'I2'. Add a 'declare' modifier or an initializer to avoid this. class C3 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I3' defines instance member property 'x', so extended class 'C3' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'I3'. Add a 'declare' modifier or an initializer to avoid this. class C4 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I4' defines instance member property 'x', so extended class 'C4' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'I4'. Add a 'declare' modifier or an initializer to avoid this. class C5 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I5' defines instance member property 'x', so extended class 'C5' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'I5'. Add a 'declare' modifier or an initializer to avoid this. class C6 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I6' defines instance member property 'x', so extended class 'C6' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'I6'. Add a 'declare' modifier or an initializer to avoid this. class C7 extends Constructor() { x: string } ~ -!!! error TS2610: Class 'I7' defines instance member property 'x', so extended class 'C7' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'I7'. Add a 'declare' modifier or an initializer to avoid this. declare function fx(x: string): string; declare class CX { a: number } diff --git a/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt b/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt index 0f4a62fd786ac..88f9150adc11d 100644 --- a/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt +++ b/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt @@ -16,19 +16,19 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI Type 'number' is not assignable to type 'string'. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(16,38): error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'T1'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(16,38): error TS2610: Class 'T1' defines instance member property 'a', so extended class 'C1' must use 'declare' to make it ambient. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(16,38): error TS2610: Property 'a' will overwrite the base property in 'T1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'T2'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2610: Class 'T2' defines instance member property 'b', so extended class 'C2' must use 'declare' to make it ambient. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2610: Property 'b' will overwrite the base property in 'T2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2610: Class 'number[]' defines instance member property 'length', so extended class 'C3' must use 'declare' to make it ambient. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2610: Property 'length' will overwrite the base property in 'number[]'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2610: Class '[string, number]' defines instance member property '0', so extended class 'C4' must use 'declare' to make it ambient. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2610: Property '0' will overwrite the base property in '[string, number]'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(20,38): error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'T5'. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(20,38): error TS2610: Class 'T5' defines instance member property 'c', so extended class 'C5' must use 'declare' to make it ambient. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(20,38): error TS2610: Property 'c' will overwrite the base property in 'T5'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(30,11): error TS2430: Interface 'I10' incorrectly extends interface 'typeof CX'. Types of property 'a' are incompatible. Type 'number' is not assignable to type 'string'. @@ -102,31 +102,31 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI !!! error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'T1'. !!! error TS2416: Type 'string' is not assignable to type 'number'. ~ -!!! error TS2610: Class 'T1' defines instance member property 'a', so extended class 'C1' must use 'declare' to make it ambient. +!!! error TS2610: Property 'a' will overwrite the base property in 'T1'. Add a 'declare' modifier or an initializer to avoid this. class C2 extends Constructor() { b: string } ~ !!! error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'T2'. !!! error TS2416: Type 'string' is not assignable to type 'number'. ~ -!!! error TS2610: Class 'T2' defines instance member property 'b', so extended class 'C2' must use 'declare' to make it ambient. +!!! error TS2610: Property 'b' will overwrite the base property in 'T2'. Add a 'declare' modifier or an initializer to avoid this. class C3 extends Constructor() { length: string } ~~~~~~ !!! error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'. !!! error TS2416: Type 'string' is not assignable to type 'number'. ~~~~~~ -!!! error TS2610: Class 'number[]' defines instance member property 'length', so extended class 'C3' must use 'declare' to make it ambient. +!!! error TS2610: Property 'length' will overwrite the base property in 'number[]'. Add a 'declare' modifier or an initializer to avoid this. class C4 extends Constructor() { 0: number } ~ !!! error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'. !!! error TS2416: Type 'number' is not assignable to type 'string'. ~ -!!! error TS2610: Class '[string, number]' defines instance member property '0', so extended class 'C4' must use 'declare' to make it ambient. +!!! error TS2610: Property '0' will overwrite the base property in '[string, number]'. Add a 'declare' modifier or an initializer to avoid this. class C5 extends Constructor() { c: number } ~ !!! error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'T5'. !!! error TS2416: Type 'number' is not assignable to type 'string'. ~ -!!! error TS2610: Class 'T5' defines instance member property 'c', so extended class 'C5' must use 'declare' to make it ambient. +!!! error TS2610: Property 'c' will overwrite the base property in 'T5'. Add a 'declare' modifier or an initializer to avoid this. declare class CX { static a: string } declare enum EX { A, B, C } diff --git a/tests/baselines/reference/multipleInheritance.errors.txt b/tests/baselines/reference/multipleInheritance.errors.txt index 0f4e79738e9e6..2e3788c895de9 100644 --- a/tests/baselines/reference/multipleInheritance.errors.txt +++ b/tests/baselines/reference/multipleInheritance.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/multipleInheritance.ts(9,21): error TS1174: Classes can only extend a single class. tests/cases/compiler/multipleInheritance.ts(18,21): error TS1174: Classes can only extend a single class. -tests/cases/compiler/multipleInheritance.ts(26,12): error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must use 'declare' to make it ambient. +tests/cases/compiler/multipleInheritance.ts(26,12): error TS2610: Property 'y' will overwrite the base property in 'N'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/compiler/multipleInheritance.ts(35,12): error TS2425: Class 'Good' defines instance member property 'f', but extended class 'Baad' defines it as instance member function. tests/cases/compiler/multipleInheritance.ts(36,12): error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type 'Good'. Type '(n: number) => number' is not assignable to type '() => number'. @@ -38,7 +38,7 @@ tests/cases/compiler/multipleInheritance.ts(36,12): error TS2416: Property 'g' i class ND extends N { // any is assignable to number public y; ~ -!!! error TS2610: Class 'N' defines instance member property 'y', so extended class 'ND' must use 'declare' to make it ambient. +!!! error TS2610: Property 'y' will overwrite the base property in 'N'. Add a 'declare' modifier or an initializer to avoid this. } class Good { diff --git a/tests/baselines/reference/mutuallyRecursiveInference.errors.txt b/tests/baselines/reference/mutuallyRecursiveInference.errors.txt index f6b5d58430f4b..cdb3abea28fee 100644 --- a/tests/baselines/reference/mutuallyRecursiveInference.errors.txt +++ b/tests/baselines/reference/mutuallyRecursiveInference.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/mutuallyRecursiveInference.ts(9,5): error TS2610: Class 'L' defines instance member property 'a', so extended class 'X' must use 'declare' to make it ambient. -tests/cases/compiler/mutuallyRecursiveInference.ts(10,5): error TS2610: Class 'L' defines instance member property 'b', so extended class 'X' must use 'declare' to make it ambient. +tests/cases/compiler/mutuallyRecursiveInference.ts(9,5): error TS2610: Property 'a' will overwrite the base property in 'L'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/compiler/mutuallyRecursiveInference.ts(10,5): error TS2610: Property 'b' will overwrite the base property in 'L'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/compiler/mutuallyRecursiveInference.ts (2 errors) ==== @@ -13,10 +13,10 @@ tests/cases/compiler/mutuallyRecursiveInference.ts(10,5): error TS2610: Class 'L class X extends L { a: 'a' | 'b' ~ -!!! error TS2610: Class 'L' defines instance member property 'a', so extended class 'X' must use 'declare' to make it ambient. +!!! error TS2610: Property 'a' will overwrite the base property in 'L'. Add a 'declare' modifier or an initializer to avoid this. b: number ~ -!!! error TS2610: Class 'L' defines instance member property 'b', so extended class 'X' must use 'declare' to make it ambient. +!!! error TS2610: Property 'b' will overwrite the base property in 'L'. Add a 'declare' modifier or an initializer to avoid this. m2() { this.a } diff --git a/tests/baselines/reference/protectedMembers.errors.txt b/tests/baselines/reference/protectedMembers.errors.txt index da2be41e9488e..563a4a757fc6c 100644 --- a/tests/baselines/reference/protectedMembers.errors.txt +++ b/tests/baselines/reference/protectedMembers.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/protectedMembers.ts(25,5): error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must use 'declare' to make it ambient. +tests/cases/compiler/protectedMembers.ts(25,5): error TS2610: Property 'x' will overwrite the base property in 'C2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/compiler/protectedMembers.ts(40,4): error TS2445: Property 'x' is protected and only accessible within class 'C1' and its subclasses. tests/cases/compiler/protectedMembers.ts(41,4): error TS2445: Property 'f' is protected and only accessible within class 'C1' and its subclasses. tests/cases/compiler/protectedMembers.ts(42,4): error TS2445: Property 'sx' is protected and only accessible within class 'C1' and its subclasses. @@ -13,10 +13,10 @@ tests/cases/compiler/protectedMembers.ts(97,1): error TS2322: Type 'B1' is not a Property 'x' is protected but type 'B1' is not a class derived from 'A1'. tests/cases/compiler/protectedMembers.ts(98,1): error TS2322: Type 'A1' is not assignable to type 'B1'. Property 'x' is protected in type 'A1' but public in type 'B1'. -tests/cases/compiler/protectedMembers.ts(104,5): error TS2610: Class 'A2' defines instance member property 'x', so extended class 'B2' must use 'declare' to make it ambient. +tests/cases/compiler/protectedMembers.ts(104,5): error TS2610: Property 'x' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/compiler/protectedMembers.ts(111,7): error TS2415: Class 'B3' incorrectly extends base class 'A3'. Property 'x' is protected in type 'B3' but public in type 'A3'. -tests/cases/compiler/protectedMembers.ts(112,15): error TS2610: Class 'A3' defines instance member property 'x', so extended class 'B3' must use 'declare' to make it ambient. +tests/cases/compiler/protectedMembers.ts(112,15): error TS2610: Property 'x' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/compiler/protectedMembers.ts (16 errors) ==== @@ -46,7 +46,7 @@ tests/cases/compiler/protectedMembers.ts(112,15): error TS2610: Class 'A3' defin class C3 extends C2 { x: number; ~ -!!! error TS2610: Class 'C2' defines instance member property 'x', so extended class 'C3' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'C2'. Add a 'declare' modifier or an initializer to avoid this. static sx: number; f() { return super.f(); @@ -153,7 +153,7 @@ tests/cases/compiler/protectedMembers.ts(112,15): error TS2610: Class 'A3' defin class B2 extends A2 { x; ~ -!!! error TS2610: Class 'A2' defines instance member property 'x', so extended class 'B2' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. } class A3 { @@ -166,7 +166,7 @@ tests/cases/compiler/protectedMembers.ts(112,15): error TS2610: Class 'A3' defin !!! error TS2415: Property 'x' is protected in type 'B3' but public in type 'A3'. protected x; ~ -!!! error TS2610: Class 'A3' defines instance member property 'x', so extended class 'B3' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/scopeTests.errors.txt b/tests/baselines/reference/scopeTests.errors.txt index cfafac1e1cada..362da88655557 100644 --- a/tests/baselines/reference/scopeTests.errors.txt +++ b/tests/baselines/reference/scopeTests.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/scopeTests.ts(2,7): error TS2415: Class 'D' incorrectly extends base class 'C'. Property 'v' is private in type 'C' but not in type 'D'. -tests/cases/compiler/scopeTests.ts(4,10): error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must use 'declare' to make it ambient. +tests/cases/compiler/scopeTests.ts(4,10): error TS2610: Property 'p' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/compiler/scopeTests.ts (2 errors) ==== @@ -12,7 +12,7 @@ tests/cases/compiler/scopeTests.ts(4,10): error TS2610: Class 'C' defines instan public v: number; public p: number ~ -!!! error TS2610: Class 'C' defines instance member property 'p', so extended class 'D' must use 'declare' to make it ambient. +!!! error TS2610: Property 'p' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. constructor() { super() this.v = 1; diff --git a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt index 44c8e7ba6a51d..33f7c1d48ec2d 100644 --- a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(8,5): error TS2416: Property 'foo' in type 'D1' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(8,5): error TS2610: Class 'C3' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(8,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts (2 errors) ==== @@ -18,7 +18,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. ~~~ -!!! error TS2610: Class 'C3' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } function f1(x: T, y: U) { diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt index d1b6e7efe3aef..d951b47e4cff9 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt @@ -1,33 +1,33 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(37,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(42,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(37,5): error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(42,5): error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'Foo'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(52,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(52,5): error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2416: Property 'foo' in type 'D5' is not assignable to the same property in base type 'B1'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. Type 'Foo' is not assignable to type 'T'. 'Foo' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'B1'. Type 'T' is not assignable to type 'U'. 'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. Type 'Foo' is not assignable to type 'U'. 'Foo' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(72,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(72,5): error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2416: Property 'foo' in type 'D9' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts (19 errors) ==== @@ -69,14 +69,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: Foo; foo: T; // ok ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D2 extends B1 { [x: string]: Foo; foo: U; // ok ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D3 extends B1 { @@ -88,14 +88,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'Foo'. ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D4 extends B1 { [x: string]: T; foo: T; // ok ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D5 extends B1 { @@ -110,7 +110,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'T'. !!! error TS2416: 'Foo' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D6 extends B1 { @@ -122,7 +122,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'T'. ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D7 extends B1 { @@ -137,14 +137,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'U'. !!! error TS2416: 'Foo' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D8 extends B1 { [x: string]: U; foo: U; // ok ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D9 extends B1 { @@ -156,5 +156,5 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D9' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'U'. ~~~ -!!! error TS2610: Class 'B1' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt index 5ef5c6aa184ed..f1c67351d3370 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt @@ -1,81 +1,81 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(63,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(63,9): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2416: Property 'foo' in type 'D2' is not assignable to the same property in base type 'Base'. Type 'U' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base'. Type 'V' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2416: Property 'foo' in type 'D4' is not assignable to the same property in base type 'Base'. Type 'T' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(83,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(83,9): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base'. Type 'V' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base'. Type 'T' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base'. Type 'U' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(103,9): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(103,9): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(115,9): error TS2416: Property 'foo' in type 'D1' is not assignable to the same property in base type 'Base2'. Type 'T' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'U' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(115,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(115,9): error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(120,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(120,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(120,9): error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base2'. Type 'V' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'V' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(130,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(130,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(130,9): error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(135,9): error TS2416: Property 'foo' in type 'D5' is not assignable to the same property in base type 'Base2'. Type 'U' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'T' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(135,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(135,9): error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base2'. Type 'V' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'V' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base2'. Type 'T' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'U' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base2'. Type 'U' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'T' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(155,9): error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(155,9): error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts (42 errors) ==== @@ -143,7 +143,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: T ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D2, U extends Foo, V extends Foo> extends Base { @@ -156,7 +156,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D3, U extends Foo, V extends Foo> extends Base { @@ -169,7 +169,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D4, U extends Foo, V extends Foo> extends Base { @@ -182,14 +182,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'T' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D5, U extends Foo, V extends Foo> extends Base { [x: string]: U; foo: U ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D6, U extends Foo, V extends Foo> extends Base { @@ -202,7 +202,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'V' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D7, U extends Foo, V extends Foo> extends Base { @@ -215,7 +215,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'T' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D8, U extends Foo, V extends Foo> extends Base { @@ -228,14 +228,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'U' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D9, U extends Foo, V extends Foo> extends Base { [x: string]: V; foo: V ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } } @@ -255,7 +255,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D2, U extends Foo, V extends Foo> extends Base2 { @@ -264,7 +264,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~ !!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D3, U extends Foo, V extends Foo> extends Base2 { @@ -279,7 +279,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D4, U extends Foo, V extends Foo> extends Base2 { @@ -288,7 +288,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~ !!! error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D5, U extends Foo, V extends Foo> extends Base2 { @@ -301,7 +301,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'T' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D6, U extends Foo, V extends Foo> extends Base2 { @@ -316,7 +316,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'V' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D7, U extends Foo, V extends Foo> extends Base2 { @@ -331,7 +331,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'U' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D8, U extends Foo, V extends Foo> extends Base2 { @@ -346,13 +346,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'T' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D9, U extends Foo, V extends Foo> extends Base2 { [x: string]: V; foo: V ~~~ -!!! error TS2610: Class 'Base2' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } } \ No newline at end of file diff --git a/tests/baselines/reference/subtypingTransitivity.errors.txt b/tests/baselines/reference/subtypingTransitivity.errors.txt index c2ca02697cdd4..aed2b0a7220b7 100644 --- a/tests/baselines/reference/subtypingTransitivity.errors.txt +++ b/tests/baselines/reference/subtypingTransitivity.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/subtypingTransitivity.ts(6,12): error TS2610: Class 'B' defines instance member property 'x', so extended class 'D' must use 'declare' to make it ambient. -tests/cases/compiler/subtypingTransitivity.ts(9,12): error TS2610: Class 'B' defines instance member property 'x', so extended class 'D2' must use 'declare' to make it ambient. +tests/cases/compiler/subtypingTransitivity.ts(6,12): error TS2610: Property 'x' will overwrite the base property in 'B'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/compiler/subtypingTransitivity.ts(9,12): error TS2610: Property 'x' will overwrite the base property in 'B'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/compiler/subtypingTransitivity.ts (2 errors) ==== @@ -10,12 +10,12 @@ tests/cases/compiler/subtypingTransitivity.ts(9,12): error TS2610: Class 'B' def class D extends B { public x: string; ~ -!!! error TS2610: Class 'B' defines instance member property 'x', so extended class 'D' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'B'. Add a 'declare' modifier or an initializer to avoid this. } class D2 extends B { public x: number; ~ -!!! error TS2610: Class 'B' defines instance member property 'x', so extended class 'D2' must use 'declare' to make it ambient. +!!! error TS2610: Property 'x' will overwrite the base property in 'B'. Add a 'declare' modifier or an initializer to avoid this. } var b: B; diff --git a/tests/baselines/reference/subtypingWithObjectMembers.errors.txt b/tests/baselines/reference/subtypingWithObjectMembers.errors.txt index b748602a82bf1..140fef4236192 100644 --- a/tests/baselines/reference/subtypingWithObjectMembers.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembers.errors.txt @@ -1,27 +1,27 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(13,5): error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(13,5): error TS2610: Property 'foo' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(14,5): error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(14,5): error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(23,5): error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(14,5): error TS2610: Property 'bar' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(23,5): error TS2610: Property '1' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(24,5): error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(24,5): error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(33,5): error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(24,5): error TS2610: Property '2.0' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(33,5): error TS2610: Property ''1'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(34,5): error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(34,5): error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(44,9): error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(34,5): error TS2610: Property ''2.0'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(44,9): error TS2610: Property 'foo' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(45,9): error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(45,9): error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(54,9): error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(45,9): error TS2610: Property 'bar' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(54,9): error TS2610: Property '1' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(55,9): error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(55,9): error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(64,9): error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(55,9): error TS2610: Property '2.0' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(64,9): error TS2610: Property ''1'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(65,9): error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(65,9): error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(65,9): error TS2610: Property ''2.0'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts (18 errors) ==== @@ -39,13 +39,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { foo: Derived; // ok ~~~ -!!! error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. bar: string; // error ~~~ !!! error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. ~~~ -!!! error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must use 'declare' to make it ambient. +!!! error TS2610: Property 'bar' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. } class A2 { @@ -56,13 +56,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B2 extends A2 { 1: Derived; // ok ~ -!!! error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must use 'declare' to make it ambient. +!!! error TS2610: Property '1' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. 2: string; // error ~ !!! error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. ~ -!!! error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must use 'declare' to make it ambient. +!!! error TS2610: Property '2.0' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. } class A3 { @@ -73,13 +73,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A3 { '1': Derived; // ok ~~~ -!!! error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must use 'declare' to make it ambient. +!!! error TS2610: Property ''1'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. '2.0': string; // error ~~~~~ !!! error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. ~~~~~ -!!! error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must use 'declare' to make it ambient. +!!! error TS2610: Property ''2.0'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. } module TwoLevels { @@ -91,13 +91,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { foo: Derived2; // ok ~~~ -!!! error TS2610: Class 'A' defines instance member property 'foo', so extended class 'B' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. bar: string; // error ~~~ !!! error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. ~~~ -!!! error TS2610: Class 'A' defines instance member property 'bar', so extended class 'B' must use 'declare' to make it ambient. +!!! error TS2610: Property 'bar' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. } class A2 { @@ -108,13 +108,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B2 extends A2 { 1: Derived2; // ok ~ -!!! error TS2610: Class 'A2' defines instance member property '1', so extended class 'B2' must use 'declare' to make it ambient. +!!! error TS2610: Property '1' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. 2: string; // error ~ !!! error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. ~ -!!! error TS2610: Class 'A2' defines instance member property '2.0', so extended class 'B2' must use 'declare' to make it ambient. +!!! error TS2610: Property '2.0' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. } class A3 { @@ -125,12 +125,12 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A3 { '1': Derived2; // ok ~~~ -!!! error TS2610: Class 'A3' defines instance member property ''1'', so extended class 'B3' must use 'declare' to make it ambient. +!!! error TS2610: Property ''1'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. '2.0': string; // error ~~~~~ !!! error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. ~~~~~ -!!! error TS2610: Class 'A3' defines instance member property ''2.0'', so extended class 'B3' must use 'declare' to make it ambient. +!!! error TS2610: Property ''2.0'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. } } \ No newline at end of file diff --git a/tests/baselines/reference/tsxGenericAttributesType5.errors.txt b/tests/baselines/reference/tsxGenericAttributesType5.errors.txt index 5143478df0c47..602526de4dfcc 100644 --- a/tests/baselines/reference/tsxGenericAttributesType5.errors.txt +++ b/tests/baselines/reference/tsxGenericAttributesType5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must use 'declare' to make it ambient. +tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Property 'props' will overwrite the base property in 'Component'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== @@ -12,7 +12,7 @@ tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Class 'Component class B extends React.Component { props: U; ~~~~~ -!!! error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must use 'declare' to make it ambient. +!!! error TS2610: Property 'props' will overwrite the base property in 'Component'. Add a 'declare' modifier or an initializer to avoid this. render() { return ; } diff --git a/tests/baselines/reference/tsxGenericAttributesType6.errors.txt b/tests/baselines/reference/tsxGenericAttributesType6.errors.txt index e1933e9a5c670..a75ae10b22a2d 100644 --- a/tests/baselines/reference/tsxGenericAttributesType6.errors.txt +++ b/tests/baselines/reference/tsxGenericAttributesType6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must use 'declare' to make it ambient. +tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Property 'props' will overwrite the base property in 'Component'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== @@ -12,7 +12,7 @@ tests/cases/conformance/jsx/file.tsx(9,5): error TS2610: Class 'Component class B extends React.Component { props: U; ~~~~~ -!!! error TS2610: Class 'Component' defines instance member property 'props', so extended class 'B' must use 'declare' to make it ambient. +!!! error TS2610: Property 'props' will overwrite the base property in 'Component'. Add a 'declare' modifier or an initializer to avoid this. render() { return ; } diff --git a/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt b/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt index eb283445e2327..021d240b8a533 100644 --- a/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt +++ b/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt @@ -1,25 +1,25 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(8,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D0' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(12,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'DA' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(16,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(20,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1A' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(25,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(29,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2A' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(34,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(38,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3A' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(43,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(47,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(52,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(56,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(61,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(68,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(73,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D10' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(78,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D11' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(86,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D12' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(95,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D13' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(100,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D14' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(105,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D15' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(114,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D16' must use 'declare' to make it ambient. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(119,5): error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D17' must use 'declare' to make it ambient. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(8,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(12,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(16,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(20,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(25,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(29,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(34,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(38,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(43,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(47,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(52,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(56,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(61,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(68,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(73,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(78,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(86,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(95,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(100,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(105,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(114,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(119,5): error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts (22 errors) ==== @@ -32,84 +32,84 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedI class D0 extends Base { foo: any; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D0' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class DA extends Base { foo: typeof undefined; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'DA' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D1 extends Base { foo: string; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D1A extends Base { foo: String; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D1A' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D2 extends Base { foo: number; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D2A extends Base { foo: Number; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D2A' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D3 extends Base { foo: boolean; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D3A extends Base { foo: Boolean; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D3A' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D4 extends Base { foo: RegExp; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D4' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D5 extends Base { foo: Date; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D5' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D6 extends Base { foo: number[]; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D6' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D7 extends Base { foo: { bar: number }; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D7' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D8 extends Base { foo: D7; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D8' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } interface I1 { @@ -118,21 +118,21 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedI class D9 extends Base { foo: I1; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D9' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D10 extends Base { foo: () => number; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D10' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } enum E { A } class D11 extends Base { foo: E; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D11' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } function f() { } @@ -142,7 +142,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedI class D12 extends Base { foo: typeof f; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D12' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } @@ -153,21 +153,21 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedI class D13 extends Base { foo: typeof c; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D13' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D14 extends Base { foo: T; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D14' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D15 extends Base { foo: U; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D15' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } //class D15 extends Base { @@ -178,13 +178,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedI class D16 extends Base { foo: Object; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D16' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D17 extends Base { foo: {}; ~~~ -!!! error TS2610: Class 'Base' defines instance member property 'foo', so extended class 'D17' must use 'declare' to make it ambient. +!!! error TS2610: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file From f11f2beb5e287b891022335030a36da3ab0ac49a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 17 Sep 2019 09:21:15 -0700 Subject: [PATCH 09/44] Add codefix to add missing 'declare' --- src/compiler/diagnosticMessages.json | 8 +++++ .../codefixes/addMissingDeclareProperty.ts | 34 +++++++++++++++++++ src/services/tsconfig.json | 1 + .../codeFixAddMissingDeclareProperty.ts | 18 ++++++++++ .../codeFixAddMissingDeclareProperty2.ts | 25 ++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 src/services/codefixes/addMissingDeclareProperty.ts create mode 100644 tests/cases/fourslash/codeFixAddMissingDeclareProperty.ts create mode 100644 tests/cases/fourslash/codeFixAddMissingDeclareProperty2.ts diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index baa77494e818b..b8cbb418b1d52 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -5148,6 +5148,14 @@ "category": "Message", "code": 95092 }, + "Prefix with 'declare'": { + "category": "Message", + "code": 95093 + }, + "Prefix all incorrect property declarations with 'declare'": { + "category": "Message", + "code": 95094 + }, "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": { "category": "Error", diff --git a/src/services/codefixes/addMissingDeclareProperty.ts b/src/services/codefixes/addMissingDeclareProperty.ts new file mode 100644 index 0000000000000..002357239ead2 --- /dev/null +++ b/src/services/codefixes/addMissingDeclareProperty.ts @@ -0,0 +1,34 @@ +/* @internal */ +namespace ts.codefix { + const fixId = "addMissingDeclareProperty"; + const errorCodes = [ + Diagnostics.Property_0_will_overwrite_the_base_property_in_1_Add_a_declare_modifier_or_an_initializer_to_avoid_this.code, + ]; + + registerCodeFix({ + errorCodes, + getCodeActions: (context) => { + const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start)); + if (changes.length > 0) { + return [createCodeFixAction(fixId, changes, Diagnostics.Prefix_with_declare, fixId, Diagnostics.Prefix_all_incorrect_property_declarations_with_declare)]; + } + }, + fixIds: [fixId], + getAllCodeActions: context => { + const fixedNodes = new NodeSet(); + return codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag.start, fixedNodes)); + }, + }); + + function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number, fixedNodes?: NodeSet) { + const token = getTokenAtPosition(sourceFile, pos); + if (!isIdentifier(token)) { + return; + } + const declaration = token.parent; + if (declaration.kind === SyntaxKind.PropertyDeclaration && + (!fixedNodes || fixedNodes.tryAdd(declaration))) { + changeTracker.insertModifierBefore(sourceFile, SyntaxKind.DeclareKeyword, declaration); + } + } +} diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index 74495bc54f88b..32472fb776f44 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -47,6 +47,7 @@ "codefixes/addConvertToUnknownForNonOverlappingTypes.ts", "codefixes/addMissingAwait.ts", "codefixes/addMissingConst.ts", + "codefixes/addMissingDeclareProperty.ts", "codefixes/addMissingInvocationForDecorator.ts", "codefixes/addNameToNamelessParameter.ts", "codefixes/annotateWithTypeFromJSDoc.ts", diff --git a/tests/cases/fourslash/codeFixAddMissingDeclareProperty.ts b/tests/cases/fourslash/codeFixAddMissingDeclareProperty.ts new file mode 100644 index 0000000000000..90dcbdd86ba8d --- /dev/null +++ b/tests/cases/fourslash/codeFixAddMissingDeclareProperty.ts @@ -0,0 +1,18 @@ +/// + +////class B { +//// p = 1 +////} +////class C extends B { +//// p: number +////} + +verify.codeFix({ + description: "Prefix with 'declare'", + newFileContent: `class B { + p = 1 +} +class C extends B { + declare p: number +}` +}); diff --git a/tests/cases/fourslash/codeFixAddMissingDeclareProperty2.ts b/tests/cases/fourslash/codeFixAddMissingDeclareProperty2.ts new file mode 100644 index 0000000000000..32dc21d9a2753 --- /dev/null +++ b/tests/cases/fourslash/codeFixAddMissingDeclareProperty2.ts @@ -0,0 +1,25 @@ +/// + +////class B { +//// p = 1 +////} +////class C extends B { +//// p: number +////} +////class D extends B { +//// p: 1 | 2 | 3 +////} + +verify.codeFixAll({ + fixId: "addMissingDeclareProperty", + fixAllDescription: "Prefix all incorrect property declarations with 'declare'", + newFileContent: `class B { + p = 1 +} +class C extends B { + declare p: number +} +class D extends B { + declare p: 1 | 2 | 3 +}` +}); From 2238b66f840a8d35aa2f8225166c470526fc50d5 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 17 Sep 2019 10:37:30 -0700 Subject: [PATCH 10/44] Always emit accessors in .d.ts files --- src/compiler/transformers/declarations.ts | 75 +++++-------------- tests/baselines/reference/classdecl.js | 7 +- .../reference/commentsdoNotEmitComments.js | 3 +- .../reference/commentsemitComments.js | 3 +- .../baselines/reference/declFileAccessors.js | 44 +++++++---- .../reference/declFilePrivateStatic.js | 8 +- ...eTypeAnnotationVisibilityErrorAccessors.js | 36 +++++---- .../declarationEmitClassMemberNameConflict.js | 4 +- .../declarationEmitProtectedMembers.js | 9 ++- .../baselines/reference/dynamicNamesErrors.js | 8 +- .../isDeclarationVisibleNodeKinds.js | 4 +- tests/baselines/reference/properties.js | 3 +- .../reference/readonlyInDeclarationFile.js | 30 +++++--- .../reference/symbolDeclarationEmit11.js | 3 +- .../reference/symbolDeclarationEmit12.js | 4 +- .../reference/symbolDeclarationEmit13.js | 4 +- .../reference/symbolDeclarationEmit14.js | 4 +- .../reference/symbolDeclarationEmit4.js | 3 +- .../reference/typeGuardOfFormThisMember.js | 5 +- .../typeGuardOfFormThisMemberErrors.js | 5 +- .../uniqueSymbolsDeclarationsErrors.js | 6 +- 21 files changed, 131 insertions(+), 137 deletions(-) diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 2b2a75e3c24c3..add17449edf3d 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -86,7 +86,6 @@ namespace ts { let emittedImports: readonly AnyImportSyntax[] | undefined; // must be declared in container so it can be `undefined` while transformer's first pass const resolver = context.getEmitResolver(); const options = context.getCompilerOptions(); - const newLine = getNewLineCharacter(options); const { noResolve, stripInternal } = options; return transformRoot; @@ -861,35 +860,25 @@ namespace ts { return cleanup(sig); } case SyntaxKind.GetAccessor: { - // For now, only emit class accessors as accessors if they were already declared in an ambient context. - if (input.flags & NodeFlags.Ambient) { - const isPrivate = hasModifier(input, ModifierFlags.Private); - const accessorType = getTypeAnnotationFromAllAccessorDeclarations(input, resolver.getAllAccessorDeclarations(input)); - return cleanup(updateGetAccessor( - input, - /*decorators*/ undefined, - ensureModifiers(input), - input.name, - updateAccessorParamsList(input, isPrivate), - !isPrivate ? ensureType(input, accessorType) : undefined, - /*body*/ undefined)); - } - const newNode = ensureAccessor(input); - return cleanup(newNode); + const isPrivate = hasModifier(input, ModifierFlags.Private); + const accessorType = getTypeAnnotationFromAllAccessorDeclarations(input, resolver.getAllAccessorDeclarations(input)); + return cleanup(updateGetAccessor( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + updateAccessorParamsList(input, isPrivate), + !isPrivate ? ensureType(input, accessorType) : undefined, + /*body*/ undefined)); } case SyntaxKind.SetAccessor: { - // For now, only emit class accessors as accessors if they were already declared in an ambient context. - if (input.flags & NodeFlags.Ambient) { - return cleanup(updateSetAccessor( - input, - /*decorators*/ undefined, - ensureModifiers(input), - input.name, - updateAccessorParamsList(input, hasModifier(input, ModifierFlags.Private)), - /*body*/ undefined)); - } - const newNode = ensureAccessor(input); - return cleanup(newNode); + return cleanup(updateSetAccessor( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + updateAccessorParamsList(input, hasModifier(input, ModifierFlags.Private)), + /*body*/ undefined)); } case SyntaxKind.PropertyDeclaration: return cleanup(updateProperty( @@ -1462,36 +1451,6 @@ namespace ts { return accessorType; } - function ensureAccessor(node: AccessorDeclaration): PropertyDeclaration | undefined { - const accessors = resolver.getAllAccessorDeclarations(node); - if (node.kind !== accessors.firstAccessor.kind) { - return; - } - const accessorType = getTypeAnnotationFromAllAccessorDeclarations(node, accessors); - const prop = createProperty(/*decorators*/ undefined, maskModifiers(node, /*mask*/ undefined, (!accessors.setAccessor) ? ModifierFlags.Readonly : ModifierFlags.None), node.name, node.questionToken, ensureType(node, accessorType), /*initializer*/ undefined); - const leadingsSyntheticCommentRanges = accessors.secondAccessor && getLeadingCommentRangesOfNode(accessors.secondAccessor, currentSourceFile); - if (leadingsSyntheticCommentRanges) { - for (const range of leadingsSyntheticCommentRanges) { - if (range.kind === SyntaxKind.MultiLineCommentTrivia) { - let text = currentSourceFile.text.slice(range.pos + 2, range.end - 2); - const lines = text.split(/\r\n?|\n/g); - if (lines.length > 1) { - const lastLines = lines.slice(1); - const indentation = guessIndentation(lastLines); - text = [lines[0], ...map(lastLines, l => l.slice(indentation))].join(newLine); - } - addSyntheticLeadingComment( - prop, - range.kind, - text, - range.hasTrailingNewLine - ); - } - } - } - return prop; - } - function transformHeritageClauses(nodes: NodeArray | undefined) { return createNodeArray(filter(map(nodes, clause => updateHeritageClause(clause, visitNodes(createNodeArray(filter(clause.types, t => { return isEntityNameExpression(t.expression) || (clause.token === SyntaxKind.ExtendsKeyword && t.expression.kind === SyntaxKind.NullKeyword); diff --git a/tests/baselines/reference/classdecl.js b/tests/baselines/reference/classdecl.js index 42dd8b7d114ab..43d67d0cb1110 100644 --- a/tests/baselines/reference/classdecl.js +++ b/tests/baselines/reference/classdecl.js @@ -218,13 +218,14 @@ declare class a { constructor(s: string); pgF(): void; pv: any; - d: number; - static readonly p2: { + get d(): number; + set d(a: number); + static get p2(): { x: number; y: number; }; private static d2; - private static readonly p3; + private static get p3(); private pv3; private foo; } diff --git a/tests/baselines/reference/commentsdoNotEmitComments.js b/tests/baselines/reference/commentsdoNotEmitComments.js index ae7442f109a64..865ae43c4de22 100644 --- a/tests/baselines/reference/commentsdoNotEmitComments.js +++ b/tests/baselines/reference/commentsdoNotEmitComments.js @@ -144,7 +144,8 @@ declare class c { constructor(); b: number; myFoo(): number; - prop1: number; + get prop1(): number; + set prop1(val: number); foo1(a: number): string; foo1(b: string): string; } diff --git a/tests/baselines/reference/commentsemitComments.js b/tests/baselines/reference/commentsemitComments.js index dd8f3608cf33f..8bfb1c59c9abd 100644 --- a/tests/baselines/reference/commentsemitComments.js +++ b/tests/baselines/reference/commentsemitComments.js @@ -160,8 +160,9 @@ declare class c { /** function comment */ myFoo(): number; /** getter comment*/ + get prop1(): number; /** setter comment*/ - prop1: number; + set prop1(val: number); /** overload signature1*/ foo1(a: number): string; /** Overload signature 2*/ diff --git a/tests/baselines/reference/declFileAccessors.js b/tests/baselines/reference/declFileAccessors.js index c6175ec7ede0a..103f86d688e69 100644 --- a/tests/baselines/reference/declFileAccessors.js +++ b/tests/baselines/reference/declFileAccessors.js @@ -273,35 +273,47 @@ var c2 = /** @class */ (function () { /** This is comment for c1*/ export declare class c1 { /** getter property*/ + get p3(): number; /** setter property*/ - p3: number; + set p3(/** this is value*/ value: number); /** private getter property*/ + private get pp3(); /** private setter property*/ - private pp3; + private set pp3(value); /** static getter property*/ + static get s3(): number; /** setter property*/ - static s3: number; - nc_p3: number; - private nc_pp3; - static nc_s3: string; - readonly onlyGetter: number; - onlySetter: number; + static set s3(/** this is value*/ value: number); + get nc_p3(): number; + set nc_p3(value: number); + private get nc_pp3(); + private set nc_pp3(value); + static get nc_s3(): string; + static set nc_s3(value: string); + get onlyGetter(): number; + set onlySetter(value: number); } //// [declFileAccessors_1.d.ts] /** This is comment for c2 - the global class*/ declare class c2 { /** getter property*/ + get p3(): number; /** setter property*/ - p3: number; + set p3(/** this is value*/ value: number); /** private getter property*/ + private get pp3(); /** private setter property*/ - private pp3; + private set pp3(value); /** static getter property*/ + static get s3(): number; /** setter property*/ - static s3: number; - nc_p3: number; - private nc_pp3; - static nc_s3: string; - readonly onlyGetter: number; - onlySetter: number; + static set s3(/** this is value*/ value: number); + get nc_p3(): number; + set nc_p3(value: number); + private get nc_pp3(); + private set nc_pp3(value); + static get nc_s3(): string; + static set nc_s3(value: string); + get onlyGetter(): number; + set onlySetter(value: number); } diff --git a/tests/baselines/reference/declFilePrivateStatic.js b/tests/baselines/reference/declFilePrivateStatic.js index 67469327265b5..9dd2adc8c59ef 100644 --- a/tests/baselines/reference/declFilePrivateStatic.js +++ b/tests/baselines/reference/declFilePrivateStatic.js @@ -51,8 +51,8 @@ declare class C { static y: number; private static a; static b(): void; - private static readonly c; - static readonly d: number; - private static e; - static f: any; + private static get c(); + static get d(): number; + private static set e(value); + static set f(v: any); } diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorAccessors.js b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorAccessors.js index 6018176153396..598ac67c20ed5 100644 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorAccessors.js +++ b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorAccessors.js @@ -271,21 +271,27 @@ declare module m { } } export class c { - readonly foo1: private1; - readonly foo2: private1; - foo3: private1; - foo4: private1; - foo5: private1; - readonly foo11: public1; - readonly foo12: public1; - foo13: public1; - foo14: public1; - foo15: public1; - readonly foo111: m2.public2; - readonly foo112: m2.public2; - foo113: m2.public2; - foo114: m2.public2; - foo115: m2.public2; + get foo1(): private1; + get foo2(): private1; + set foo3(param: private1); + get foo4(): private1; + set foo4(param: private1); + get foo5(): private1; + set foo5(param: private1); + get foo11(): public1; + get foo12(): public1; + set foo13(param: public1); + get foo14(): public1; + set foo14(param: public1); + get foo15(): public1; + set foo15(param: public1); + get foo111(): m2.public2; + get foo112(): m2.public2; + set foo113(param: m2.public2); + get foo114(): m2.public2; + set foo114(param: m2.public2); + get foo115(): m2.public2; + set foo115(param: m2.public2); } export {}; } diff --git a/tests/baselines/reference/declarationEmitClassMemberNameConflict.js b/tests/baselines/reference/declarationEmitClassMemberNameConflict.js index 77732ea94f889..43523aba38f0e 100644 --- a/tests/baselines/reference/declarationEmitClassMemberNameConflict.js +++ b/tests/baselines/reference/declarationEmitClassMemberNameConflict.js @@ -103,10 +103,10 @@ export declare class C2 { bar(): (t: typeof C2) => void; } export declare class C3 { - readonly C3: number; + get C3(): number; bar(): (t: typeof C3) => void; } export declare class C4 { - C4: any; + set C4(v: any); bar(): (t: typeof C4) => void; } diff --git a/tests/baselines/reference/declarationEmitProtectedMembers.js b/tests/baselines/reference/declarationEmitProtectedMembers.js index fb0a9cb933914..e0a2b40ffd50c 100644 --- a/tests/baselines/reference/declarationEmitProtectedMembers.js +++ b/tests/baselines/reference/declarationEmitProtectedMembers.js @@ -138,11 +138,12 @@ var C4 = /** @class */ (function () { declare class C1 { protected x: number; protected f(): number; - protected accessor: number; + protected set accessor(a: number); + protected get accessor(): number; protected static sx: number; protected static sf(): number; - protected static staticSetter: number; - protected static readonly staticGetter: number; + protected static set staticSetter(a: number); + protected static get staticGetter(): number; } declare class C2 extends C1 { protected f(): number; @@ -153,7 +154,7 @@ declare class C3 extends C2 { static sx: number; f(): number; static sf(): number; - static readonly staticGetter: number; + static get staticGetter(): number; } declare class C4 { protected a: number; diff --git a/tests/baselines/reference/dynamicNamesErrors.js b/tests/baselines/reference/dynamicNamesErrors.js index ff6bdec604f31..8433527d73fd6 100644 --- a/tests/baselines/reference/dynamicNamesErrors.js +++ b/tests/baselines/reference/dynamicNamesErrors.js @@ -101,12 +101,12 @@ export interface InterfaceMemberVisibility { export declare class ClassMemberVisibility { static [x]: number; static [y](): number; - static readonly [z]: number; - static [w]: number; + static get [z](): number; + static set [w](value: number); [x]: number; [y](): number; - readonly [z]: number; - [w]: number; + get [z](): number; + set [w](value: number); } export declare type ObjectTypeVisibility = { [x]: number; diff --git a/tests/baselines/reference/isDeclarationVisibleNodeKinds.js b/tests/baselines/reference/isDeclarationVisibleNodeKinds.js index 83a926ab7d2eb..40f5e59083c0c 100644 --- a/tests/baselines/reference/isDeclarationVisibleNodeKinds.js +++ b/tests/baselines/reference/isDeclarationVisibleNodeKinds.js @@ -184,7 +184,7 @@ declare module schema { } declare module schema { class T { - readonly createValidator9: (data: T) => T; - createValidator10: (data: T) => T; + get createValidator9(): (data: T) => T; + set createValidator10(v: (data: T) => T); } } diff --git a/tests/baselines/reference/properties.js b/tests/baselines/reference/properties.js index 0b81d7671cdbb..27688f5837578 100644 --- a/tests/baselines/reference/properties.js +++ b/tests/baselines/reference/properties.js @@ -32,5 +32,6 @@ var MyClass = /** @class */ (function () { //// [properties.d.ts] declare class MyClass { - Count: number; + get Count(): number; + set Count(value: number); } diff --git a/tests/baselines/reference/readonlyInDeclarationFile.js b/tests/baselines/reference/readonlyInDeclarationFile.js index 667d2582f100d..7419e27c013b5 100644 --- a/tests/baselines/reference/readonlyInDeclarationFile.js +++ b/tests/baselines/reference/readonlyInDeclarationFile.js @@ -149,21 +149,27 @@ declare class C { private readonly a1; protected readonly a2: number; readonly a3: number; - private readonly b1; - protected readonly b2: number; - readonly b3: number; - private c1; - protected c2: number; - c3: number; + private get b1(); + protected get b2(): number; + get b3(): number; + private get c1(); + private set c1(value); + protected get c2(): number; + protected set c2(value: number); + get c3(): number; + set c3(value: number); private static readonly s1; protected static readonly s2: number; static readonly s3: number; - private static readonly t1; - protected static readonly t2: number; - static readonly t3: number; - private static u1; - protected static u2: number; - static u3: number; + private static get t1(); + protected static get t2(): number; + static get t3(): number; + private static get u1(); + private static set u1(value); + protected static get u2(): number; + protected static set u2(value: number); + static get u3(): number; + static set u3(value: number); } declare var z: { readonly a: string; diff --git a/tests/baselines/reference/symbolDeclarationEmit11.js b/tests/baselines/reference/symbolDeclarationEmit11.js index 25af4c4306475..b0cd9cfddbd5b 100644 --- a/tests/baselines/reference/symbolDeclarationEmit11.js +++ b/tests/baselines/reference/symbolDeclarationEmit11.js @@ -19,5 +19,6 @@ C[Symbol.iterator] = 0; declare class C { static [Symbol.iterator]: number; static [Symbol.isConcatSpreadable](): void; - static [Symbol.toPrimitive]: string; + static get [Symbol.toPrimitive](): string; + static set [Symbol.toPrimitive](x: string); } diff --git a/tests/baselines/reference/symbolDeclarationEmit12.js b/tests/baselines/reference/symbolDeclarationEmit12.js index 0b2034e045000..5d9f70334d44e 100644 --- a/tests/baselines/reference/symbolDeclarationEmit12.js +++ b/tests/baselines/reference/symbolDeclarationEmit12.js @@ -35,8 +35,8 @@ declare module M { [Symbol.iterator]: I; [Symbol.toPrimitive](x: I): void; [Symbol.isConcatSpreadable](): I; - readonly [Symbol.toPrimitive]: any; - [Symbol.toPrimitive]: I; + get [Symbol.toPrimitive](): any; + set [Symbol.toPrimitive](x: I); } export {}; } diff --git a/tests/baselines/reference/symbolDeclarationEmit13.js b/tests/baselines/reference/symbolDeclarationEmit13.js index bbd2c15cfcd1a..dc00d00fc9828 100644 --- a/tests/baselines/reference/symbolDeclarationEmit13.js +++ b/tests/baselines/reference/symbolDeclarationEmit13.js @@ -13,6 +13,6 @@ class C { //// [symbolDeclarationEmit13.d.ts] declare class C { - readonly [Symbol.toPrimitive]: string; - [Symbol.toStringTag]: any; + get [Symbol.toPrimitive](): string; + set [Symbol.toStringTag](x: any); } diff --git a/tests/baselines/reference/symbolDeclarationEmit14.js b/tests/baselines/reference/symbolDeclarationEmit14.js index d4ae3eeb43c35..f79c4e254f03b 100644 --- a/tests/baselines/reference/symbolDeclarationEmit14.js +++ b/tests/baselines/reference/symbolDeclarationEmit14.js @@ -13,6 +13,6 @@ class C { //// [symbolDeclarationEmit14.d.ts] declare class C { - readonly [Symbol.toPrimitive]: string; - readonly [Symbol.toStringTag]: string; + get [Symbol.toPrimitive](): string; + get [Symbol.toStringTag](): string; } diff --git a/tests/baselines/reference/symbolDeclarationEmit4.js b/tests/baselines/reference/symbolDeclarationEmit4.js index 75680aacb66fa..fb3099ec49dbd 100644 --- a/tests/baselines/reference/symbolDeclarationEmit4.js +++ b/tests/baselines/reference/symbolDeclarationEmit4.js @@ -13,5 +13,6 @@ class C { //// [symbolDeclarationEmit4.d.ts] declare class C { - [Symbol.toPrimitive]: string; + get [Symbol.toPrimitive](): string; + set [Symbol.toPrimitive](x: string); } diff --git a/tests/baselines/reference/typeGuardOfFormThisMember.js b/tests/baselines/reference/typeGuardOfFormThisMember.js index 1d4d9df79e22d..50c8ff0f7890a 100644 --- a/tests/baselines/reference/typeGuardOfFormThisMember.js +++ b/tests/baselines/reference/typeGuardOfFormThisMember.js @@ -178,8 +178,9 @@ declare namespace Test { class FileSystemObject { path: string; isFSO: this is FileSystemObject; - isFile: this is File; - readonly isDirectory: this is Directory; + get isFile(): this is File; + set isFile(param: this is File); + get isDirectory(): this is Directory; isNetworked: this is (Networked & this); constructor(path: string); } diff --git a/tests/baselines/reference/typeGuardOfFormThisMemberErrors.js b/tests/baselines/reference/typeGuardOfFormThisMemberErrors.js index 1992c339b328d..8456dc1797ee8 100644 --- a/tests/baselines/reference/typeGuardOfFormThisMemberErrors.js +++ b/tests/baselines/reference/typeGuardOfFormThisMemberErrors.js @@ -103,8 +103,9 @@ declare namespace Test { class FileSystemObject { path: string; isFSO: this is FileSystemObject; - isFile: this is File; - readonly isDirectory: this is Directory; + get isFile(): this is File; + set isFile(param: this is File); + get isDirectory(): this is Directory; isNetworked: this is (Networked & this); constructor(path: string); } diff --git a/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.js b/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.js index 871d8977a9de2..723ec89c0a65d 100644 --- a/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.js +++ b/tests/baselines/reference/uniqueSymbolsDeclarationsErrors.js @@ -141,7 +141,9 @@ export declare class ClassWithPrivateNamedMethods { static [s](): void; } export declare class ClassWithPrivateNamedAccessors { - [s]: any; - static [s]: any; + get [s](): any; + set [s](v: any); + static get [s](): any; + static set [s](v: any); } export {}; From fcf0ff1dfde03a31100102af2adc8a512819e66c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 17 Sep 2019 11:24:47 -0700 Subject: [PATCH 11/44] Allow 'declare' on any uninitialised property decl --- src/compiler/checker.ts | 15 --------------- src/compiler/diagnosticMessages.json | 4 ---- .../classExpressionPropertyModifiers.errors.txt | 5 +---- ...vedUninitializedPropertyDeclaration.errors.txt | 12 +++--------- .../derivedUninitializedPropertyDeclaration.js | 4 ++-- ...erivedUninitializedPropertyDeclaration.symbols | 4 ++-- .../derivedUninitializedPropertyDeclaration.types | 4 ++-- .../illegalModifiersOnClassElements.errors.txt | 5 +---- .../parserMemberAccessorDeclaration11.errors.txt | 5 +---- .../parserMemberFunctionDeclaration5.errors.txt | 5 +---- .../parserMemberVariableDeclaration5.errors.txt | 9 --------- .../derivedUninitializedPropertyDeclaration.ts | 4 ++-- 12 files changed, 15 insertions(+), 61 deletions(-) delete mode 100644 tests/baselines/reference/parserMemberVariableDeclaration5.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0b1e43dc205ba..6340bb3b27ad7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29358,7 +29358,6 @@ namespace ts { checkKindsOfPropertyMemberOverrides(type, baseType); } } - checkAmbientPropertyMemberOverrides(type, baseType); const implementedTypeNodes = getClassImplementsHeritageClauseElements(node); if (implementedTypeNodes) { @@ -29562,20 +29561,6 @@ namespace ts { } } - function checkAmbientPropertyMemberOverrides(type: Type, baseType?: Type) { - for (const derivedProperty of getPropertiesOfType(type)) { - const derived = getTargetSymbol(derivedProperty); - if (derived.flags & SymbolFlags.Prototype) { - continue; - } - const base = baseType && getPropertyOfObjectType(baseType, derived.escapedName); - if (!base && getDeclarationModifierFlagsFromSymbol(derived) & ModifierFlags.Ambient) { - const errorMessage = Diagnostics.Ambient_property_declarations_must_override_a_property_in_a_base_class; - error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage); - } - } - } - function checkInheritedPropertiesAreIdentical(type: InterfaceType, typeNode: Node): boolean { const baseTypes = getBaseTypes(type); if (baseTypes.length < 2) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e6c5ca99ab16e..957e1911ec3fa 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2208,10 +2208,6 @@ "category": "Error", "code": 2610 }, - "Ambient property declarations must override a property in a base class.": { - "category": "Error", - "code": 2611 - }, "Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": { "category": "Error", "code": 2649 diff --git a/tests/baselines/reference/classExpressionPropertyModifiers.errors.txt b/tests/baselines/reference/classExpressionPropertyModifiers.errors.txt index 94f55b688b19b..cb01d6561260f 100644 --- a/tests/baselines/reference/classExpressionPropertyModifiers.errors.txt +++ b/tests/baselines/reference/classExpressionPropertyModifiers.errors.txt @@ -1,13 +1,10 @@ -tests/cases/compiler/classExpressionPropertyModifiers.ts(2,13): error TS2611: Ambient property declarations must override a property in a base class. tests/cases/compiler/classExpressionPropertyModifiers.ts(2,36): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/compiler/classExpressionPropertyModifiers.ts(3,5): error TS1031: 'export' modifier cannot appear on a class element. -==== tests/cases/compiler/classExpressionPropertyModifiers.ts (3 errors) ==== +==== tests/cases/compiler/classExpressionPropertyModifiers.ts (2 errors) ==== const a = class Cat { declare [Symbol.toStringTag] = "uh"; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2611: Ambient property declarations must override a property in a base class. ~~~~ !!! error TS1039: Initializers are not allowed in ambient contexts. export foo = 1; diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt index 737c83bd0ce8c..ee271d7fb7f76 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt @@ -1,15 +1,13 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(6,5): error TS2610: Property 'property' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(15,5): error TS1031: 'declare' modifier cannot appear on a class element. -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(16,13): error TS2611: Ambient property declarations must override a property in a base class. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(17,24): error TS1039: Initializers are not allowed in ambient contexts. -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(20,13): error TS2611: Ambient property declarations must override a property in a base class. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(24,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2610: Property 'p' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(39,5): error TS2610: Property 'p1' will overwrite the base property in 'E'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (9 errors) ==== +==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (7 errors) ==== class A { property = 'x'; m() { return 1 } @@ -29,17 +27,13 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP declare m() { return 2 } // not allowed on methods ~~~~~~~ !!! error TS1031: 'declare' modifier cannot appear on a class element. - declare nonce: any; // only allowed when exists in base - ~~~~~ -!!! error TS2611: Ambient property declarations must override a property in a base class. + declare nonce: any; // ok, even though it's not in the base declare property = 'y' // initialiser not allowed with declare ~~~ !!! error TS1039: Initializers are not allowed in ambient contexts. } class U { - declare nonce: any; // ambient declaration only allowed when an override - ~~~~~ -!!! error TS2611: Ambient property declarations must override a property in a base class. + declare nonce: any; // ok, even though there's no base } class C { diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js index a07c27531cfd5..ca2d410a8e9eb 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js @@ -14,11 +14,11 @@ class BDBang extends A { } class BOther extends A { declare m() { return 2 } // not allowed on methods - declare nonce: any; // only allowed when exists in base + declare nonce: any; // ok, even though it's not in the base declare property = 'y' // initialiser not allowed with declare } class U { - declare nonce: any; // ambient declaration only allowed when an override + declare nonce: any; // ok, even though there's no base } class C { diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols index 298022d3c2fd1..4375b9010cf4b 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols @@ -36,7 +36,7 @@ class BOther extends A { declare m() { return 2 } // not allowed on methods >m : Symbol(BOther.m, Decl(derivedUninitializedPropertyDeclaration.ts, 13, 24)) - declare nonce: any; // only allowed when exists in base + declare nonce: any; // ok, even though it's not in the base >nonce : Symbol(BOther.nonce, Decl(derivedUninitializedPropertyDeclaration.ts, 14, 28)) declare property = 'y' // initialiser not allowed with declare @@ -45,7 +45,7 @@ class BOther extends A { class U { >U : Symbol(U, Decl(derivedUninitializedPropertyDeclaration.ts, 17, 1)) - declare nonce: any; // ambient declaration only allowed when an override + declare nonce: any; // ok, even though there's no base >nonce : Symbol(U.nonce, Decl(derivedUninitializedPropertyDeclaration.ts, 18, 9)) } diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types index 44d839492b5eb..cc82567babba3 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types @@ -39,7 +39,7 @@ class BOther extends A { >m : () => number >2 : 2 - declare nonce: any; // only allowed when exists in base + declare nonce: any; // ok, even though it's not in the base >nonce : any declare property = 'y' // initialiser not allowed with declare @@ -49,7 +49,7 @@ class BOther extends A { class U { >U : U - declare nonce: any; // ambient declaration only allowed when an override + declare nonce: any; // ok, even though there's no base >nonce : any } diff --git a/tests/baselines/reference/illegalModifiersOnClassElements.errors.txt b/tests/baselines/reference/illegalModifiersOnClassElements.errors.txt index d8e6e10158f54..99ba043b52a80 100644 --- a/tests/baselines/reference/illegalModifiersOnClassElements.errors.txt +++ b/tests/baselines/reference/illegalModifiersOnClassElements.errors.txt @@ -1,13 +1,10 @@ -tests/cases/compiler/illegalModifiersOnClassElements.ts(2,13): error TS2611: Ambient property declarations must override a property in a base class. tests/cases/compiler/illegalModifiersOnClassElements.ts(2,19): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/compiler/illegalModifiersOnClassElements.ts(3,5): error TS1031: 'export' modifier cannot appear on a class element. -==== tests/cases/compiler/illegalModifiersOnClassElements.ts (3 errors) ==== +==== tests/cases/compiler/illegalModifiersOnClassElements.ts (2 errors) ==== class C { declare foo = 1; - ~~~ -!!! error TS2611: Ambient property declarations must override a property in a base class. ~ !!! error TS1039: Initializers are not allowed in ambient contexts. export bar = 1; diff --git a/tests/baselines/reference/parserMemberAccessorDeclaration11.errors.txt b/tests/baselines/reference/parserMemberAccessorDeclaration11.errors.txt index 47a9e27f73e2d..3a04bfbbd0296 100644 --- a/tests/baselines/reference/parserMemberAccessorDeclaration11.errors.txt +++ b/tests/baselines/reference/parserMemberAccessorDeclaration11.errors.txt @@ -1,15 +1,12 @@ tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration11.ts(2,5): error TS1031: 'declare' modifier cannot appear on a class element. tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration11.ts(2,17): error TS2378: A 'get' accessor must return a value. -tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration11.ts(2,17): error TS2611: Ambient property declarations must override a property in a base class. -==== tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration11.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration11.ts (2 errors) ==== class C { declare get Foo() { } ~~~~~~~ !!! error TS1031: 'declare' modifier cannot appear on a class element. ~~~ !!! error TS2378: A 'get' accessor must return a value. - ~~~ -!!! error TS2611: Ambient property declarations must override a property in a base class. } \ No newline at end of file diff --git a/tests/baselines/reference/parserMemberFunctionDeclaration5.errors.txt b/tests/baselines/reference/parserMemberFunctionDeclaration5.errors.txt index 25544ddeda5c4..dc19cb0f8550a 100644 --- a/tests/baselines/reference/parserMemberFunctionDeclaration5.errors.txt +++ b/tests/baselines/reference/parserMemberFunctionDeclaration5.errors.txt @@ -1,12 +1,9 @@ tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration5.ts(2,5): error TS1031: 'declare' modifier cannot appear on a class element. -tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration5.ts(2,13): error TS2611: Ambient property declarations must override a property in a base class. -==== tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration5.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration5.ts (1 errors) ==== class C { declare Foo() { } ~~~~~~~ !!! error TS1031: 'declare' modifier cannot appear on a class element. - ~~~ -!!! error TS2611: Ambient property declarations must override a property in a base class. } \ No newline at end of file diff --git a/tests/baselines/reference/parserMemberVariableDeclaration5.errors.txt b/tests/baselines/reference/parserMemberVariableDeclaration5.errors.txt deleted file mode 100644 index 9ad6081cdf6d9..0000000000000 --- a/tests/baselines/reference/parserMemberVariableDeclaration5.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration5.ts(2,11): error TS2611: Ambient property declarations must override a property in a base class. - - -==== tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration5.ts (1 errors) ==== - class C { - declare Foo; - ~~~ -!!! error TS2611: Ambient property declarations must override a property in a base class. - } \ No newline at end of file diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts index fa4fd86f01e85..a28beddd0205e 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts @@ -14,11 +14,11 @@ class BDBang extends A { } class BOther extends A { declare m() { return 2 } // not allowed on methods - declare nonce: any; // only allowed when exists in base + declare nonce: any; // ok, even though it's not in the base declare property = 'y' // initialiser not allowed with declare } class U { - declare nonce: any; // ambient declaration only allowed when an override + declare nonce: any; // ok, even though there's no base } class C { From 810f923d54445346fbc28cadf46271372c204c11 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 17 Sep 2019 11:27:21 -0700 Subject: [PATCH 12/44] Undo code moves --- src/compiler/checker.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6340bb3b27ad7..0d57f278e8eb5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29206,11 +29206,6 @@ namespace ts { } } - function getClassOrInterfaceDeclarationsOfSymbol(symbol: Symbol) { - return filter(symbol.declarations, (d: Declaration): d is ClassDeclaration | InterfaceDeclaration => - d.kind === SyntaxKind.ClassDeclaration || d.kind === SyntaxKind.InterfaceDeclaration); - } - function areTypeParametersIdentical(declarations: readonly (ClassDeclaration | InterfaceDeclaration)[], targetParameters: TypeParameter[]) { const maxTypeArgumentCount = length(targetParameters); const minTypeArgumentCount = getMinTypeArgumentCount(targetParameters); @@ -29304,7 +29299,6 @@ namespace ts { checkClassForStaticPropertyNameConflicts(node); } - let baseType: BaseType | undefined; const baseTypeNode = getEffectiveBaseTypeNode(node); if (baseTypeNode) { if (languageVersion < ScriptTarget.ES2015) { @@ -29318,7 +29312,7 @@ namespace ts { const baseTypes = getBaseTypes(type); if (baseTypes.length && produceDiagnostics) { - baseType = baseTypes[0]; + const baseType = baseTypes[0]; const baseConstructorType = getBaseConstructorTypeOfClass(type); const staticBaseType = getApparentType(baseConstructorType); checkBaseTypeAccessibility(staticBaseType, baseTypeNode); @@ -29443,6 +29437,11 @@ namespace ts { return getCheckFlags(s) & CheckFlags.Instantiated ? (s).target! : s; } + function getClassOrInterfaceDeclarationsOfSymbol(symbol: Symbol) { + return filter(symbol.declarations, (d: Declaration): d is ClassDeclaration | InterfaceDeclaration => + d.kind === SyntaxKind.ClassDeclaration || d.kind === SyntaxKind.InterfaceDeclaration); + } + /** * TypeScript 1.0 spec (April 2014): 8.2.3 * A derived class inherits all members from its base class it doesn't override. From 6408d7abe6bc39e703ab568e40063c75b83bceee Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 17 Sep 2019 11:29:54 -0700 Subject: [PATCH 13/44] Let sleeping dogs lie --- src/compiler/checker.ts | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0d57f278e8eb5..6c9e06fb33e2a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29442,22 +29442,21 @@ namespace ts { d.kind === SyntaxKind.ClassDeclaration || d.kind === SyntaxKind.InterfaceDeclaration); } - /** - * TypeScript 1.0 spec (April 2014): 8.2.3 - * A derived class inherits all members from its base class it doesn't override. - * Inheritance means that a derived class implicitly contains all non - overridden members of the base class. - * Both public and private property members are inherited, but only public property members can be overridden. - * A property member in a derived class is said to override a property member in a base class - * when the derived class property member has the same name and kind(instance or static) - * as the base class property member. - * The type of an overriding property member must be assignable(section 3.8.4) - * to the type of the overridden property member, or otherwise a compile - time error occurs. - * Base class instance member functions can be overridden by derived class instance member functions, - * but not by other kinds of members. - * Base class instance member variables and accessors can be overridden by - * derived class instance member variables and accessors, but not by other kinds of members. - */ function checkKindsOfPropertyMemberOverrides(type: InterfaceType, baseType: BaseType): void { + // TypeScript 1.0 spec (April 2014): 8.2.3 + // A derived class inherits all members from its base class it doesn't override. + // Inheritance means that a derived class implicitly contains all non - overridden members of the base class. + // Both public and private property members are inherited, but only public property members can be overridden. + // A property member in a derived class is said to override a property member in a base class + // when the derived class property member has the same name and kind(instance or static) + // as the base class property member. + // The type of an overriding property member must be assignable(section 3.8.4) + // to the type of the overridden property member, or otherwise a compile - time error occurs. + // Base class instance member functions can be overridden by derived class instance member functions, + // but not by other kinds of members. + // Base class instance member variables and accessors can be overridden by + // derived class instance member variables and accessors, but not by other kinds of members. + // NOTE: assignability is checked in checkClassDeclaration const baseProperties = getPropertiesOfType(baseType); basePropertyCheck: for (const baseProperty of baseProperties) { From 5ee327185c07853791361d2fe692798930461c8e Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 17 Sep 2019 13:45:51 -0700 Subject: [PATCH 14/44] Correctly set NodeFlags.Ambient And simplify redundant parts of check. --- src/compiler/checker.ts | 3 +-- src/compiler/parser.ts | 12 ++++++++++-- ...erivedUninitializedPropertyDeclaration.errors.txt | 10 ++++++++-- .../derivedUninitializedPropertyDeclaration.js | 2 +- .../derivedUninitializedPropertyDeclaration.symbols | 2 +- .../derivedUninitializedPropertyDeclaration.types | 2 +- .../parserMemberFunctionDeclaration5.errors.txt | 5 ++++- .../derivedUninitializedPropertyDeclaration.ts | 2 +- 8 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6c9e06fb33e2a..2012a98534fd1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29519,10 +29519,9 @@ namespace ts { if (base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) { const uninitialized = find(derived.declarations, d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer); if (uninitialized - && derived.flags & SymbolFlags.Property && !(derived.flags & SymbolFlags.Transient) && !(baseDeclarationFlags & ModifierFlags.Abstract) - && !(derivedDeclarationFlags & (ModifierFlags.Ambient | ModifierFlags.Abstract)) + && !(derivedDeclarationFlags & ModifierFlags.Abstract) && !derived.declarations.some(d => d.flags & NodeFlags.Ambient)) { const constructor = findConstructorDeclaration(getClassLikeDeclarationOfSymbol(type.symbol)!); const propName = (uninitialized as PropertyDeclaration).name; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f437ca697a854..669c41094a697 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -5982,8 +5982,16 @@ namespace ts { token() === SyntaxKind.NumericLiteral || token() === SyntaxKind.AsteriskToken || token() === SyntaxKind.OpenBracketToken) { - - return parsePropertyOrMethodDeclaration(node); + const isAmbient = node.modifiers && some(node.modifiers, isDeclareModifier); + if (isAmbient) { + for (const m of node.modifiers!) { + m.flags |= NodeFlags.Ambient; + } + return doInsideOfContext(NodeFlags.Ambient, () => parsePropertyOrMethodDeclaration(node as PropertyDeclaration | MethodDeclaration)); + } + else { + return parsePropertyOrMethodDeclaration(node as PropertyDeclaration | MethodDeclaration); + } } if (node.decorators || node.modifiers) { diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt index ee271d7fb7f76..62c7aedfbbea7 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt @@ -1,5 +1,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(6,5): error TS2610: Property 'property' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(12,21): error TS1255: A definite assignment assertion '!' is not permitted in this context. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(15,5): error TS1031: 'declare' modifier cannot appear on a class element. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(15,17): error TS1183: An implementation cannot be declared in ambient contexts. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(17,24): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(24,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. @@ -7,7 +9,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(39,5): error TS2610: Property 'p1' will overwrite the base property in 'E'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (7 errors) ==== +==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (9 errors) ==== class A { property = 'x'; m() { return 1 } @@ -21,12 +23,16 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP declare property: any; // ok because it's implicitly initialised } class BDBang extends A { - declare property!: any; // doesn't need !, but is still allowed + declare property!: any; // ! is not allowed, this is an ambient declaration + ~ +!!! error TS1255: A definite assignment assertion '!' is not permitted in this context. } class BOther extends A { declare m() { return 2 } // not allowed on methods ~~~~~~~ !!! error TS1031: 'declare' modifier cannot appear on a class element. + ~ +!!! error TS1183: An implementation cannot be declared in ambient contexts. declare nonce: any; // ok, even though it's not in the base declare property = 'y' // initialiser not allowed with declare ~~~ diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js index ca2d410a8e9eb..decc56a4867c2 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js @@ -10,7 +10,7 @@ class BD extends A { declare property: any; // ok because it's implicitly initialised } class BDBang extends A { - declare property!: any; // doesn't need !, but is still allowed + declare property!: any; // ! is not allowed, this is an ambient declaration } class BOther extends A { declare m() { return 2 } // not allowed on methods diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols index 4375b9010cf4b..2ed91c2c2d172 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols @@ -26,7 +26,7 @@ class BDBang extends A { >BDBang : Symbol(BDBang, Decl(derivedUninitializedPropertyDeclaration.ts, 9, 1)) >A : Symbol(A, Decl(derivedUninitializedPropertyDeclaration.ts, 0, 0)) - declare property!: any; // doesn't need !, but is still allowed + declare property!: any; // ! is not allowed, this is an ambient declaration >property : Symbol(BDBang.property, Decl(derivedUninitializedPropertyDeclaration.ts, 10, 24)) } class BOther extends A { diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types index cc82567babba3..aa4e7ba501e42 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types @@ -28,7 +28,7 @@ class BDBang extends A { >BDBang : BDBang >A : A - declare property!: any; // doesn't need !, but is still allowed + declare property!: any; // ! is not allowed, this is an ambient declaration >property : any } class BOther extends A { diff --git a/tests/baselines/reference/parserMemberFunctionDeclaration5.errors.txt b/tests/baselines/reference/parserMemberFunctionDeclaration5.errors.txt index dc19cb0f8550a..402355919a031 100644 --- a/tests/baselines/reference/parserMemberFunctionDeclaration5.errors.txt +++ b/tests/baselines/reference/parserMemberFunctionDeclaration5.errors.txt @@ -1,9 +1,12 @@ tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration5.ts(2,5): error TS1031: 'declare' modifier cannot appear on a class element. +tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration5.ts(2,19): error TS1183: An implementation cannot be declared in ambient contexts. -==== tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration5.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration5.ts (2 errors) ==== class C { declare Foo() { } ~~~~~~~ !!! error TS1031: 'declare' modifier cannot appear on a class element. + ~ +!!! error TS1183: An implementation cannot be declared in ambient contexts. } \ No newline at end of file diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts index a28beddd0205e..a3f126c10aec8 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts @@ -10,7 +10,7 @@ class BD extends A { declare property: any; // ok because it's implicitly initialised } class BDBang extends A { - declare property!: any; // doesn't need !, but is still allowed + declare property!: any; // ! is not allowed, this is an ambient declaration } class BOther extends A { declare m() { return 2 } // not allowed on methods From e0ddced06c4c68ab881e58c76cafd4f027b7ed7c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 17 Sep 2019 14:03:01 -0700 Subject: [PATCH 15/44] Remove more unneeded 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 2012a98534fd1..308ddaac6427f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -33637,7 +33637,7 @@ namespace ts { } } - if (node.flags & NodeFlags.Ambient || getModifierFlags(node) & ModifierFlags.Ambient) { + if (node.flags & NodeFlags.Ambient) { checkAmbientInitializer(node); } From 6a066b9a7edc8cdc89ccbecccb633f7f5fcc2b3a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 17 Sep 2019 15:00:00 -0700 Subject: [PATCH 16/44] Update baselines --- .../reference/commentsInheritance.errors.txt | 159 ++++++++++++++++++ .../reference/parserAstSpans1.errors.txt | 8 +- .../reference/parserRealSource11.errors.txt | 8 +- .../reference/parserharness.errors.txt | 14 +- ...AccessibleWithinNestedSubclass1.errors.txt | 5 +- ...opertyAccessibleWithinSubclass2.errors.txt | 5 +- ...sOfTypeParameterWithConstraints.errors.txt | 89 +++++++++- 7 files changed, 282 insertions(+), 6 deletions(-) create mode 100644 tests/baselines/reference/commentsInheritance.errors.txt diff --git a/tests/baselines/reference/commentsInheritance.errors.txt b/tests/baselines/reference/commentsInheritance.errors.txt new file mode 100644 index 0000000000000..2a9a5eff5dca7 --- /dev/null +++ b/tests/baselines/reference/commentsInheritance.errors.txt @@ -0,0 +1,159 @@ +tests/cases/compiler/commentsInheritance.ts(90,12): error TS2610: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/compiler/commentsInheritance.ts(98,12): error TS2610: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. + + +==== tests/cases/compiler/commentsInheritance.ts (2 errors) ==== + /** i1 is interface with properties*/ + interface i1 { + /** i1_p1*/ + i1_p1: number; + /** i1_f1*/ + i1_f1(): void; + /** i1_l1*/ + i1_l1: () => void; + // il_nc_p1 + i1_nc_p1: number; + i1_nc_f1(): void; + i1_nc_l1: () => void; + p1: number; + f1(): void; + l1: () => void; + nc_p1: number; + nc_f1(): void; + nc_l1: () => void; + } + class c1 implements i1 { + public i1_p1: number; + // i1_f1 + public i1_f1() { + } + public i1_l1: () => void; + public i1_nc_p1: number; + public i1_nc_f1() { + } + public i1_nc_l1: () => void; + /** c1_p1*/ + public p1: number; + /** c1_f1*/ + public f1() { + } + /** c1_l1*/ + public l1: () => void; + /** c1_nc_p1*/ + public nc_p1: number; + /** c1_nc_f1*/ + public nc_f1() { + } + /** c1_nc_l1*/ + public nc_l1: () => void; + } + var i1_i: i1; + var c1_i = new c1(); + // assign to interface + i1_i = c1_i; + class c2 { + /** c2 c2_p1*/ + public c2_p1: number; + /** c2 c2_f1*/ + public c2_f1() { + } + /** c2 c2_prop*/ + public get c2_prop() { + return 10; + } + public c2_nc_p1: number; + public c2_nc_f1() { + } + public get c2_nc_prop() { + return 10; + } + /** c2 p1*/ + public p1: number; + /** c2 f1*/ + public f1() { + } + /** c2 prop*/ + public get prop() { + return 10; + } + public nc_p1: number; + public nc_f1() { + } + public get nc_prop() { + return 10; + } + /** c2 constructor*/ + constructor(a: number) { + this.c2_p1 = a; + } + } + class c3 extends c2 { + constructor() { + super(10); + } + /** c3 p1*/ + public p1: number; + ~~ +!!! error TS2610: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. + /** c3 f1*/ + public f1() { + } + /** c3 prop*/ + public get prop() { + return 10; + } + public nc_p1: number; + ~~~~~ +!!! error TS2610: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. + public nc_f1() { + } + public get nc_prop() { + return 10; + } + } + var c2_i = new c2(10); + var c3_i = new c3(); + // assign + c2_i = c3_i; + class c4 extends c2 { + } + var c4_i = new c4(10); + interface i2 { + /** i2_p1*/ + i2_p1: number; + /** i2_f1*/ + i2_f1(): void; + /** i2_l1*/ + i2_l1: () => void; + // i2_nc_p1 + i2_nc_p1: number; + i2_nc_f1(): void; + i2_nc_l1: () => void; + /** i2 p1*/ + p1: number; + /** i2 f1*/ + f1(): void; + /** i2 l1*/ + l1: () => void; + nc_p1: number; + nc_f1(): void; + nc_l1: () => void; + } + interface i3 extends i2 { + /** i3 p1 */ + p1: number; + /** + * i3 f1 + */ + f1(): void; + /** i3 l1*/ + l1: () => void; + nc_p1: number; + nc_f1(): void; + nc_l1: () => void; + } + var i2_i: i2; + var i3_i: i3; + // assign to interface + i2_i = i3_i; + \ No newline at end of file diff --git a/tests/baselines/reference/parserAstSpans1.errors.txt b/tests/baselines/reference/parserAstSpans1.errors.txt index 648929e974e3e..6fa8715a8f6ea 100644 --- a/tests/baselines/reference/parserAstSpans1.errors.txt +++ b/tests/baselines/reference/parserAstSpans1.errors.txt @@ -3,12 +3,14 @@ tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(85,16): error TS10 tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(94,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(100,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(111,25): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. +tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(114,12): error TS2610: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(119,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(122,12): error TS2610: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(125,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(217,24): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. -==== tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts (8 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts (10 errors) ==== /** i1 is interface with properties*/ interface i1 { /** i1_p1*/ @@ -133,6 +135,8 @@ tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(217,24): error TS2 } /** c3 p1*/ public p1: number; + ~~ +!!! error TS2610: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. /** c3 f1*/ public f1() { } @@ -143,6 +147,8 @@ tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(217,24): error TS2 return 10; } public nc_p1: number; + ~~~~~ +!!! error TS2610: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. public nc_f1() { } public get nc_prop() { diff --git a/tests/baselines/reference/parserRealSource11.errors.txt b/tests/baselines/reference/parserRealSource11.errors.txt index bb0a52e0a9997..fdfb15759460e 100644 --- a/tests/baselines/reference/parserRealSource11.errors.txt +++ b/tests/baselines/reference/parserRealSource11.errors.txt @@ -288,6 +288,8 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1095,29): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1098,56): error TS2304: Cannot find name 'FncFlags'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1098,79): error TS2304: Cannot find name 'FncFlags'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1111,33): error TS2304: Cannot find name 'IFileReference'. +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1120,16): error TS2610: Property 'vars' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1121,16): error TS2610: Property 'scopes' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1127,84): error TS2304: Cannot find name 'NodeType'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1132,36): error TS2304: Cannot find name 'TypeFlow'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1144,42): error TS2304: Cannot find name 'NodeType'. @@ -511,7 +513,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,30): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error TS2304: Cannot find name 'TokenID'. -==== tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts (511 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts (513 errors) ==== // Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. @@ -2212,7 +2214,11 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error public leftCurlyCount = 0; public rightCurlyCount = 0; public vars: ASTList; + ~~~~ +!!! error TS2610: Property 'vars' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. public scopes: ASTList; + ~~~~~~ +!!! error TS2610: Property 'scopes' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. // Remember if the script contains Unicode chars, that is needed when generating code for this script object to decide the output file correct encoding. public containsUnicodeChar = false; public containsUnicodeCharInComment = false; diff --git a/tests/baselines/reference/parserharness.errors.txt b/tests/baselines/reference/parserharness.errors.txt index 990fa5816c787..9c00868b16d22 100644 --- a/tests/baselines/reference/parserharness.errors.txt +++ b/tests/baselines/reference/parserharness.errors.txt @@ -12,6 +12,10 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(347,13): e tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(351,17): error TS2662: Cannot find name 'errorHandlerStack'. Did you mean the static member 'Runnable.errorHandlerStack'? tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(354,17): error TS2662: Cannot find name 'errorHandlerStack'. Did you mean the static member 'Runnable.errorHandlerStack'? tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(354,35): error TS2662: Cannot find name 'errorHandlerStack'. Did you mean the static member 'Runnable.errorHandlerStack'? +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(359,16): error TS2610: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(360,16): error TS2610: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(402,16): error TS2610: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(403,16): error TS2610: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(691,50): error TS2304: Cannot find name 'ITextWriter'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(716,47): error TS2503: Cannot find namespace 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(721,62): error TS2304: Cannot find name 'ITextWriter'. @@ -110,7 +114,7 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(1787,68): tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): error TS2304: Cannot find name 'Diff'. -==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (110 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (114 errors) ==== // // Copyright (c) Microsoft Corporation. All rights reserved. // @@ -498,7 +502,11 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): } export class TestCase extends Runnable { public description: string; + ~~~~~~~~~~~ +!!! error TS2610: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. public block; + ~~~~~ +!!! error TS2610: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. constructor(description: string, block: any) { super(description, block); @@ -541,7 +549,11 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): export class Scenario extends Runnable { public description: string; + ~~~~~~~~~~~ +!!! error TS2610: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. public block; + ~~~~~ +!!! error TS2610: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. constructor(description: string, block: any) { super(description, block); diff --git a/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt b/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt index 2d882681d7269..dd395b2a2a4a2 100644 --- a/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt +++ b/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt @@ -6,6 +6,7 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(52,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(53,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(55,20): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(63,15): error TS2610: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(73,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(74,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(75,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. @@ -21,7 +22,7 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(114,4): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses. -==== tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts (21 errors) ==== +==== tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts (22 errors) ==== class Base { protected x: string; method() { @@ -101,6 +102,8 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce class Derived3 extends Derived1 { protected x: string; + ~ +!!! error TS2610: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. method3() { class D { method3d() { diff --git a/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass2.errors.txt b/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass2.errors.txt index 996d62c165212..2d43267ed419e 100644 --- a/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass2.errors.txt +++ b/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass2.errors.txt @@ -6,6 +6,7 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(42,11): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(43,12): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(45,12): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(51,15): error TS2610: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(59,11): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(60,12): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(61,12): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. @@ -21,7 +22,7 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(94,4): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses. -==== tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts (21 errors) ==== +==== tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts (22 errors) ==== class Base { protected x: string; method() { @@ -89,6 +90,8 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce class Derived3 extends Derived1 { protected x: string; + ~ +!!! error TS2610: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. method3() { var b: Base; var d1: Derived1; diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt index 5fe0186e04a1b..37ae8137c5a2b 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt @@ -1,21 +1,39 @@ +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(9,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(14,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(24,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(33,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(38,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(43,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. Type 'V' is not assignable to type 'T'. 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(55,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(60,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2416: Property 'foo' in type 'D11' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'T'. 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2416: Property 'foo' in type 'D12' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'U'. 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint '{}'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(77,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(85,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(90,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(95,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(100,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(107,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2416: Property 'foo' in type 'D19' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. @@ -24,33 +42,44 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. Type 'Date' is not assignable to type 'T'. 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(117,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(122,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(129,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2416: Property 'foo' in type 'D23' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'T'. 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. Type 'Date' is not assignable to type 'T'. 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2416: Property 'foo' in type 'D24' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'U'. 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. Type 'Date' is not assignable to type 'U'. 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(144,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(151,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2416: Property 'foo' in type 'D27' is not assignable to the same property in base type 'C3'. Type 'Date' is not assignable to type 'T'. 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2416: Property 'foo' in type 'D28' is not assignable to the same property in base type 'C3'. Type 'Date' is not assignable to type 'U'. 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2416: Property 'foo' in type 'D29' is not assignable to the same property in base type 'C3'. Type 'Date' is not assignable to type 'V'. 'Date' is assignable to the constraint of type 'V', but 'V' could be instantiated with a different subtype of constraint 'Date'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts (20 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts (49 errors) ==== // checking whether other types are subtypes of type parameters with constraints class C3 { @@ -60,11 +89,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D1 extends C3 { [x: string]: T; foo: T; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D2 extends C3 { [x: string]: U; foo: T; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D3 extends C3 { @@ -76,11 +109,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D4 extends C3 { [x: string]: U; foo: U; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } @@ -90,16 +127,22 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D5 extends C3 { [x: string]: T; foo: T; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D6 extends C3 { [x: string]: U; foo: T; + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D7 extends C3 { [x: string]: V; foo: T; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if U is a subtype of T, U, V @@ -115,16 +158,22 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D9 extends C3 { [x: string]: U; foo: U; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D10 extends C3 { [x: string]: V; foo: U; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if V is a subtype of T, U, V @@ -138,6 +187,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D11' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D12 extends C3 { @@ -149,11 +200,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D12' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'V' is not assignable to type 'U'. !!! error TS2416: 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint '{}'. + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D13 extends C3 { [x: string]: V; foo: V; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // Date > V > U > T @@ -162,21 +217,29 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D14 extends C3 { [x: string]: Date; foo: T; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D15 extends C3 { [x: string]: T; foo: T; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D16 extends C3 { [x: string]: U; foo: T; + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D17 extends C3 { [x: string]: V; foo: T; + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if U is a subtype of T, U, V, Date @@ -184,6 +247,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D18 extends C3 { [x: string]: Date; foo: T; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D19 extends C3 { @@ -199,16 +264,22 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. !!! error TS2416: Type 'Date' is not assignable to type 'T'. !!! error TS2416: 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D20 extends C3 { [x: string]: U; foo: U; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D21 extends C3 { [x: string]: V; foo: U; + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if V is a subtype of T, U, V, Date @@ -216,6 +287,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D22 extends C3 { [x: string]: Date; foo: T; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D23 extends C3 { @@ -229,6 +302,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. !!! error TS2416: Type 'Date' is not assignable to type 'T'. !!! error TS2416: 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D24 extends C3 { @@ -242,11 +317,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. !!! error TS2416: Type 'Date' is not assignable to type 'U'. !!! error TS2416: 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D25 extends C3 { [x: string]: V; foo: V; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if Date is a subtype of T, U, V, Date @@ -254,6 +333,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D26 extends C3 { [x: string]: Date; foo: Date; // ok + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D27 extends C3 { @@ -265,6 +346,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D27' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'Date' is not assignable to type 'T'. !!! error TS2416: 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D28 extends C3 { @@ -276,6 +359,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D28' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'Date' is not assignable to type 'U'. !!! error TS2416: 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D29 extends C3 { @@ -287,4 +372,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D29' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'Date' is not assignable to type 'V'. !!! error TS2416: 'Date' is assignable to the constraint of type 'V', but 'V' could be instantiated with a different subtype of constraint 'Date'. + ~~~ +!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file From 7f69be7b0c4aba6dc44e0026b3e59527b516d03b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 17 Sep 2019 15:18:25 -0700 Subject: [PATCH 17/44] Update baselines --- .../reference/commentsClassMembers.js | 44 +- .../reference/commentsInheritance.js | 12 +- tests/baselines/reference/giant.js | 24 +- tests/baselines/reference/moduledecl.js | 4 +- .../reference/privacyAccessorDeclFile.js | 324 ++++++------- .../privacyCannotNameAccessorDeclFile.js | 24 +- .../stripInternal.js | 37 +- .../stripInternal.js | 402 ++++++++-------- .../initial-Build/stripInternal.js | 405 ++++++++-------- ...en-one-two-three-are-prepended-in-order.js | 371 ++++++++------- ...en-one-two-three-are-prepended-in-order.js | 37 +- ...en-one-two-three-are-prepended-in-order.js | 37 +- ...en-one-two-three-are-prepended-in-order.js | 37 +- ...en-one-two-three-are-prepended-in-order.js | 37 +- ...en-one-two-three-are-prepended-in-order.js | 368 ++++++++------- ...en-one-two-three-are-prepended-in-order.js | 368 ++++++++------- ...en-one-two-three-are-prepended-in-order.js | 370 ++++++++------- ...en-one-two-three-are-prepended-in-order.js | 371 ++++++++------- .../stripInternal-jsdoc-style-comment.js | 371 ++++++++------- ...en-one-two-three-are-prepended-in-order.js | 443 ++++++++++-------- ...-jsdoc-style-with-comments-emit-enabled.js | 443 ++++++++++-------- ...en-one-two-three-are-prepended-in-order.js | 371 ++++++++------- ...en-one-two-three-are-prepended-in-order.js | 373 ++++++++------- ...tripInternal-with-comments-emit-enabled.js | 373 ++++++++------- .../initial-Build/stripInternal.js | 371 ++++++++------- 25 files changed, 3252 insertions(+), 2765 deletions(-) diff --git a/tests/baselines/reference/commentsClassMembers.js b/tests/baselines/reference/commentsClassMembers.js index 9918b0758ae40..bba4b44fc6023 100644 --- a/tests/baselines/reference/commentsClassMembers.js +++ b/tests/baselines/reference/commentsClassMembers.js @@ -486,15 +486,17 @@ declare class c1 { /** sum with property*/ p2(/** number to add*/ b: number): number; /** getter property*/ + get p3(): number; /** setter property*/ - p3: number; + set p3(/** this is value*/ value: number); /** pp1 is property of c1*/ private pp1; /** sum with property*/ private pp2; /** getter property*/ + private get pp3(); /** setter property*/ - private pp3; + private set pp3(value); /** Constructor method*/ constructor(); /** s1 is static property of c1*/ @@ -502,49 +504,59 @@ declare class c1 { /** static sum with property*/ static s2(/** number to add*/ b: number): number; /** static getter property*/ + static get s3(): number; /** setter property*/ - static s3: number; + static set s3(/** this is value*/ value: number); nc_p1: number; nc_p2(b: number): number; - nc_p3: number; + get nc_p3(): number; + set nc_p3(value: number); private nc_pp1; private nc_pp2; - private nc_pp3; + private get nc_pp3(); + private set nc_pp3(value); static nc_s1: number; static nc_s2(b: number): number; - static nc_s3: number; + static get nc_s3(): number; + static set nc_s3(value: number); a_p1: number; a_p2(b: number): number; - a_p3: number; + get a_p3(): number; + set a_p3(value: number); private a_pp1; private a_pp2; - private a_pp3; + private get a_pp3(); + private set a_pp3(value); static a_s1: number; static a_s2(b: number): number; - static a_s3: number; + static get a_s3(): number; + static set a_s3(value: number); /** p1 is property of c1 */ b_p1: number; /** sum with property */ b_p2(b: number): number; /** getter property */ + get b_p3(): number; /** setter property */ - b_p3: number; + set b_p3(value: number); /** pp1 is property of c1 */ private b_pp1; /** sum with property */ private b_pp2; /** getter property */ + private get b_pp3(); /** setter property */ - private b_pp3; + private set b_pp3(value); /** s1 is static property of c1 */ static b_s1: number; /** static sum with property */ static b_s2(b: number): number; /** static getter property */ + static get b_s3(): number; /** setter property */ - static b_s3: number; + static set b_s3(value: number); } declare var i1: c1; declare var i1_p: number; @@ -567,11 +579,11 @@ declare var i1_c: typeof c1; declare class cProperties { private val; /** getter only property*/ - readonly p1: number; - readonly nc_p1: number; + get p1(): number; + get nc_p1(): number; /**setter only property*/ - p2: number; - nc_p2: number; + set p2(value: number); + set nc_p2(value: number); x: number; private y; } diff --git a/tests/baselines/reference/commentsInheritance.js b/tests/baselines/reference/commentsInheritance.js index 58e243301b4e2..9779df371a2ec 100644 --- a/tests/baselines/reference/commentsInheritance.js +++ b/tests/baselines/reference/commentsInheritance.js @@ -323,19 +323,19 @@ declare class c2 { /** c2 c2_f1*/ c2_f1(): void; /** c2 c2_prop*/ - readonly c2_prop: number; + get c2_prop(): number; c2_nc_p1: number; c2_nc_f1(): void; - readonly c2_nc_prop: number; + get c2_nc_prop(): number; /** c2 p1*/ p1: number; /** c2 f1*/ f1(): void; /** c2 prop*/ - readonly prop: number; + get prop(): number; nc_p1: number; nc_f1(): void; - readonly nc_prop: number; + get nc_prop(): number; /** c2 constructor*/ constructor(a: number); } @@ -346,10 +346,10 @@ declare class c3 extends c2 { /** c3 f1*/ f1(): void; /** c3 prop*/ - readonly prop: number; + get prop(): number; nc_p1: number; nc_f1(): void; - readonly nc_prop: number; + get nc_prop(): number; } declare var c2_i: c2; declare var c3_i: c3; diff --git a/tests/baselines/reference/giant.js b/tests/baselines/reference/giant.js index 85686faa01e98..9adf046d8cfc2 100644 --- a/tests/baselines/reference/giant.js +++ b/tests/baselines/reference/giant.js @@ -1120,19 +1120,19 @@ export declare class eC { pF(): void; private rF; pgF(): void; - readonly pgF: any; + get pgF(): any; psF(param: any): void; - psF: any; + set psF(param: any); private rgF; - private readonly rgF; - private rsF; + private get rgF(); private rsF; + private set rsF(value); static tV: any; static tF(): void; static tsF(param: any): void; - static tsF: any; + static set tsF(param: any); static tgF(): void; - static readonly tgF: any; + static get tgF(): any; } export interface eI { (): any; @@ -1172,19 +1172,19 @@ export declare module eM { pF(): void; private rF; pgF(): void; - readonly pgF: any; + get pgF(): any; psF(param: any): void; - psF: any; + set psF(param: any); private rgF; - private readonly rgF; - private rsF; + private get rgF(); private rsF; + private set rsF(value); static tV: any; static tF(): void; static tsF(param: any): void; - static tsF: any; + static set tsF(param: any); static tgF(): void; - static readonly tgF: any; + static get tgF(): any; } interface eI { (): any; diff --git a/tests/baselines/reference/moduledecl.js b/tests/baselines/reference/moduledecl.js index de7a5434e4df6..9672b980929b0 100644 --- a/tests/baselines/reference/moduledecl.js +++ b/tests/baselines/reference/moduledecl.js @@ -457,10 +457,10 @@ declare module exportTests { class C3_public { private getC2_private; private setC2_private; - private readonly c2; + private get c2(); getC1_public(): C1_public; setC1_public(arg: C1_public): void; - readonly c1: C1_public; + get c1(): C1_public; } } declare module mAmbient { diff --git a/tests/baselines/reference/privacyAccessorDeclFile.js b/tests/baselines/reference/privacyAccessorDeclFile.js index a7eb6296f5c8e..1c84bd63749d6 100644 --- a/tests/baselines/reference/privacyAccessorDeclFile.js +++ b/tests/baselines/reference/privacyAccessorDeclFile.js @@ -3562,46 +3562,46 @@ declare class privateClass { export declare class publicClass { } export declare class publicClassWithWithPrivateGetAccessorTypes { - static readonly myPublicStaticMethod: privateClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: privateClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: privateClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: privateClass; - private readonly myPrivateMethod1; + static get myPublicStaticMethod(): privateClass; + private static get myPrivateStaticMethod(); + get myPublicMethod(): privateClass; + private get myPrivateMethod(); + static get myPublicStaticMethod1(): privateClass; + private static get myPrivateStaticMethod1(); + get myPublicMethod1(): privateClass; + private get myPrivateMethod1(); } export declare class publicClassWithWithPublicGetAccessorTypes { - static readonly myPublicStaticMethod: publicClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: publicClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: publicClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: publicClass; - private readonly myPrivateMethod1; + static get myPublicStaticMethod(): publicClass; + private static get myPrivateStaticMethod(); + get myPublicMethod(): publicClass; + private get myPrivateMethod(); + static get myPublicStaticMethod1(): publicClass; + private static get myPrivateStaticMethod1(); + get myPublicMethod1(): publicClass; + private get myPrivateMethod1(); } export declare class publicClassWithWithPrivateSetAccessorTypes { - static myPublicStaticMethod: privateClass; - private static myPrivateStaticMethod; - myPublicMethod: privateClass; - private myPrivateMethod; + static set myPublicStaticMethod(param: privateClass); + private static set myPrivateStaticMethod(value); + set myPublicMethod(param: privateClass); + private set myPrivateMethod(value); } export declare class publicClassWithWithPublicSetAccessorTypes { - static myPublicStaticMethod: publicClass; - private static myPrivateStaticMethod; - myPublicMethod: publicClass; - private myPrivateMethod; + static set myPublicStaticMethod(param: publicClass); + private static set myPrivateStaticMethod(value); + set myPublicMethod(param: publicClass); + private set myPrivateMethod(value); } export declare class publicClassWithPrivateModuleGetAccessorTypes { - static readonly myPublicStaticMethod: privateModule.publicClass; - readonly myPublicMethod: privateModule.publicClass; - static readonly myPublicStaticMethod1: privateModule.publicClass; - readonly myPublicMethod1: privateModule.publicClass; + static get myPublicStaticMethod(): privateModule.publicClass; + get myPublicMethod(): privateModule.publicClass; + static get myPublicStaticMethod1(): privateModule.publicClass; + get myPublicMethod1(): privateModule.publicClass; } export declare class publicClassWithPrivateModuleSetAccessorTypes { - static myPublicStaticMethod: privateModule.publicClass; - myPublicMethod: privateModule.publicClass; + static set myPublicStaticMethod(param: privateModule.publicClass); + set myPublicMethod(param: privateModule.publicClass); } export declare module publicModule { class privateClass { @@ -3609,46 +3609,46 @@ export declare module publicModule { export class publicClass { } export class publicClassWithWithPrivateGetAccessorTypes { - static readonly myPublicStaticMethod: privateClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: privateClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: privateClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: privateClass; - private readonly myPrivateMethod1; + static get myPublicStaticMethod(): privateClass; + private static get myPrivateStaticMethod(); + get myPublicMethod(): privateClass; + private get myPrivateMethod(); + static get myPublicStaticMethod1(): privateClass; + private static get myPrivateStaticMethod1(); + get myPublicMethod1(): privateClass; + private get myPrivateMethod1(); } export class publicClassWithWithPublicGetAccessorTypes { - static readonly myPublicStaticMethod: publicClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: publicClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: publicClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: publicClass; - private readonly myPrivateMethod1; + static get myPublicStaticMethod(): publicClass; + private static get myPrivateStaticMethod(); + get myPublicMethod(): publicClass; + private get myPrivateMethod(); + static get myPublicStaticMethod1(): publicClass; + private static get myPrivateStaticMethod1(); + get myPublicMethod1(): publicClass; + private get myPrivateMethod1(); } export class publicClassWithWithPrivateSetAccessorTypes { - static myPublicStaticMethod: privateClass; - private static myPrivateStaticMethod; - myPublicMethod: privateClass; - private myPrivateMethod; + static set myPublicStaticMethod(param: privateClass); + private static set myPrivateStaticMethod(value); + set myPublicMethod(param: privateClass); + private set myPrivateMethod(value); } export class publicClassWithWithPublicSetAccessorTypes { - static myPublicStaticMethod: publicClass; - private static myPrivateStaticMethod; - myPublicMethod: publicClass; - private myPrivateMethod; + static set myPublicStaticMethod(param: publicClass); + private static set myPrivateStaticMethod(value); + set myPublicMethod(param: publicClass); + private set myPrivateMethod(value); } export class publicClassWithPrivateModuleGetAccessorTypes { - static readonly myPublicStaticMethod: privateModule.publicClass; - readonly myPublicMethod: privateModule.publicClass; - static readonly myPublicStaticMethod1: privateModule.publicClass; - readonly myPublicMethod1: privateModule.publicClass; + static get myPublicStaticMethod(): privateModule.publicClass; + get myPublicMethod(): privateModule.publicClass; + static get myPublicStaticMethod1(): privateModule.publicClass; + get myPublicMethod1(): privateModule.publicClass; } export class publicClassWithPrivateModuleSetAccessorTypes { - static myPublicStaticMethod: privateModule.publicClass; - myPublicMethod: privateModule.publicClass; + static set myPublicStaticMethod(param: privateModule.publicClass); + set myPublicMethod(param: privateModule.publicClass); } export {}; } @@ -3658,46 +3658,46 @@ declare module privateModule { export class publicClass { } export class publicClassWithWithPrivateGetAccessorTypes { - static readonly myPublicStaticMethod: privateClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: privateClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: privateClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: privateClass; - private readonly myPrivateMethod1; + static get myPublicStaticMethod(): privateClass; + private static get myPrivateStaticMethod(); + get myPublicMethod(): privateClass; + private get myPrivateMethod(); + static get myPublicStaticMethod1(): privateClass; + private static get myPrivateStaticMethod1(); + get myPublicMethod1(): privateClass; + private get myPrivateMethod1(); } export class publicClassWithWithPublicGetAccessorTypes { - static readonly myPublicStaticMethod: publicClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: publicClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: publicClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: publicClass; - private readonly myPrivateMethod1; + static get myPublicStaticMethod(): publicClass; + private static get myPrivateStaticMethod(); + get myPublicMethod(): publicClass; + private get myPrivateMethod(); + static get myPublicStaticMethod1(): publicClass; + private static get myPrivateStaticMethod1(); + get myPublicMethod1(): publicClass; + private get myPrivateMethod1(); } export class publicClassWithWithPrivateSetAccessorTypes { - static myPublicStaticMethod: privateClass; - private static myPrivateStaticMethod; - myPublicMethod: privateClass; - private myPrivateMethod; + static set myPublicStaticMethod(param: privateClass); + private static set myPrivateStaticMethod(value); + set myPublicMethod(param: privateClass); + private set myPrivateMethod(value); } export class publicClassWithWithPublicSetAccessorTypes { - static myPublicStaticMethod: publicClass; - private static myPrivateStaticMethod; - myPublicMethod: publicClass; - private myPrivateMethod; + static set myPublicStaticMethod(param: publicClass); + private static set myPrivateStaticMethod(value); + set myPublicMethod(param: publicClass); + private set myPrivateMethod(value); } export class publicClassWithPrivateModuleGetAccessorTypes { - static readonly myPublicStaticMethod: privateModule.publicClass; - readonly myPublicMethod: privateModule.publicClass; - static readonly myPublicStaticMethod1: publicClass; - readonly myPublicMethod1: publicClass; + static get myPublicStaticMethod(): privateModule.publicClass; + get myPublicMethod(): privateModule.publicClass; + static get myPublicStaticMethod1(): publicClass; + get myPublicMethod1(): publicClass; } export class publicClassWithPrivateModuleSetAccessorTypes { - static myPublicStaticMethod: privateModule.publicClass; - myPublicMethod: privateModule.publicClass; + static set myPublicStaticMethod(param: privateModule.publicClass); + set myPublicMethod(param: privateModule.publicClass); } export {}; } @@ -3706,20 +3706,20 @@ export {}; declare class publicClassInGlobal { } declare class publicClassInGlobalWithPublicGetAccessorTypes { - static readonly myPublicStaticMethod: publicClassInGlobal; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: publicClassInGlobal; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: publicClassInGlobal; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: publicClassInGlobal; - private readonly myPrivateMethod1; + static get myPublicStaticMethod(): publicClassInGlobal; + private static get myPrivateStaticMethod(); + get myPublicMethod(): publicClassInGlobal; + private get myPrivateMethod(); + static get myPublicStaticMethod1(): publicClassInGlobal; + private static get myPrivateStaticMethod1(); + get myPublicMethod1(): publicClassInGlobal; + private get myPrivateMethod1(); } declare class publicClassInGlobalWithWithPublicSetAccessorTypes { - static myPublicStaticMethod: publicClassInGlobal; - private static myPrivateStaticMethod; - myPublicMethod: publicClassInGlobal; - private myPrivateMethod; + static set myPublicStaticMethod(param: publicClassInGlobal); + private static set myPrivateStaticMethod(value); + set myPublicMethod(param: publicClassInGlobal); + private set myPrivateMethod(value); } declare module publicModuleInGlobal { class privateClass { @@ -3732,90 +3732,90 @@ declare module publicModuleInGlobal { export class publicClass { } export class publicClassWithWithPrivateGetAccessorTypes { - static readonly myPublicStaticMethod: privateClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: privateClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: privateClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: privateClass; - private readonly myPrivateMethod1; + static get myPublicStaticMethod(): privateClass; + private static get myPrivateStaticMethod(); + get myPublicMethod(): privateClass; + private get myPrivateMethod(); + static get myPublicStaticMethod1(): privateClass; + private static get myPrivateStaticMethod1(); + get myPublicMethod1(): privateClass; + private get myPrivateMethod1(); } export class publicClassWithWithPublicGetAccessorTypes { - static readonly myPublicStaticMethod: publicClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: publicClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: publicClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: publicClass; - private readonly myPrivateMethod1; + static get myPublicStaticMethod(): publicClass; + private static get myPrivateStaticMethod(); + get myPublicMethod(): publicClass; + private get myPrivateMethod(); + static get myPublicStaticMethod1(): publicClass; + private static get myPrivateStaticMethod1(); + get myPublicMethod1(): publicClass; + private get myPrivateMethod1(); } export class publicClassWithWithPrivateSetAccessorTypes { - static myPublicStaticMethod: privateClass; - private static myPrivateStaticMethod; - myPublicMethod: privateClass; - private myPrivateMethod; + static set myPublicStaticMethod(param: privateClass); + private static set myPrivateStaticMethod(value); + set myPublicMethod(param: privateClass); + private set myPrivateMethod(value); } export class publicClassWithWithPublicSetAccessorTypes { - static myPublicStaticMethod: publicClass; - private static myPrivateStaticMethod; - myPublicMethod: publicClass; - private myPrivateMethod; + static set myPublicStaticMethod(param: publicClass); + private static set myPrivateStaticMethod(value); + set myPublicMethod(param: publicClass); + private set myPrivateMethod(value); } export class publicClassWithPrivateModuleGetAccessorTypes { - static readonly myPublicStaticMethod: privateModule.publicClass; - readonly myPublicMethod: privateModule.publicClass; - static readonly myPublicStaticMethod1: publicClass; - readonly myPublicMethod1: publicClass; + static get myPublicStaticMethod(): privateModule.publicClass; + get myPublicMethod(): privateModule.publicClass; + static get myPublicStaticMethod1(): publicClass; + get myPublicMethod1(): publicClass; } export class publicClassWithPrivateModuleSetAccessorTypes { - static myPublicStaticMethod: privateModule.publicClass; - myPublicMethod: privateModule.publicClass; + static set myPublicStaticMethod(param: privateModule.publicClass); + set myPublicMethod(param: privateModule.publicClass); } export {}; } export class publicClassWithWithPrivateGetAccessorTypes { - static readonly myPublicStaticMethod: privateClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: privateClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: privateClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: privateClass; - private readonly myPrivateMethod1; + static get myPublicStaticMethod(): privateClass; + private static get myPrivateStaticMethod(); + get myPublicMethod(): privateClass; + private get myPrivateMethod(); + static get myPublicStaticMethod1(): privateClass; + private static get myPrivateStaticMethod1(); + get myPublicMethod1(): privateClass; + private get myPrivateMethod1(); } export class publicClassWithWithPublicGetAccessorTypes { - static readonly myPublicStaticMethod: publicClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: publicClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: publicClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: publicClass; - private readonly myPrivateMethod1; + static get myPublicStaticMethod(): publicClass; + private static get myPrivateStaticMethod(); + get myPublicMethod(): publicClass; + private get myPrivateMethod(); + static get myPublicStaticMethod1(): publicClass; + private static get myPrivateStaticMethod1(); + get myPublicMethod1(): publicClass; + private get myPrivateMethod1(); } export class publicClassWithWithPrivateSetAccessorTypes { - static myPublicStaticMethod: privateClass; - private static myPrivateStaticMethod; - myPublicMethod: privateClass; - private myPrivateMethod; + static set myPublicStaticMethod(param: privateClass); + private static set myPrivateStaticMethod(value); + set myPublicMethod(param: privateClass); + private set myPrivateMethod(value); } export class publicClassWithWithPublicSetAccessorTypes { - static myPublicStaticMethod: publicClass; - private static myPrivateStaticMethod; - myPublicMethod: publicClass; - private myPrivateMethod; + static set myPublicStaticMethod(param: publicClass); + private static set myPrivateStaticMethod(value); + set myPublicMethod(param: publicClass); + private set myPrivateMethod(value); } export class publicClassWithPrivateModuleGetAccessorTypes { - static readonly myPublicStaticMethod: privateModule.publicClass; - readonly myPublicMethod: privateModule.publicClass; - static readonly myPublicStaticMethod1: privateModule.publicClass; - readonly myPublicMethod1: privateModule.publicClass; + static get myPublicStaticMethod(): privateModule.publicClass; + get myPublicMethod(): privateModule.publicClass; + static get myPublicStaticMethod1(): privateModule.publicClass; + get myPublicMethod1(): privateModule.publicClass; } export class publicClassWithPrivateModuleSetAccessorTypes { - static myPublicStaticMethod: privateModule.publicClass; - myPublicMethod: privateModule.publicClass; + static set myPublicStaticMethod(param: privateModule.publicClass); + set myPublicMethod(param: privateModule.publicClass); } export {}; } diff --git a/tests/baselines/reference/privacyCannotNameAccessorDeclFile.js b/tests/baselines/reference/privacyCannotNameAccessorDeclFile.js index 42f7639986913..e0dc38bcfcd58 100644 --- a/tests/baselines/reference/privacyCannotNameAccessorDeclFile.js +++ b/tests/baselines/reference/privacyCannotNameAccessorDeclFile.js @@ -417,18 +417,18 @@ export declare function createExportedWidget4(): Widgets1.SpecializedGlobalWidge //// [privacyCannotNameAccessorDeclFile_consumer.d.ts] /// export declare class publicClassWithWithPrivateGetAccessorTypes { - static readonly myPublicStaticMethod: import("./privacyCannotNameAccessorDeclFile_Widgets").Widget1; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: import("./privacyCannotNameAccessorDeclFile_Widgets").Widget1; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: import("GlobalWidgets").Widget3; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: import("GlobalWidgets").Widget3; - private readonly myPrivateMethod1; + static get myPublicStaticMethod(): import("./privacyCannotNameAccessorDeclFile_Widgets").Widget1; + private static get myPrivateStaticMethod(); + get myPublicMethod(): import("./privacyCannotNameAccessorDeclFile_Widgets").Widget1; + private get myPrivateMethod(); + static get myPublicStaticMethod1(): import("GlobalWidgets").Widget3; + private static get myPrivateStaticMethod1(); + get myPublicMethod1(): import("GlobalWidgets").Widget3; + private get myPrivateMethod1(); } export declare class publicClassWithPrivateModuleGetAccessorTypes { - static readonly myPublicStaticMethod: import("./privacyCannotNameAccessorDeclFile_Widgets").SpecializedWidget.Widget2; - readonly myPublicMethod: import("./privacyCannotNameAccessorDeclFile_Widgets").SpecializedWidget.Widget2; - static readonly myPublicStaticMethod1: import("GlobalWidgets").SpecializedGlobalWidget.Widget4; - readonly myPublicMethod1: import("GlobalWidgets").SpecializedGlobalWidget.Widget4; + static get myPublicStaticMethod(): import("./privacyCannotNameAccessorDeclFile_Widgets").SpecializedWidget.Widget2; + get myPublicMethod(): import("./privacyCannotNameAccessorDeclFile_Widgets").SpecializedWidget.Widget2; + static get myPublicStaticMethod1(): import("GlobalWidgets").SpecializedGlobalWidget.Widget4; + get myPublicMethod1(): import("GlobalWidgets").SpecializedGlobalWidget.Widget4; } diff --git a/tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/stripInternal.js b/tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/stripInternal.js index 4de45c6d0ecf5..ebb144304fbb6 100644 --- a/tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/stripInternal.js +++ b/tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/stripInternal.js @@ -3533,32 +3533,32 @@ sourceFile:global.ts }, { "pos": 108, - "end": 212, + "end": 233, "kind": "internal" }, { - "pos": 214, - "end": 253, + "pos": 235, + "end": 274, "kind": "text" }, { - "pos": 253, - "end": 721, + "pos": 274, + "end": 742, "kind": "internal" }, { - "pos": 723, - "end": 730, + "pos": 744, + "end": 751, "kind": "text" }, { - "pos": 730, - "end": 1219, + "pos": 751, + "end": 1240, "kind": "internal" }, { - "pos": 1221, - "end": 1312, + "pos": 1242, + "end": 1333, "kind": "text" } ] @@ -3689,18 +3689,19 @@ declare module "file1" { export class normalC { ---------------------------------------------------------------------- -internal: (108-212) +internal: (108-233) constructor(); prop: string; method(): void; - /*@internal*/ c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (214-253) +text: (235-274) } export namespace normalN { ---------------------------------------------------------------------- -internal: (253-721) +internal: (274-742) class C { } function foo(): void; @@ -3721,11 +3722,11 @@ internal: (253-721) c = 2 } ---------------------------------------------------------------------- -text: (723-730) +text: (744-751) } ---------------------------------------------------------------------- -internal: (730-1219) +internal: (751-1240) export class internalC { } export function internalfoo(): void; @@ -3746,7 +3747,7 @@ internal: (730-1219) c = 2 } ---------------------------------------------------------------------- -text: (1221-1312) +text: (1242-1333) } declare module "file2" { export const y = 20; diff --git a/tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-headers-change-without-dts-changes/stripInternal.js b/tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-headers-change-without-dts-changes/stripInternal.js index 218681bea8ffd..62a70092797fd 100644 --- a/tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-headers-change-without-dts-changes/stripInternal.js +++ b/tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-headers-change-without-dts-changes/stripInternal.js @@ -2073,7 +2073,7 @@ export namespace normalN { //// [/src/lib/module.d.ts] file written with same contents //// [/src/lib/module.d.ts.map] -{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["file0.ts","file1.ts","file2.ts","global.ts"],"names":[],"mappings":"AAAc,QAAA,MAAM,MAAM,KAAK,CAAC;;ICAlB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;IAClC,MAAM,OAAO,OAAO;;QAEF,IAAI,EAAE,MAAM,CAAC;QACb,MAAM;sBACF,CAAC,EACM,MAAM;KAClC;IACD,MAAM,WAAW,OAAO,CAAC;QACP,MAAa,CAAC;SAAI;QAClB,SAAgB,GAAG,SAAK;QACxB,UAAiB,aAAa,CAAC;YAAE,MAAa,CAAC;aAAG;SAAE;QACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;YAAE,MAAa,SAAS;aAAG;SAAE;QAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;QAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;QAC9B,MAAM,aAAa,KAAK,CAAC;QAChC,KAAY,YAAY;YAAG,CAAC,IAAA;YAAE,CAAC,IAAA;YAAE,CAAC,IAAA;SAAE;KACrD;IACa,MAAM,OAAO,SAAS;KAAG;IACzB,MAAM,UAAU,WAAW,SAAK;IAChC,MAAM,WAAW,iBAAiB,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAChE,MAAM,WAAW,aAAa,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IACtE,MAAM,QAAQ,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;IAC3D,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC;IACrC,MAAM,CAAC,MAAM,aAAa,KAAK,CAAC;IAChC,MAAM,MAAM,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;;;ICzBlD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;;ACApB,QAAA,MAAM,WAAW,KAAK,CAAC"} +{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["file0.ts","file1.ts","file2.ts","global.ts"],"names":[],"mappings":"AAAc,QAAA,MAAM,MAAM,KAAK,CAAC;;ICAlB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;IAClC,MAAM,OAAO,OAAO;;QAEF,IAAI,EAAE,MAAM,CAAC;QACb,MAAM;QACN,IAAI,CAAC,IACM,MAAM,CADK;QACtB,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;KACvC;IACD,MAAM,WAAW,OAAO,CAAC;QACP,MAAa,CAAC;SAAI;QAClB,SAAgB,GAAG,SAAK;QACxB,UAAiB,aAAa,CAAC;YAAE,MAAa,CAAC;aAAG;SAAE;QACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;YAAE,MAAa,SAAS;aAAG;SAAE;QAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;QAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;QAC9B,MAAM,aAAa,KAAK,CAAC;QAChC,KAAY,YAAY;YAAG,CAAC,IAAA;YAAE,CAAC,IAAA;YAAE,CAAC,IAAA;SAAE;KACrD;IACa,MAAM,OAAO,SAAS;KAAG;IACzB,MAAM,UAAU,WAAW,SAAK;IAChC,MAAM,WAAW,iBAAiB,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAChE,MAAM,WAAW,aAAa,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IACtE,MAAM,QAAQ,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;IAC3D,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC;IACrC,MAAM,CAAC,MAAM,aAAa,KAAK,CAAC;IAChC,MAAM,MAAM,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;;;ICzBlD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;;ACApB,QAAA,MAAM,WAAW,KAAK,CAAC"} //// [/src/lib/module.d.ts.map.baseline.txt] =================================================================== @@ -2174,35 +2174,66 @@ sourceFile:file1.ts >>> method(): void; 1->^^^^^^^^ 2 > ^^^^^^ -3 > ^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^-> 1-> > /*@internal*/ 2 > method 1->Emitted(7, 9) Source(5, 19) + SourceIndex(1) 2 >Emitted(7, 15) Source(5, 25) + SourceIndex(1) --- ->>> /*@internal*/ c: number; -1->^^^^^^^^^^^^^^^^^^^^^^ -2 > ^ -3 > ^^ -4 > ^^^^^^ +>>> get c(): number; +1->^^^^^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^^ +5 > ^^^^^^ +6 > ^ +7 > ^^^^-> 1->() { } - > /*@internal*/ get -2 > c -3 > () { return 10; } - > /*@internal*/ set c(val: -4 > number -1->Emitted(8, 23) Source(6, 23) + SourceIndex(1) -2 >Emitted(8, 24) Source(6, 24) + SourceIndex(1) -3 >Emitted(8, 26) Source(7, 30) + SourceIndex(1) -4 >Emitted(8, 32) Source(7, 36) + SourceIndex(1) + > /*@internal*/ +2 > get +3 > c +4 > () { return 10; } + > /*@internal*/ set c(val: +5 > number +6 > +1->Emitted(8, 9) Source(6, 19) + SourceIndex(1) +2 >Emitted(8, 13) Source(6, 23) + SourceIndex(1) +3 >Emitted(8, 14) Source(6, 24) + SourceIndex(1) +4 >Emitted(8, 18) Source(7, 30) + SourceIndex(1) +5 >Emitted(8, 24) Source(7, 36) + SourceIndex(1) +6 >Emitted(8, 25) Source(6, 41) + SourceIndex(1) +--- +>>> set c(val: number); +1->^^^^^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^ +6 > ^^^^^^ +7 > ^^ +1-> + > /*@internal*/ +2 > set +3 > c +4 > ( +5 > val: +6 > number +7 > ) { } +1->Emitted(9, 9) Source(7, 19) + SourceIndex(1) +2 >Emitted(9, 13) Source(7, 23) + SourceIndex(1) +3 >Emitted(9, 14) Source(7, 24) + SourceIndex(1) +4 >Emitted(9, 15) Source(7, 25) + SourceIndex(1) +5 >Emitted(9, 20) Source(7, 30) + SourceIndex(1) +6 >Emitted(9, 26) Source(7, 36) + SourceIndex(1) +7 >Emitted(9, 28) Source(7, 41) + SourceIndex(1) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(9, 6) Source(8, 2) + SourceIndex(1) +1 >Emitted(10, 6) Source(8, 2) + SourceIndex(1) --- >>> export namespace normalN { 1->^^^^ @@ -2216,11 +2247,11 @@ sourceFile:file1.ts 3 > namespace 4 > normalN 5 > -1->Emitted(10, 5) Source(9, 1) + SourceIndex(1) -2 >Emitted(10, 11) Source(9, 7) + SourceIndex(1) -3 >Emitted(10, 22) Source(9, 18) + SourceIndex(1) -4 >Emitted(10, 29) Source(9, 25) + SourceIndex(1) -5 >Emitted(10, 30) Source(9, 26) + SourceIndex(1) +1->Emitted(11, 5) Source(9, 1) + SourceIndex(1) +2 >Emitted(11, 11) Source(9, 7) + SourceIndex(1) +3 >Emitted(11, 22) Source(9, 18) + SourceIndex(1) +4 >Emitted(11, 29) Source(9, 25) + SourceIndex(1) +5 >Emitted(11, 30) Source(9, 26) + SourceIndex(1) --- >>> class C { 1 >^^^^^^^^ @@ -2230,15 +2261,15 @@ sourceFile:file1.ts > /*@internal*/ 2 > export class 3 > C -1 >Emitted(11, 9) Source(10, 19) + SourceIndex(1) -2 >Emitted(11, 15) Source(10, 32) + SourceIndex(1) -3 >Emitted(11, 16) Source(10, 33) + SourceIndex(1) +1 >Emitted(12, 9) Source(10, 19) + SourceIndex(1) +2 >Emitted(12, 15) Source(10, 32) + SourceIndex(1) +3 >Emitted(12, 16) Source(10, 33) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(12, 10) Source(10, 37) + SourceIndex(1) +1 >Emitted(13, 10) Source(10, 37) + SourceIndex(1) --- >>> function foo(): void; 1->^^^^^^^^ @@ -2251,10 +2282,10 @@ sourceFile:file1.ts 2 > export function 3 > foo 4 > () {} -1->Emitted(13, 9) Source(11, 19) + SourceIndex(1) -2 >Emitted(13, 18) Source(11, 35) + SourceIndex(1) -3 >Emitted(13, 21) Source(11, 38) + SourceIndex(1) -4 >Emitted(13, 30) Source(11, 43) + SourceIndex(1) +1->Emitted(14, 9) Source(11, 19) + SourceIndex(1) +2 >Emitted(14, 18) Source(11, 35) + SourceIndex(1) +3 >Emitted(14, 21) Source(11, 38) + SourceIndex(1) +4 >Emitted(14, 30) Source(11, 43) + SourceIndex(1) --- >>> namespace someNamespace { 1->^^^^^^^^ @@ -2266,10 +2297,10 @@ sourceFile:file1.ts 2 > export namespace 3 > someNamespace 4 > -1->Emitted(14, 9) Source(12, 19) + SourceIndex(1) -2 >Emitted(14, 19) Source(12, 36) + SourceIndex(1) -3 >Emitted(14, 32) Source(12, 49) + SourceIndex(1) -4 >Emitted(14, 33) Source(12, 50) + SourceIndex(1) +1->Emitted(15, 9) Source(12, 19) + SourceIndex(1) +2 >Emitted(15, 19) Source(12, 36) + SourceIndex(1) +3 >Emitted(15, 32) Source(12, 49) + SourceIndex(1) +4 >Emitted(15, 33) Source(12, 50) + SourceIndex(1) --- >>> class C { 1 >^^^^^^^^^^^^ @@ -2278,20 +2309,20 @@ sourceFile:file1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(15, 13) Source(12, 52) + SourceIndex(1) -2 >Emitted(15, 19) Source(12, 65) + SourceIndex(1) -3 >Emitted(15, 20) Source(12, 66) + SourceIndex(1) +1 >Emitted(16, 13) Source(12, 52) + SourceIndex(1) +2 >Emitted(16, 19) Source(12, 65) + SourceIndex(1) +3 >Emitted(16, 20) Source(12, 66) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^^^^^ 1 > {} -1 >Emitted(16, 14) Source(12, 69) + SourceIndex(1) +1 >Emitted(17, 14) Source(12, 69) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(17, 10) Source(12, 71) + SourceIndex(1) +1 >Emitted(18, 10) Source(12, 71) + SourceIndex(1) --- >>> namespace someOther.something { 1->^^^^^^^^ @@ -2307,12 +2338,12 @@ sourceFile:file1.ts 4 > . 5 > something 6 > -1->Emitted(18, 9) Source(13, 19) + SourceIndex(1) -2 >Emitted(18, 19) Source(13, 36) + SourceIndex(1) -3 >Emitted(18, 28) Source(13, 45) + SourceIndex(1) -4 >Emitted(18, 29) Source(13, 46) + SourceIndex(1) -5 >Emitted(18, 38) Source(13, 55) + SourceIndex(1) -6 >Emitted(18, 39) Source(13, 56) + SourceIndex(1) +1->Emitted(19, 9) Source(13, 19) + SourceIndex(1) +2 >Emitted(19, 19) Source(13, 36) + SourceIndex(1) +3 >Emitted(19, 28) Source(13, 45) + SourceIndex(1) +4 >Emitted(19, 29) Source(13, 46) + SourceIndex(1) +5 >Emitted(19, 38) Source(13, 55) + SourceIndex(1) +6 >Emitted(19, 39) Source(13, 56) + SourceIndex(1) --- >>> class someClass { 1 >^^^^^^^^^^^^ @@ -2321,20 +2352,20 @@ sourceFile:file1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(19, 13) Source(13, 58) + SourceIndex(1) -2 >Emitted(19, 19) Source(13, 71) + SourceIndex(1) -3 >Emitted(19, 28) Source(13, 80) + SourceIndex(1) +1 >Emitted(20, 13) Source(13, 58) + SourceIndex(1) +2 >Emitted(20, 19) Source(13, 71) + SourceIndex(1) +3 >Emitted(20, 28) Source(13, 80) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^^^^^ 1 > {} -1 >Emitted(20, 14) Source(13, 83) + SourceIndex(1) +1 >Emitted(21, 14) Source(13, 83) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(21, 10) Source(13, 85) + SourceIndex(1) +1 >Emitted(22, 10) Source(13, 85) + SourceIndex(1) --- >>> export import someImport = someNamespace.C; 1->^^^^^^^^ @@ -2356,15 +2387,15 @@ sourceFile:file1.ts 7 > . 8 > C 9 > ; -1->Emitted(22, 9) Source(14, 19) + SourceIndex(1) -2 >Emitted(22, 15) Source(14, 25) + SourceIndex(1) -3 >Emitted(22, 23) Source(14, 33) + SourceIndex(1) -4 >Emitted(22, 33) Source(14, 43) + SourceIndex(1) -5 >Emitted(22, 36) Source(14, 46) + SourceIndex(1) -6 >Emitted(22, 49) Source(14, 59) + SourceIndex(1) -7 >Emitted(22, 50) Source(14, 60) + SourceIndex(1) -8 >Emitted(22, 51) Source(14, 61) + SourceIndex(1) -9 >Emitted(22, 52) Source(14, 62) + SourceIndex(1) +1->Emitted(23, 9) Source(14, 19) + SourceIndex(1) +2 >Emitted(23, 15) Source(14, 25) + SourceIndex(1) +3 >Emitted(23, 23) Source(14, 33) + SourceIndex(1) +4 >Emitted(23, 33) Source(14, 43) + SourceIndex(1) +5 >Emitted(23, 36) Source(14, 46) + SourceIndex(1) +6 >Emitted(23, 49) Source(14, 59) + SourceIndex(1) +7 >Emitted(23, 50) Source(14, 60) + SourceIndex(1) +8 >Emitted(23, 51) Source(14, 61) + SourceIndex(1) +9 >Emitted(23, 52) Source(14, 62) + SourceIndex(1) --- >>> type internalType = internalC; 1 >^^^^^^^^ @@ -2380,12 +2411,12 @@ sourceFile:file1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(23, 9) Source(15, 19) + SourceIndex(1) -2 >Emitted(23, 14) Source(15, 31) + SourceIndex(1) -3 >Emitted(23, 26) Source(15, 43) + SourceIndex(1) -4 >Emitted(23, 29) Source(15, 46) + SourceIndex(1) -5 >Emitted(23, 38) Source(15, 55) + SourceIndex(1) -6 >Emitted(23, 39) Source(15, 56) + SourceIndex(1) +1 >Emitted(24, 9) Source(15, 19) + SourceIndex(1) +2 >Emitted(24, 14) Source(15, 31) + SourceIndex(1) +3 >Emitted(24, 26) Source(15, 43) + SourceIndex(1) +4 >Emitted(24, 29) Source(15, 46) + SourceIndex(1) +5 >Emitted(24, 38) Source(15, 55) + SourceIndex(1) +6 >Emitted(24, 39) Source(15, 56) + SourceIndex(1) --- >>> const internalConst = 10; 1 >^^^^^^^^ @@ -2399,11 +2430,11 @@ sourceFile:file1.ts 3 > internalConst 4 > = 10 5 > ; -1 >Emitted(24, 9) Source(16, 26) + SourceIndex(1) -2 >Emitted(24, 15) Source(16, 32) + SourceIndex(1) -3 >Emitted(24, 28) Source(16, 45) + SourceIndex(1) -4 >Emitted(24, 33) Source(16, 50) + SourceIndex(1) -5 >Emitted(24, 34) Source(16, 51) + SourceIndex(1) +1 >Emitted(25, 9) Source(16, 26) + SourceIndex(1) +2 >Emitted(25, 15) Source(16, 32) + SourceIndex(1) +3 >Emitted(25, 28) Source(16, 45) + SourceIndex(1) +4 >Emitted(25, 33) Source(16, 50) + SourceIndex(1) +5 >Emitted(25, 34) Source(16, 51) + SourceIndex(1) --- >>> enum internalEnum { 1 >^^^^^^^^ @@ -2413,9 +2444,9 @@ sourceFile:file1.ts > /*@internal*/ 2 > export enum 3 > internalEnum -1 >Emitted(25, 9) Source(17, 19) + SourceIndex(1) -2 >Emitted(25, 14) Source(17, 31) + SourceIndex(1) -3 >Emitted(25, 26) Source(17, 43) + SourceIndex(1) +1 >Emitted(26, 9) Source(17, 19) + SourceIndex(1) +2 >Emitted(26, 14) Source(17, 31) + SourceIndex(1) +3 >Emitted(26, 26) Source(17, 43) + SourceIndex(1) --- >>> a = 0, 1 >^^^^^^^^^^^^ @@ -2425,9 +2456,9 @@ sourceFile:file1.ts 1 > { 2 > a 3 > -1 >Emitted(26, 13) Source(17, 46) + SourceIndex(1) -2 >Emitted(26, 14) Source(17, 47) + SourceIndex(1) -3 >Emitted(26, 18) Source(17, 47) + SourceIndex(1) +1 >Emitted(27, 13) Source(17, 46) + SourceIndex(1) +2 >Emitted(27, 14) Source(17, 47) + SourceIndex(1) +3 >Emitted(27, 18) Source(17, 47) + SourceIndex(1) --- >>> b = 1, 1->^^^^^^^^^^^^ @@ -2437,9 +2468,9 @@ sourceFile:file1.ts 1->, 2 > b 3 > -1->Emitted(27, 13) Source(17, 49) + SourceIndex(1) -2 >Emitted(27, 14) Source(17, 50) + SourceIndex(1) -3 >Emitted(27, 18) Source(17, 50) + SourceIndex(1) +1->Emitted(28, 13) Source(17, 49) + SourceIndex(1) +2 >Emitted(28, 14) Source(17, 50) + SourceIndex(1) +3 >Emitted(28, 18) Source(17, 50) + SourceIndex(1) --- >>> c = 2 1->^^^^^^^^^^^^ @@ -2448,21 +2479,21 @@ sourceFile:file1.ts 1->, 2 > c 3 > -1->Emitted(28, 13) Source(17, 52) + SourceIndex(1) -2 >Emitted(28, 14) Source(17, 53) + SourceIndex(1) -3 >Emitted(28, 18) Source(17, 53) + SourceIndex(1) +1->Emitted(29, 13) Source(17, 52) + SourceIndex(1) +2 >Emitted(29, 14) Source(17, 53) + SourceIndex(1) +3 >Emitted(29, 18) Source(17, 53) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^ 1 > } -1 >Emitted(29, 10) Source(17, 55) + SourceIndex(1) +1 >Emitted(30, 10) Source(17, 55) + SourceIndex(1) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(30, 6) Source(18, 2) + SourceIndex(1) +1 >Emitted(31, 6) Source(18, 2) + SourceIndex(1) --- >>> export class internalC { 1->^^^^ @@ -2474,16 +2505,16 @@ sourceFile:file1.ts 2 > export 3 > class 4 > internalC -1->Emitted(31, 5) Source(19, 15) + SourceIndex(1) -2 >Emitted(31, 11) Source(19, 21) + SourceIndex(1) -3 >Emitted(31, 18) Source(19, 28) + SourceIndex(1) -4 >Emitted(31, 27) Source(19, 37) + SourceIndex(1) +1->Emitted(32, 5) Source(19, 15) + SourceIndex(1) +2 >Emitted(32, 11) Source(19, 21) + SourceIndex(1) +3 >Emitted(32, 18) Source(19, 28) + SourceIndex(1) +4 >Emitted(32, 27) Source(19, 37) + SourceIndex(1) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(32, 6) Source(19, 40) + SourceIndex(1) +1 >Emitted(33, 6) Source(19, 40) + SourceIndex(1) --- >>> export function internalfoo(): void; 1->^^^^ @@ -2498,11 +2529,11 @@ sourceFile:file1.ts 3 > function 4 > internalfoo 5 > () {} -1->Emitted(33, 5) Source(20, 15) + SourceIndex(1) -2 >Emitted(33, 11) Source(20, 21) + SourceIndex(1) -3 >Emitted(33, 21) Source(20, 31) + SourceIndex(1) -4 >Emitted(33, 32) Source(20, 42) + SourceIndex(1) -5 >Emitted(33, 41) Source(20, 47) + SourceIndex(1) +1->Emitted(34, 5) Source(20, 15) + SourceIndex(1) +2 >Emitted(34, 11) Source(20, 21) + SourceIndex(1) +3 >Emitted(34, 21) Source(20, 31) + SourceIndex(1) +4 >Emitted(34, 32) Source(20, 42) + SourceIndex(1) +5 >Emitted(34, 41) Source(20, 47) + SourceIndex(1) --- >>> export namespace internalNamespace { 1->^^^^ @@ -2516,11 +2547,11 @@ sourceFile:file1.ts 3 > namespace 4 > internalNamespace 5 > -1->Emitted(34, 5) Source(21, 15) + SourceIndex(1) -2 >Emitted(34, 11) Source(21, 21) + SourceIndex(1) -3 >Emitted(34, 22) Source(21, 32) + SourceIndex(1) -4 >Emitted(34, 39) Source(21, 49) + SourceIndex(1) -5 >Emitted(34, 40) Source(21, 50) + SourceIndex(1) +1->Emitted(35, 5) Source(21, 15) + SourceIndex(1) +2 >Emitted(35, 11) Source(21, 21) + SourceIndex(1) +3 >Emitted(35, 22) Source(21, 32) + SourceIndex(1) +4 >Emitted(35, 39) Source(21, 49) + SourceIndex(1) +5 >Emitted(35, 40) Source(21, 50) + SourceIndex(1) --- >>> class someClass { 1 >^^^^^^^^ @@ -2529,20 +2560,20 @@ sourceFile:file1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(35, 9) Source(21, 52) + SourceIndex(1) -2 >Emitted(35, 15) Source(21, 65) + SourceIndex(1) -3 >Emitted(35, 24) Source(21, 74) + SourceIndex(1) +1 >Emitted(36, 9) Source(21, 52) + SourceIndex(1) +2 >Emitted(36, 15) Source(21, 65) + SourceIndex(1) +3 >Emitted(36, 24) Source(21, 74) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(36, 10) Source(21, 77) + SourceIndex(1) +1 >Emitted(37, 10) Source(21, 77) + SourceIndex(1) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(37, 6) Source(21, 79) + SourceIndex(1) +1 >Emitted(38, 6) Source(21, 79) + SourceIndex(1) --- >>> export namespace internalOther.something { 1->^^^^ @@ -2560,13 +2591,13 @@ sourceFile:file1.ts 5 > . 6 > something 7 > -1->Emitted(38, 5) Source(22, 15) + SourceIndex(1) -2 >Emitted(38, 11) Source(22, 21) + SourceIndex(1) -3 >Emitted(38, 22) Source(22, 32) + SourceIndex(1) -4 >Emitted(38, 35) Source(22, 45) + SourceIndex(1) -5 >Emitted(38, 36) Source(22, 46) + SourceIndex(1) -6 >Emitted(38, 45) Source(22, 55) + SourceIndex(1) -7 >Emitted(38, 46) Source(22, 56) + SourceIndex(1) +1->Emitted(39, 5) Source(22, 15) + SourceIndex(1) +2 >Emitted(39, 11) Source(22, 21) + SourceIndex(1) +3 >Emitted(39, 22) Source(22, 32) + SourceIndex(1) +4 >Emitted(39, 35) Source(22, 45) + SourceIndex(1) +5 >Emitted(39, 36) Source(22, 46) + SourceIndex(1) +6 >Emitted(39, 45) Source(22, 55) + SourceIndex(1) +7 >Emitted(39, 46) Source(22, 56) + SourceIndex(1) --- >>> class someClass { 1 >^^^^^^^^ @@ -2575,20 +2606,20 @@ sourceFile:file1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(39, 9) Source(22, 58) + SourceIndex(1) -2 >Emitted(39, 15) Source(22, 71) + SourceIndex(1) -3 >Emitted(39, 24) Source(22, 80) + SourceIndex(1) +1 >Emitted(40, 9) Source(22, 58) + SourceIndex(1) +2 >Emitted(40, 15) Source(22, 71) + SourceIndex(1) +3 >Emitted(40, 24) Source(22, 80) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(40, 10) Source(22, 83) + SourceIndex(1) +1 >Emitted(41, 10) Source(22, 83) + SourceIndex(1) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(41, 6) Source(22, 85) + SourceIndex(1) +1 >Emitted(42, 6) Source(22, 85) + SourceIndex(1) --- >>> export import internalImport = internalNamespace.someClass; 1->^^^^ @@ -2610,15 +2641,15 @@ sourceFile:file1.ts 7 > . 8 > someClass 9 > ; -1->Emitted(42, 5) Source(23, 15) + SourceIndex(1) -2 >Emitted(42, 11) Source(23, 21) + SourceIndex(1) -3 >Emitted(42, 19) Source(23, 29) + SourceIndex(1) -4 >Emitted(42, 33) Source(23, 43) + SourceIndex(1) -5 >Emitted(42, 36) Source(23, 46) + SourceIndex(1) -6 >Emitted(42, 53) Source(23, 63) + SourceIndex(1) -7 >Emitted(42, 54) Source(23, 64) + SourceIndex(1) -8 >Emitted(42, 63) Source(23, 73) + SourceIndex(1) -9 >Emitted(42, 64) Source(23, 74) + SourceIndex(1) +1->Emitted(43, 5) Source(23, 15) + SourceIndex(1) +2 >Emitted(43, 11) Source(23, 21) + SourceIndex(1) +3 >Emitted(43, 19) Source(23, 29) + SourceIndex(1) +4 >Emitted(43, 33) Source(23, 43) + SourceIndex(1) +5 >Emitted(43, 36) Source(23, 46) + SourceIndex(1) +6 >Emitted(43, 53) Source(23, 63) + SourceIndex(1) +7 >Emitted(43, 54) Source(23, 64) + SourceIndex(1) +8 >Emitted(43, 63) Source(23, 73) + SourceIndex(1) +9 >Emitted(43, 64) Source(23, 74) + SourceIndex(1) --- >>> export type internalType = internalC; 1 >^^^^ @@ -2636,13 +2667,13 @@ sourceFile:file1.ts 5 > = 6 > internalC 7 > ; -1 >Emitted(43, 5) Source(24, 15) + SourceIndex(1) -2 >Emitted(43, 11) Source(24, 21) + SourceIndex(1) -3 >Emitted(43, 17) Source(24, 27) + SourceIndex(1) -4 >Emitted(43, 29) Source(24, 39) + SourceIndex(1) -5 >Emitted(43, 32) Source(24, 42) + SourceIndex(1) -6 >Emitted(43, 41) Source(24, 51) + SourceIndex(1) -7 >Emitted(43, 42) Source(24, 52) + SourceIndex(1) +1 >Emitted(44, 5) Source(24, 15) + SourceIndex(1) +2 >Emitted(44, 11) Source(24, 21) + SourceIndex(1) +3 >Emitted(44, 17) Source(24, 27) + SourceIndex(1) +4 >Emitted(44, 29) Source(24, 39) + SourceIndex(1) +5 >Emitted(44, 32) Source(24, 42) + SourceIndex(1) +6 >Emitted(44, 41) Source(24, 51) + SourceIndex(1) +7 >Emitted(44, 42) Source(24, 52) + SourceIndex(1) --- >>> export const internalConst = 10; 1 >^^^^ @@ -2660,13 +2691,13 @@ sourceFile:file1.ts 5 > internalConst 6 > = 10 7 > ; -1 >Emitted(44, 5) Source(25, 15) + SourceIndex(1) -2 >Emitted(44, 11) Source(25, 21) + SourceIndex(1) -3 >Emitted(44, 12) Source(25, 22) + SourceIndex(1) -4 >Emitted(44, 18) Source(25, 28) + SourceIndex(1) -5 >Emitted(44, 31) Source(25, 41) + SourceIndex(1) -6 >Emitted(44, 36) Source(25, 46) + SourceIndex(1) -7 >Emitted(44, 37) Source(25, 47) + SourceIndex(1) +1 >Emitted(45, 5) Source(25, 15) + SourceIndex(1) +2 >Emitted(45, 11) Source(25, 21) + SourceIndex(1) +3 >Emitted(45, 12) Source(25, 22) + SourceIndex(1) +4 >Emitted(45, 18) Source(25, 28) + SourceIndex(1) +5 >Emitted(45, 31) Source(25, 41) + SourceIndex(1) +6 >Emitted(45, 36) Source(25, 46) + SourceIndex(1) +7 >Emitted(45, 37) Source(25, 47) + SourceIndex(1) --- >>> export enum internalEnum { 1 >^^^^ @@ -2678,10 +2709,10 @@ sourceFile:file1.ts 2 > export 3 > enum 4 > internalEnum -1 >Emitted(45, 5) Source(26, 15) + SourceIndex(1) -2 >Emitted(45, 11) Source(26, 21) + SourceIndex(1) -3 >Emitted(45, 17) Source(26, 27) + SourceIndex(1) -4 >Emitted(45, 29) Source(26, 39) + SourceIndex(1) +1 >Emitted(46, 5) Source(26, 15) + SourceIndex(1) +2 >Emitted(46, 11) Source(26, 21) + SourceIndex(1) +3 >Emitted(46, 17) Source(26, 27) + SourceIndex(1) +4 >Emitted(46, 29) Source(26, 39) + SourceIndex(1) --- >>> a = 0, 1 >^^^^^^^^ @@ -2691,9 +2722,9 @@ sourceFile:file1.ts 1 > { 2 > a 3 > -1 >Emitted(46, 9) Source(26, 42) + SourceIndex(1) -2 >Emitted(46, 10) Source(26, 43) + SourceIndex(1) -3 >Emitted(46, 14) Source(26, 43) + SourceIndex(1) +1 >Emitted(47, 9) Source(26, 42) + SourceIndex(1) +2 >Emitted(47, 10) Source(26, 43) + SourceIndex(1) +3 >Emitted(47, 14) Source(26, 43) + SourceIndex(1) --- >>> b = 1, 1->^^^^^^^^ @@ -2703,9 +2734,9 @@ sourceFile:file1.ts 1->, 2 > b 3 > -1->Emitted(47, 9) Source(26, 45) + SourceIndex(1) -2 >Emitted(47, 10) Source(26, 46) + SourceIndex(1) -3 >Emitted(47, 14) Source(26, 46) + SourceIndex(1) +1->Emitted(48, 9) Source(26, 45) + SourceIndex(1) +2 >Emitted(48, 10) Source(26, 46) + SourceIndex(1) +3 >Emitted(48, 14) Source(26, 46) + SourceIndex(1) --- >>> c = 2 1->^^^^^^^^ @@ -2714,14 +2745,14 @@ sourceFile:file1.ts 1->, 2 > c 3 > -1->Emitted(48, 9) Source(26, 48) + SourceIndex(1) -2 >Emitted(48, 10) Source(26, 49) + SourceIndex(1) -3 >Emitted(48, 14) Source(26, 49) + SourceIndex(1) +1->Emitted(49, 9) Source(26, 48) + SourceIndex(1) +2 >Emitted(49, 10) Source(26, 49) + SourceIndex(1) +3 >Emitted(49, 14) Source(26, 49) + SourceIndex(1) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(49, 6) Source(26, 51) + SourceIndex(1) +1 >Emitted(50, 6) Source(26, 51) + SourceIndex(1) --- ------------------------------------------------------------------- emittedFile:/src/lib/module.d.ts @@ -2744,13 +2775,13 @@ sourceFile:file2.ts 5 > y 6 > = 20 7 > ; -1 >Emitted(52, 5) Source(1, 1) + SourceIndex(2) -2 >Emitted(52, 11) Source(1, 7) + SourceIndex(2) -3 >Emitted(52, 12) Source(1, 8) + SourceIndex(2) -4 >Emitted(52, 18) Source(1, 14) + SourceIndex(2) -5 >Emitted(52, 19) Source(1, 15) + SourceIndex(2) -6 >Emitted(52, 24) Source(1, 20) + SourceIndex(2) -7 >Emitted(52, 25) Source(1, 21) + SourceIndex(2) +1 >Emitted(53, 5) Source(1, 1) + SourceIndex(2) +2 >Emitted(53, 11) Source(1, 7) + SourceIndex(2) +3 >Emitted(53, 12) Source(1, 8) + SourceIndex(2) +4 >Emitted(53, 18) Source(1, 14) + SourceIndex(2) +5 >Emitted(53, 19) Source(1, 15) + SourceIndex(2) +6 >Emitted(53, 24) Source(1, 20) + SourceIndex(2) +7 >Emitted(53, 25) Source(1, 21) + SourceIndex(2) --- ------------------------------------------------------------------- emittedFile:/src/lib/module.d.ts @@ -2771,12 +2802,12 @@ sourceFile:global.ts 4 > globalConst 5 > = 10 6 > ; -1 >Emitted(54, 1) Source(1, 1) + SourceIndex(3) -2 >Emitted(54, 9) Source(1, 1) + SourceIndex(3) -3 >Emitted(54, 15) Source(1, 7) + SourceIndex(3) -4 >Emitted(54, 26) Source(1, 18) + SourceIndex(3) -5 >Emitted(54, 31) Source(1, 23) + SourceIndex(3) -6 >Emitted(54, 32) Source(1, 24) + SourceIndex(3) +1 >Emitted(55, 1) Source(1, 1) + SourceIndex(3) +2 >Emitted(55, 9) Source(1, 1) + SourceIndex(3) +3 >Emitted(55, 15) Source(1, 7) + SourceIndex(3) +4 >Emitted(55, 26) Source(1, 18) + SourceIndex(3) +5 >Emitted(55, 31) Source(1, 23) + SourceIndex(3) +6 >Emitted(55, 32) Source(1, 24) + SourceIndex(3) --- >>>//# sourceMappingURL=module.d.ts.map @@ -4406,32 +4437,32 @@ sourceFile:global.ts }, { "pos": 108, - "end": 212, + "end": 233, "kind": "internal" }, { - "pos": 214, - "end": 253, + "pos": 235, + "end": 274, "kind": "text" }, { - "pos": 253, - "end": 721, + "pos": 274, + "end": 742, "kind": "internal" }, { - "pos": 723, - "end": 730, + "pos": 744, + "end": 751, "kind": "text" }, { - "pos": 730, - "end": 1219, + "pos": 751, + "end": 1240, "kind": "internal" }, { - "pos": 1221, - "end": 1312, + "pos": 1242, + "end": 1333, "kind": "text" } ] @@ -4566,18 +4597,19 @@ text: (80-108) export class normalC { ---------------------------------------------------------------------- -internal: (108-212) +internal: (108-233) constructor(); prop: string; method(): void; - /*@internal*/ c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (214-253) +text: (235-274) } export namespace normalN { ---------------------------------------------------------------------- -internal: (253-721) +internal: (274-742) class C { } function foo(): void; @@ -4598,11 +4630,11 @@ internal: (253-721) c = 2 } ---------------------------------------------------------------------- -text: (723-730) +text: (744-751) } ---------------------------------------------------------------------- -internal: (730-1219) +internal: (751-1240) export class internalC { } export function internalfoo(): void; @@ -4623,7 +4655,7 @@ internal: (730-1219) c = 2 } ---------------------------------------------------------------------- -text: (1221-1312) +text: (1242-1333) } declare module "file2" { export const y = 20; diff --git a/tests/baselines/reference/tsbuild/amdModulesWithOut/initial-Build/stripInternal.js b/tests/baselines/reference/tsbuild/amdModulesWithOut/initial-Build/stripInternal.js index dcac12cae9f3b..6f01109d21024 100644 --- a/tests/baselines/reference/tsbuild/amdModulesWithOut/initial-Build/stripInternal.js +++ b/tests/baselines/reference/tsbuild/amdModulesWithOut/initial-Build/stripInternal.js @@ -2120,7 +2120,8 @@ declare module "file1" { constructor(); prop: string; method(): void; - /*@internal*/ c: number; + get c(): number; + set c(val: number); } export namespace normalN { class C { @@ -2170,7 +2171,7 @@ declare const globalConst = 10; //# sourceMappingURL=module.d.ts.map //// [/src/lib/module.d.ts.map] -{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["file0.ts","file1.ts","file2.ts","global.ts"],"names":[],"mappings":"AAAc,QAAA,MAAM,MAAM,KAAK,CAAC;;ICAhC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;IACpB,MAAM,OAAO,OAAO;;QAEF,IAAI,EAAE,MAAM,CAAC;QACb,MAAM;sBACF,CAAC,EACM,MAAM;KAClC;IACD,MAAM,WAAW,OAAO,CAAC;QACP,MAAa,CAAC;SAAI;QAClB,SAAgB,GAAG,SAAK;QACxB,UAAiB,aAAa,CAAC;YAAE,MAAa,CAAC;aAAG;SAAE;QACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;YAAE,MAAa,SAAS;aAAG;SAAE;QAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;QAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;QAC9B,MAAM,aAAa,KAAK,CAAC;QAChC,KAAY,YAAY;YAAG,CAAC,IAAA;YAAE,CAAC,IAAA;YAAE,CAAC,IAAA;SAAE;KACrD;IACa,MAAM,OAAO,SAAS;KAAG;IACzB,MAAM,UAAU,WAAW,SAAK;IAChC,MAAM,WAAW,iBAAiB,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAChE,MAAM,WAAW,aAAa,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IACtE,MAAM,QAAQ,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;IAC3D,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC;IACrC,MAAM,CAAC,MAAM,aAAa,KAAK,CAAC;IAChC,MAAM,MAAM,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;;;ICzBlD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;;ACApB,QAAA,MAAM,WAAW,KAAK,CAAC"} +{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["file0.ts","file1.ts","file2.ts","global.ts"],"names":[],"mappings":"AAAc,QAAA,MAAM,MAAM,KAAK,CAAC;;ICAhC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;IACpB,MAAM,OAAO,OAAO;;QAEF,IAAI,EAAE,MAAM,CAAC;QACb,MAAM;QACN,IAAI,CAAC,IACM,MAAM,CADK;QACtB,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;KACvC;IACD,MAAM,WAAW,OAAO,CAAC;QACP,MAAa,CAAC;SAAI;QAClB,SAAgB,GAAG,SAAK;QACxB,UAAiB,aAAa,CAAC;YAAE,MAAa,CAAC;aAAG;SAAE;QACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;YAAE,MAAa,SAAS;aAAG;SAAE;QAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;QAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;QAC9B,MAAM,aAAa,KAAK,CAAC;QAChC,KAAY,YAAY;YAAG,CAAC,IAAA;YAAE,CAAC,IAAA;YAAE,CAAC,IAAA;SAAE;KACrD;IACa,MAAM,OAAO,SAAS;KAAG;IACzB,MAAM,UAAU,WAAW,SAAK;IAChC,MAAM,WAAW,iBAAiB,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAChE,MAAM,WAAW,aAAa,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IACtE,MAAM,QAAQ,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;IAC3D,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC;IACrC,MAAM,CAAC,MAAM,aAAa,KAAK,CAAC;IAChC,MAAM,MAAM,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;;;ICzBlD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;;ACApB,QAAA,MAAM,WAAW,KAAK,CAAC"} //// [/src/lib/module.d.ts.map.baseline.txt] =================================================================== @@ -2271,35 +2272,66 @@ sourceFile:file1.ts >>> method(): void; 1->^^^^^^^^ 2 > ^^^^^^ -3 > ^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^-> 1-> > /*@internal*/ 2 > method 1->Emitted(7, 9) Source(5, 19) + SourceIndex(1) 2 >Emitted(7, 15) Source(5, 25) + SourceIndex(1) --- ->>> /*@internal*/ c: number; -1->^^^^^^^^^^^^^^^^^^^^^^ -2 > ^ -3 > ^^ -4 > ^^^^^^ +>>> get c(): number; +1->^^^^^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^^ +5 > ^^^^^^ +6 > ^ +7 > ^^^^-> 1->() { } - > /*@internal*/ get -2 > c -3 > () { return 10; } - > /*@internal*/ set c(val: -4 > number -1->Emitted(8, 23) Source(6, 23) + SourceIndex(1) -2 >Emitted(8, 24) Source(6, 24) + SourceIndex(1) -3 >Emitted(8, 26) Source(7, 30) + SourceIndex(1) -4 >Emitted(8, 32) Source(7, 36) + SourceIndex(1) + > /*@internal*/ +2 > get +3 > c +4 > () { return 10; } + > /*@internal*/ set c(val: +5 > number +6 > +1->Emitted(8, 9) Source(6, 19) + SourceIndex(1) +2 >Emitted(8, 13) Source(6, 23) + SourceIndex(1) +3 >Emitted(8, 14) Source(6, 24) + SourceIndex(1) +4 >Emitted(8, 18) Source(7, 30) + SourceIndex(1) +5 >Emitted(8, 24) Source(7, 36) + SourceIndex(1) +6 >Emitted(8, 25) Source(6, 41) + SourceIndex(1) +--- +>>> set c(val: number); +1->^^^^^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^ +6 > ^^^^^^ +7 > ^^ +1-> + > /*@internal*/ +2 > set +3 > c +4 > ( +5 > val: +6 > number +7 > ) { } +1->Emitted(9, 9) Source(7, 19) + SourceIndex(1) +2 >Emitted(9, 13) Source(7, 23) + SourceIndex(1) +3 >Emitted(9, 14) Source(7, 24) + SourceIndex(1) +4 >Emitted(9, 15) Source(7, 25) + SourceIndex(1) +5 >Emitted(9, 20) Source(7, 30) + SourceIndex(1) +6 >Emitted(9, 26) Source(7, 36) + SourceIndex(1) +7 >Emitted(9, 28) Source(7, 41) + SourceIndex(1) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(9, 6) Source(8, 2) + SourceIndex(1) +1 >Emitted(10, 6) Source(8, 2) + SourceIndex(1) --- >>> export namespace normalN { 1->^^^^ @@ -2313,11 +2345,11 @@ sourceFile:file1.ts 3 > namespace 4 > normalN 5 > -1->Emitted(10, 5) Source(9, 1) + SourceIndex(1) -2 >Emitted(10, 11) Source(9, 7) + SourceIndex(1) -3 >Emitted(10, 22) Source(9, 18) + SourceIndex(1) -4 >Emitted(10, 29) Source(9, 25) + SourceIndex(1) -5 >Emitted(10, 30) Source(9, 26) + SourceIndex(1) +1->Emitted(11, 5) Source(9, 1) + SourceIndex(1) +2 >Emitted(11, 11) Source(9, 7) + SourceIndex(1) +3 >Emitted(11, 22) Source(9, 18) + SourceIndex(1) +4 >Emitted(11, 29) Source(9, 25) + SourceIndex(1) +5 >Emitted(11, 30) Source(9, 26) + SourceIndex(1) --- >>> class C { 1 >^^^^^^^^ @@ -2327,15 +2359,15 @@ sourceFile:file1.ts > /*@internal*/ 2 > export class 3 > C -1 >Emitted(11, 9) Source(10, 19) + SourceIndex(1) -2 >Emitted(11, 15) Source(10, 32) + SourceIndex(1) -3 >Emitted(11, 16) Source(10, 33) + SourceIndex(1) +1 >Emitted(12, 9) Source(10, 19) + SourceIndex(1) +2 >Emitted(12, 15) Source(10, 32) + SourceIndex(1) +3 >Emitted(12, 16) Source(10, 33) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(12, 10) Source(10, 37) + SourceIndex(1) +1 >Emitted(13, 10) Source(10, 37) + SourceIndex(1) --- >>> function foo(): void; 1->^^^^^^^^ @@ -2348,10 +2380,10 @@ sourceFile:file1.ts 2 > export function 3 > foo 4 > () {} -1->Emitted(13, 9) Source(11, 19) + SourceIndex(1) -2 >Emitted(13, 18) Source(11, 35) + SourceIndex(1) -3 >Emitted(13, 21) Source(11, 38) + SourceIndex(1) -4 >Emitted(13, 30) Source(11, 43) + SourceIndex(1) +1->Emitted(14, 9) Source(11, 19) + SourceIndex(1) +2 >Emitted(14, 18) Source(11, 35) + SourceIndex(1) +3 >Emitted(14, 21) Source(11, 38) + SourceIndex(1) +4 >Emitted(14, 30) Source(11, 43) + SourceIndex(1) --- >>> namespace someNamespace { 1->^^^^^^^^ @@ -2363,10 +2395,10 @@ sourceFile:file1.ts 2 > export namespace 3 > someNamespace 4 > -1->Emitted(14, 9) Source(12, 19) + SourceIndex(1) -2 >Emitted(14, 19) Source(12, 36) + SourceIndex(1) -3 >Emitted(14, 32) Source(12, 49) + SourceIndex(1) -4 >Emitted(14, 33) Source(12, 50) + SourceIndex(1) +1->Emitted(15, 9) Source(12, 19) + SourceIndex(1) +2 >Emitted(15, 19) Source(12, 36) + SourceIndex(1) +3 >Emitted(15, 32) Source(12, 49) + SourceIndex(1) +4 >Emitted(15, 33) Source(12, 50) + SourceIndex(1) --- >>> class C { 1 >^^^^^^^^^^^^ @@ -2375,20 +2407,20 @@ sourceFile:file1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(15, 13) Source(12, 52) + SourceIndex(1) -2 >Emitted(15, 19) Source(12, 65) + SourceIndex(1) -3 >Emitted(15, 20) Source(12, 66) + SourceIndex(1) +1 >Emitted(16, 13) Source(12, 52) + SourceIndex(1) +2 >Emitted(16, 19) Source(12, 65) + SourceIndex(1) +3 >Emitted(16, 20) Source(12, 66) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^^^^^ 1 > {} -1 >Emitted(16, 14) Source(12, 69) + SourceIndex(1) +1 >Emitted(17, 14) Source(12, 69) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(17, 10) Source(12, 71) + SourceIndex(1) +1 >Emitted(18, 10) Source(12, 71) + SourceIndex(1) --- >>> namespace someOther.something { 1->^^^^^^^^ @@ -2404,12 +2436,12 @@ sourceFile:file1.ts 4 > . 5 > something 6 > -1->Emitted(18, 9) Source(13, 19) + SourceIndex(1) -2 >Emitted(18, 19) Source(13, 36) + SourceIndex(1) -3 >Emitted(18, 28) Source(13, 45) + SourceIndex(1) -4 >Emitted(18, 29) Source(13, 46) + SourceIndex(1) -5 >Emitted(18, 38) Source(13, 55) + SourceIndex(1) -6 >Emitted(18, 39) Source(13, 56) + SourceIndex(1) +1->Emitted(19, 9) Source(13, 19) + SourceIndex(1) +2 >Emitted(19, 19) Source(13, 36) + SourceIndex(1) +3 >Emitted(19, 28) Source(13, 45) + SourceIndex(1) +4 >Emitted(19, 29) Source(13, 46) + SourceIndex(1) +5 >Emitted(19, 38) Source(13, 55) + SourceIndex(1) +6 >Emitted(19, 39) Source(13, 56) + SourceIndex(1) --- >>> class someClass { 1 >^^^^^^^^^^^^ @@ -2418,20 +2450,20 @@ sourceFile:file1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(19, 13) Source(13, 58) + SourceIndex(1) -2 >Emitted(19, 19) Source(13, 71) + SourceIndex(1) -3 >Emitted(19, 28) Source(13, 80) + SourceIndex(1) +1 >Emitted(20, 13) Source(13, 58) + SourceIndex(1) +2 >Emitted(20, 19) Source(13, 71) + SourceIndex(1) +3 >Emitted(20, 28) Source(13, 80) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^^^^^ 1 > {} -1 >Emitted(20, 14) Source(13, 83) + SourceIndex(1) +1 >Emitted(21, 14) Source(13, 83) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(21, 10) Source(13, 85) + SourceIndex(1) +1 >Emitted(22, 10) Source(13, 85) + SourceIndex(1) --- >>> export import someImport = someNamespace.C; 1->^^^^^^^^ @@ -2453,15 +2485,15 @@ sourceFile:file1.ts 7 > . 8 > C 9 > ; -1->Emitted(22, 9) Source(14, 19) + SourceIndex(1) -2 >Emitted(22, 15) Source(14, 25) + SourceIndex(1) -3 >Emitted(22, 23) Source(14, 33) + SourceIndex(1) -4 >Emitted(22, 33) Source(14, 43) + SourceIndex(1) -5 >Emitted(22, 36) Source(14, 46) + SourceIndex(1) -6 >Emitted(22, 49) Source(14, 59) + SourceIndex(1) -7 >Emitted(22, 50) Source(14, 60) + SourceIndex(1) -8 >Emitted(22, 51) Source(14, 61) + SourceIndex(1) -9 >Emitted(22, 52) Source(14, 62) + SourceIndex(1) +1->Emitted(23, 9) Source(14, 19) + SourceIndex(1) +2 >Emitted(23, 15) Source(14, 25) + SourceIndex(1) +3 >Emitted(23, 23) Source(14, 33) + SourceIndex(1) +4 >Emitted(23, 33) Source(14, 43) + SourceIndex(1) +5 >Emitted(23, 36) Source(14, 46) + SourceIndex(1) +6 >Emitted(23, 49) Source(14, 59) + SourceIndex(1) +7 >Emitted(23, 50) Source(14, 60) + SourceIndex(1) +8 >Emitted(23, 51) Source(14, 61) + SourceIndex(1) +9 >Emitted(23, 52) Source(14, 62) + SourceIndex(1) --- >>> type internalType = internalC; 1 >^^^^^^^^ @@ -2477,12 +2509,12 @@ sourceFile:file1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(23, 9) Source(15, 19) + SourceIndex(1) -2 >Emitted(23, 14) Source(15, 31) + SourceIndex(1) -3 >Emitted(23, 26) Source(15, 43) + SourceIndex(1) -4 >Emitted(23, 29) Source(15, 46) + SourceIndex(1) -5 >Emitted(23, 38) Source(15, 55) + SourceIndex(1) -6 >Emitted(23, 39) Source(15, 56) + SourceIndex(1) +1 >Emitted(24, 9) Source(15, 19) + SourceIndex(1) +2 >Emitted(24, 14) Source(15, 31) + SourceIndex(1) +3 >Emitted(24, 26) Source(15, 43) + SourceIndex(1) +4 >Emitted(24, 29) Source(15, 46) + SourceIndex(1) +5 >Emitted(24, 38) Source(15, 55) + SourceIndex(1) +6 >Emitted(24, 39) Source(15, 56) + SourceIndex(1) --- >>> const internalConst = 10; 1 >^^^^^^^^ @@ -2496,11 +2528,11 @@ sourceFile:file1.ts 3 > internalConst 4 > = 10 5 > ; -1 >Emitted(24, 9) Source(16, 26) + SourceIndex(1) -2 >Emitted(24, 15) Source(16, 32) + SourceIndex(1) -3 >Emitted(24, 28) Source(16, 45) + SourceIndex(1) -4 >Emitted(24, 33) Source(16, 50) + SourceIndex(1) -5 >Emitted(24, 34) Source(16, 51) + SourceIndex(1) +1 >Emitted(25, 9) Source(16, 26) + SourceIndex(1) +2 >Emitted(25, 15) Source(16, 32) + SourceIndex(1) +3 >Emitted(25, 28) Source(16, 45) + SourceIndex(1) +4 >Emitted(25, 33) Source(16, 50) + SourceIndex(1) +5 >Emitted(25, 34) Source(16, 51) + SourceIndex(1) --- >>> enum internalEnum { 1 >^^^^^^^^ @@ -2510,9 +2542,9 @@ sourceFile:file1.ts > /*@internal*/ 2 > export enum 3 > internalEnum -1 >Emitted(25, 9) Source(17, 19) + SourceIndex(1) -2 >Emitted(25, 14) Source(17, 31) + SourceIndex(1) -3 >Emitted(25, 26) Source(17, 43) + SourceIndex(1) +1 >Emitted(26, 9) Source(17, 19) + SourceIndex(1) +2 >Emitted(26, 14) Source(17, 31) + SourceIndex(1) +3 >Emitted(26, 26) Source(17, 43) + SourceIndex(1) --- >>> a = 0, 1 >^^^^^^^^^^^^ @@ -2522,9 +2554,9 @@ sourceFile:file1.ts 1 > { 2 > a 3 > -1 >Emitted(26, 13) Source(17, 46) + SourceIndex(1) -2 >Emitted(26, 14) Source(17, 47) + SourceIndex(1) -3 >Emitted(26, 18) Source(17, 47) + SourceIndex(1) +1 >Emitted(27, 13) Source(17, 46) + SourceIndex(1) +2 >Emitted(27, 14) Source(17, 47) + SourceIndex(1) +3 >Emitted(27, 18) Source(17, 47) + SourceIndex(1) --- >>> b = 1, 1->^^^^^^^^^^^^ @@ -2534,9 +2566,9 @@ sourceFile:file1.ts 1->, 2 > b 3 > -1->Emitted(27, 13) Source(17, 49) + SourceIndex(1) -2 >Emitted(27, 14) Source(17, 50) + SourceIndex(1) -3 >Emitted(27, 18) Source(17, 50) + SourceIndex(1) +1->Emitted(28, 13) Source(17, 49) + SourceIndex(1) +2 >Emitted(28, 14) Source(17, 50) + SourceIndex(1) +3 >Emitted(28, 18) Source(17, 50) + SourceIndex(1) --- >>> c = 2 1->^^^^^^^^^^^^ @@ -2545,21 +2577,21 @@ sourceFile:file1.ts 1->, 2 > c 3 > -1->Emitted(28, 13) Source(17, 52) + SourceIndex(1) -2 >Emitted(28, 14) Source(17, 53) + SourceIndex(1) -3 >Emitted(28, 18) Source(17, 53) + SourceIndex(1) +1->Emitted(29, 13) Source(17, 52) + SourceIndex(1) +2 >Emitted(29, 14) Source(17, 53) + SourceIndex(1) +3 >Emitted(29, 18) Source(17, 53) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^ 1 > } -1 >Emitted(29, 10) Source(17, 55) + SourceIndex(1) +1 >Emitted(30, 10) Source(17, 55) + SourceIndex(1) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(30, 6) Source(18, 2) + SourceIndex(1) +1 >Emitted(31, 6) Source(18, 2) + SourceIndex(1) --- >>> export class internalC { 1->^^^^ @@ -2571,16 +2603,16 @@ sourceFile:file1.ts 2 > export 3 > class 4 > internalC -1->Emitted(31, 5) Source(19, 15) + SourceIndex(1) -2 >Emitted(31, 11) Source(19, 21) + SourceIndex(1) -3 >Emitted(31, 18) Source(19, 28) + SourceIndex(1) -4 >Emitted(31, 27) Source(19, 37) + SourceIndex(1) +1->Emitted(32, 5) Source(19, 15) + SourceIndex(1) +2 >Emitted(32, 11) Source(19, 21) + SourceIndex(1) +3 >Emitted(32, 18) Source(19, 28) + SourceIndex(1) +4 >Emitted(32, 27) Source(19, 37) + SourceIndex(1) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(32, 6) Source(19, 40) + SourceIndex(1) +1 >Emitted(33, 6) Source(19, 40) + SourceIndex(1) --- >>> export function internalfoo(): void; 1->^^^^ @@ -2595,11 +2627,11 @@ sourceFile:file1.ts 3 > function 4 > internalfoo 5 > () {} -1->Emitted(33, 5) Source(20, 15) + SourceIndex(1) -2 >Emitted(33, 11) Source(20, 21) + SourceIndex(1) -3 >Emitted(33, 21) Source(20, 31) + SourceIndex(1) -4 >Emitted(33, 32) Source(20, 42) + SourceIndex(1) -5 >Emitted(33, 41) Source(20, 47) + SourceIndex(1) +1->Emitted(34, 5) Source(20, 15) + SourceIndex(1) +2 >Emitted(34, 11) Source(20, 21) + SourceIndex(1) +3 >Emitted(34, 21) Source(20, 31) + SourceIndex(1) +4 >Emitted(34, 32) Source(20, 42) + SourceIndex(1) +5 >Emitted(34, 41) Source(20, 47) + SourceIndex(1) --- >>> export namespace internalNamespace { 1->^^^^ @@ -2613,11 +2645,11 @@ sourceFile:file1.ts 3 > namespace 4 > internalNamespace 5 > -1->Emitted(34, 5) Source(21, 15) + SourceIndex(1) -2 >Emitted(34, 11) Source(21, 21) + SourceIndex(1) -3 >Emitted(34, 22) Source(21, 32) + SourceIndex(1) -4 >Emitted(34, 39) Source(21, 49) + SourceIndex(1) -5 >Emitted(34, 40) Source(21, 50) + SourceIndex(1) +1->Emitted(35, 5) Source(21, 15) + SourceIndex(1) +2 >Emitted(35, 11) Source(21, 21) + SourceIndex(1) +3 >Emitted(35, 22) Source(21, 32) + SourceIndex(1) +4 >Emitted(35, 39) Source(21, 49) + SourceIndex(1) +5 >Emitted(35, 40) Source(21, 50) + SourceIndex(1) --- >>> class someClass { 1 >^^^^^^^^ @@ -2626,20 +2658,20 @@ sourceFile:file1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(35, 9) Source(21, 52) + SourceIndex(1) -2 >Emitted(35, 15) Source(21, 65) + SourceIndex(1) -3 >Emitted(35, 24) Source(21, 74) + SourceIndex(1) +1 >Emitted(36, 9) Source(21, 52) + SourceIndex(1) +2 >Emitted(36, 15) Source(21, 65) + SourceIndex(1) +3 >Emitted(36, 24) Source(21, 74) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(36, 10) Source(21, 77) + SourceIndex(1) +1 >Emitted(37, 10) Source(21, 77) + SourceIndex(1) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(37, 6) Source(21, 79) + SourceIndex(1) +1 >Emitted(38, 6) Source(21, 79) + SourceIndex(1) --- >>> export namespace internalOther.something { 1->^^^^ @@ -2657,13 +2689,13 @@ sourceFile:file1.ts 5 > . 6 > something 7 > -1->Emitted(38, 5) Source(22, 15) + SourceIndex(1) -2 >Emitted(38, 11) Source(22, 21) + SourceIndex(1) -3 >Emitted(38, 22) Source(22, 32) + SourceIndex(1) -4 >Emitted(38, 35) Source(22, 45) + SourceIndex(1) -5 >Emitted(38, 36) Source(22, 46) + SourceIndex(1) -6 >Emitted(38, 45) Source(22, 55) + SourceIndex(1) -7 >Emitted(38, 46) Source(22, 56) + SourceIndex(1) +1->Emitted(39, 5) Source(22, 15) + SourceIndex(1) +2 >Emitted(39, 11) Source(22, 21) + SourceIndex(1) +3 >Emitted(39, 22) Source(22, 32) + SourceIndex(1) +4 >Emitted(39, 35) Source(22, 45) + SourceIndex(1) +5 >Emitted(39, 36) Source(22, 46) + SourceIndex(1) +6 >Emitted(39, 45) Source(22, 55) + SourceIndex(1) +7 >Emitted(39, 46) Source(22, 56) + SourceIndex(1) --- >>> class someClass { 1 >^^^^^^^^ @@ -2672,20 +2704,20 @@ sourceFile:file1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(39, 9) Source(22, 58) + SourceIndex(1) -2 >Emitted(39, 15) Source(22, 71) + SourceIndex(1) -3 >Emitted(39, 24) Source(22, 80) + SourceIndex(1) +1 >Emitted(40, 9) Source(22, 58) + SourceIndex(1) +2 >Emitted(40, 15) Source(22, 71) + SourceIndex(1) +3 >Emitted(40, 24) Source(22, 80) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(40, 10) Source(22, 83) + SourceIndex(1) +1 >Emitted(41, 10) Source(22, 83) + SourceIndex(1) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(41, 6) Source(22, 85) + SourceIndex(1) +1 >Emitted(42, 6) Source(22, 85) + SourceIndex(1) --- >>> export import internalImport = internalNamespace.someClass; 1->^^^^ @@ -2707,15 +2739,15 @@ sourceFile:file1.ts 7 > . 8 > someClass 9 > ; -1->Emitted(42, 5) Source(23, 15) + SourceIndex(1) -2 >Emitted(42, 11) Source(23, 21) + SourceIndex(1) -3 >Emitted(42, 19) Source(23, 29) + SourceIndex(1) -4 >Emitted(42, 33) Source(23, 43) + SourceIndex(1) -5 >Emitted(42, 36) Source(23, 46) + SourceIndex(1) -6 >Emitted(42, 53) Source(23, 63) + SourceIndex(1) -7 >Emitted(42, 54) Source(23, 64) + SourceIndex(1) -8 >Emitted(42, 63) Source(23, 73) + SourceIndex(1) -9 >Emitted(42, 64) Source(23, 74) + SourceIndex(1) +1->Emitted(43, 5) Source(23, 15) + SourceIndex(1) +2 >Emitted(43, 11) Source(23, 21) + SourceIndex(1) +3 >Emitted(43, 19) Source(23, 29) + SourceIndex(1) +4 >Emitted(43, 33) Source(23, 43) + SourceIndex(1) +5 >Emitted(43, 36) Source(23, 46) + SourceIndex(1) +6 >Emitted(43, 53) Source(23, 63) + SourceIndex(1) +7 >Emitted(43, 54) Source(23, 64) + SourceIndex(1) +8 >Emitted(43, 63) Source(23, 73) + SourceIndex(1) +9 >Emitted(43, 64) Source(23, 74) + SourceIndex(1) --- >>> export type internalType = internalC; 1 >^^^^ @@ -2733,13 +2765,13 @@ sourceFile:file1.ts 5 > = 6 > internalC 7 > ; -1 >Emitted(43, 5) Source(24, 15) + SourceIndex(1) -2 >Emitted(43, 11) Source(24, 21) + SourceIndex(1) -3 >Emitted(43, 17) Source(24, 27) + SourceIndex(1) -4 >Emitted(43, 29) Source(24, 39) + SourceIndex(1) -5 >Emitted(43, 32) Source(24, 42) + SourceIndex(1) -6 >Emitted(43, 41) Source(24, 51) + SourceIndex(1) -7 >Emitted(43, 42) Source(24, 52) + SourceIndex(1) +1 >Emitted(44, 5) Source(24, 15) + SourceIndex(1) +2 >Emitted(44, 11) Source(24, 21) + SourceIndex(1) +3 >Emitted(44, 17) Source(24, 27) + SourceIndex(1) +4 >Emitted(44, 29) Source(24, 39) + SourceIndex(1) +5 >Emitted(44, 32) Source(24, 42) + SourceIndex(1) +6 >Emitted(44, 41) Source(24, 51) + SourceIndex(1) +7 >Emitted(44, 42) Source(24, 52) + SourceIndex(1) --- >>> export const internalConst = 10; 1 >^^^^ @@ -2757,13 +2789,13 @@ sourceFile:file1.ts 5 > internalConst 6 > = 10 7 > ; -1 >Emitted(44, 5) Source(25, 15) + SourceIndex(1) -2 >Emitted(44, 11) Source(25, 21) + SourceIndex(1) -3 >Emitted(44, 12) Source(25, 22) + SourceIndex(1) -4 >Emitted(44, 18) Source(25, 28) + SourceIndex(1) -5 >Emitted(44, 31) Source(25, 41) + SourceIndex(1) -6 >Emitted(44, 36) Source(25, 46) + SourceIndex(1) -7 >Emitted(44, 37) Source(25, 47) + SourceIndex(1) +1 >Emitted(45, 5) Source(25, 15) + SourceIndex(1) +2 >Emitted(45, 11) Source(25, 21) + SourceIndex(1) +3 >Emitted(45, 12) Source(25, 22) + SourceIndex(1) +4 >Emitted(45, 18) Source(25, 28) + SourceIndex(1) +5 >Emitted(45, 31) Source(25, 41) + SourceIndex(1) +6 >Emitted(45, 36) Source(25, 46) + SourceIndex(1) +7 >Emitted(45, 37) Source(25, 47) + SourceIndex(1) --- >>> export enum internalEnum { 1 >^^^^ @@ -2775,10 +2807,10 @@ sourceFile:file1.ts 2 > export 3 > enum 4 > internalEnum -1 >Emitted(45, 5) Source(26, 15) + SourceIndex(1) -2 >Emitted(45, 11) Source(26, 21) + SourceIndex(1) -3 >Emitted(45, 17) Source(26, 27) + SourceIndex(1) -4 >Emitted(45, 29) Source(26, 39) + SourceIndex(1) +1 >Emitted(46, 5) Source(26, 15) + SourceIndex(1) +2 >Emitted(46, 11) Source(26, 21) + SourceIndex(1) +3 >Emitted(46, 17) Source(26, 27) + SourceIndex(1) +4 >Emitted(46, 29) Source(26, 39) + SourceIndex(1) --- >>> a = 0, 1 >^^^^^^^^ @@ -2788,9 +2820,9 @@ sourceFile:file1.ts 1 > { 2 > a 3 > -1 >Emitted(46, 9) Source(26, 42) + SourceIndex(1) -2 >Emitted(46, 10) Source(26, 43) + SourceIndex(1) -3 >Emitted(46, 14) Source(26, 43) + SourceIndex(1) +1 >Emitted(47, 9) Source(26, 42) + SourceIndex(1) +2 >Emitted(47, 10) Source(26, 43) + SourceIndex(1) +3 >Emitted(47, 14) Source(26, 43) + SourceIndex(1) --- >>> b = 1, 1->^^^^^^^^ @@ -2800,9 +2832,9 @@ sourceFile:file1.ts 1->, 2 > b 3 > -1->Emitted(47, 9) Source(26, 45) + SourceIndex(1) -2 >Emitted(47, 10) Source(26, 46) + SourceIndex(1) -3 >Emitted(47, 14) Source(26, 46) + SourceIndex(1) +1->Emitted(48, 9) Source(26, 45) + SourceIndex(1) +2 >Emitted(48, 10) Source(26, 46) + SourceIndex(1) +3 >Emitted(48, 14) Source(26, 46) + SourceIndex(1) --- >>> c = 2 1->^^^^^^^^ @@ -2811,14 +2843,14 @@ sourceFile:file1.ts 1->, 2 > c 3 > -1->Emitted(48, 9) Source(26, 48) + SourceIndex(1) -2 >Emitted(48, 10) Source(26, 49) + SourceIndex(1) -3 >Emitted(48, 14) Source(26, 49) + SourceIndex(1) +1->Emitted(49, 9) Source(26, 48) + SourceIndex(1) +2 >Emitted(49, 10) Source(26, 49) + SourceIndex(1) +3 >Emitted(49, 14) Source(26, 49) + SourceIndex(1) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(49, 6) Source(26, 51) + SourceIndex(1) +1 >Emitted(50, 6) Source(26, 51) + SourceIndex(1) --- ------------------------------------------------------------------- emittedFile:/src/lib/module.d.ts @@ -2841,13 +2873,13 @@ sourceFile:file2.ts 5 > y 6 > = 20 7 > ; -1 >Emitted(52, 5) Source(1, 1) + SourceIndex(2) -2 >Emitted(52, 11) Source(1, 7) + SourceIndex(2) -3 >Emitted(52, 12) Source(1, 8) + SourceIndex(2) -4 >Emitted(52, 18) Source(1, 14) + SourceIndex(2) -5 >Emitted(52, 19) Source(1, 15) + SourceIndex(2) -6 >Emitted(52, 24) Source(1, 20) + SourceIndex(2) -7 >Emitted(52, 25) Source(1, 21) + SourceIndex(2) +1 >Emitted(53, 5) Source(1, 1) + SourceIndex(2) +2 >Emitted(53, 11) Source(1, 7) + SourceIndex(2) +3 >Emitted(53, 12) Source(1, 8) + SourceIndex(2) +4 >Emitted(53, 18) Source(1, 14) + SourceIndex(2) +5 >Emitted(53, 19) Source(1, 15) + SourceIndex(2) +6 >Emitted(53, 24) Source(1, 20) + SourceIndex(2) +7 >Emitted(53, 25) Source(1, 21) + SourceIndex(2) --- ------------------------------------------------------------------- emittedFile:/src/lib/module.d.ts @@ -2868,12 +2900,12 @@ sourceFile:global.ts 4 > globalConst 5 > = 10 6 > ; -1 >Emitted(54, 1) Source(1, 1) + SourceIndex(3) -2 >Emitted(54, 9) Source(1, 1) + SourceIndex(3) -3 >Emitted(54, 15) Source(1, 7) + SourceIndex(3) -4 >Emitted(54, 26) Source(1, 18) + SourceIndex(3) -5 >Emitted(54, 31) Source(1, 23) + SourceIndex(3) -6 >Emitted(54, 32) Source(1, 24) + SourceIndex(3) +1 >Emitted(55, 1) Source(1, 1) + SourceIndex(3) +2 >Emitted(55, 9) Source(1, 1) + SourceIndex(3) +3 >Emitted(55, 15) Source(1, 7) + SourceIndex(3) +4 >Emitted(55, 26) Source(1, 18) + SourceIndex(3) +5 >Emitted(55, 31) Source(1, 23) + SourceIndex(3) +6 >Emitted(55, 32) Source(1, 24) + SourceIndex(3) --- >>>//# sourceMappingURL=module.d.ts.map @@ -4487,32 +4519,32 @@ sourceFile:global.ts }, { "pos": 108, - "end": 212, + "end": 233, "kind": "internal" }, { - "pos": 214, - "end": 253, + "pos": 235, + "end": 274, "kind": "text" }, { - "pos": 253, - "end": 721, + "pos": 274, + "end": 742, "kind": "internal" }, { - "pos": 723, - "end": 730, + "pos": 744, + "end": 751, "kind": "text" }, { - "pos": 730, - "end": 1219, + "pos": 751, + "end": 1240, "kind": "internal" }, { - "pos": 1221, - "end": 1312, + "pos": 1242, + "end": 1333, "kind": "text" } ] @@ -4642,18 +4674,19 @@ declare module "file1" { export class normalC { ---------------------------------------------------------------------- -internal: (108-212) +internal: (108-233) constructor(); prop: string; method(): void; - /*@internal*/ c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (214-253) +text: (235-274) } export namespace normalN { ---------------------------------------------------------------------- -internal: (253-721) +internal: (274-742) class C { } function foo(): void; @@ -4674,11 +4707,11 @@ internal: (253-721) c = 2 } ---------------------------------------------------------------------- -text: (723-730) +text: (744-751) } ---------------------------------------------------------------------- -internal: (730-1219) +internal: (751-1240) export class internalC { } export function internalfoo(): void; @@ -4699,7 +4732,7 @@ internal: (730-1219) c = 2 } ---------------------------------------------------------------------- -text: (1221-1312) +text: (1242-1333) } declare module "file2" { export const y = 20; diff --git a/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-changes/stripInternal-when-one-two-three-are-prepended-in-order.js b/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-changes/stripInternal-when-one-two-three-are-prepended-in-order.js index 0b7ac11a1009b..1c2a86364ce2b 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-changes/stripInternal-when-one-two-three-are-prepended-in-order.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-changes/stripInternal-when-one-two-three-are-prepended-in-order.js @@ -15,7 +15,8 @@ declare class normalC { constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); } declare namespace normalN { class C { @@ -63,7 +64,7 @@ declare class C { //# sourceMappingURL=second-output.d.ts.map //// [/src/2/second-output.d.ts.map] -{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAc,UAAU,QAAQ;IAC5B,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,gBAAgB,CAAC;AAExB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACF,CAAC,EACM,MAAM;CAClC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} +{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAc,UAAU,QAAQ;IAC5B,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,gBAAgB,CAAC;AAExB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACN,IAAI,CAAC,IACM,MAAM,CADK;IACtB,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;CACvC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} //// [/src/2/second-output.d.ts.map.baseline.txt] =================================================================== @@ -283,35 +284,66 @@ sourceFile:../second/second_part1.ts >>> method(): void; 1->^^^^ 2 > ^^^^^^ -3 > ^^^^^-> +3 > ^^^^^^^^^^^-> 1-> > /*@internal*/ 2 > method 1->Emitted(16, 5) Source(16, 19) + SourceIndex(2) 2 >Emitted(16, 11) Source(16, 25) + SourceIndex(2) --- ->>> c: number; +>>> get c(): number; 1->^^^^ -2 > ^ -3 > ^^ -4 > ^^^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^^ +5 > ^^^^^^ +6 > ^ +7 > ^^^^-> 1->() { } - > /*@internal*/ get -2 > c -3 > () { return 10; } - > /*@internal*/ set c(val: -4 > number -1->Emitted(17, 5) Source(17, 23) + SourceIndex(2) -2 >Emitted(17, 6) Source(17, 24) + SourceIndex(2) -3 >Emitted(17, 8) Source(18, 30) + SourceIndex(2) -4 >Emitted(17, 14) Source(18, 36) + SourceIndex(2) + > /*@internal*/ +2 > get +3 > c +4 > () { return 10; } + > /*@internal*/ set c(val: +5 > number +6 > +1->Emitted(17, 5) Source(17, 19) + SourceIndex(2) +2 >Emitted(17, 9) Source(17, 23) + SourceIndex(2) +3 >Emitted(17, 10) Source(17, 24) + SourceIndex(2) +4 >Emitted(17, 14) Source(18, 30) + SourceIndex(2) +5 >Emitted(17, 20) Source(18, 36) + SourceIndex(2) +6 >Emitted(17, 21) Source(17, 41) + SourceIndex(2) +--- +>>> set c(val: number); +1->^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^ +6 > ^^^^^^ +7 > ^^ +1-> + > /*@internal*/ +2 > set +3 > c +4 > ( +5 > val: +6 > number +7 > ) { } +1->Emitted(18, 5) Source(18, 19) + SourceIndex(2) +2 >Emitted(18, 9) Source(18, 23) + SourceIndex(2) +3 >Emitted(18, 10) Source(18, 24) + SourceIndex(2) +4 >Emitted(18, 11) Source(18, 25) + SourceIndex(2) +5 >Emitted(18, 16) Source(18, 30) + SourceIndex(2) +6 >Emitted(18, 22) Source(18, 36) + SourceIndex(2) +7 >Emitted(18, 24) Source(18, 41) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(18, 2) Source(19, 2) + SourceIndex(2) +1 >Emitted(19, 2) Source(19, 2) + SourceIndex(2) --- >>>declare namespace normalN { 1-> @@ -323,10 +355,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > normalN 4 > -1->Emitted(19, 1) Source(20, 1) + SourceIndex(2) -2 >Emitted(19, 19) Source(20, 11) + SourceIndex(2) -3 >Emitted(19, 26) Source(20, 18) + SourceIndex(2) -4 >Emitted(19, 27) Source(20, 19) + SourceIndex(2) +1->Emitted(20, 1) Source(20, 1) + SourceIndex(2) +2 >Emitted(20, 19) Source(20, 11) + SourceIndex(2) +3 >Emitted(20, 26) Source(20, 18) + SourceIndex(2) +4 >Emitted(20, 27) Source(20, 19) + SourceIndex(2) --- >>> class C { 1 >^^^^ @@ -336,15 +368,15 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export class 3 > C -1 >Emitted(20, 5) Source(21, 19) + SourceIndex(2) -2 >Emitted(20, 11) Source(21, 32) + SourceIndex(2) -3 >Emitted(20, 12) Source(21, 33) + SourceIndex(2) +1 >Emitted(21, 5) Source(21, 19) + SourceIndex(2) +2 >Emitted(21, 11) Source(21, 32) + SourceIndex(2) +3 >Emitted(21, 12) Source(21, 33) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(21, 6) Source(21, 37) + SourceIndex(2) +1 >Emitted(22, 6) Source(21, 37) + SourceIndex(2) --- >>> function foo(): void; 1->^^^^ @@ -357,10 +389,10 @@ sourceFile:../second/second_part1.ts 2 > export function 3 > foo 4 > () {} -1->Emitted(22, 5) Source(22, 19) + SourceIndex(2) -2 >Emitted(22, 14) Source(22, 35) + SourceIndex(2) -3 >Emitted(22, 17) Source(22, 38) + SourceIndex(2) -4 >Emitted(22, 26) Source(22, 43) + SourceIndex(2) +1->Emitted(23, 5) Source(22, 19) + SourceIndex(2) +2 >Emitted(23, 14) Source(22, 35) + SourceIndex(2) +3 >Emitted(23, 17) Source(22, 38) + SourceIndex(2) +4 >Emitted(23, 26) Source(22, 43) + SourceIndex(2) --- >>> namespace someNamespace { 1->^^^^ @@ -372,10 +404,10 @@ sourceFile:../second/second_part1.ts 2 > export namespace 3 > someNamespace 4 > -1->Emitted(23, 5) Source(23, 19) + SourceIndex(2) -2 >Emitted(23, 15) Source(23, 36) + SourceIndex(2) -3 >Emitted(23, 28) Source(23, 49) + SourceIndex(2) -4 >Emitted(23, 29) Source(23, 50) + SourceIndex(2) +1->Emitted(24, 5) Source(23, 19) + SourceIndex(2) +2 >Emitted(24, 15) Source(23, 36) + SourceIndex(2) +3 >Emitted(24, 28) Source(23, 49) + SourceIndex(2) +4 >Emitted(24, 29) Source(23, 50) + SourceIndex(2) --- >>> class C { 1 >^^^^^^^^ @@ -384,20 +416,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(24, 9) Source(23, 52) + SourceIndex(2) -2 >Emitted(24, 15) Source(23, 65) + SourceIndex(2) -3 >Emitted(24, 16) Source(23, 66) + SourceIndex(2) +1 >Emitted(25, 9) Source(23, 52) + SourceIndex(2) +2 >Emitted(25, 15) Source(23, 65) + SourceIndex(2) +3 >Emitted(25, 16) Source(23, 66) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(25, 10) Source(23, 69) + SourceIndex(2) +1 >Emitted(26, 10) Source(23, 69) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(26, 6) Source(23, 71) + SourceIndex(2) +1 >Emitted(27, 6) Source(23, 71) + SourceIndex(2) --- >>> namespace someOther.something { 1->^^^^ @@ -413,12 +445,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(27, 5) Source(24, 19) + SourceIndex(2) -2 >Emitted(27, 15) Source(24, 36) + SourceIndex(2) -3 >Emitted(27, 24) Source(24, 45) + SourceIndex(2) -4 >Emitted(27, 25) Source(24, 46) + SourceIndex(2) -5 >Emitted(27, 34) Source(24, 55) + SourceIndex(2) -6 >Emitted(27, 35) Source(24, 56) + SourceIndex(2) +1->Emitted(28, 5) Source(24, 19) + SourceIndex(2) +2 >Emitted(28, 15) Source(24, 36) + SourceIndex(2) +3 >Emitted(28, 24) Source(24, 45) + SourceIndex(2) +4 >Emitted(28, 25) Source(24, 46) + SourceIndex(2) +5 >Emitted(28, 34) Source(24, 55) + SourceIndex(2) +6 >Emitted(28, 35) Source(24, 56) + SourceIndex(2) --- >>> class someClass { 1 >^^^^^^^^ @@ -427,20 +459,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(28, 9) Source(24, 58) + SourceIndex(2) -2 >Emitted(28, 15) Source(24, 71) + SourceIndex(2) -3 >Emitted(28, 24) Source(24, 80) + SourceIndex(2) +1 >Emitted(29, 9) Source(24, 58) + SourceIndex(2) +2 >Emitted(29, 15) Source(24, 71) + SourceIndex(2) +3 >Emitted(29, 24) Source(24, 80) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(29, 10) Source(24, 83) + SourceIndex(2) +1 >Emitted(30, 10) Source(24, 83) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(30, 6) Source(24, 85) + SourceIndex(2) +1 >Emitted(31, 6) Source(24, 85) + SourceIndex(2) --- >>> export import someImport = someNamespace.C; 1->^^^^ @@ -462,15 +494,15 @@ sourceFile:../second/second_part1.ts 7 > . 8 > C 9 > ; -1->Emitted(31, 5) Source(25, 19) + SourceIndex(2) -2 >Emitted(31, 11) Source(25, 25) + SourceIndex(2) -3 >Emitted(31, 19) Source(25, 33) + SourceIndex(2) -4 >Emitted(31, 29) Source(25, 43) + SourceIndex(2) -5 >Emitted(31, 32) Source(25, 46) + SourceIndex(2) -6 >Emitted(31, 45) Source(25, 59) + SourceIndex(2) -7 >Emitted(31, 46) Source(25, 60) + SourceIndex(2) -8 >Emitted(31, 47) Source(25, 61) + SourceIndex(2) -9 >Emitted(31, 48) Source(25, 62) + SourceIndex(2) +1->Emitted(32, 5) Source(25, 19) + SourceIndex(2) +2 >Emitted(32, 11) Source(25, 25) + SourceIndex(2) +3 >Emitted(32, 19) Source(25, 33) + SourceIndex(2) +4 >Emitted(32, 29) Source(25, 43) + SourceIndex(2) +5 >Emitted(32, 32) Source(25, 46) + SourceIndex(2) +6 >Emitted(32, 45) Source(25, 59) + SourceIndex(2) +7 >Emitted(32, 46) Source(25, 60) + SourceIndex(2) +8 >Emitted(32, 47) Source(25, 61) + SourceIndex(2) +9 >Emitted(32, 48) Source(25, 62) + SourceIndex(2) --- >>> type internalType = internalC; 1 >^^^^ @@ -486,12 +518,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(32, 5) Source(26, 19) + SourceIndex(2) -2 >Emitted(32, 10) Source(26, 31) + SourceIndex(2) -3 >Emitted(32, 22) Source(26, 43) + SourceIndex(2) -4 >Emitted(32, 25) Source(26, 46) + SourceIndex(2) -5 >Emitted(32, 34) Source(26, 55) + SourceIndex(2) -6 >Emitted(32, 35) Source(26, 56) + SourceIndex(2) +1 >Emitted(33, 5) Source(26, 19) + SourceIndex(2) +2 >Emitted(33, 10) Source(26, 31) + SourceIndex(2) +3 >Emitted(33, 22) Source(26, 43) + SourceIndex(2) +4 >Emitted(33, 25) Source(26, 46) + SourceIndex(2) +5 >Emitted(33, 34) Source(26, 55) + SourceIndex(2) +6 >Emitted(33, 35) Source(26, 56) + SourceIndex(2) --- >>> const internalConst = 10; 1 >^^^^ @@ -505,11 +537,11 @@ sourceFile:../second/second_part1.ts 3 > internalConst 4 > = 10 5 > ; -1 >Emitted(33, 5) Source(27, 26) + SourceIndex(2) -2 >Emitted(33, 11) Source(27, 32) + SourceIndex(2) -3 >Emitted(33, 24) Source(27, 45) + SourceIndex(2) -4 >Emitted(33, 29) Source(27, 50) + SourceIndex(2) -5 >Emitted(33, 30) Source(27, 51) + SourceIndex(2) +1 >Emitted(34, 5) Source(27, 26) + SourceIndex(2) +2 >Emitted(34, 11) Source(27, 32) + SourceIndex(2) +3 >Emitted(34, 24) Source(27, 45) + SourceIndex(2) +4 >Emitted(34, 29) Source(27, 50) + SourceIndex(2) +5 >Emitted(34, 30) Source(27, 51) + SourceIndex(2) --- >>> enum internalEnum { 1 >^^^^ @@ -519,9 +551,9 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export enum 3 > internalEnum -1 >Emitted(34, 5) Source(28, 19) + SourceIndex(2) -2 >Emitted(34, 10) Source(28, 31) + SourceIndex(2) -3 >Emitted(34, 22) Source(28, 43) + SourceIndex(2) +1 >Emitted(35, 5) Source(28, 19) + SourceIndex(2) +2 >Emitted(35, 10) Source(28, 31) + SourceIndex(2) +3 >Emitted(35, 22) Source(28, 43) + SourceIndex(2) --- >>> a = 0, 1 >^^^^^^^^ @@ -531,9 +563,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(35, 9) Source(28, 46) + SourceIndex(2) -2 >Emitted(35, 10) Source(28, 47) + SourceIndex(2) -3 >Emitted(35, 14) Source(28, 47) + SourceIndex(2) +1 >Emitted(36, 9) Source(28, 46) + SourceIndex(2) +2 >Emitted(36, 10) Source(28, 47) + SourceIndex(2) +3 >Emitted(36, 14) Source(28, 47) + SourceIndex(2) --- >>> b = 1, 1->^^^^^^^^ @@ -543,9 +575,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(36, 9) Source(28, 49) + SourceIndex(2) -2 >Emitted(36, 10) Source(28, 50) + SourceIndex(2) -3 >Emitted(36, 14) Source(28, 50) + SourceIndex(2) +1->Emitted(37, 9) Source(28, 49) + SourceIndex(2) +2 >Emitted(37, 10) Source(28, 50) + SourceIndex(2) +3 >Emitted(37, 14) Source(28, 50) + SourceIndex(2) --- >>> c = 2 1->^^^^^^^^ @@ -554,21 +586,21 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(37, 9) Source(28, 52) + SourceIndex(2) -2 >Emitted(37, 10) Source(28, 53) + SourceIndex(2) -3 >Emitted(37, 14) Source(28, 53) + SourceIndex(2) +1->Emitted(38, 9) Source(28, 52) + SourceIndex(2) +2 >Emitted(38, 10) Source(28, 53) + SourceIndex(2) +3 >Emitted(38, 14) Source(28, 53) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(38, 6) Source(28, 55) + SourceIndex(2) +1 >Emitted(39, 6) Source(28, 55) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(39, 2) Source(29, 2) + SourceIndex(2) +1 >Emitted(40, 2) Source(29, 2) + SourceIndex(2) --- >>>declare class internalC { 1-> @@ -578,15 +610,15 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >class 3 > internalC -1->Emitted(40, 1) Source(30, 15) + SourceIndex(2) -2 >Emitted(40, 15) Source(30, 21) + SourceIndex(2) -3 >Emitted(40, 24) Source(30, 30) + SourceIndex(2) +1->Emitted(41, 1) Source(30, 15) + SourceIndex(2) +2 >Emitted(41, 15) Source(30, 21) + SourceIndex(2) +3 >Emitted(41, 24) Source(30, 30) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(41, 2) Source(30, 33) + SourceIndex(2) +1 >Emitted(42, 2) Source(30, 33) + SourceIndex(2) --- >>>declare function internalfoo(): void; 1-> @@ -599,10 +631,10 @@ sourceFile:../second/second_part1.ts 2 >function 3 > internalfoo 4 > () {} -1->Emitted(42, 1) Source(31, 15) + SourceIndex(2) -2 >Emitted(42, 18) Source(31, 24) + SourceIndex(2) -3 >Emitted(42, 29) Source(31, 35) + SourceIndex(2) -4 >Emitted(42, 38) Source(31, 40) + SourceIndex(2) +1->Emitted(43, 1) Source(31, 15) + SourceIndex(2) +2 >Emitted(43, 18) Source(31, 24) + SourceIndex(2) +3 >Emitted(43, 29) Source(31, 35) + SourceIndex(2) +4 >Emitted(43, 38) Source(31, 40) + SourceIndex(2) --- >>>declare namespace internalNamespace { 1-> @@ -614,10 +646,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > internalNamespace 4 > -1->Emitted(43, 1) Source(32, 15) + SourceIndex(2) -2 >Emitted(43, 19) Source(32, 25) + SourceIndex(2) -3 >Emitted(43, 36) Source(32, 42) + SourceIndex(2) -4 >Emitted(43, 37) Source(32, 43) + SourceIndex(2) +1->Emitted(44, 1) Source(32, 15) + SourceIndex(2) +2 >Emitted(44, 19) Source(32, 25) + SourceIndex(2) +3 >Emitted(44, 36) Source(32, 42) + SourceIndex(2) +4 >Emitted(44, 37) Source(32, 43) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -626,20 +658,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(44, 5) Source(32, 45) + SourceIndex(2) -2 >Emitted(44, 11) Source(32, 58) + SourceIndex(2) -3 >Emitted(44, 20) Source(32, 67) + SourceIndex(2) +1 >Emitted(45, 5) Source(32, 45) + SourceIndex(2) +2 >Emitted(45, 11) Source(32, 58) + SourceIndex(2) +3 >Emitted(45, 20) Source(32, 67) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(45, 6) Source(32, 70) + SourceIndex(2) +1 >Emitted(46, 6) Source(32, 70) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(46, 2) Source(32, 72) + SourceIndex(2) +1 >Emitted(47, 2) Source(32, 72) + SourceIndex(2) --- >>>declare namespace internalOther.something { 1-> @@ -655,12 +687,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(47, 1) Source(33, 15) + SourceIndex(2) -2 >Emitted(47, 19) Source(33, 25) + SourceIndex(2) -3 >Emitted(47, 32) Source(33, 38) + SourceIndex(2) -4 >Emitted(47, 33) Source(33, 39) + SourceIndex(2) -5 >Emitted(47, 42) Source(33, 48) + SourceIndex(2) -6 >Emitted(47, 43) Source(33, 49) + SourceIndex(2) +1->Emitted(48, 1) Source(33, 15) + SourceIndex(2) +2 >Emitted(48, 19) Source(33, 25) + SourceIndex(2) +3 >Emitted(48, 32) Source(33, 38) + SourceIndex(2) +4 >Emitted(48, 33) Source(33, 39) + SourceIndex(2) +5 >Emitted(48, 42) Source(33, 48) + SourceIndex(2) +6 >Emitted(48, 43) Source(33, 49) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -669,20 +701,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(48, 5) Source(33, 51) + SourceIndex(2) -2 >Emitted(48, 11) Source(33, 64) + SourceIndex(2) -3 >Emitted(48, 20) Source(33, 73) + SourceIndex(2) +1 >Emitted(49, 5) Source(33, 51) + SourceIndex(2) +2 >Emitted(49, 11) Source(33, 64) + SourceIndex(2) +3 >Emitted(49, 20) Source(33, 73) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(49, 6) Source(33, 76) + SourceIndex(2) +1 >Emitted(50, 6) Source(33, 76) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(50, 2) Source(33, 78) + SourceIndex(2) +1 >Emitted(51, 2) Source(33, 78) + SourceIndex(2) --- >>>import internalImport = internalNamespace.someClass; 1-> @@ -702,14 +734,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > someClass 8 > ; -1->Emitted(51, 1) Source(34, 15) + SourceIndex(2) -2 >Emitted(51, 8) Source(34, 22) + SourceIndex(2) -3 >Emitted(51, 22) Source(34, 36) + SourceIndex(2) -4 >Emitted(51, 25) Source(34, 39) + SourceIndex(2) -5 >Emitted(51, 42) Source(34, 56) + SourceIndex(2) -6 >Emitted(51, 43) Source(34, 57) + SourceIndex(2) -7 >Emitted(51, 52) Source(34, 66) + SourceIndex(2) -8 >Emitted(51, 53) Source(34, 67) + SourceIndex(2) +1->Emitted(52, 1) Source(34, 15) + SourceIndex(2) +2 >Emitted(52, 8) Source(34, 22) + SourceIndex(2) +3 >Emitted(52, 22) Source(34, 36) + SourceIndex(2) +4 >Emitted(52, 25) Source(34, 39) + SourceIndex(2) +5 >Emitted(52, 42) Source(34, 56) + SourceIndex(2) +6 >Emitted(52, 43) Source(34, 57) + SourceIndex(2) +7 >Emitted(52, 52) Source(34, 66) + SourceIndex(2) +8 >Emitted(52, 53) Source(34, 67) + SourceIndex(2) --- >>>declare type internalType = internalC; 1 > @@ -725,12 +757,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(52, 1) Source(35, 15) + SourceIndex(2) -2 >Emitted(52, 14) Source(35, 20) + SourceIndex(2) -3 >Emitted(52, 26) Source(35, 32) + SourceIndex(2) -4 >Emitted(52, 29) Source(35, 35) + SourceIndex(2) -5 >Emitted(52, 38) Source(35, 44) + SourceIndex(2) -6 >Emitted(52, 39) Source(35, 45) + SourceIndex(2) +1 >Emitted(53, 1) Source(35, 15) + SourceIndex(2) +2 >Emitted(53, 14) Source(35, 20) + SourceIndex(2) +3 >Emitted(53, 26) Source(35, 32) + SourceIndex(2) +4 >Emitted(53, 29) Source(35, 35) + SourceIndex(2) +5 >Emitted(53, 38) Source(35, 44) + SourceIndex(2) +6 >Emitted(53, 39) Source(35, 45) + SourceIndex(2) --- >>>declare const internalConst = 10; 1 > @@ -746,12 +778,12 @@ sourceFile:../second/second_part1.ts 4 > internalConst 5 > = 10 6 > ; -1 >Emitted(53, 1) Source(36, 15) + SourceIndex(2) -2 >Emitted(53, 9) Source(36, 15) + SourceIndex(2) -3 >Emitted(53, 15) Source(36, 21) + SourceIndex(2) -4 >Emitted(53, 28) Source(36, 34) + SourceIndex(2) -5 >Emitted(53, 33) Source(36, 39) + SourceIndex(2) -6 >Emitted(53, 34) Source(36, 40) + SourceIndex(2) +1 >Emitted(54, 1) Source(36, 15) + SourceIndex(2) +2 >Emitted(54, 9) Source(36, 15) + SourceIndex(2) +3 >Emitted(54, 15) Source(36, 21) + SourceIndex(2) +4 >Emitted(54, 28) Source(36, 34) + SourceIndex(2) +5 >Emitted(54, 33) Source(36, 39) + SourceIndex(2) +6 >Emitted(54, 34) Source(36, 40) + SourceIndex(2) --- >>>declare enum internalEnum { 1 > @@ -761,9 +793,9 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >enum 3 > internalEnum -1 >Emitted(54, 1) Source(37, 15) + SourceIndex(2) -2 >Emitted(54, 14) Source(37, 20) + SourceIndex(2) -3 >Emitted(54, 26) Source(37, 32) + SourceIndex(2) +1 >Emitted(55, 1) Source(37, 15) + SourceIndex(2) +2 >Emitted(55, 14) Source(37, 20) + SourceIndex(2) +3 >Emitted(55, 26) Source(37, 32) + SourceIndex(2) --- >>> a = 0, 1 >^^^^ @@ -773,9 +805,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(55, 5) Source(37, 35) + SourceIndex(2) -2 >Emitted(55, 6) Source(37, 36) + SourceIndex(2) -3 >Emitted(55, 10) Source(37, 36) + SourceIndex(2) +1 >Emitted(56, 5) Source(37, 35) + SourceIndex(2) +2 >Emitted(56, 6) Source(37, 36) + SourceIndex(2) +3 >Emitted(56, 10) Source(37, 36) + SourceIndex(2) --- >>> b = 1, 1->^^^^ @@ -785,9 +817,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(56, 5) Source(37, 38) + SourceIndex(2) -2 >Emitted(56, 6) Source(37, 39) + SourceIndex(2) -3 >Emitted(56, 10) Source(37, 39) + SourceIndex(2) +1->Emitted(57, 5) Source(37, 38) + SourceIndex(2) +2 >Emitted(57, 6) Source(37, 39) + SourceIndex(2) +3 >Emitted(57, 10) Source(37, 39) + SourceIndex(2) --- >>> c = 2 1->^^^^ @@ -796,15 +828,15 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(57, 5) Source(37, 41) + SourceIndex(2) -2 >Emitted(57, 6) Source(37, 42) + SourceIndex(2) -3 >Emitted(57, 10) Source(37, 42) + SourceIndex(2) +1->Emitted(58, 5) Source(37, 41) + SourceIndex(2) +2 >Emitted(58, 6) Source(37, 42) + SourceIndex(2) +3 >Emitted(58, 10) Source(37, 42) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(58, 2) Source(37, 44) + SourceIndex(2) +1 >Emitted(59, 2) Source(37, 44) + SourceIndex(2) --- ------------------------------------------------------------------- emittedFile:/src/2/second-output.d.ts @@ -818,9 +850,9 @@ sourceFile:../second/second_part2.ts 1-> 2 >class 3 > C -1->Emitted(59, 1) Source(1, 1) + SourceIndex(3) -2 >Emitted(59, 15) Source(1, 7) + SourceIndex(3) -3 >Emitted(59, 16) Source(1, 8) + SourceIndex(3) +1->Emitted(60, 1) Source(1, 1) + SourceIndex(3) +2 >Emitted(60, 15) Source(1, 7) + SourceIndex(3) +3 >Emitted(60, 16) Source(1, 8) + SourceIndex(3) --- >>> doSomething(): void; 1->^^^^ @@ -828,8 +860,8 @@ sourceFile:../second/second_part2.ts 1-> { > 2 > doSomething -1->Emitted(60, 5) Source(2, 5) + SourceIndex(3) -2 >Emitted(60, 16) Source(2, 16) + SourceIndex(3) +1->Emitted(61, 5) Source(2, 5) + SourceIndex(3) +2 >Emitted(61, 16) Source(2, 16) + SourceIndex(3) --- >>>} 1 >^ @@ -838,7 +870,7 @@ sourceFile:../second/second_part2.ts > console.log("something got done"); > } >} -1 >Emitted(61, 2) Source(5, 2) + SourceIndex(3) +1 >Emitted(62, 2) Source(5, 2) + SourceIndex(3) --- >>>//# sourceMappingURL=second-output.d.ts.map @@ -2594,32 +2626,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 233, - "end": 307, + "end": 338, "kind": "internal" }, { - "pos": 309, - "end": 341, + "pos": 340, + "end": 372, "kind": "text" }, { - "pos": 341, - "end": 733, + "pos": 372, + "end": 764, "kind": "internal" }, { - "pos": 735, - "end": 738, + "pos": 766, + "end": 769, "kind": "text" }, { - "pos": 738, - "end": 1151, + "pos": 769, + "end": 1182, "kind": "internal" }, { - "pos": 1153, - "end": 1201, + "pos": 1184, + "end": 1232, "kind": "text" } ] @@ -2774,18 +2806,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (233-307) +internal: (233-338) constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (309-341) +text: (340-372) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (341-733) +internal: (372-764) class C { } function foo(): void; @@ -2806,11 +2839,11 @@ internal: (341-733) c = 2 } ---------------------------------------------------------------------- -text: (735-738) +text: (766-769) } ---------------------------------------------------------------------- -internal: (738-1151) +internal: (769-1182) declare class internalC { } declare function internalfoo(): void; @@ -2831,7 +2864,7 @@ declare enum internalEnum { c = 2 } ---------------------------------------------------------------------- -text: (1153-1201) +text: (1184-1232) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-jsdoc-style-comment-when-one-two-three-are-prepended-in-order.js b/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-jsdoc-style-comment-when-one-two-three-are-prepended-in-order.js index 6ec1100b4bd03..a7fbe3e9d156e 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-jsdoc-style-comment-when-one-two-three-are-prepended-in-order.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-jsdoc-style-comment-when-one-two-three-are-prepended-in-order.js @@ -1779,32 +1779,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 234, - "end": 308, + "end": 339, "kind": "internal" }, { - "pos": 310, - "end": 342, + "pos": 341, + "end": 373, "kind": "text" }, { - "pos": 342, - "end": 734, + "pos": 373, + "end": 765, "kind": "internal" }, { - "pos": 736, - "end": 739, + "pos": 767, + "end": 770, "kind": "text" }, { - "pos": 739, - "end": 1152, + "pos": 770, + "end": 1183, "kind": "internal" }, { - "pos": 1154, - "end": 1202, + "pos": 1185, + "end": 1233, "kind": "text" } ] @@ -1960,18 +1960,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (234-308) +internal: (234-339) constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (310-342) +text: (341-373) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (342-734) +internal: (373-765) class C { } function foo(): void; @@ -1992,11 +1993,11 @@ internal: (342-734) c = 2 } ---------------------------------------------------------------------- -text: (736-739) +text: (767-770) } ---------------------------------------------------------------------- -internal: (739-1152) +internal: (770-1183) declare class internalC { } declare function internalfoo(): void; @@ -2017,7 +2018,7 @@ declare enum internalEnum { c = 2 } ---------------------------------------------------------------------- -text: (1154-1202) +text: (1185-1233) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-jsdoc-style-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js b/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-jsdoc-style-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js index d68b80c42a4e4..136200af1da65 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-jsdoc-style-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-jsdoc-style-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js @@ -1879,32 +1879,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 249, - "end": 398, + "end": 429, "kind": "internal" }, { - "pos": 400, - "end": 432, + "pos": 431, + "end": 463, "kind": "text" }, { - "pos": 432, - "end": 944, + "pos": 463, + "end": 975, "kind": "internal" }, { - "pos": 946, - "end": 949, + "pos": 977, + "end": 980, "kind": "text" }, { - "pos": 949, - "end": 1482, + "pos": 980, + "end": 1513, "kind": "internal" }, { - "pos": 1484, - "end": 1532, + "pos": 1515, + "end": 1563, "kind": "text" } ] @@ -2060,18 +2060,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (249-398) +internal: (249-429) /**@internal*/ constructor(); /**@internal*/ prop: string; /**@internal*/ method(): void; - /**@internal*/ /**@internal*/ c: number; + /**@internal*/ get c(): number; + /**@internal*/ set c(val: number); ---------------------------------------------------------------------- -text: (400-432) +text: (431-463) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (432-944) +internal: (463-975) /**@internal*/ class C { } /**@internal*/ function foo(): void; @@ -2092,11 +2093,11 @@ internal: (432-944) c = 2 } ---------------------------------------------------------------------- -text: (946-949) +text: (977-980) } ---------------------------------------------------------------------- -internal: (949-1482) +internal: (980-1513) /**@internal*/ declare class internalC { } /**@internal*/ declare function internalfoo(): void; @@ -2117,7 +2118,7 @@ internal: (949-1482) c = 2 } ---------------------------------------------------------------------- -text: (1484-1532) +text: (1515-1563) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-when-one-two-three-are-prepended-in-order.js b/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-when-one-two-three-are-prepended-in-order.js index f312697a7264c..4569a944bd610 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-when-one-two-three-are-prepended-in-order.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-when-one-two-three-are-prepended-in-order.js @@ -1779,32 +1779,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 234, - "end": 308, + "end": 339, "kind": "internal" }, { - "pos": 310, - "end": 342, + "pos": 341, + "end": 373, "kind": "text" }, { - "pos": 342, - "end": 734, + "pos": 373, + "end": 765, "kind": "internal" }, { - "pos": 736, - "end": 739, + "pos": 767, + "end": 770, "kind": "text" }, { - "pos": 739, - "end": 1152, + "pos": 770, + "end": 1183, "kind": "internal" }, { - "pos": 1154, - "end": 1202, + "pos": 1185, + "end": 1233, "kind": "text" } ] @@ -1960,18 +1960,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (234-308) +internal: (234-339) constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (310-342) +text: (341-373) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (342-734) +internal: (373-765) class C { } function foo(): void; @@ -1992,11 +1993,11 @@ internal: (342-734) c = 2 } ---------------------------------------------------------------------- -text: (736-739) +text: (767-770) } ---------------------------------------------------------------------- -internal: (739-1152) +internal: (770-1183) declare class internalC { } declare function internalfoo(): void; @@ -2017,7 +2018,7 @@ declare enum internalEnum { c = 2 } ---------------------------------------------------------------------- -text: (1154-1202) +text: (1185-1233) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js b/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js index 4ccb69a5a8d12..505e12c4d28cf 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/incremental-declaration-doesnt-change/stripInternal-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js @@ -1879,32 +1879,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 234, - "end": 322, + "end": 339, "kind": "internal" }, { - "pos": 324, - "end": 356, + "pos": 341, + "end": 373, "kind": "text" }, { - "pos": 356, - "end": 748, + "pos": 373, + "end": 765, "kind": "internal" }, { - "pos": 750, - "end": 753, + "pos": 767, + "end": 770, "kind": "text" }, { - "pos": 753, - "end": 1166, + "pos": 770, + "end": 1183, "kind": "internal" }, { - "pos": 1168, - "end": 1216, + "pos": 1185, + "end": 1233, "kind": "text" } ] @@ -2060,18 +2060,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (234-322) +internal: (234-339) constructor(); prop: string; method(): void; - /*@internal*/ c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (324-356) +text: (341-373) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (356-748) +internal: (373-765) class C { } function foo(): void; @@ -2092,11 +2093,11 @@ internal: (356-748) c = 2 } ---------------------------------------------------------------------- -text: (750-753) +text: (767-770) } ---------------------------------------------------------------------- -internal: (753-1166) +internal: (770-1183) declare class internalC { } declare function internalfoo(): void; @@ -2117,7 +2118,7 @@ declare enum internalEnum { c = 2 } ---------------------------------------------------------------------- -text: (1168-1216) +text: (1185-1233) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/incremental-headers-change-without-dts-changes/stripInternal-jsdoc-style-comment-when-one-two-three-are-prepended-in-order.js b/tests/baselines/reference/tsbuild/outfile-concat/incremental-headers-change-without-dts-changes/stripInternal-jsdoc-style-comment-when-one-two-three-are-prepended-in-order.js index 887c845e48b84..11620e047da3b 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/incremental-headers-change-without-dts-changes/stripInternal-jsdoc-style-comment-when-one-two-three-are-prepended-in-order.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/incremental-headers-change-without-dts-changes/stripInternal-jsdoc-style-comment-when-one-two-three-are-prepended-in-order.js @@ -1,5 +1,5 @@ //// [/src/2/second-output.d.ts.map] -{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,UAAU,QAAQ;IACd,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEM,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACF,CAAC,EACM,MAAM;CACnC;AACD,kBAAU,OAAO,CAAC;IACC,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACtD;AACc,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC5C,cAAM,CAAC;IACH,WAAW;CAGd"} +{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,UAAU,QAAQ;IACd,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEM,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACN,IAAI,CAAC,IACM,MAAM,CADK;IACtB,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;CACxC;AACD,kBAAU,OAAO,CAAC;IACC,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACtD;AACc,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC5C,cAAM,CAAC;IACH,WAAW;CAGd"} //// [/src/2/second-output.d.ts.map.baseline.txt] =================================================================== @@ -219,35 +219,66 @@ sourceFile:../second/second_part1.ts >>> method(): void; 1->^^^^ 2 > ^^^^^^ -3 > ^^^^^-> +3 > ^^^^^^^^^^^-> 1-> > /**@internal*/ 2 > method 1->Emitted(16, 5) Source(16, 20) + SourceIndex(2) 2 >Emitted(16, 11) Source(16, 26) + SourceIndex(2) --- ->>> c: number; +>>> get c(): number; 1->^^^^ -2 > ^ -3 > ^^ -4 > ^^^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^^ +5 > ^^^^^^ +6 > ^ +7 > ^^^^-> 1->() { } - > /**@internal*/ get -2 > c -3 > () { return 10; } - > /**@internal*/ set c(val: -4 > number -1->Emitted(17, 5) Source(17, 24) + SourceIndex(2) -2 >Emitted(17, 6) Source(17, 25) + SourceIndex(2) -3 >Emitted(17, 8) Source(18, 31) + SourceIndex(2) -4 >Emitted(17, 14) Source(18, 37) + SourceIndex(2) + > /**@internal*/ +2 > get +3 > c +4 > () { return 10; } + > /**@internal*/ set c(val: +5 > number +6 > +1->Emitted(17, 5) Source(17, 20) + SourceIndex(2) +2 >Emitted(17, 9) Source(17, 24) + SourceIndex(2) +3 >Emitted(17, 10) Source(17, 25) + SourceIndex(2) +4 >Emitted(17, 14) Source(18, 31) + SourceIndex(2) +5 >Emitted(17, 20) Source(18, 37) + SourceIndex(2) +6 >Emitted(17, 21) Source(17, 42) + SourceIndex(2) +--- +>>> set c(val: number); +1->^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^ +6 > ^^^^^^ +7 > ^^ +1-> + > /**@internal*/ +2 > set +3 > c +4 > ( +5 > val: +6 > number +7 > ) { } +1->Emitted(18, 5) Source(18, 20) + SourceIndex(2) +2 >Emitted(18, 9) Source(18, 24) + SourceIndex(2) +3 >Emitted(18, 10) Source(18, 25) + SourceIndex(2) +4 >Emitted(18, 11) Source(18, 26) + SourceIndex(2) +5 >Emitted(18, 16) Source(18, 31) + SourceIndex(2) +6 >Emitted(18, 22) Source(18, 37) + SourceIndex(2) +7 >Emitted(18, 24) Source(18, 42) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(18, 2) Source(19, 2) + SourceIndex(2) +1 >Emitted(19, 2) Source(19, 2) + SourceIndex(2) --- >>>declare namespace normalN { 1-> @@ -259,10 +290,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > normalN 4 > -1->Emitted(19, 1) Source(20, 1) + SourceIndex(2) -2 >Emitted(19, 19) Source(20, 11) + SourceIndex(2) -3 >Emitted(19, 26) Source(20, 18) + SourceIndex(2) -4 >Emitted(19, 27) Source(20, 19) + SourceIndex(2) +1->Emitted(20, 1) Source(20, 1) + SourceIndex(2) +2 >Emitted(20, 19) Source(20, 11) + SourceIndex(2) +3 >Emitted(20, 26) Source(20, 18) + SourceIndex(2) +4 >Emitted(20, 27) Source(20, 19) + SourceIndex(2) --- >>> class C { 1 >^^^^ @@ -272,15 +303,15 @@ sourceFile:../second/second_part1.ts > /**@internal*/ 2 > export class 3 > C -1 >Emitted(20, 5) Source(21, 20) + SourceIndex(2) -2 >Emitted(20, 11) Source(21, 33) + SourceIndex(2) -3 >Emitted(20, 12) Source(21, 34) + SourceIndex(2) +1 >Emitted(21, 5) Source(21, 20) + SourceIndex(2) +2 >Emitted(21, 11) Source(21, 33) + SourceIndex(2) +3 >Emitted(21, 12) Source(21, 34) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(21, 6) Source(21, 38) + SourceIndex(2) +1 >Emitted(22, 6) Source(21, 38) + SourceIndex(2) --- >>> function foo(): void; 1->^^^^ @@ -293,10 +324,10 @@ sourceFile:../second/second_part1.ts 2 > export function 3 > foo 4 > () {} -1->Emitted(22, 5) Source(22, 20) + SourceIndex(2) -2 >Emitted(22, 14) Source(22, 36) + SourceIndex(2) -3 >Emitted(22, 17) Source(22, 39) + SourceIndex(2) -4 >Emitted(22, 26) Source(22, 44) + SourceIndex(2) +1->Emitted(23, 5) Source(22, 20) + SourceIndex(2) +2 >Emitted(23, 14) Source(22, 36) + SourceIndex(2) +3 >Emitted(23, 17) Source(22, 39) + SourceIndex(2) +4 >Emitted(23, 26) Source(22, 44) + SourceIndex(2) --- >>> namespace someNamespace { 1->^^^^ @@ -308,10 +339,10 @@ sourceFile:../second/second_part1.ts 2 > export namespace 3 > someNamespace 4 > -1->Emitted(23, 5) Source(23, 20) + SourceIndex(2) -2 >Emitted(23, 15) Source(23, 37) + SourceIndex(2) -3 >Emitted(23, 28) Source(23, 50) + SourceIndex(2) -4 >Emitted(23, 29) Source(23, 51) + SourceIndex(2) +1->Emitted(24, 5) Source(23, 20) + SourceIndex(2) +2 >Emitted(24, 15) Source(23, 37) + SourceIndex(2) +3 >Emitted(24, 28) Source(23, 50) + SourceIndex(2) +4 >Emitted(24, 29) Source(23, 51) + SourceIndex(2) --- >>> class C { 1 >^^^^^^^^ @@ -320,20 +351,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(24, 9) Source(23, 53) + SourceIndex(2) -2 >Emitted(24, 15) Source(23, 66) + SourceIndex(2) -3 >Emitted(24, 16) Source(23, 67) + SourceIndex(2) +1 >Emitted(25, 9) Source(23, 53) + SourceIndex(2) +2 >Emitted(25, 15) Source(23, 66) + SourceIndex(2) +3 >Emitted(25, 16) Source(23, 67) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(25, 10) Source(23, 70) + SourceIndex(2) +1 >Emitted(26, 10) Source(23, 70) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(26, 6) Source(23, 72) + SourceIndex(2) +1 >Emitted(27, 6) Source(23, 72) + SourceIndex(2) --- >>> namespace someOther.something { 1->^^^^ @@ -349,12 +380,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(27, 5) Source(24, 20) + SourceIndex(2) -2 >Emitted(27, 15) Source(24, 37) + SourceIndex(2) -3 >Emitted(27, 24) Source(24, 46) + SourceIndex(2) -4 >Emitted(27, 25) Source(24, 47) + SourceIndex(2) -5 >Emitted(27, 34) Source(24, 56) + SourceIndex(2) -6 >Emitted(27, 35) Source(24, 57) + SourceIndex(2) +1->Emitted(28, 5) Source(24, 20) + SourceIndex(2) +2 >Emitted(28, 15) Source(24, 37) + SourceIndex(2) +3 >Emitted(28, 24) Source(24, 46) + SourceIndex(2) +4 >Emitted(28, 25) Source(24, 47) + SourceIndex(2) +5 >Emitted(28, 34) Source(24, 56) + SourceIndex(2) +6 >Emitted(28, 35) Source(24, 57) + SourceIndex(2) --- >>> class someClass { 1 >^^^^^^^^ @@ -363,20 +394,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(28, 9) Source(24, 59) + SourceIndex(2) -2 >Emitted(28, 15) Source(24, 72) + SourceIndex(2) -3 >Emitted(28, 24) Source(24, 81) + SourceIndex(2) +1 >Emitted(29, 9) Source(24, 59) + SourceIndex(2) +2 >Emitted(29, 15) Source(24, 72) + SourceIndex(2) +3 >Emitted(29, 24) Source(24, 81) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(29, 10) Source(24, 84) + SourceIndex(2) +1 >Emitted(30, 10) Source(24, 84) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(30, 6) Source(24, 86) + SourceIndex(2) +1 >Emitted(31, 6) Source(24, 86) + SourceIndex(2) --- >>> export import someImport = someNamespace.C; 1->^^^^ @@ -398,15 +429,15 @@ sourceFile:../second/second_part1.ts 7 > . 8 > C 9 > ; -1->Emitted(31, 5) Source(25, 20) + SourceIndex(2) -2 >Emitted(31, 11) Source(25, 26) + SourceIndex(2) -3 >Emitted(31, 19) Source(25, 34) + SourceIndex(2) -4 >Emitted(31, 29) Source(25, 44) + SourceIndex(2) -5 >Emitted(31, 32) Source(25, 47) + SourceIndex(2) -6 >Emitted(31, 45) Source(25, 60) + SourceIndex(2) -7 >Emitted(31, 46) Source(25, 61) + SourceIndex(2) -8 >Emitted(31, 47) Source(25, 62) + SourceIndex(2) -9 >Emitted(31, 48) Source(25, 63) + SourceIndex(2) +1->Emitted(32, 5) Source(25, 20) + SourceIndex(2) +2 >Emitted(32, 11) Source(25, 26) + SourceIndex(2) +3 >Emitted(32, 19) Source(25, 34) + SourceIndex(2) +4 >Emitted(32, 29) Source(25, 44) + SourceIndex(2) +5 >Emitted(32, 32) Source(25, 47) + SourceIndex(2) +6 >Emitted(32, 45) Source(25, 60) + SourceIndex(2) +7 >Emitted(32, 46) Source(25, 61) + SourceIndex(2) +8 >Emitted(32, 47) Source(25, 62) + SourceIndex(2) +9 >Emitted(32, 48) Source(25, 63) + SourceIndex(2) --- >>> type internalType = internalC; 1 >^^^^ @@ -422,12 +453,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(32, 5) Source(26, 20) + SourceIndex(2) -2 >Emitted(32, 10) Source(26, 32) + SourceIndex(2) -3 >Emitted(32, 22) Source(26, 44) + SourceIndex(2) -4 >Emitted(32, 25) Source(26, 47) + SourceIndex(2) -5 >Emitted(32, 34) Source(26, 56) + SourceIndex(2) -6 >Emitted(32, 35) Source(26, 57) + SourceIndex(2) +1 >Emitted(33, 5) Source(26, 20) + SourceIndex(2) +2 >Emitted(33, 10) Source(26, 32) + SourceIndex(2) +3 >Emitted(33, 22) Source(26, 44) + SourceIndex(2) +4 >Emitted(33, 25) Source(26, 47) + SourceIndex(2) +5 >Emitted(33, 34) Source(26, 56) + SourceIndex(2) +6 >Emitted(33, 35) Source(26, 57) + SourceIndex(2) --- >>> const internalConst = 10; 1 >^^^^ @@ -441,11 +472,11 @@ sourceFile:../second/second_part1.ts 3 > internalConst 4 > = 10 5 > ; -1 >Emitted(33, 5) Source(27, 27) + SourceIndex(2) -2 >Emitted(33, 11) Source(27, 33) + SourceIndex(2) -3 >Emitted(33, 24) Source(27, 46) + SourceIndex(2) -4 >Emitted(33, 29) Source(27, 51) + SourceIndex(2) -5 >Emitted(33, 30) Source(27, 52) + SourceIndex(2) +1 >Emitted(34, 5) Source(27, 27) + SourceIndex(2) +2 >Emitted(34, 11) Source(27, 33) + SourceIndex(2) +3 >Emitted(34, 24) Source(27, 46) + SourceIndex(2) +4 >Emitted(34, 29) Source(27, 51) + SourceIndex(2) +5 >Emitted(34, 30) Source(27, 52) + SourceIndex(2) --- >>> enum internalEnum { 1 >^^^^ @@ -455,9 +486,9 @@ sourceFile:../second/second_part1.ts > /**@internal*/ 2 > export enum 3 > internalEnum -1 >Emitted(34, 5) Source(28, 20) + SourceIndex(2) -2 >Emitted(34, 10) Source(28, 32) + SourceIndex(2) -3 >Emitted(34, 22) Source(28, 44) + SourceIndex(2) +1 >Emitted(35, 5) Source(28, 20) + SourceIndex(2) +2 >Emitted(35, 10) Source(28, 32) + SourceIndex(2) +3 >Emitted(35, 22) Source(28, 44) + SourceIndex(2) --- >>> a = 0, 1 >^^^^^^^^ @@ -467,9 +498,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(35, 9) Source(28, 47) + SourceIndex(2) -2 >Emitted(35, 10) Source(28, 48) + SourceIndex(2) -3 >Emitted(35, 14) Source(28, 48) + SourceIndex(2) +1 >Emitted(36, 9) Source(28, 47) + SourceIndex(2) +2 >Emitted(36, 10) Source(28, 48) + SourceIndex(2) +3 >Emitted(36, 14) Source(28, 48) + SourceIndex(2) --- >>> b = 1, 1->^^^^^^^^ @@ -479,9 +510,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(36, 9) Source(28, 50) + SourceIndex(2) -2 >Emitted(36, 10) Source(28, 51) + SourceIndex(2) -3 >Emitted(36, 14) Source(28, 51) + SourceIndex(2) +1->Emitted(37, 9) Source(28, 50) + SourceIndex(2) +2 >Emitted(37, 10) Source(28, 51) + SourceIndex(2) +3 >Emitted(37, 14) Source(28, 51) + SourceIndex(2) --- >>> c = 2 1->^^^^^^^^ @@ -490,21 +521,21 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(37, 9) Source(28, 53) + SourceIndex(2) -2 >Emitted(37, 10) Source(28, 54) + SourceIndex(2) -3 >Emitted(37, 14) Source(28, 54) + SourceIndex(2) +1->Emitted(38, 9) Source(28, 53) + SourceIndex(2) +2 >Emitted(38, 10) Source(28, 54) + SourceIndex(2) +3 >Emitted(38, 14) Source(28, 54) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(38, 6) Source(28, 56) + SourceIndex(2) +1 >Emitted(39, 6) Source(28, 56) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(39, 2) Source(29, 2) + SourceIndex(2) +1 >Emitted(40, 2) Source(29, 2) + SourceIndex(2) --- >>>declare class internalC { 1-> @@ -514,15 +545,15 @@ sourceFile:../second/second_part1.ts >/**@internal*/ 2 >class 3 > internalC -1->Emitted(40, 1) Source(30, 16) + SourceIndex(2) -2 >Emitted(40, 15) Source(30, 22) + SourceIndex(2) -3 >Emitted(40, 24) Source(30, 31) + SourceIndex(2) +1->Emitted(41, 1) Source(30, 16) + SourceIndex(2) +2 >Emitted(41, 15) Source(30, 22) + SourceIndex(2) +3 >Emitted(41, 24) Source(30, 31) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(41, 2) Source(30, 34) + SourceIndex(2) +1 >Emitted(42, 2) Source(30, 34) + SourceIndex(2) --- >>>declare function internalfoo(): void; 1-> @@ -535,10 +566,10 @@ sourceFile:../second/second_part1.ts 2 >function 3 > internalfoo 4 > () {} -1->Emitted(42, 1) Source(31, 16) + SourceIndex(2) -2 >Emitted(42, 18) Source(31, 25) + SourceIndex(2) -3 >Emitted(42, 29) Source(31, 36) + SourceIndex(2) -4 >Emitted(42, 38) Source(31, 41) + SourceIndex(2) +1->Emitted(43, 1) Source(31, 16) + SourceIndex(2) +2 >Emitted(43, 18) Source(31, 25) + SourceIndex(2) +3 >Emitted(43, 29) Source(31, 36) + SourceIndex(2) +4 >Emitted(43, 38) Source(31, 41) + SourceIndex(2) --- >>>declare namespace internalNamespace { 1-> @@ -550,10 +581,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > internalNamespace 4 > -1->Emitted(43, 1) Source(32, 16) + SourceIndex(2) -2 >Emitted(43, 19) Source(32, 26) + SourceIndex(2) -3 >Emitted(43, 36) Source(32, 43) + SourceIndex(2) -4 >Emitted(43, 37) Source(32, 44) + SourceIndex(2) +1->Emitted(44, 1) Source(32, 16) + SourceIndex(2) +2 >Emitted(44, 19) Source(32, 26) + SourceIndex(2) +3 >Emitted(44, 36) Source(32, 43) + SourceIndex(2) +4 >Emitted(44, 37) Source(32, 44) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -562,20 +593,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(44, 5) Source(32, 46) + SourceIndex(2) -2 >Emitted(44, 11) Source(32, 59) + SourceIndex(2) -3 >Emitted(44, 20) Source(32, 68) + SourceIndex(2) +1 >Emitted(45, 5) Source(32, 46) + SourceIndex(2) +2 >Emitted(45, 11) Source(32, 59) + SourceIndex(2) +3 >Emitted(45, 20) Source(32, 68) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(45, 6) Source(32, 71) + SourceIndex(2) +1 >Emitted(46, 6) Source(32, 71) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(46, 2) Source(32, 73) + SourceIndex(2) +1 >Emitted(47, 2) Source(32, 73) + SourceIndex(2) --- >>>declare namespace internalOther.something { 1-> @@ -591,12 +622,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(47, 1) Source(33, 16) + SourceIndex(2) -2 >Emitted(47, 19) Source(33, 26) + SourceIndex(2) -3 >Emitted(47, 32) Source(33, 39) + SourceIndex(2) -4 >Emitted(47, 33) Source(33, 40) + SourceIndex(2) -5 >Emitted(47, 42) Source(33, 49) + SourceIndex(2) -6 >Emitted(47, 43) Source(33, 50) + SourceIndex(2) +1->Emitted(48, 1) Source(33, 16) + SourceIndex(2) +2 >Emitted(48, 19) Source(33, 26) + SourceIndex(2) +3 >Emitted(48, 32) Source(33, 39) + SourceIndex(2) +4 >Emitted(48, 33) Source(33, 40) + SourceIndex(2) +5 >Emitted(48, 42) Source(33, 49) + SourceIndex(2) +6 >Emitted(48, 43) Source(33, 50) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -605,20 +636,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(48, 5) Source(33, 52) + SourceIndex(2) -2 >Emitted(48, 11) Source(33, 65) + SourceIndex(2) -3 >Emitted(48, 20) Source(33, 74) + SourceIndex(2) +1 >Emitted(49, 5) Source(33, 52) + SourceIndex(2) +2 >Emitted(49, 11) Source(33, 65) + SourceIndex(2) +3 >Emitted(49, 20) Source(33, 74) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(49, 6) Source(33, 77) + SourceIndex(2) +1 >Emitted(50, 6) Source(33, 77) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(50, 2) Source(33, 79) + SourceIndex(2) +1 >Emitted(51, 2) Source(33, 79) + SourceIndex(2) --- >>>import internalImport = internalNamespace.someClass; 1-> @@ -638,14 +669,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > someClass 8 > ; -1->Emitted(51, 1) Source(34, 16) + SourceIndex(2) -2 >Emitted(51, 8) Source(34, 23) + SourceIndex(2) -3 >Emitted(51, 22) Source(34, 37) + SourceIndex(2) -4 >Emitted(51, 25) Source(34, 40) + SourceIndex(2) -5 >Emitted(51, 42) Source(34, 57) + SourceIndex(2) -6 >Emitted(51, 43) Source(34, 58) + SourceIndex(2) -7 >Emitted(51, 52) Source(34, 67) + SourceIndex(2) -8 >Emitted(51, 53) Source(34, 68) + SourceIndex(2) +1->Emitted(52, 1) Source(34, 16) + SourceIndex(2) +2 >Emitted(52, 8) Source(34, 23) + SourceIndex(2) +3 >Emitted(52, 22) Source(34, 37) + SourceIndex(2) +4 >Emitted(52, 25) Source(34, 40) + SourceIndex(2) +5 >Emitted(52, 42) Source(34, 57) + SourceIndex(2) +6 >Emitted(52, 43) Source(34, 58) + SourceIndex(2) +7 >Emitted(52, 52) Source(34, 67) + SourceIndex(2) +8 >Emitted(52, 53) Source(34, 68) + SourceIndex(2) --- >>>declare type internalType = internalC; 1 > @@ -661,12 +692,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(52, 1) Source(35, 16) + SourceIndex(2) -2 >Emitted(52, 14) Source(35, 21) + SourceIndex(2) -3 >Emitted(52, 26) Source(35, 33) + SourceIndex(2) -4 >Emitted(52, 29) Source(35, 36) + SourceIndex(2) -5 >Emitted(52, 38) Source(35, 45) + SourceIndex(2) -6 >Emitted(52, 39) Source(35, 46) + SourceIndex(2) +1 >Emitted(53, 1) Source(35, 16) + SourceIndex(2) +2 >Emitted(53, 14) Source(35, 21) + SourceIndex(2) +3 >Emitted(53, 26) Source(35, 33) + SourceIndex(2) +4 >Emitted(53, 29) Source(35, 36) + SourceIndex(2) +5 >Emitted(53, 38) Source(35, 45) + SourceIndex(2) +6 >Emitted(53, 39) Source(35, 46) + SourceIndex(2) --- >>>declare const internalConst = 10; 1 > @@ -682,12 +713,12 @@ sourceFile:../second/second_part1.ts 4 > internalConst 5 > = 10 6 > ; -1 >Emitted(53, 1) Source(36, 16) + SourceIndex(2) -2 >Emitted(53, 9) Source(36, 16) + SourceIndex(2) -3 >Emitted(53, 15) Source(36, 22) + SourceIndex(2) -4 >Emitted(53, 28) Source(36, 35) + SourceIndex(2) -5 >Emitted(53, 33) Source(36, 40) + SourceIndex(2) -6 >Emitted(53, 34) Source(36, 41) + SourceIndex(2) +1 >Emitted(54, 1) Source(36, 16) + SourceIndex(2) +2 >Emitted(54, 9) Source(36, 16) + SourceIndex(2) +3 >Emitted(54, 15) Source(36, 22) + SourceIndex(2) +4 >Emitted(54, 28) Source(36, 35) + SourceIndex(2) +5 >Emitted(54, 33) Source(36, 40) + SourceIndex(2) +6 >Emitted(54, 34) Source(36, 41) + SourceIndex(2) --- >>>declare enum internalEnum { 1 > @@ -697,9 +728,9 @@ sourceFile:../second/second_part1.ts >/**@internal*/ 2 >enum 3 > internalEnum -1 >Emitted(54, 1) Source(37, 16) + SourceIndex(2) -2 >Emitted(54, 14) Source(37, 21) + SourceIndex(2) -3 >Emitted(54, 26) Source(37, 33) + SourceIndex(2) +1 >Emitted(55, 1) Source(37, 16) + SourceIndex(2) +2 >Emitted(55, 14) Source(37, 21) + SourceIndex(2) +3 >Emitted(55, 26) Source(37, 33) + SourceIndex(2) --- >>> a = 0, 1 >^^^^ @@ -709,9 +740,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(55, 5) Source(37, 36) + SourceIndex(2) -2 >Emitted(55, 6) Source(37, 37) + SourceIndex(2) -3 >Emitted(55, 10) Source(37, 37) + SourceIndex(2) +1 >Emitted(56, 5) Source(37, 36) + SourceIndex(2) +2 >Emitted(56, 6) Source(37, 37) + SourceIndex(2) +3 >Emitted(56, 10) Source(37, 37) + SourceIndex(2) --- >>> b = 1, 1->^^^^ @@ -721,9 +752,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(56, 5) Source(37, 39) + SourceIndex(2) -2 >Emitted(56, 6) Source(37, 40) + SourceIndex(2) -3 >Emitted(56, 10) Source(37, 40) + SourceIndex(2) +1->Emitted(57, 5) Source(37, 39) + SourceIndex(2) +2 >Emitted(57, 6) Source(37, 40) + SourceIndex(2) +3 >Emitted(57, 10) Source(37, 40) + SourceIndex(2) --- >>> c = 2 1->^^^^ @@ -732,15 +763,15 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(57, 5) Source(37, 42) + SourceIndex(2) -2 >Emitted(57, 6) Source(37, 43) + SourceIndex(2) -3 >Emitted(57, 10) Source(37, 43) + SourceIndex(2) +1->Emitted(58, 5) Source(37, 42) + SourceIndex(2) +2 >Emitted(58, 6) Source(37, 43) + SourceIndex(2) +3 >Emitted(58, 10) Source(37, 43) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(58, 2) Source(37, 45) + SourceIndex(2) +1 >Emitted(59, 2) Source(37, 45) + SourceIndex(2) --- ------------------------------------------------------------------- emittedFile:/src/2/second-output.d.ts @@ -754,9 +785,9 @@ sourceFile:../second/second_part2.ts 1-> 2 >class 3 > C -1->Emitted(59, 1) Source(1, 1) + SourceIndex(3) -2 >Emitted(59, 15) Source(1, 7) + SourceIndex(3) -3 >Emitted(59, 16) Source(1, 8) + SourceIndex(3) +1->Emitted(60, 1) Source(1, 1) + SourceIndex(3) +2 >Emitted(60, 15) Source(1, 7) + SourceIndex(3) +3 >Emitted(60, 16) Source(1, 8) + SourceIndex(3) --- >>> doSomething(): void; 1->^^^^ @@ -764,8 +795,8 @@ sourceFile:../second/second_part2.ts 1-> { > 2 > doSomething -1->Emitted(60, 5) Source(2, 5) + SourceIndex(3) -2 >Emitted(60, 16) Source(2, 16) + SourceIndex(3) +1->Emitted(61, 5) Source(2, 5) + SourceIndex(3) +2 >Emitted(61, 16) Source(2, 16) + SourceIndex(3) --- >>>} 1 >^ @@ -774,7 +805,7 @@ sourceFile:../second/second_part2.ts > console.log("something got done"); > } >} -1 >Emitted(61, 2) Source(5, 2) + SourceIndex(3) +1 >Emitted(62, 2) Source(5, 2) + SourceIndex(3) --- >>>//# sourceMappingURL=second-output.d.ts.map @@ -830,32 +861,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 234, - "end": 308, + "end": 339, "kind": "internal" }, { - "pos": 310, - "end": 342, + "pos": 341, + "end": 373, "kind": "text" }, { - "pos": 342, - "end": 734, + "pos": 373, + "end": 765, "kind": "internal" }, { - "pos": 736, - "end": 739, + "pos": 767, + "end": 770, "kind": "text" }, { - "pos": 739, - "end": 1152, + "pos": 770, + "end": 1183, "kind": "internal" }, { - "pos": 1154, - "end": 1202, + "pos": 1185, + "end": 1233, "kind": "text" } ] @@ -1008,18 +1039,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (234-308) +internal: (234-339) constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (310-342) +text: (341-373) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (342-734) +internal: (373-765) class C { } function foo(): void; @@ -1040,11 +1072,11 @@ internal: (342-734) c = 2 } ---------------------------------------------------------------------- -text: (736-739) +text: (767-770) } ---------------------------------------------------------------------- -internal: (739-1152) +internal: (770-1183) declare class internalC { } declare function internalfoo(): void; @@ -1065,7 +1097,7 @@ declare enum internalEnum { c = 2 } ---------------------------------------------------------------------- -text: (1154-1202) +text: (1185-1233) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/incremental-headers-change-without-dts-changes/stripInternal-when-one-two-three-are-prepended-in-order.js b/tests/baselines/reference/tsbuild/outfile-concat/incremental-headers-change-without-dts-changes/stripInternal-when-one-two-three-are-prepended-in-order.js index 5f9b856f99c4e..3d71e41c0df1e 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/incremental-headers-change-without-dts-changes/stripInternal-when-one-two-three-are-prepended-in-order.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/incremental-headers-change-without-dts-changes/stripInternal-when-one-two-three-are-prepended-in-order.js @@ -1,5 +1,5 @@ //// [/src/2/second-output.d.ts.map] -{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,UAAU,QAAQ;IACd,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACF,CAAC,EACM,MAAM;CAClC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} +{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,UAAU,QAAQ;IACd,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACN,IAAI,CAAC,IACM,MAAM,CADK;IACtB,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;CACvC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} //// [/src/2/second-output.d.ts.map.baseline.txt] =================================================================== @@ -219,35 +219,66 @@ sourceFile:../second/second_part1.ts >>> method(): void; 1->^^^^ 2 > ^^^^^^ -3 > ^^^^^-> +3 > ^^^^^^^^^^^-> 1-> > /*@internal*/ 2 > method 1->Emitted(16, 5) Source(16, 19) + SourceIndex(2) 2 >Emitted(16, 11) Source(16, 25) + SourceIndex(2) --- ->>> c: number; +>>> get c(): number; 1->^^^^ -2 > ^ -3 > ^^ -4 > ^^^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^^ +5 > ^^^^^^ +6 > ^ +7 > ^^^^-> 1->() { } - > /*@internal*/ get -2 > c -3 > () { return 10; } - > /*@internal*/ set c(val: -4 > number -1->Emitted(17, 5) Source(17, 23) + SourceIndex(2) -2 >Emitted(17, 6) Source(17, 24) + SourceIndex(2) -3 >Emitted(17, 8) Source(18, 30) + SourceIndex(2) -4 >Emitted(17, 14) Source(18, 36) + SourceIndex(2) + > /*@internal*/ +2 > get +3 > c +4 > () { return 10; } + > /*@internal*/ set c(val: +5 > number +6 > +1->Emitted(17, 5) Source(17, 19) + SourceIndex(2) +2 >Emitted(17, 9) Source(17, 23) + SourceIndex(2) +3 >Emitted(17, 10) Source(17, 24) + SourceIndex(2) +4 >Emitted(17, 14) Source(18, 30) + SourceIndex(2) +5 >Emitted(17, 20) Source(18, 36) + SourceIndex(2) +6 >Emitted(17, 21) Source(17, 41) + SourceIndex(2) +--- +>>> set c(val: number); +1->^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^ +6 > ^^^^^^ +7 > ^^ +1-> + > /*@internal*/ +2 > set +3 > c +4 > ( +5 > val: +6 > number +7 > ) { } +1->Emitted(18, 5) Source(18, 19) + SourceIndex(2) +2 >Emitted(18, 9) Source(18, 23) + SourceIndex(2) +3 >Emitted(18, 10) Source(18, 24) + SourceIndex(2) +4 >Emitted(18, 11) Source(18, 25) + SourceIndex(2) +5 >Emitted(18, 16) Source(18, 30) + SourceIndex(2) +6 >Emitted(18, 22) Source(18, 36) + SourceIndex(2) +7 >Emitted(18, 24) Source(18, 41) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(18, 2) Source(19, 2) + SourceIndex(2) +1 >Emitted(19, 2) Source(19, 2) + SourceIndex(2) --- >>>declare namespace normalN { 1-> @@ -259,10 +290,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > normalN 4 > -1->Emitted(19, 1) Source(20, 1) + SourceIndex(2) -2 >Emitted(19, 19) Source(20, 11) + SourceIndex(2) -3 >Emitted(19, 26) Source(20, 18) + SourceIndex(2) -4 >Emitted(19, 27) Source(20, 19) + SourceIndex(2) +1->Emitted(20, 1) Source(20, 1) + SourceIndex(2) +2 >Emitted(20, 19) Source(20, 11) + SourceIndex(2) +3 >Emitted(20, 26) Source(20, 18) + SourceIndex(2) +4 >Emitted(20, 27) Source(20, 19) + SourceIndex(2) --- >>> class C { 1 >^^^^ @@ -272,15 +303,15 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export class 3 > C -1 >Emitted(20, 5) Source(21, 19) + SourceIndex(2) -2 >Emitted(20, 11) Source(21, 32) + SourceIndex(2) -3 >Emitted(20, 12) Source(21, 33) + SourceIndex(2) +1 >Emitted(21, 5) Source(21, 19) + SourceIndex(2) +2 >Emitted(21, 11) Source(21, 32) + SourceIndex(2) +3 >Emitted(21, 12) Source(21, 33) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(21, 6) Source(21, 37) + SourceIndex(2) +1 >Emitted(22, 6) Source(21, 37) + SourceIndex(2) --- >>> function foo(): void; 1->^^^^ @@ -293,10 +324,10 @@ sourceFile:../second/second_part1.ts 2 > export function 3 > foo 4 > () {} -1->Emitted(22, 5) Source(22, 19) + SourceIndex(2) -2 >Emitted(22, 14) Source(22, 35) + SourceIndex(2) -3 >Emitted(22, 17) Source(22, 38) + SourceIndex(2) -4 >Emitted(22, 26) Source(22, 43) + SourceIndex(2) +1->Emitted(23, 5) Source(22, 19) + SourceIndex(2) +2 >Emitted(23, 14) Source(22, 35) + SourceIndex(2) +3 >Emitted(23, 17) Source(22, 38) + SourceIndex(2) +4 >Emitted(23, 26) Source(22, 43) + SourceIndex(2) --- >>> namespace someNamespace { 1->^^^^ @@ -308,10 +339,10 @@ sourceFile:../second/second_part1.ts 2 > export namespace 3 > someNamespace 4 > -1->Emitted(23, 5) Source(23, 19) + SourceIndex(2) -2 >Emitted(23, 15) Source(23, 36) + SourceIndex(2) -3 >Emitted(23, 28) Source(23, 49) + SourceIndex(2) -4 >Emitted(23, 29) Source(23, 50) + SourceIndex(2) +1->Emitted(24, 5) Source(23, 19) + SourceIndex(2) +2 >Emitted(24, 15) Source(23, 36) + SourceIndex(2) +3 >Emitted(24, 28) Source(23, 49) + SourceIndex(2) +4 >Emitted(24, 29) Source(23, 50) + SourceIndex(2) --- >>> class C { 1 >^^^^^^^^ @@ -320,20 +351,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(24, 9) Source(23, 52) + SourceIndex(2) -2 >Emitted(24, 15) Source(23, 65) + SourceIndex(2) -3 >Emitted(24, 16) Source(23, 66) + SourceIndex(2) +1 >Emitted(25, 9) Source(23, 52) + SourceIndex(2) +2 >Emitted(25, 15) Source(23, 65) + SourceIndex(2) +3 >Emitted(25, 16) Source(23, 66) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(25, 10) Source(23, 69) + SourceIndex(2) +1 >Emitted(26, 10) Source(23, 69) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(26, 6) Source(23, 71) + SourceIndex(2) +1 >Emitted(27, 6) Source(23, 71) + SourceIndex(2) --- >>> namespace someOther.something { 1->^^^^ @@ -349,12 +380,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(27, 5) Source(24, 19) + SourceIndex(2) -2 >Emitted(27, 15) Source(24, 36) + SourceIndex(2) -3 >Emitted(27, 24) Source(24, 45) + SourceIndex(2) -4 >Emitted(27, 25) Source(24, 46) + SourceIndex(2) -5 >Emitted(27, 34) Source(24, 55) + SourceIndex(2) -6 >Emitted(27, 35) Source(24, 56) + SourceIndex(2) +1->Emitted(28, 5) Source(24, 19) + SourceIndex(2) +2 >Emitted(28, 15) Source(24, 36) + SourceIndex(2) +3 >Emitted(28, 24) Source(24, 45) + SourceIndex(2) +4 >Emitted(28, 25) Source(24, 46) + SourceIndex(2) +5 >Emitted(28, 34) Source(24, 55) + SourceIndex(2) +6 >Emitted(28, 35) Source(24, 56) + SourceIndex(2) --- >>> class someClass { 1 >^^^^^^^^ @@ -363,20 +394,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(28, 9) Source(24, 58) + SourceIndex(2) -2 >Emitted(28, 15) Source(24, 71) + SourceIndex(2) -3 >Emitted(28, 24) Source(24, 80) + SourceIndex(2) +1 >Emitted(29, 9) Source(24, 58) + SourceIndex(2) +2 >Emitted(29, 15) Source(24, 71) + SourceIndex(2) +3 >Emitted(29, 24) Source(24, 80) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(29, 10) Source(24, 83) + SourceIndex(2) +1 >Emitted(30, 10) Source(24, 83) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(30, 6) Source(24, 85) + SourceIndex(2) +1 >Emitted(31, 6) Source(24, 85) + SourceIndex(2) --- >>> export import someImport = someNamespace.C; 1->^^^^ @@ -398,15 +429,15 @@ sourceFile:../second/second_part1.ts 7 > . 8 > C 9 > ; -1->Emitted(31, 5) Source(25, 19) + SourceIndex(2) -2 >Emitted(31, 11) Source(25, 25) + SourceIndex(2) -3 >Emitted(31, 19) Source(25, 33) + SourceIndex(2) -4 >Emitted(31, 29) Source(25, 43) + SourceIndex(2) -5 >Emitted(31, 32) Source(25, 46) + SourceIndex(2) -6 >Emitted(31, 45) Source(25, 59) + SourceIndex(2) -7 >Emitted(31, 46) Source(25, 60) + SourceIndex(2) -8 >Emitted(31, 47) Source(25, 61) + SourceIndex(2) -9 >Emitted(31, 48) Source(25, 62) + SourceIndex(2) +1->Emitted(32, 5) Source(25, 19) + SourceIndex(2) +2 >Emitted(32, 11) Source(25, 25) + SourceIndex(2) +3 >Emitted(32, 19) Source(25, 33) + SourceIndex(2) +4 >Emitted(32, 29) Source(25, 43) + SourceIndex(2) +5 >Emitted(32, 32) Source(25, 46) + SourceIndex(2) +6 >Emitted(32, 45) Source(25, 59) + SourceIndex(2) +7 >Emitted(32, 46) Source(25, 60) + SourceIndex(2) +8 >Emitted(32, 47) Source(25, 61) + SourceIndex(2) +9 >Emitted(32, 48) Source(25, 62) + SourceIndex(2) --- >>> type internalType = internalC; 1 >^^^^ @@ -422,12 +453,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(32, 5) Source(26, 19) + SourceIndex(2) -2 >Emitted(32, 10) Source(26, 31) + SourceIndex(2) -3 >Emitted(32, 22) Source(26, 43) + SourceIndex(2) -4 >Emitted(32, 25) Source(26, 46) + SourceIndex(2) -5 >Emitted(32, 34) Source(26, 55) + SourceIndex(2) -6 >Emitted(32, 35) Source(26, 56) + SourceIndex(2) +1 >Emitted(33, 5) Source(26, 19) + SourceIndex(2) +2 >Emitted(33, 10) Source(26, 31) + SourceIndex(2) +3 >Emitted(33, 22) Source(26, 43) + SourceIndex(2) +4 >Emitted(33, 25) Source(26, 46) + SourceIndex(2) +5 >Emitted(33, 34) Source(26, 55) + SourceIndex(2) +6 >Emitted(33, 35) Source(26, 56) + SourceIndex(2) --- >>> const internalConst = 10; 1 >^^^^ @@ -441,11 +472,11 @@ sourceFile:../second/second_part1.ts 3 > internalConst 4 > = 10 5 > ; -1 >Emitted(33, 5) Source(27, 26) + SourceIndex(2) -2 >Emitted(33, 11) Source(27, 32) + SourceIndex(2) -3 >Emitted(33, 24) Source(27, 45) + SourceIndex(2) -4 >Emitted(33, 29) Source(27, 50) + SourceIndex(2) -5 >Emitted(33, 30) Source(27, 51) + SourceIndex(2) +1 >Emitted(34, 5) Source(27, 26) + SourceIndex(2) +2 >Emitted(34, 11) Source(27, 32) + SourceIndex(2) +3 >Emitted(34, 24) Source(27, 45) + SourceIndex(2) +4 >Emitted(34, 29) Source(27, 50) + SourceIndex(2) +5 >Emitted(34, 30) Source(27, 51) + SourceIndex(2) --- >>> enum internalEnum { 1 >^^^^ @@ -455,9 +486,9 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export enum 3 > internalEnum -1 >Emitted(34, 5) Source(28, 19) + SourceIndex(2) -2 >Emitted(34, 10) Source(28, 31) + SourceIndex(2) -3 >Emitted(34, 22) Source(28, 43) + SourceIndex(2) +1 >Emitted(35, 5) Source(28, 19) + SourceIndex(2) +2 >Emitted(35, 10) Source(28, 31) + SourceIndex(2) +3 >Emitted(35, 22) Source(28, 43) + SourceIndex(2) --- >>> a = 0, 1 >^^^^^^^^ @@ -467,9 +498,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(35, 9) Source(28, 46) + SourceIndex(2) -2 >Emitted(35, 10) Source(28, 47) + SourceIndex(2) -3 >Emitted(35, 14) Source(28, 47) + SourceIndex(2) +1 >Emitted(36, 9) Source(28, 46) + SourceIndex(2) +2 >Emitted(36, 10) Source(28, 47) + SourceIndex(2) +3 >Emitted(36, 14) Source(28, 47) + SourceIndex(2) --- >>> b = 1, 1->^^^^^^^^ @@ -479,9 +510,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(36, 9) Source(28, 49) + SourceIndex(2) -2 >Emitted(36, 10) Source(28, 50) + SourceIndex(2) -3 >Emitted(36, 14) Source(28, 50) + SourceIndex(2) +1->Emitted(37, 9) Source(28, 49) + SourceIndex(2) +2 >Emitted(37, 10) Source(28, 50) + SourceIndex(2) +3 >Emitted(37, 14) Source(28, 50) + SourceIndex(2) --- >>> c = 2 1->^^^^^^^^ @@ -490,21 +521,21 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(37, 9) Source(28, 52) + SourceIndex(2) -2 >Emitted(37, 10) Source(28, 53) + SourceIndex(2) -3 >Emitted(37, 14) Source(28, 53) + SourceIndex(2) +1->Emitted(38, 9) Source(28, 52) + SourceIndex(2) +2 >Emitted(38, 10) Source(28, 53) + SourceIndex(2) +3 >Emitted(38, 14) Source(28, 53) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(38, 6) Source(28, 55) + SourceIndex(2) +1 >Emitted(39, 6) Source(28, 55) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(39, 2) Source(29, 2) + SourceIndex(2) +1 >Emitted(40, 2) Source(29, 2) + SourceIndex(2) --- >>>declare class internalC { 1-> @@ -514,15 +545,15 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >class 3 > internalC -1->Emitted(40, 1) Source(30, 15) + SourceIndex(2) -2 >Emitted(40, 15) Source(30, 21) + SourceIndex(2) -3 >Emitted(40, 24) Source(30, 30) + SourceIndex(2) +1->Emitted(41, 1) Source(30, 15) + SourceIndex(2) +2 >Emitted(41, 15) Source(30, 21) + SourceIndex(2) +3 >Emitted(41, 24) Source(30, 30) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(41, 2) Source(30, 33) + SourceIndex(2) +1 >Emitted(42, 2) Source(30, 33) + SourceIndex(2) --- >>>declare function internalfoo(): void; 1-> @@ -535,10 +566,10 @@ sourceFile:../second/second_part1.ts 2 >function 3 > internalfoo 4 > () {} -1->Emitted(42, 1) Source(31, 15) + SourceIndex(2) -2 >Emitted(42, 18) Source(31, 24) + SourceIndex(2) -3 >Emitted(42, 29) Source(31, 35) + SourceIndex(2) -4 >Emitted(42, 38) Source(31, 40) + SourceIndex(2) +1->Emitted(43, 1) Source(31, 15) + SourceIndex(2) +2 >Emitted(43, 18) Source(31, 24) + SourceIndex(2) +3 >Emitted(43, 29) Source(31, 35) + SourceIndex(2) +4 >Emitted(43, 38) Source(31, 40) + SourceIndex(2) --- >>>declare namespace internalNamespace { 1-> @@ -550,10 +581,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > internalNamespace 4 > -1->Emitted(43, 1) Source(32, 15) + SourceIndex(2) -2 >Emitted(43, 19) Source(32, 25) + SourceIndex(2) -3 >Emitted(43, 36) Source(32, 42) + SourceIndex(2) -4 >Emitted(43, 37) Source(32, 43) + SourceIndex(2) +1->Emitted(44, 1) Source(32, 15) + SourceIndex(2) +2 >Emitted(44, 19) Source(32, 25) + SourceIndex(2) +3 >Emitted(44, 36) Source(32, 42) + SourceIndex(2) +4 >Emitted(44, 37) Source(32, 43) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -562,20 +593,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(44, 5) Source(32, 45) + SourceIndex(2) -2 >Emitted(44, 11) Source(32, 58) + SourceIndex(2) -3 >Emitted(44, 20) Source(32, 67) + SourceIndex(2) +1 >Emitted(45, 5) Source(32, 45) + SourceIndex(2) +2 >Emitted(45, 11) Source(32, 58) + SourceIndex(2) +3 >Emitted(45, 20) Source(32, 67) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(45, 6) Source(32, 70) + SourceIndex(2) +1 >Emitted(46, 6) Source(32, 70) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(46, 2) Source(32, 72) + SourceIndex(2) +1 >Emitted(47, 2) Source(32, 72) + SourceIndex(2) --- >>>declare namespace internalOther.something { 1-> @@ -591,12 +622,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(47, 1) Source(33, 15) + SourceIndex(2) -2 >Emitted(47, 19) Source(33, 25) + SourceIndex(2) -3 >Emitted(47, 32) Source(33, 38) + SourceIndex(2) -4 >Emitted(47, 33) Source(33, 39) + SourceIndex(2) -5 >Emitted(47, 42) Source(33, 48) + SourceIndex(2) -6 >Emitted(47, 43) Source(33, 49) + SourceIndex(2) +1->Emitted(48, 1) Source(33, 15) + SourceIndex(2) +2 >Emitted(48, 19) Source(33, 25) + SourceIndex(2) +3 >Emitted(48, 32) Source(33, 38) + SourceIndex(2) +4 >Emitted(48, 33) Source(33, 39) + SourceIndex(2) +5 >Emitted(48, 42) Source(33, 48) + SourceIndex(2) +6 >Emitted(48, 43) Source(33, 49) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -605,20 +636,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(48, 5) Source(33, 51) + SourceIndex(2) -2 >Emitted(48, 11) Source(33, 64) + SourceIndex(2) -3 >Emitted(48, 20) Source(33, 73) + SourceIndex(2) +1 >Emitted(49, 5) Source(33, 51) + SourceIndex(2) +2 >Emitted(49, 11) Source(33, 64) + SourceIndex(2) +3 >Emitted(49, 20) Source(33, 73) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(49, 6) Source(33, 76) + SourceIndex(2) +1 >Emitted(50, 6) Source(33, 76) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(50, 2) Source(33, 78) + SourceIndex(2) +1 >Emitted(51, 2) Source(33, 78) + SourceIndex(2) --- >>>import internalImport = internalNamespace.someClass; 1-> @@ -638,14 +669,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > someClass 8 > ; -1->Emitted(51, 1) Source(34, 15) + SourceIndex(2) -2 >Emitted(51, 8) Source(34, 22) + SourceIndex(2) -3 >Emitted(51, 22) Source(34, 36) + SourceIndex(2) -4 >Emitted(51, 25) Source(34, 39) + SourceIndex(2) -5 >Emitted(51, 42) Source(34, 56) + SourceIndex(2) -6 >Emitted(51, 43) Source(34, 57) + SourceIndex(2) -7 >Emitted(51, 52) Source(34, 66) + SourceIndex(2) -8 >Emitted(51, 53) Source(34, 67) + SourceIndex(2) +1->Emitted(52, 1) Source(34, 15) + SourceIndex(2) +2 >Emitted(52, 8) Source(34, 22) + SourceIndex(2) +3 >Emitted(52, 22) Source(34, 36) + SourceIndex(2) +4 >Emitted(52, 25) Source(34, 39) + SourceIndex(2) +5 >Emitted(52, 42) Source(34, 56) + SourceIndex(2) +6 >Emitted(52, 43) Source(34, 57) + SourceIndex(2) +7 >Emitted(52, 52) Source(34, 66) + SourceIndex(2) +8 >Emitted(52, 53) Source(34, 67) + SourceIndex(2) --- >>>declare type internalType = internalC; 1 > @@ -661,12 +692,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(52, 1) Source(35, 15) + SourceIndex(2) -2 >Emitted(52, 14) Source(35, 20) + SourceIndex(2) -3 >Emitted(52, 26) Source(35, 32) + SourceIndex(2) -4 >Emitted(52, 29) Source(35, 35) + SourceIndex(2) -5 >Emitted(52, 38) Source(35, 44) + SourceIndex(2) -6 >Emitted(52, 39) Source(35, 45) + SourceIndex(2) +1 >Emitted(53, 1) Source(35, 15) + SourceIndex(2) +2 >Emitted(53, 14) Source(35, 20) + SourceIndex(2) +3 >Emitted(53, 26) Source(35, 32) + SourceIndex(2) +4 >Emitted(53, 29) Source(35, 35) + SourceIndex(2) +5 >Emitted(53, 38) Source(35, 44) + SourceIndex(2) +6 >Emitted(53, 39) Source(35, 45) + SourceIndex(2) --- >>>declare const internalConst = 10; 1 > @@ -682,12 +713,12 @@ sourceFile:../second/second_part1.ts 4 > internalConst 5 > = 10 6 > ; -1 >Emitted(53, 1) Source(36, 15) + SourceIndex(2) -2 >Emitted(53, 9) Source(36, 15) + SourceIndex(2) -3 >Emitted(53, 15) Source(36, 21) + SourceIndex(2) -4 >Emitted(53, 28) Source(36, 34) + SourceIndex(2) -5 >Emitted(53, 33) Source(36, 39) + SourceIndex(2) -6 >Emitted(53, 34) Source(36, 40) + SourceIndex(2) +1 >Emitted(54, 1) Source(36, 15) + SourceIndex(2) +2 >Emitted(54, 9) Source(36, 15) + SourceIndex(2) +3 >Emitted(54, 15) Source(36, 21) + SourceIndex(2) +4 >Emitted(54, 28) Source(36, 34) + SourceIndex(2) +5 >Emitted(54, 33) Source(36, 39) + SourceIndex(2) +6 >Emitted(54, 34) Source(36, 40) + SourceIndex(2) --- >>>declare enum internalEnum { 1 > @@ -697,9 +728,9 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >enum 3 > internalEnum -1 >Emitted(54, 1) Source(37, 15) + SourceIndex(2) -2 >Emitted(54, 14) Source(37, 20) + SourceIndex(2) -3 >Emitted(54, 26) Source(37, 32) + SourceIndex(2) +1 >Emitted(55, 1) Source(37, 15) + SourceIndex(2) +2 >Emitted(55, 14) Source(37, 20) + SourceIndex(2) +3 >Emitted(55, 26) Source(37, 32) + SourceIndex(2) --- >>> a = 0, 1 >^^^^ @@ -709,9 +740,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(55, 5) Source(37, 35) + SourceIndex(2) -2 >Emitted(55, 6) Source(37, 36) + SourceIndex(2) -3 >Emitted(55, 10) Source(37, 36) + SourceIndex(2) +1 >Emitted(56, 5) Source(37, 35) + SourceIndex(2) +2 >Emitted(56, 6) Source(37, 36) + SourceIndex(2) +3 >Emitted(56, 10) Source(37, 36) + SourceIndex(2) --- >>> b = 1, 1->^^^^ @@ -721,9 +752,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(56, 5) Source(37, 38) + SourceIndex(2) -2 >Emitted(56, 6) Source(37, 39) + SourceIndex(2) -3 >Emitted(56, 10) Source(37, 39) + SourceIndex(2) +1->Emitted(57, 5) Source(37, 38) + SourceIndex(2) +2 >Emitted(57, 6) Source(37, 39) + SourceIndex(2) +3 >Emitted(57, 10) Source(37, 39) + SourceIndex(2) --- >>> c = 2 1->^^^^ @@ -732,15 +763,15 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(57, 5) Source(37, 41) + SourceIndex(2) -2 >Emitted(57, 6) Source(37, 42) + SourceIndex(2) -3 >Emitted(57, 10) Source(37, 42) + SourceIndex(2) +1->Emitted(58, 5) Source(37, 41) + SourceIndex(2) +2 >Emitted(58, 6) Source(37, 42) + SourceIndex(2) +3 >Emitted(58, 10) Source(37, 42) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(58, 2) Source(37, 44) + SourceIndex(2) +1 >Emitted(59, 2) Source(37, 44) + SourceIndex(2) --- ------------------------------------------------------------------- emittedFile:/src/2/second-output.d.ts @@ -754,9 +785,9 @@ sourceFile:../second/second_part2.ts 1-> 2 >class 3 > C -1->Emitted(59, 1) Source(1, 1) + SourceIndex(3) -2 >Emitted(59, 15) Source(1, 7) + SourceIndex(3) -3 >Emitted(59, 16) Source(1, 8) + SourceIndex(3) +1->Emitted(60, 1) Source(1, 1) + SourceIndex(3) +2 >Emitted(60, 15) Source(1, 7) + SourceIndex(3) +3 >Emitted(60, 16) Source(1, 8) + SourceIndex(3) --- >>> doSomething(): void; 1->^^^^ @@ -764,8 +795,8 @@ sourceFile:../second/second_part2.ts 1-> { > 2 > doSomething -1->Emitted(60, 5) Source(2, 5) + SourceIndex(3) -2 >Emitted(60, 16) Source(2, 16) + SourceIndex(3) +1->Emitted(61, 5) Source(2, 5) + SourceIndex(3) +2 >Emitted(61, 16) Source(2, 16) + SourceIndex(3) --- >>>} 1 >^ @@ -774,7 +805,7 @@ sourceFile:../second/second_part2.ts > console.log("something got done"); > } >} -1 >Emitted(61, 2) Source(5, 2) + SourceIndex(3) +1 >Emitted(62, 2) Source(5, 2) + SourceIndex(3) --- >>>//# sourceMappingURL=second-output.d.ts.map @@ -830,32 +861,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 234, - "end": 308, + "end": 339, "kind": "internal" }, { - "pos": 310, - "end": 342, + "pos": 341, + "end": 373, "kind": "text" }, { - "pos": 342, - "end": 734, + "pos": 373, + "end": 765, "kind": "internal" }, { - "pos": 736, - "end": 739, + "pos": 767, + "end": 770, "kind": "text" }, { - "pos": 739, - "end": 1152, + "pos": 770, + "end": 1183, "kind": "internal" }, { - "pos": 1154, - "end": 1202, + "pos": 1185, + "end": 1233, "kind": "text" } ] @@ -1008,18 +1039,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (234-308) +internal: (234-339) constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (310-342) +text: (341-373) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (342-734) +internal: (373-765) class C { } function foo(): void; @@ -1040,11 +1072,11 @@ internal: (342-734) c = 2 } ---------------------------------------------------------------------- -text: (736-739) +text: (767-770) } ---------------------------------------------------------------------- -internal: (739-1152) +internal: (770-1183) declare class internalC { } declare function internalfoo(): void; @@ -1065,7 +1097,7 @@ declare enum internalEnum { c = 2 } ---------------------------------------------------------------------- -text: (1154-1202) +text: (1185-1233) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/incremental-headers-change-without-dts-changes/stripInternal-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js b/tests/baselines/reference/tsbuild/outfile-concat/incremental-headers-change-without-dts-changes/stripInternal-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js index dcaa317a0d208..2fb042f17fa62 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/incremental-headers-change-without-dts-changes/stripInternal-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/incremental-headers-change-without-dts-changes/stripInternal-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js @@ -1,5 +1,5 @@ //// [/src/2/second-output.d.ts.map] -{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,UAAU,QAAQ;IACd,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;kBACF,CAAC,EACM,MAAM;CAClC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} +{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,UAAU,QAAQ;IACd,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACN,IAAI,CAAC,IACM,MAAM,CADK;IACtB,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;CACvC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} //// [/src/2/second-output.d.ts.map.baseline.txt] =================================================================== @@ -219,35 +219,66 @@ sourceFile:../second/second_part1.ts >>> method(): void; 1->^^^^ 2 > ^^^^^^ -3 > ^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^-> 1-> > /*@internal*/ 2 > method 1->Emitted(16, 5) Source(16, 19) + SourceIndex(2) 2 >Emitted(16, 11) Source(16, 25) + SourceIndex(2) --- ->>> /*@internal*/ c: number; -1->^^^^^^^^^^^^^^^^^^ -2 > ^ -3 > ^^ -4 > ^^^^^^ +>>> get c(): number; +1->^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^^ +5 > ^^^^^^ +6 > ^ +7 > ^^^^-> 1->() { } - > /*@internal*/ get -2 > c -3 > () { return 10; } - > /*@internal*/ set c(val: -4 > number -1->Emitted(17, 19) Source(17, 23) + SourceIndex(2) -2 >Emitted(17, 20) Source(17, 24) + SourceIndex(2) -3 >Emitted(17, 22) Source(18, 30) + SourceIndex(2) -4 >Emitted(17, 28) Source(18, 36) + SourceIndex(2) + > /*@internal*/ +2 > get +3 > c +4 > () { return 10; } + > /*@internal*/ set c(val: +5 > number +6 > +1->Emitted(17, 5) Source(17, 19) + SourceIndex(2) +2 >Emitted(17, 9) Source(17, 23) + SourceIndex(2) +3 >Emitted(17, 10) Source(17, 24) + SourceIndex(2) +4 >Emitted(17, 14) Source(18, 30) + SourceIndex(2) +5 >Emitted(17, 20) Source(18, 36) + SourceIndex(2) +6 >Emitted(17, 21) Source(17, 41) + SourceIndex(2) +--- +>>> set c(val: number); +1->^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^ +6 > ^^^^^^ +7 > ^^ +1-> + > /*@internal*/ +2 > set +3 > c +4 > ( +5 > val: +6 > number +7 > ) { } +1->Emitted(18, 5) Source(18, 19) + SourceIndex(2) +2 >Emitted(18, 9) Source(18, 23) + SourceIndex(2) +3 >Emitted(18, 10) Source(18, 24) + SourceIndex(2) +4 >Emitted(18, 11) Source(18, 25) + SourceIndex(2) +5 >Emitted(18, 16) Source(18, 30) + SourceIndex(2) +6 >Emitted(18, 22) Source(18, 36) + SourceIndex(2) +7 >Emitted(18, 24) Source(18, 41) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(18, 2) Source(19, 2) + SourceIndex(2) +1 >Emitted(19, 2) Source(19, 2) + SourceIndex(2) --- >>>declare namespace normalN { 1-> @@ -259,10 +290,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > normalN 4 > -1->Emitted(19, 1) Source(20, 1) + SourceIndex(2) -2 >Emitted(19, 19) Source(20, 11) + SourceIndex(2) -3 >Emitted(19, 26) Source(20, 18) + SourceIndex(2) -4 >Emitted(19, 27) Source(20, 19) + SourceIndex(2) +1->Emitted(20, 1) Source(20, 1) + SourceIndex(2) +2 >Emitted(20, 19) Source(20, 11) + SourceIndex(2) +3 >Emitted(20, 26) Source(20, 18) + SourceIndex(2) +4 >Emitted(20, 27) Source(20, 19) + SourceIndex(2) --- >>> class C { 1 >^^^^ @@ -272,15 +303,15 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export class 3 > C -1 >Emitted(20, 5) Source(21, 19) + SourceIndex(2) -2 >Emitted(20, 11) Source(21, 32) + SourceIndex(2) -3 >Emitted(20, 12) Source(21, 33) + SourceIndex(2) +1 >Emitted(21, 5) Source(21, 19) + SourceIndex(2) +2 >Emitted(21, 11) Source(21, 32) + SourceIndex(2) +3 >Emitted(21, 12) Source(21, 33) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(21, 6) Source(21, 37) + SourceIndex(2) +1 >Emitted(22, 6) Source(21, 37) + SourceIndex(2) --- >>> function foo(): void; 1->^^^^ @@ -293,10 +324,10 @@ sourceFile:../second/second_part1.ts 2 > export function 3 > foo 4 > () {} -1->Emitted(22, 5) Source(22, 19) + SourceIndex(2) -2 >Emitted(22, 14) Source(22, 35) + SourceIndex(2) -3 >Emitted(22, 17) Source(22, 38) + SourceIndex(2) -4 >Emitted(22, 26) Source(22, 43) + SourceIndex(2) +1->Emitted(23, 5) Source(22, 19) + SourceIndex(2) +2 >Emitted(23, 14) Source(22, 35) + SourceIndex(2) +3 >Emitted(23, 17) Source(22, 38) + SourceIndex(2) +4 >Emitted(23, 26) Source(22, 43) + SourceIndex(2) --- >>> namespace someNamespace { 1->^^^^ @@ -308,10 +339,10 @@ sourceFile:../second/second_part1.ts 2 > export namespace 3 > someNamespace 4 > -1->Emitted(23, 5) Source(23, 19) + SourceIndex(2) -2 >Emitted(23, 15) Source(23, 36) + SourceIndex(2) -3 >Emitted(23, 28) Source(23, 49) + SourceIndex(2) -4 >Emitted(23, 29) Source(23, 50) + SourceIndex(2) +1->Emitted(24, 5) Source(23, 19) + SourceIndex(2) +2 >Emitted(24, 15) Source(23, 36) + SourceIndex(2) +3 >Emitted(24, 28) Source(23, 49) + SourceIndex(2) +4 >Emitted(24, 29) Source(23, 50) + SourceIndex(2) --- >>> class C { 1 >^^^^^^^^ @@ -320,20 +351,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(24, 9) Source(23, 52) + SourceIndex(2) -2 >Emitted(24, 15) Source(23, 65) + SourceIndex(2) -3 >Emitted(24, 16) Source(23, 66) + SourceIndex(2) +1 >Emitted(25, 9) Source(23, 52) + SourceIndex(2) +2 >Emitted(25, 15) Source(23, 65) + SourceIndex(2) +3 >Emitted(25, 16) Source(23, 66) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(25, 10) Source(23, 69) + SourceIndex(2) +1 >Emitted(26, 10) Source(23, 69) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(26, 6) Source(23, 71) + SourceIndex(2) +1 >Emitted(27, 6) Source(23, 71) + SourceIndex(2) --- >>> namespace someOther.something { 1->^^^^ @@ -349,12 +380,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(27, 5) Source(24, 19) + SourceIndex(2) -2 >Emitted(27, 15) Source(24, 36) + SourceIndex(2) -3 >Emitted(27, 24) Source(24, 45) + SourceIndex(2) -4 >Emitted(27, 25) Source(24, 46) + SourceIndex(2) -5 >Emitted(27, 34) Source(24, 55) + SourceIndex(2) -6 >Emitted(27, 35) Source(24, 56) + SourceIndex(2) +1->Emitted(28, 5) Source(24, 19) + SourceIndex(2) +2 >Emitted(28, 15) Source(24, 36) + SourceIndex(2) +3 >Emitted(28, 24) Source(24, 45) + SourceIndex(2) +4 >Emitted(28, 25) Source(24, 46) + SourceIndex(2) +5 >Emitted(28, 34) Source(24, 55) + SourceIndex(2) +6 >Emitted(28, 35) Source(24, 56) + SourceIndex(2) --- >>> class someClass { 1 >^^^^^^^^ @@ -363,20 +394,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(28, 9) Source(24, 58) + SourceIndex(2) -2 >Emitted(28, 15) Source(24, 71) + SourceIndex(2) -3 >Emitted(28, 24) Source(24, 80) + SourceIndex(2) +1 >Emitted(29, 9) Source(24, 58) + SourceIndex(2) +2 >Emitted(29, 15) Source(24, 71) + SourceIndex(2) +3 >Emitted(29, 24) Source(24, 80) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(29, 10) Source(24, 83) + SourceIndex(2) +1 >Emitted(30, 10) Source(24, 83) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(30, 6) Source(24, 85) + SourceIndex(2) +1 >Emitted(31, 6) Source(24, 85) + SourceIndex(2) --- >>> export import someImport = someNamespace.C; 1->^^^^ @@ -398,15 +429,15 @@ sourceFile:../second/second_part1.ts 7 > . 8 > C 9 > ; -1->Emitted(31, 5) Source(25, 19) + SourceIndex(2) -2 >Emitted(31, 11) Source(25, 25) + SourceIndex(2) -3 >Emitted(31, 19) Source(25, 33) + SourceIndex(2) -4 >Emitted(31, 29) Source(25, 43) + SourceIndex(2) -5 >Emitted(31, 32) Source(25, 46) + SourceIndex(2) -6 >Emitted(31, 45) Source(25, 59) + SourceIndex(2) -7 >Emitted(31, 46) Source(25, 60) + SourceIndex(2) -8 >Emitted(31, 47) Source(25, 61) + SourceIndex(2) -9 >Emitted(31, 48) Source(25, 62) + SourceIndex(2) +1->Emitted(32, 5) Source(25, 19) + SourceIndex(2) +2 >Emitted(32, 11) Source(25, 25) + SourceIndex(2) +3 >Emitted(32, 19) Source(25, 33) + SourceIndex(2) +4 >Emitted(32, 29) Source(25, 43) + SourceIndex(2) +5 >Emitted(32, 32) Source(25, 46) + SourceIndex(2) +6 >Emitted(32, 45) Source(25, 59) + SourceIndex(2) +7 >Emitted(32, 46) Source(25, 60) + SourceIndex(2) +8 >Emitted(32, 47) Source(25, 61) + SourceIndex(2) +9 >Emitted(32, 48) Source(25, 62) + SourceIndex(2) --- >>> type internalType = internalC; 1 >^^^^ @@ -422,12 +453,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(32, 5) Source(26, 19) + SourceIndex(2) -2 >Emitted(32, 10) Source(26, 31) + SourceIndex(2) -3 >Emitted(32, 22) Source(26, 43) + SourceIndex(2) -4 >Emitted(32, 25) Source(26, 46) + SourceIndex(2) -5 >Emitted(32, 34) Source(26, 55) + SourceIndex(2) -6 >Emitted(32, 35) Source(26, 56) + SourceIndex(2) +1 >Emitted(33, 5) Source(26, 19) + SourceIndex(2) +2 >Emitted(33, 10) Source(26, 31) + SourceIndex(2) +3 >Emitted(33, 22) Source(26, 43) + SourceIndex(2) +4 >Emitted(33, 25) Source(26, 46) + SourceIndex(2) +5 >Emitted(33, 34) Source(26, 55) + SourceIndex(2) +6 >Emitted(33, 35) Source(26, 56) + SourceIndex(2) --- >>> const internalConst = 10; 1 >^^^^ @@ -441,11 +472,11 @@ sourceFile:../second/second_part1.ts 3 > internalConst 4 > = 10 5 > ; -1 >Emitted(33, 5) Source(27, 26) + SourceIndex(2) -2 >Emitted(33, 11) Source(27, 32) + SourceIndex(2) -3 >Emitted(33, 24) Source(27, 45) + SourceIndex(2) -4 >Emitted(33, 29) Source(27, 50) + SourceIndex(2) -5 >Emitted(33, 30) Source(27, 51) + SourceIndex(2) +1 >Emitted(34, 5) Source(27, 26) + SourceIndex(2) +2 >Emitted(34, 11) Source(27, 32) + SourceIndex(2) +3 >Emitted(34, 24) Source(27, 45) + SourceIndex(2) +4 >Emitted(34, 29) Source(27, 50) + SourceIndex(2) +5 >Emitted(34, 30) Source(27, 51) + SourceIndex(2) --- >>> enum internalEnum { 1 >^^^^ @@ -455,9 +486,9 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export enum 3 > internalEnum -1 >Emitted(34, 5) Source(28, 19) + SourceIndex(2) -2 >Emitted(34, 10) Source(28, 31) + SourceIndex(2) -3 >Emitted(34, 22) Source(28, 43) + SourceIndex(2) +1 >Emitted(35, 5) Source(28, 19) + SourceIndex(2) +2 >Emitted(35, 10) Source(28, 31) + SourceIndex(2) +3 >Emitted(35, 22) Source(28, 43) + SourceIndex(2) --- >>> a = 0, 1 >^^^^^^^^ @@ -467,9 +498,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(35, 9) Source(28, 46) + SourceIndex(2) -2 >Emitted(35, 10) Source(28, 47) + SourceIndex(2) -3 >Emitted(35, 14) Source(28, 47) + SourceIndex(2) +1 >Emitted(36, 9) Source(28, 46) + SourceIndex(2) +2 >Emitted(36, 10) Source(28, 47) + SourceIndex(2) +3 >Emitted(36, 14) Source(28, 47) + SourceIndex(2) --- >>> b = 1, 1->^^^^^^^^ @@ -479,9 +510,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(36, 9) Source(28, 49) + SourceIndex(2) -2 >Emitted(36, 10) Source(28, 50) + SourceIndex(2) -3 >Emitted(36, 14) Source(28, 50) + SourceIndex(2) +1->Emitted(37, 9) Source(28, 49) + SourceIndex(2) +2 >Emitted(37, 10) Source(28, 50) + SourceIndex(2) +3 >Emitted(37, 14) Source(28, 50) + SourceIndex(2) --- >>> c = 2 1->^^^^^^^^ @@ -490,21 +521,21 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(37, 9) Source(28, 52) + SourceIndex(2) -2 >Emitted(37, 10) Source(28, 53) + SourceIndex(2) -3 >Emitted(37, 14) Source(28, 53) + SourceIndex(2) +1->Emitted(38, 9) Source(28, 52) + SourceIndex(2) +2 >Emitted(38, 10) Source(28, 53) + SourceIndex(2) +3 >Emitted(38, 14) Source(28, 53) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(38, 6) Source(28, 55) + SourceIndex(2) +1 >Emitted(39, 6) Source(28, 55) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(39, 2) Source(29, 2) + SourceIndex(2) +1 >Emitted(40, 2) Source(29, 2) + SourceIndex(2) --- >>>declare class internalC { 1-> @@ -514,15 +545,15 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >class 3 > internalC -1->Emitted(40, 1) Source(30, 15) + SourceIndex(2) -2 >Emitted(40, 15) Source(30, 21) + SourceIndex(2) -3 >Emitted(40, 24) Source(30, 30) + SourceIndex(2) +1->Emitted(41, 1) Source(30, 15) + SourceIndex(2) +2 >Emitted(41, 15) Source(30, 21) + SourceIndex(2) +3 >Emitted(41, 24) Source(30, 30) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(41, 2) Source(30, 33) + SourceIndex(2) +1 >Emitted(42, 2) Source(30, 33) + SourceIndex(2) --- >>>declare function internalfoo(): void; 1-> @@ -535,10 +566,10 @@ sourceFile:../second/second_part1.ts 2 >function 3 > internalfoo 4 > () {} -1->Emitted(42, 1) Source(31, 15) + SourceIndex(2) -2 >Emitted(42, 18) Source(31, 24) + SourceIndex(2) -3 >Emitted(42, 29) Source(31, 35) + SourceIndex(2) -4 >Emitted(42, 38) Source(31, 40) + SourceIndex(2) +1->Emitted(43, 1) Source(31, 15) + SourceIndex(2) +2 >Emitted(43, 18) Source(31, 24) + SourceIndex(2) +3 >Emitted(43, 29) Source(31, 35) + SourceIndex(2) +4 >Emitted(43, 38) Source(31, 40) + SourceIndex(2) --- >>>declare namespace internalNamespace { 1-> @@ -550,10 +581,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > internalNamespace 4 > -1->Emitted(43, 1) Source(32, 15) + SourceIndex(2) -2 >Emitted(43, 19) Source(32, 25) + SourceIndex(2) -3 >Emitted(43, 36) Source(32, 42) + SourceIndex(2) -4 >Emitted(43, 37) Source(32, 43) + SourceIndex(2) +1->Emitted(44, 1) Source(32, 15) + SourceIndex(2) +2 >Emitted(44, 19) Source(32, 25) + SourceIndex(2) +3 >Emitted(44, 36) Source(32, 42) + SourceIndex(2) +4 >Emitted(44, 37) Source(32, 43) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -562,20 +593,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(44, 5) Source(32, 45) + SourceIndex(2) -2 >Emitted(44, 11) Source(32, 58) + SourceIndex(2) -3 >Emitted(44, 20) Source(32, 67) + SourceIndex(2) +1 >Emitted(45, 5) Source(32, 45) + SourceIndex(2) +2 >Emitted(45, 11) Source(32, 58) + SourceIndex(2) +3 >Emitted(45, 20) Source(32, 67) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(45, 6) Source(32, 70) + SourceIndex(2) +1 >Emitted(46, 6) Source(32, 70) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(46, 2) Source(32, 72) + SourceIndex(2) +1 >Emitted(47, 2) Source(32, 72) + SourceIndex(2) --- >>>declare namespace internalOther.something { 1-> @@ -591,12 +622,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(47, 1) Source(33, 15) + SourceIndex(2) -2 >Emitted(47, 19) Source(33, 25) + SourceIndex(2) -3 >Emitted(47, 32) Source(33, 38) + SourceIndex(2) -4 >Emitted(47, 33) Source(33, 39) + SourceIndex(2) -5 >Emitted(47, 42) Source(33, 48) + SourceIndex(2) -6 >Emitted(47, 43) Source(33, 49) + SourceIndex(2) +1->Emitted(48, 1) Source(33, 15) + SourceIndex(2) +2 >Emitted(48, 19) Source(33, 25) + SourceIndex(2) +3 >Emitted(48, 32) Source(33, 38) + SourceIndex(2) +4 >Emitted(48, 33) Source(33, 39) + SourceIndex(2) +5 >Emitted(48, 42) Source(33, 48) + SourceIndex(2) +6 >Emitted(48, 43) Source(33, 49) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -605,20 +636,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(48, 5) Source(33, 51) + SourceIndex(2) -2 >Emitted(48, 11) Source(33, 64) + SourceIndex(2) -3 >Emitted(48, 20) Source(33, 73) + SourceIndex(2) +1 >Emitted(49, 5) Source(33, 51) + SourceIndex(2) +2 >Emitted(49, 11) Source(33, 64) + SourceIndex(2) +3 >Emitted(49, 20) Source(33, 73) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(49, 6) Source(33, 76) + SourceIndex(2) +1 >Emitted(50, 6) Source(33, 76) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(50, 2) Source(33, 78) + SourceIndex(2) +1 >Emitted(51, 2) Source(33, 78) + SourceIndex(2) --- >>>import internalImport = internalNamespace.someClass; 1-> @@ -638,14 +669,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > someClass 8 > ; -1->Emitted(51, 1) Source(34, 15) + SourceIndex(2) -2 >Emitted(51, 8) Source(34, 22) + SourceIndex(2) -3 >Emitted(51, 22) Source(34, 36) + SourceIndex(2) -4 >Emitted(51, 25) Source(34, 39) + SourceIndex(2) -5 >Emitted(51, 42) Source(34, 56) + SourceIndex(2) -6 >Emitted(51, 43) Source(34, 57) + SourceIndex(2) -7 >Emitted(51, 52) Source(34, 66) + SourceIndex(2) -8 >Emitted(51, 53) Source(34, 67) + SourceIndex(2) +1->Emitted(52, 1) Source(34, 15) + SourceIndex(2) +2 >Emitted(52, 8) Source(34, 22) + SourceIndex(2) +3 >Emitted(52, 22) Source(34, 36) + SourceIndex(2) +4 >Emitted(52, 25) Source(34, 39) + SourceIndex(2) +5 >Emitted(52, 42) Source(34, 56) + SourceIndex(2) +6 >Emitted(52, 43) Source(34, 57) + SourceIndex(2) +7 >Emitted(52, 52) Source(34, 66) + SourceIndex(2) +8 >Emitted(52, 53) Source(34, 67) + SourceIndex(2) --- >>>declare type internalType = internalC; 1 > @@ -661,12 +692,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(52, 1) Source(35, 15) + SourceIndex(2) -2 >Emitted(52, 14) Source(35, 20) + SourceIndex(2) -3 >Emitted(52, 26) Source(35, 32) + SourceIndex(2) -4 >Emitted(52, 29) Source(35, 35) + SourceIndex(2) -5 >Emitted(52, 38) Source(35, 44) + SourceIndex(2) -6 >Emitted(52, 39) Source(35, 45) + SourceIndex(2) +1 >Emitted(53, 1) Source(35, 15) + SourceIndex(2) +2 >Emitted(53, 14) Source(35, 20) + SourceIndex(2) +3 >Emitted(53, 26) Source(35, 32) + SourceIndex(2) +4 >Emitted(53, 29) Source(35, 35) + SourceIndex(2) +5 >Emitted(53, 38) Source(35, 44) + SourceIndex(2) +6 >Emitted(53, 39) Source(35, 45) + SourceIndex(2) --- >>>declare const internalConst = 10; 1 > @@ -682,12 +713,12 @@ sourceFile:../second/second_part1.ts 4 > internalConst 5 > = 10 6 > ; -1 >Emitted(53, 1) Source(36, 15) + SourceIndex(2) -2 >Emitted(53, 9) Source(36, 15) + SourceIndex(2) -3 >Emitted(53, 15) Source(36, 21) + SourceIndex(2) -4 >Emitted(53, 28) Source(36, 34) + SourceIndex(2) -5 >Emitted(53, 33) Source(36, 39) + SourceIndex(2) -6 >Emitted(53, 34) Source(36, 40) + SourceIndex(2) +1 >Emitted(54, 1) Source(36, 15) + SourceIndex(2) +2 >Emitted(54, 9) Source(36, 15) + SourceIndex(2) +3 >Emitted(54, 15) Source(36, 21) + SourceIndex(2) +4 >Emitted(54, 28) Source(36, 34) + SourceIndex(2) +5 >Emitted(54, 33) Source(36, 39) + SourceIndex(2) +6 >Emitted(54, 34) Source(36, 40) + SourceIndex(2) --- >>>declare enum internalEnum { 1 > @@ -697,9 +728,9 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >enum 3 > internalEnum -1 >Emitted(54, 1) Source(37, 15) + SourceIndex(2) -2 >Emitted(54, 14) Source(37, 20) + SourceIndex(2) -3 >Emitted(54, 26) Source(37, 32) + SourceIndex(2) +1 >Emitted(55, 1) Source(37, 15) + SourceIndex(2) +2 >Emitted(55, 14) Source(37, 20) + SourceIndex(2) +3 >Emitted(55, 26) Source(37, 32) + SourceIndex(2) --- >>> a = 0, 1 >^^^^ @@ -709,9 +740,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(55, 5) Source(37, 35) + SourceIndex(2) -2 >Emitted(55, 6) Source(37, 36) + SourceIndex(2) -3 >Emitted(55, 10) Source(37, 36) + SourceIndex(2) +1 >Emitted(56, 5) Source(37, 35) + SourceIndex(2) +2 >Emitted(56, 6) Source(37, 36) + SourceIndex(2) +3 >Emitted(56, 10) Source(37, 36) + SourceIndex(2) --- >>> b = 1, 1->^^^^ @@ -721,9 +752,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(56, 5) Source(37, 38) + SourceIndex(2) -2 >Emitted(56, 6) Source(37, 39) + SourceIndex(2) -3 >Emitted(56, 10) Source(37, 39) + SourceIndex(2) +1->Emitted(57, 5) Source(37, 38) + SourceIndex(2) +2 >Emitted(57, 6) Source(37, 39) + SourceIndex(2) +3 >Emitted(57, 10) Source(37, 39) + SourceIndex(2) --- >>> c = 2 1->^^^^ @@ -732,15 +763,15 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(57, 5) Source(37, 41) + SourceIndex(2) -2 >Emitted(57, 6) Source(37, 42) + SourceIndex(2) -3 >Emitted(57, 10) Source(37, 42) + SourceIndex(2) +1->Emitted(58, 5) Source(37, 41) + SourceIndex(2) +2 >Emitted(58, 6) Source(37, 42) + SourceIndex(2) +3 >Emitted(58, 10) Source(37, 42) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(58, 2) Source(37, 44) + SourceIndex(2) +1 >Emitted(59, 2) Source(37, 44) + SourceIndex(2) --- ------------------------------------------------------------------- emittedFile:/src/2/second-output.d.ts @@ -754,9 +785,9 @@ sourceFile:../second/second_part2.ts 1-> 2 >class 3 > C -1->Emitted(59, 1) Source(1, 1) + SourceIndex(3) -2 >Emitted(59, 15) Source(1, 7) + SourceIndex(3) -3 >Emitted(59, 16) Source(1, 8) + SourceIndex(3) +1->Emitted(60, 1) Source(1, 1) + SourceIndex(3) +2 >Emitted(60, 15) Source(1, 7) + SourceIndex(3) +3 >Emitted(60, 16) Source(1, 8) + SourceIndex(3) --- >>> doSomething(): void; 1->^^^^ @@ -764,8 +795,8 @@ sourceFile:../second/second_part2.ts 1-> { > 2 > doSomething -1->Emitted(60, 5) Source(2, 5) + SourceIndex(3) -2 >Emitted(60, 16) Source(2, 16) + SourceIndex(3) +1->Emitted(61, 5) Source(2, 5) + SourceIndex(3) +2 >Emitted(61, 16) Source(2, 16) + SourceIndex(3) --- >>>} 1 >^ @@ -774,7 +805,7 @@ sourceFile:../second/second_part2.ts > console.log("something got done"); > } >} -1 >Emitted(61, 2) Source(5, 2) + SourceIndex(3) +1 >Emitted(62, 2) Source(5, 2) + SourceIndex(3) --- >>>//# sourceMappingURL=second-output.d.ts.map @@ -830,32 +861,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 234, - "end": 322, + "end": 339, "kind": "internal" }, { - "pos": 324, - "end": 356, + "pos": 341, + "end": 373, "kind": "text" }, { - "pos": 356, - "end": 748, + "pos": 373, + "end": 765, "kind": "internal" }, { - "pos": 750, - "end": 753, + "pos": 767, + "end": 770, "kind": "text" }, { - "pos": 753, - "end": 1166, + "pos": 770, + "end": 1183, "kind": "internal" }, { - "pos": 1168, - "end": 1216, + "pos": 1185, + "end": 1233, "kind": "text" } ] @@ -1008,18 +1039,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (234-322) +internal: (234-339) constructor(); prop: string; method(): void; - /*@internal*/ c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (324-356) +text: (341-373) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (356-748) +internal: (373-765) class C { } function foo(): void; @@ -1040,11 +1072,11 @@ internal: (356-748) c = 2 } ---------------------------------------------------------------------- -text: (750-753) +text: (767-770) } ---------------------------------------------------------------------- -internal: (753-1166) +internal: (770-1183) declare class internalC { } declare function internalfoo(): void; @@ -1065,7 +1097,7 @@ declare enum internalEnum { c = 2 } ---------------------------------------------------------------------- -text: (1168-1216) +text: (1185-1233) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-comment-when-one-two-three-are-prepended-in-order.js b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-comment-when-one-two-three-are-prepended-in-order.js index 7a5d6f628edcd..fbbe3730e5074 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-comment-when-one-two-three-are-prepended-in-order.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-comment-when-one-two-three-are-prepended-in-order.js @@ -15,7 +15,8 @@ declare class normalC { constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); } declare namespace normalN { class C { @@ -63,7 +64,7 @@ declare class C { //# sourceMappingURL=second-output.d.ts.map //// [/src/2/second-output.d.ts.map] -{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAe,UAAU,QAAQ;IAC7B,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEM,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACF,CAAC,EACM,MAAM;CACnC;AACD,kBAAU,OAAO,CAAC;IACC,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACtD;AACc,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC5C,cAAM,CAAC;IACH,WAAW;CAGd"} +{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAe,UAAU,QAAQ;IAC7B,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEM,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACN,IAAI,CAAC,IACM,MAAM,CADK;IACtB,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;CACxC;AACD,kBAAU,OAAO,CAAC;IACC,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACtD;AACc,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC5C,cAAM,CAAC;IACH,WAAW;CAGd"} //// [/src/2/second-output.d.ts.map.baseline.txt] =================================================================== @@ -283,35 +284,66 @@ sourceFile:../second/second_part1.ts >>> method(): void; 1->^^^^ 2 > ^^^^^^ -3 > ^^^^^-> +3 > ^^^^^^^^^^^-> 1-> > /**@internal*/ 2 > method 1->Emitted(16, 5) Source(16, 20) + SourceIndex(2) 2 >Emitted(16, 11) Source(16, 26) + SourceIndex(2) --- ->>> c: number; +>>> get c(): number; 1->^^^^ -2 > ^ -3 > ^^ -4 > ^^^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^^ +5 > ^^^^^^ +6 > ^ +7 > ^^^^-> 1->() { } - > /**@internal*/ get -2 > c -3 > () { return 10; } - > /**@internal*/ set c(val: -4 > number -1->Emitted(17, 5) Source(17, 24) + SourceIndex(2) -2 >Emitted(17, 6) Source(17, 25) + SourceIndex(2) -3 >Emitted(17, 8) Source(18, 31) + SourceIndex(2) -4 >Emitted(17, 14) Source(18, 37) + SourceIndex(2) + > /**@internal*/ +2 > get +3 > c +4 > () { return 10; } + > /**@internal*/ set c(val: +5 > number +6 > +1->Emitted(17, 5) Source(17, 20) + SourceIndex(2) +2 >Emitted(17, 9) Source(17, 24) + SourceIndex(2) +3 >Emitted(17, 10) Source(17, 25) + SourceIndex(2) +4 >Emitted(17, 14) Source(18, 31) + SourceIndex(2) +5 >Emitted(17, 20) Source(18, 37) + SourceIndex(2) +6 >Emitted(17, 21) Source(17, 42) + SourceIndex(2) +--- +>>> set c(val: number); +1->^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^ +6 > ^^^^^^ +7 > ^^ +1-> + > /**@internal*/ +2 > set +3 > c +4 > ( +5 > val: +6 > number +7 > ) { } +1->Emitted(18, 5) Source(18, 20) + SourceIndex(2) +2 >Emitted(18, 9) Source(18, 24) + SourceIndex(2) +3 >Emitted(18, 10) Source(18, 25) + SourceIndex(2) +4 >Emitted(18, 11) Source(18, 26) + SourceIndex(2) +5 >Emitted(18, 16) Source(18, 31) + SourceIndex(2) +6 >Emitted(18, 22) Source(18, 37) + SourceIndex(2) +7 >Emitted(18, 24) Source(18, 42) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(18, 2) Source(19, 2) + SourceIndex(2) +1 >Emitted(19, 2) Source(19, 2) + SourceIndex(2) --- >>>declare namespace normalN { 1-> @@ -323,10 +355,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > normalN 4 > -1->Emitted(19, 1) Source(20, 1) + SourceIndex(2) -2 >Emitted(19, 19) Source(20, 11) + SourceIndex(2) -3 >Emitted(19, 26) Source(20, 18) + SourceIndex(2) -4 >Emitted(19, 27) Source(20, 19) + SourceIndex(2) +1->Emitted(20, 1) Source(20, 1) + SourceIndex(2) +2 >Emitted(20, 19) Source(20, 11) + SourceIndex(2) +3 >Emitted(20, 26) Source(20, 18) + SourceIndex(2) +4 >Emitted(20, 27) Source(20, 19) + SourceIndex(2) --- >>> class C { 1 >^^^^ @@ -336,15 +368,15 @@ sourceFile:../second/second_part1.ts > /**@internal*/ 2 > export class 3 > C -1 >Emitted(20, 5) Source(21, 20) + SourceIndex(2) -2 >Emitted(20, 11) Source(21, 33) + SourceIndex(2) -3 >Emitted(20, 12) Source(21, 34) + SourceIndex(2) +1 >Emitted(21, 5) Source(21, 20) + SourceIndex(2) +2 >Emitted(21, 11) Source(21, 33) + SourceIndex(2) +3 >Emitted(21, 12) Source(21, 34) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(21, 6) Source(21, 38) + SourceIndex(2) +1 >Emitted(22, 6) Source(21, 38) + SourceIndex(2) --- >>> function foo(): void; 1->^^^^ @@ -357,10 +389,10 @@ sourceFile:../second/second_part1.ts 2 > export function 3 > foo 4 > () {} -1->Emitted(22, 5) Source(22, 20) + SourceIndex(2) -2 >Emitted(22, 14) Source(22, 36) + SourceIndex(2) -3 >Emitted(22, 17) Source(22, 39) + SourceIndex(2) -4 >Emitted(22, 26) Source(22, 44) + SourceIndex(2) +1->Emitted(23, 5) Source(22, 20) + SourceIndex(2) +2 >Emitted(23, 14) Source(22, 36) + SourceIndex(2) +3 >Emitted(23, 17) Source(22, 39) + SourceIndex(2) +4 >Emitted(23, 26) Source(22, 44) + SourceIndex(2) --- >>> namespace someNamespace { 1->^^^^ @@ -372,10 +404,10 @@ sourceFile:../second/second_part1.ts 2 > export namespace 3 > someNamespace 4 > -1->Emitted(23, 5) Source(23, 20) + SourceIndex(2) -2 >Emitted(23, 15) Source(23, 37) + SourceIndex(2) -3 >Emitted(23, 28) Source(23, 50) + SourceIndex(2) -4 >Emitted(23, 29) Source(23, 51) + SourceIndex(2) +1->Emitted(24, 5) Source(23, 20) + SourceIndex(2) +2 >Emitted(24, 15) Source(23, 37) + SourceIndex(2) +3 >Emitted(24, 28) Source(23, 50) + SourceIndex(2) +4 >Emitted(24, 29) Source(23, 51) + SourceIndex(2) --- >>> class C { 1 >^^^^^^^^ @@ -384,20 +416,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(24, 9) Source(23, 53) + SourceIndex(2) -2 >Emitted(24, 15) Source(23, 66) + SourceIndex(2) -3 >Emitted(24, 16) Source(23, 67) + SourceIndex(2) +1 >Emitted(25, 9) Source(23, 53) + SourceIndex(2) +2 >Emitted(25, 15) Source(23, 66) + SourceIndex(2) +3 >Emitted(25, 16) Source(23, 67) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(25, 10) Source(23, 70) + SourceIndex(2) +1 >Emitted(26, 10) Source(23, 70) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(26, 6) Source(23, 72) + SourceIndex(2) +1 >Emitted(27, 6) Source(23, 72) + SourceIndex(2) --- >>> namespace someOther.something { 1->^^^^ @@ -413,12 +445,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(27, 5) Source(24, 20) + SourceIndex(2) -2 >Emitted(27, 15) Source(24, 37) + SourceIndex(2) -3 >Emitted(27, 24) Source(24, 46) + SourceIndex(2) -4 >Emitted(27, 25) Source(24, 47) + SourceIndex(2) -5 >Emitted(27, 34) Source(24, 56) + SourceIndex(2) -6 >Emitted(27, 35) Source(24, 57) + SourceIndex(2) +1->Emitted(28, 5) Source(24, 20) + SourceIndex(2) +2 >Emitted(28, 15) Source(24, 37) + SourceIndex(2) +3 >Emitted(28, 24) Source(24, 46) + SourceIndex(2) +4 >Emitted(28, 25) Source(24, 47) + SourceIndex(2) +5 >Emitted(28, 34) Source(24, 56) + SourceIndex(2) +6 >Emitted(28, 35) Source(24, 57) + SourceIndex(2) --- >>> class someClass { 1 >^^^^^^^^ @@ -427,20 +459,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(28, 9) Source(24, 59) + SourceIndex(2) -2 >Emitted(28, 15) Source(24, 72) + SourceIndex(2) -3 >Emitted(28, 24) Source(24, 81) + SourceIndex(2) +1 >Emitted(29, 9) Source(24, 59) + SourceIndex(2) +2 >Emitted(29, 15) Source(24, 72) + SourceIndex(2) +3 >Emitted(29, 24) Source(24, 81) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(29, 10) Source(24, 84) + SourceIndex(2) +1 >Emitted(30, 10) Source(24, 84) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(30, 6) Source(24, 86) + SourceIndex(2) +1 >Emitted(31, 6) Source(24, 86) + SourceIndex(2) --- >>> export import someImport = someNamespace.C; 1->^^^^ @@ -462,15 +494,15 @@ sourceFile:../second/second_part1.ts 7 > . 8 > C 9 > ; -1->Emitted(31, 5) Source(25, 20) + SourceIndex(2) -2 >Emitted(31, 11) Source(25, 26) + SourceIndex(2) -3 >Emitted(31, 19) Source(25, 34) + SourceIndex(2) -4 >Emitted(31, 29) Source(25, 44) + SourceIndex(2) -5 >Emitted(31, 32) Source(25, 47) + SourceIndex(2) -6 >Emitted(31, 45) Source(25, 60) + SourceIndex(2) -7 >Emitted(31, 46) Source(25, 61) + SourceIndex(2) -8 >Emitted(31, 47) Source(25, 62) + SourceIndex(2) -9 >Emitted(31, 48) Source(25, 63) + SourceIndex(2) +1->Emitted(32, 5) Source(25, 20) + SourceIndex(2) +2 >Emitted(32, 11) Source(25, 26) + SourceIndex(2) +3 >Emitted(32, 19) Source(25, 34) + SourceIndex(2) +4 >Emitted(32, 29) Source(25, 44) + SourceIndex(2) +5 >Emitted(32, 32) Source(25, 47) + SourceIndex(2) +6 >Emitted(32, 45) Source(25, 60) + SourceIndex(2) +7 >Emitted(32, 46) Source(25, 61) + SourceIndex(2) +8 >Emitted(32, 47) Source(25, 62) + SourceIndex(2) +9 >Emitted(32, 48) Source(25, 63) + SourceIndex(2) --- >>> type internalType = internalC; 1 >^^^^ @@ -486,12 +518,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(32, 5) Source(26, 20) + SourceIndex(2) -2 >Emitted(32, 10) Source(26, 32) + SourceIndex(2) -3 >Emitted(32, 22) Source(26, 44) + SourceIndex(2) -4 >Emitted(32, 25) Source(26, 47) + SourceIndex(2) -5 >Emitted(32, 34) Source(26, 56) + SourceIndex(2) -6 >Emitted(32, 35) Source(26, 57) + SourceIndex(2) +1 >Emitted(33, 5) Source(26, 20) + SourceIndex(2) +2 >Emitted(33, 10) Source(26, 32) + SourceIndex(2) +3 >Emitted(33, 22) Source(26, 44) + SourceIndex(2) +4 >Emitted(33, 25) Source(26, 47) + SourceIndex(2) +5 >Emitted(33, 34) Source(26, 56) + SourceIndex(2) +6 >Emitted(33, 35) Source(26, 57) + SourceIndex(2) --- >>> const internalConst = 10; 1 >^^^^ @@ -505,11 +537,11 @@ sourceFile:../second/second_part1.ts 3 > internalConst 4 > = 10 5 > ; -1 >Emitted(33, 5) Source(27, 27) + SourceIndex(2) -2 >Emitted(33, 11) Source(27, 33) + SourceIndex(2) -3 >Emitted(33, 24) Source(27, 46) + SourceIndex(2) -4 >Emitted(33, 29) Source(27, 51) + SourceIndex(2) -5 >Emitted(33, 30) Source(27, 52) + SourceIndex(2) +1 >Emitted(34, 5) Source(27, 27) + SourceIndex(2) +2 >Emitted(34, 11) Source(27, 33) + SourceIndex(2) +3 >Emitted(34, 24) Source(27, 46) + SourceIndex(2) +4 >Emitted(34, 29) Source(27, 51) + SourceIndex(2) +5 >Emitted(34, 30) Source(27, 52) + SourceIndex(2) --- >>> enum internalEnum { 1 >^^^^ @@ -519,9 +551,9 @@ sourceFile:../second/second_part1.ts > /**@internal*/ 2 > export enum 3 > internalEnum -1 >Emitted(34, 5) Source(28, 20) + SourceIndex(2) -2 >Emitted(34, 10) Source(28, 32) + SourceIndex(2) -3 >Emitted(34, 22) Source(28, 44) + SourceIndex(2) +1 >Emitted(35, 5) Source(28, 20) + SourceIndex(2) +2 >Emitted(35, 10) Source(28, 32) + SourceIndex(2) +3 >Emitted(35, 22) Source(28, 44) + SourceIndex(2) --- >>> a = 0, 1 >^^^^^^^^ @@ -531,9 +563,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(35, 9) Source(28, 47) + SourceIndex(2) -2 >Emitted(35, 10) Source(28, 48) + SourceIndex(2) -3 >Emitted(35, 14) Source(28, 48) + SourceIndex(2) +1 >Emitted(36, 9) Source(28, 47) + SourceIndex(2) +2 >Emitted(36, 10) Source(28, 48) + SourceIndex(2) +3 >Emitted(36, 14) Source(28, 48) + SourceIndex(2) --- >>> b = 1, 1->^^^^^^^^ @@ -543,9 +575,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(36, 9) Source(28, 50) + SourceIndex(2) -2 >Emitted(36, 10) Source(28, 51) + SourceIndex(2) -3 >Emitted(36, 14) Source(28, 51) + SourceIndex(2) +1->Emitted(37, 9) Source(28, 50) + SourceIndex(2) +2 >Emitted(37, 10) Source(28, 51) + SourceIndex(2) +3 >Emitted(37, 14) Source(28, 51) + SourceIndex(2) --- >>> c = 2 1->^^^^^^^^ @@ -554,21 +586,21 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(37, 9) Source(28, 53) + SourceIndex(2) -2 >Emitted(37, 10) Source(28, 54) + SourceIndex(2) -3 >Emitted(37, 14) Source(28, 54) + SourceIndex(2) +1->Emitted(38, 9) Source(28, 53) + SourceIndex(2) +2 >Emitted(38, 10) Source(28, 54) + SourceIndex(2) +3 >Emitted(38, 14) Source(28, 54) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(38, 6) Source(28, 56) + SourceIndex(2) +1 >Emitted(39, 6) Source(28, 56) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(39, 2) Source(29, 2) + SourceIndex(2) +1 >Emitted(40, 2) Source(29, 2) + SourceIndex(2) --- >>>declare class internalC { 1-> @@ -578,15 +610,15 @@ sourceFile:../second/second_part1.ts >/**@internal*/ 2 >class 3 > internalC -1->Emitted(40, 1) Source(30, 16) + SourceIndex(2) -2 >Emitted(40, 15) Source(30, 22) + SourceIndex(2) -3 >Emitted(40, 24) Source(30, 31) + SourceIndex(2) +1->Emitted(41, 1) Source(30, 16) + SourceIndex(2) +2 >Emitted(41, 15) Source(30, 22) + SourceIndex(2) +3 >Emitted(41, 24) Source(30, 31) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(41, 2) Source(30, 34) + SourceIndex(2) +1 >Emitted(42, 2) Source(30, 34) + SourceIndex(2) --- >>>declare function internalfoo(): void; 1-> @@ -599,10 +631,10 @@ sourceFile:../second/second_part1.ts 2 >function 3 > internalfoo 4 > () {} -1->Emitted(42, 1) Source(31, 16) + SourceIndex(2) -2 >Emitted(42, 18) Source(31, 25) + SourceIndex(2) -3 >Emitted(42, 29) Source(31, 36) + SourceIndex(2) -4 >Emitted(42, 38) Source(31, 41) + SourceIndex(2) +1->Emitted(43, 1) Source(31, 16) + SourceIndex(2) +2 >Emitted(43, 18) Source(31, 25) + SourceIndex(2) +3 >Emitted(43, 29) Source(31, 36) + SourceIndex(2) +4 >Emitted(43, 38) Source(31, 41) + SourceIndex(2) --- >>>declare namespace internalNamespace { 1-> @@ -614,10 +646,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > internalNamespace 4 > -1->Emitted(43, 1) Source(32, 16) + SourceIndex(2) -2 >Emitted(43, 19) Source(32, 26) + SourceIndex(2) -3 >Emitted(43, 36) Source(32, 43) + SourceIndex(2) -4 >Emitted(43, 37) Source(32, 44) + SourceIndex(2) +1->Emitted(44, 1) Source(32, 16) + SourceIndex(2) +2 >Emitted(44, 19) Source(32, 26) + SourceIndex(2) +3 >Emitted(44, 36) Source(32, 43) + SourceIndex(2) +4 >Emitted(44, 37) Source(32, 44) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -626,20 +658,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(44, 5) Source(32, 46) + SourceIndex(2) -2 >Emitted(44, 11) Source(32, 59) + SourceIndex(2) -3 >Emitted(44, 20) Source(32, 68) + SourceIndex(2) +1 >Emitted(45, 5) Source(32, 46) + SourceIndex(2) +2 >Emitted(45, 11) Source(32, 59) + SourceIndex(2) +3 >Emitted(45, 20) Source(32, 68) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(45, 6) Source(32, 71) + SourceIndex(2) +1 >Emitted(46, 6) Source(32, 71) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(46, 2) Source(32, 73) + SourceIndex(2) +1 >Emitted(47, 2) Source(32, 73) + SourceIndex(2) --- >>>declare namespace internalOther.something { 1-> @@ -655,12 +687,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(47, 1) Source(33, 16) + SourceIndex(2) -2 >Emitted(47, 19) Source(33, 26) + SourceIndex(2) -3 >Emitted(47, 32) Source(33, 39) + SourceIndex(2) -4 >Emitted(47, 33) Source(33, 40) + SourceIndex(2) -5 >Emitted(47, 42) Source(33, 49) + SourceIndex(2) -6 >Emitted(47, 43) Source(33, 50) + SourceIndex(2) +1->Emitted(48, 1) Source(33, 16) + SourceIndex(2) +2 >Emitted(48, 19) Source(33, 26) + SourceIndex(2) +3 >Emitted(48, 32) Source(33, 39) + SourceIndex(2) +4 >Emitted(48, 33) Source(33, 40) + SourceIndex(2) +5 >Emitted(48, 42) Source(33, 49) + SourceIndex(2) +6 >Emitted(48, 43) Source(33, 50) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -669,20 +701,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(48, 5) Source(33, 52) + SourceIndex(2) -2 >Emitted(48, 11) Source(33, 65) + SourceIndex(2) -3 >Emitted(48, 20) Source(33, 74) + SourceIndex(2) +1 >Emitted(49, 5) Source(33, 52) + SourceIndex(2) +2 >Emitted(49, 11) Source(33, 65) + SourceIndex(2) +3 >Emitted(49, 20) Source(33, 74) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(49, 6) Source(33, 77) + SourceIndex(2) +1 >Emitted(50, 6) Source(33, 77) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(50, 2) Source(33, 79) + SourceIndex(2) +1 >Emitted(51, 2) Source(33, 79) + SourceIndex(2) --- >>>import internalImport = internalNamespace.someClass; 1-> @@ -702,14 +734,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > someClass 8 > ; -1->Emitted(51, 1) Source(34, 16) + SourceIndex(2) -2 >Emitted(51, 8) Source(34, 23) + SourceIndex(2) -3 >Emitted(51, 22) Source(34, 37) + SourceIndex(2) -4 >Emitted(51, 25) Source(34, 40) + SourceIndex(2) -5 >Emitted(51, 42) Source(34, 57) + SourceIndex(2) -6 >Emitted(51, 43) Source(34, 58) + SourceIndex(2) -7 >Emitted(51, 52) Source(34, 67) + SourceIndex(2) -8 >Emitted(51, 53) Source(34, 68) + SourceIndex(2) +1->Emitted(52, 1) Source(34, 16) + SourceIndex(2) +2 >Emitted(52, 8) Source(34, 23) + SourceIndex(2) +3 >Emitted(52, 22) Source(34, 37) + SourceIndex(2) +4 >Emitted(52, 25) Source(34, 40) + SourceIndex(2) +5 >Emitted(52, 42) Source(34, 57) + SourceIndex(2) +6 >Emitted(52, 43) Source(34, 58) + SourceIndex(2) +7 >Emitted(52, 52) Source(34, 67) + SourceIndex(2) +8 >Emitted(52, 53) Source(34, 68) + SourceIndex(2) --- >>>declare type internalType = internalC; 1 > @@ -725,12 +757,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(52, 1) Source(35, 16) + SourceIndex(2) -2 >Emitted(52, 14) Source(35, 21) + SourceIndex(2) -3 >Emitted(52, 26) Source(35, 33) + SourceIndex(2) -4 >Emitted(52, 29) Source(35, 36) + SourceIndex(2) -5 >Emitted(52, 38) Source(35, 45) + SourceIndex(2) -6 >Emitted(52, 39) Source(35, 46) + SourceIndex(2) +1 >Emitted(53, 1) Source(35, 16) + SourceIndex(2) +2 >Emitted(53, 14) Source(35, 21) + SourceIndex(2) +3 >Emitted(53, 26) Source(35, 33) + SourceIndex(2) +4 >Emitted(53, 29) Source(35, 36) + SourceIndex(2) +5 >Emitted(53, 38) Source(35, 45) + SourceIndex(2) +6 >Emitted(53, 39) Source(35, 46) + SourceIndex(2) --- >>>declare const internalConst = 10; 1 > @@ -746,12 +778,12 @@ sourceFile:../second/second_part1.ts 4 > internalConst 5 > = 10 6 > ; -1 >Emitted(53, 1) Source(36, 16) + SourceIndex(2) -2 >Emitted(53, 9) Source(36, 16) + SourceIndex(2) -3 >Emitted(53, 15) Source(36, 22) + SourceIndex(2) -4 >Emitted(53, 28) Source(36, 35) + SourceIndex(2) -5 >Emitted(53, 33) Source(36, 40) + SourceIndex(2) -6 >Emitted(53, 34) Source(36, 41) + SourceIndex(2) +1 >Emitted(54, 1) Source(36, 16) + SourceIndex(2) +2 >Emitted(54, 9) Source(36, 16) + SourceIndex(2) +3 >Emitted(54, 15) Source(36, 22) + SourceIndex(2) +4 >Emitted(54, 28) Source(36, 35) + SourceIndex(2) +5 >Emitted(54, 33) Source(36, 40) + SourceIndex(2) +6 >Emitted(54, 34) Source(36, 41) + SourceIndex(2) --- >>>declare enum internalEnum { 1 > @@ -761,9 +793,9 @@ sourceFile:../second/second_part1.ts >/**@internal*/ 2 >enum 3 > internalEnum -1 >Emitted(54, 1) Source(37, 16) + SourceIndex(2) -2 >Emitted(54, 14) Source(37, 21) + SourceIndex(2) -3 >Emitted(54, 26) Source(37, 33) + SourceIndex(2) +1 >Emitted(55, 1) Source(37, 16) + SourceIndex(2) +2 >Emitted(55, 14) Source(37, 21) + SourceIndex(2) +3 >Emitted(55, 26) Source(37, 33) + SourceIndex(2) --- >>> a = 0, 1 >^^^^ @@ -773,9 +805,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(55, 5) Source(37, 36) + SourceIndex(2) -2 >Emitted(55, 6) Source(37, 37) + SourceIndex(2) -3 >Emitted(55, 10) Source(37, 37) + SourceIndex(2) +1 >Emitted(56, 5) Source(37, 36) + SourceIndex(2) +2 >Emitted(56, 6) Source(37, 37) + SourceIndex(2) +3 >Emitted(56, 10) Source(37, 37) + SourceIndex(2) --- >>> b = 1, 1->^^^^ @@ -785,9 +817,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(56, 5) Source(37, 39) + SourceIndex(2) -2 >Emitted(56, 6) Source(37, 40) + SourceIndex(2) -3 >Emitted(56, 10) Source(37, 40) + SourceIndex(2) +1->Emitted(57, 5) Source(37, 39) + SourceIndex(2) +2 >Emitted(57, 6) Source(37, 40) + SourceIndex(2) +3 >Emitted(57, 10) Source(37, 40) + SourceIndex(2) --- >>> c = 2 1->^^^^ @@ -796,15 +828,15 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(57, 5) Source(37, 42) + SourceIndex(2) -2 >Emitted(57, 6) Source(37, 43) + SourceIndex(2) -3 >Emitted(57, 10) Source(37, 43) + SourceIndex(2) +1->Emitted(58, 5) Source(37, 42) + SourceIndex(2) +2 >Emitted(58, 6) Source(37, 43) + SourceIndex(2) +3 >Emitted(58, 10) Source(37, 43) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(58, 2) Source(37, 45) + SourceIndex(2) +1 >Emitted(59, 2) Source(37, 45) + SourceIndex(2) --- ------------------------------------------------------------------- emittedFile:/src/2/second-output.d.ts @@ -818,9 +850,9 @@ sourceFile:../second/second_part2.ts 1-> 2 >class 3 > C -1->Emitted(59, 1) Source(1, 1) + SourceIndex(3) -2 >Emitted(59, 15) Source(1, 7) + SourceIndex(3) -3 >Emitted(59, 16) Source(1, 8) + SourceIndex(3) +1->Emitted(60, 1) Source(1, 1) + SourceIndex(3) +2 >Emitted(60, 15) Source(1, 7) + SourceIndex(3) +3 >Emitted(60, 16) Source(1, 8) + SourceIndex(3) --- >>> doSomething(): void; 1->^^^^ @@ -828,8 +860,8 @@ sourceFile:../second/second_part2.ts 1-> { > 2 > doSomething -1->Emitted(60, 5) Source(2, 5) + SourceIndex(3) -2 >Emitted(60, 16) Source(2, 16) + SourceIndex(3) +1->Emitted(61, 5) Source(2, 5) + SourceIndex(3) +2 >Emitted(61, 16) Source(2, 16) + SourceIndex(3) --- >>>} 1 >^ @@ -838,7 +870,7 @@ sourceFile:../second/second_part2.ts > console.log("something got done"); > } >} -1 >Emitted(61, 2) Source(5, 2) + SourceIndex(3) +1 >Emitted(62, 2) Source(5, 2) + SourceIndex(3) --- >>>//# sourceMappingURL=second-output.d.ts.map @@ -2594,32 +2626,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 234, - "end": 308, + "end": 339, "kind": "internal" }, { - "pos": 310, - "end": 342, + "pos": 341, + "end": 373, "kind": "text" }, { - "pos": 342, - "end": 734, + "pos": 373, + "end": 765, "kind": "internal" }, { - "pos": 736, - "end": 739, + "pos": 767, + "end": 770, "kind": "text" }, { - "pos": 739, - "end": 1152, + "pos": 770, + "end": 1183, "kind": "internal" }, { - "pos": 1154, - "end": 1202, + "pos": 1185, + "end": 1233, "kind": "text" } ] @@ -2774,18 +2806,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (234-308) +internal: (234-339) constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (310-342) +text: (341-373) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (342-734) +internal: (373-765) class C { } function foo(): void; @@ -2806,11 +2839,11 @@ internal: (342-734) c = 2 } ---------------------------------------------------------------------- -text: (736-739) +text: (767-770) } ---------------------------------------------------------------------- -internal: (739-1152) +internal: (770-1183) declare class internalC { } declare function internalfoo(): void; @@ -2831,7 +2864,7 @@ declare enum internalEnum { c = 2 } ---------------------------------------------------------------------- -text: (1154-1202) +text: (1185-1233) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-comment.js b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-comment.js index 6e4cd6c0d2641..36f65b47c6232 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-comment.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-comment.js @@ -7,7 +7,8 @@ declare class normalC { constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); } declare namespace normalN { class C { @@ -55,7 +56,7 @@ declare class C { //# sourceMappingURL=second-output.d.ts.map //// [/src/2/second-output.d.ts.map] -{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEM,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACF,CAAC,EACM,MAAM;CACnC;AACD,kBAAU,OAAO,CAAC;IACC,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACtD;AACc,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC5C,cAAM,CAAC;IACH,WAAW;CAGd"} +{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEM,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACN,IAAI,CAAC,IACM,MAAM,CADK;IACtB,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;CACxC;AACD,kBAAU,OAAO,CAAC;IACC,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACtD;AACc,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC5C,cAAM,CAAC;IACH,WAAW;CAGd"} //// [/src/2/second-output.d.ts.map.baseline.txt] =================================================================== @@ -155,35 +156,66 @@ sourceFile:../second/second_part1.ts >>> method(): void; 1->^^^^ 2 > ^^^^^^ -3 > ^^^^^-> +3 > ^^^^^^^^^^^-> 1-> > /**@internal*/ 2 > method 1->Emitted(8, 5) Source(16, 20) + SourceIndex(0) 2 >Emitted(8, 11) Source(16, 26) + SourceIndex(0) --- ->>> c: number; +>>> get c(): number; 1->^^^^ -2 > ^ -3 > ^^ -4 > ^^^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^^ +5 > ^^^^^^ +6 > ^ +7 > ^^^^-> 1->() { } - > /**@internal*/ get -2 > c -3 > () { return 10; } - > /**@internal*/ set c(val: -4 > number -1->Emitted(9, 5) Source(17, 24) + SourceIndex(0) -2 >Emitted(9, 6) Source(17, 25) + SourceIndex(0) -3 >Emitted(9, 8) Source(18, 31) + SourceIndex(0) -4 >Emitted(9, 14) Source(18, 37) + SourceIndex(0) + > /**@internal*/ +2 > get +3 > c +4 > () { return 10; } + > /**@internal*/ set c(val: +5 > number +6 > +1->Emitted(9, 5) Source(17, 20) + SourceIndex(0) +2 >Emitted(9, 9) Source(17, 24) + SourceIndex(0) +3 >Emitted(9, 10) Source(17, 25) + SourceIndex(0) +4 >Emitted(9, 14) Source(18, 31) + SourceIndex(0) +5 >Emitted(9, 20) Source(18, 37) + SourceIndex(0) +6 >Emitted(9, 21) Source(17, 42) + SourceIndex(0) +--- +>>> set c(val: number); +1->^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^ +6 > ^^^^^^ +7 > ^^ +1-> + > /**@internal*/ +2 > set +3 > c +4 > ( +5 > val: +6 > number +7 > ) { } +1->Emitted(10, 5) Source(18, 20) + SourceIndex(0) +2 >Emitted(10, 9) Source(18, 24) + SourceIndex(0) +3 >Emitted(10, 10) Source(18, 25) + SourceIndex(0) +4 >Emitted(10, 11) Source(18, 26) + SourceIndex(0) +5 >Emitted(10, 16) Source(18, 31) + SourceIndex(0) +6 >Emitted(10, 22) Source(18, 37) + SourceIndex(0) +7 >Emitted(10, 24) Source(18, 42) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(10, 2) Source(19, 2) + SourceIndex(0) +1 >Emitted(11, 2) Source(19, 2) + SourceIndex(0) --- >>>declare namespace normalN { 1-> @@ -195,10 +227,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > normalN 4 > -1->Emitted(11, 1) Source(20, 1) + SourceIndex(0) -2 >Emitted(11, 19) Source(20, 11) + SourceIndex(0) -3 >Emitted(11, 26) Source(20, 18) + SourceIndex(0) -4 >Emitted(11, 27) Source(20, 19) + SourceIndex(0) +1->Emitted(12, 1) Source(20, 1) + SourceIndex(0) +2 >Emitted(12, 19) Source(20, 11) + SourceIndex(0) +3 >Emitted(12, 26) Source(20, 18) + SourceIndex(0) +4 >Emitted(12, 27) Source(20, 19) + SourceIndex(0) --- >>> class C { 1 >^^^^ @@ -208,15 +240,15 @@ sourceFile:../second/second_part1.ts > /**@internal*/ 2 > export class 3 > C -1 >Emitted(12, 5) Source(21, 20) + SourceIndex(0) -2 >Emitted(12, 11) Source(21, 33) + SourceIndex(0) -3 >Emitted(12, 12) Source(21, 34) + SourceIndex(0) +1 >Emitted(13, 5) Source(21, 20) + SourceIndex(0) +2 >Emitted(13, 11) Source(21, 33) + SourceIndex(0) +3 >Emitted(13, 12) Source(21, 34) + SourceIndex(0) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(13, 6) Source(21, 38) + SourceIndex(0) +1 >Emitted(14, 6) Source(21, 38) + SourceIndex(0) --- >>> function foo(): void; 1->^^^^ @@ -229,10 +261,10 @@ sourceFile:../second/second_part1.ts 2 > export function 3 > foo 4 > () {} -1->Emitted(14, 5) Source(22, 20) + SourceIndex(0) -2 >Emitted(14, 14) Source(22, 36) + SourceIndex(0) -3 >Emitted(14, 17) Source(22, 39) + SourceIndex(0) -4 >Emitted(14, 26) Source(22, 44) + SourceIndex(0) +1->Emitted(15, 5) Source(22, 20) + SourceIndex(0) +2 >Emitted(15, 14) Source(22, 36) + SourceIndex(0) +3 >Emitted(15, 17) Source(22, 39) + SourceIndex(0) +4 >Emitted(15, 26) Source(22, 44) + SourceIndex(0) --- >>> namespace someNamespace { 1->^^^^ @@ -244,10 +276,10 @@ sourceFile:../second/second_part1.ts 2 > export namespace 3 > someNamespace 4 > -1->Emitted(15, 5) Source(23, 20) + SourceIndex(0) -2 >Emitted(15, 15) Source(23, 37) + SourceIndex(0) -3 >Emitted(15, 28) Source(23, 50) + SourceIndex(0) -4 >Emitted(15, 29) Source(23, 51) + SourceIndex(0) +1->Emitted(16, 5) Source(23, 20) + SourceIndex(0) +2 >Emitted(16, 15) Source(23, 37) + SourceIndex(0) +3 >Emitted(16, 28) Source(23, 50) + SourceIndex(0) +4 >Emitted(16, 29) Source(23, 51) + SourceIndex(0) --- >>> class C { 1 >^^^^^^^^ @@ -256,20 +288,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(16, 9) Source(23, 53) + SourceIndex(0) -2 >Emitted(16, 15) Source(23, 66) + SourceIndex(0) -3 >Emitted(16, 16) Source(23, 67) + SourceIndex(0) +1 >Emitted(17, 9) Source(23, 53) + SourceIndex(0) +2 >Emitted(17, 15) Source(23, 66) + SourceIndex(0) +3 >Emitted(17, 16) Source(23, 67) + SourceIndex(0) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(17, 10) Source(23, 70) + SourceIndex(0) +1 >Emitted(18, 10) Source(23, 70) + SourceIndex(0) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(18, 6) Source(23, 72) + SourceIndex(0) +1 >Emitted(19, 6) Source(23, 72) + SourceIndex(0) --- >>> namespace someOther.something { 1->^^^^ @@ -285,12 +317,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(19, 5) Source(24, 20) + SourceIndex(0) -2 >Emitted(19, 15) Source(24, 37) + SourceIndex(0) -3 >Emitted(19, 24) Source(24, 46) + SourceIndex(0) -4 >Emitted(19, 25) Source(24, 47) + SourceIndex(0) -5 >Emitted(19, 34) Source(24, 56) + SourceIndex(0) -6 >Emitted(19, 35) Source(24, 57) + SourceIndex(0) +1->Emitted(20, 5) Source(24, 20) + SourceIndex(0) +2 >Emitted(20, 15) Source(24, 37) + SourceIndex(0) +3 >Emitted(20, 24) Source(24, 46) + SourceIndex(0) +4 >Emitted(20, 25) Source(24, 47) + SourceIndex(0) +5 >Emitted(20, 34) Source(24, 56) + SourceIndex(0) +6 >Emitted(20, 35) Source(24, 57) + SourceIndex(0) --- >>> class someClass { 1 >^^^^^^^^ @@ -299,20 +331,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(20, 9) Source(24, 59) + SourceIndex(0) -2 >Emitted(20, 15) Source(24, 72) + SourceIndex(0) -3 >Emitted(20, 24) Source(24, 81) + SourceIndex(0) +1 >Emitted(21, 9) Source(24, 59) + SourceIndex(0) +2 >Emitted(21, 15) Source(24, 72) + SourceIndex(0) +3 >Emitted(21, 24) Source(24, 81) + SourceIndex(0) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(21, 10) Source(24, 84) + SourceIndex(0) +1 >Emitted(22, 10) Source(24, 84) + SourceIndex(0) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(22, 6) Source(24, 86) + SourceIndex(0) +1 >Emitted(23, 6) Source(24, 86) + SourceIndex(0) --- >>> export import someImport = someNamespace.C; 1->^^^^ @@ -334,15 +366,15 @@ sourceFile:../second/second_part1.ts 7 > . 8 > C 9 > ; -1->Emitted(23, 5) Source(25, 20) + SourceIndex(0) -2 >Emitted(23, 11) Source(25, 26) + SourceIndex(0) -3 >Emitted(23, 19) Source(25, 34) + SourceIndex(0) -4 >Emitted(23, 29) Source(25, 44) + SourceIndex(0) -5 >Emitted(23, 32) Source(25, 47) + SourceIndex(0) -6 >Emitted(23, 45) Source(25, 60) + SourceIndex(0) -7 >Emitted(23, 46) Source(25, 61) + SourceIndex(0) -8 >Emitted(23, 47) Source(25, 62) + SourceIndex(0) -9 >Emitted(23, 48) Source(25, 63) + SourceIndex(0) +1->Emitted(24, 5) Source(25, 20) + SourceIndex(0) +2 >Emitted(24, 11) Source(25, 26) + SourceIndex(0) +3 >Emitted(24, 19) Source(25, 34) + SourceIndex(0) +4 >Emitted(24, 29) Source(25, 44) + SourceIndex(0) +5 >Emitted(24, 32) Source(25, 47) + SourceIndex(0) +6 >Emitted(24, 45) Source(25, 60) + SourceIndex(0) +7 >Emitted(24, 46) Source(25, 61) + SourceIndex(0) +8 >Emitted(24, 47) Source(25, 62) + SourceIndex(0) +9 >Emitted(24, 48) Source(25, 63) + SourceIndex(0) --- >>> type internalType = internalC; 1 >^^^^ @@ -358,12 +390,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(24, 5) Source(26, 20) + SourceIndex(0) -2 >Emitted(24, 10) Source(26, 32) + SourceIndex(0) -3 >Emitted(24, 22) Source(26, 44) + SourceIndex(0) -4 >Emitted(24, 25) Source(26, 47) + SourceIndex(0) -5 >Emitted(24, 34) Source(26, 56) + SourceIndex(0) -6 >Emitted(24, 35) Source(26, 57) + SourceIndex(0) +1 >Emitted(25, 5) Source(26, 20) + SourceIndex(0) +2 >Emitted(25, 10) Source(26, 32) + SourceIndex(0) +3 >Emitted(25, 22) Source(26, 44) + SourceIndex(0) +4 >Emitted(25, 25) Source(26, 47) + SourceIndex(0) +5 >Emitted(25, 34) Source(26, 56) + SourceIndex(0) +6 >Emitted(25, 35) Source(26, 57) + SourceIndex(0) --- >>> const internalConst = 10; 1 >^^^^ @@ -377,11 +409,11 @@ sourceFile:../second/second_part1.ts 3 > internalConst 4 > = 10 5 > ; -1 >Emitted(25, 5) Source(27, 27) + SourceIndex(0) -2 >Emitted(25, 11) Source(27, 33) + SourceIndex(0) -3 >Emitted(25, 24) Source(27, 46) + SourceIndex(0) -4 >Emitted(25, 29) Source(27, 51) + SourceIndex(0) -5 >Emitted(25, 30) Source(27, 52) + SourceIndex(0) +1 >Emitted(26, 5) Source(27, 27) + SourceIndex(0) +2 >Emitted(26, 11) Source(27, 33) + SourceIndex(0) +3 >Emitted(26, 24) Source(27, 46) + SourceIndex(0) +4 >Emitted(26, 29) Source(27, 51) + SourceIndex(0) +5 >Emitted(26, 30) Source(27, 52) + SourceIndex(0) --- >>> enum internalEnum { 1 >^^^^ @@ -391,9 +423,9 @@ sourceFile:../second/second_part1.ts > /**@internal*/ 2 > export enum 3 > internalEnum -1 >Emitted(26, 5) Source(28, 20) + SourceIndex(0) -2 >Emitted(26, 10) Source(28, 32) + SourceIndex(0) -3 >Emitted(26, 22) Source(28, 44) + SourceIndex(0) +1 >Emitted(27, 5) Source(28, 20) + SourceIndex(0) +2 >Emitted(27, 10) Source(28, 32) + SourceIndex(0) +3 >Emitted(27, 22) Source(28, 44) + SourceIndex(0) --- >>> a = 0, 1 >^^^^^^^^ @@ -403,9 +435,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(27, 9) Source(28, 47) + SourceIndex(0) -2 >Emitted(27, 10) Source(28, 48) + SourceIndex(0) -3 >Emitted(27, 14) Source(28, 48) + SourceIndex(0) +1 >Emitted(28, 9) Source(28, 47) + SourceIndex(0) +2 >Emitted(28, 10) Source(28, 48) + SourceIndex(0) +3 >Emitted(28, 14) Source(28, 48) + SourceIndex(0) --- >>> b = 1, 1->^^^^^^^^ @@ -415,9 +447,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(28, 9) Source(28, 50) + SourceIndex(0) -2 >Emitted(28, 10) Source(28, 51) + SourceIndex(0) -3 >Emitted(28, 14) Source(28, 51) + SourceIndex(0) +1->Emitted(29, 9) Source(28, 50) + SourceIndex(0) +2 >Emitted(29, 10) Source(28, 51) + SourceIndex(0) +3 >Emitted(29, 14) Source(28, 51) + SourceIndex(0) --- >>> c = 2 1->^^^^^^^^ @@ -426,21 +458,21 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(29, 9) Source(28, 53) + SourceIndex(0) -2 >Emitted(29, 10) Source(28, 54) + SourceIndex(0) -3 >Emitted(29, 14) Source(28, 54) + SourceIndex(0) +1->Emitted(30, 9) Source(28, 53) + SourceIndex(0) +2 >Emitted(30, 10) Source(28, 54) + SourceIndex(0) +3 >Emitted(30, 14) Source(28, 54) + SourceIndex(0) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(30, 6) Source(28, 56) + SourceIndex(0) +1 >Emitted(31, 6) Source(28, 56) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(31, 2) Source(29, 2) + SourceIndex(0) +1 >Emitted(32, 2) Source(29, 2) + SourceIndex(0) --- >>>declare class internalC { 1-> @@ -450,15 +482,15 @@ sourceFile:../second/second_part1.ts >/**@internal*/ 2 >class 3 > internalC -1->Emitted(32, 1) Source(30, 16) + SourceIndex(0) -2 >Emitted(32, 15) Source(30, 22) + SourceIndex(0) -3 >Emitted(32, 24) Source(30, 31) + SourceIndex(0) +1->Emitted(33, 1) Source(30, 16) + SourceIndex(0) +2 >Emitted(33, 15) Source(30, 22) + SourceIndex(0) +3 >Emitted(33, 24) Source(30, 31) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(33, 2) Source(30, 34) + SourceIndex(0) +1 >Emitted(34, 2) Source(30, 34) + SourceIndex(0) --- >>>declare function internalfoo(): void; 1-> @@ -471,10 +503,10 @@ sourceFile:../second/second_part1.ts 2 >function 3 > internalfoo 4 > () {} -1->Emitted(34, 1) Source(31, 16) + SourceIndex(0) -2 >Emitted(34, 18) Source(31, 25) + SourceIndex(0) -3 >Emitted(34, 29) Source(31, 36) + SourceIndex(0) -4 >Emitted(34, 38) Source(31, 41) + SourceIndex(0) +1->Emitted(35, 1) Source(31, 16) + SourceIndex(0) +2 >Emitted(35, 18) Source(31, 25) + SourceIndex(0) +3 >Emitted(35, 29) Source(31, 36) + SourceIndex(0) +4 >Emitted(35, 38) Source(31, 41) + SourceIndex(0) --- >>>declare namespace internalNamespace { 1-> @@ -486,10 +518,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > internalNamespace 4 > -1->Emitted(35, 1) Source(32, 16) + SourceIndex(0) -2 >Emitted(35, 19) Source(32, 26) + SourceIndex(0) -3 >Emitted(35, 36) Source(32, 43) + SourceIndex(0) -4 >Emitted(35, 37) Source(32, 44) + SourceIndex(0) +1->Emitted(36, 1) Source(32, 16) + SourceIndex(0) +2 >Emitted(36, 19) Source(32, 26) + SourceIndex(0) +3 >Emitted(36, 36) Source(32, 43) + SourceIndex(0) +4 >Emitted(36, 37) Source(32, 44) + SourceIndex(0) --- >>> class someClass { 1 >^^^^ @@ -498,20 +530,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(36, 5) Source(32, 46) + SourceIndex(0) -2 >Emitted(36, 11) Source(32, 59) + SourceIndex(0) -3 >Emitted(36, 20) Source(32, 68) + SourceIndex(0) +1 >Emitted(37, 5) Source(32, 46) + SourceIndex(0) +2 >Emitted(37, 11) Source(32, 59) + SourceIndex(0) +3 >Emitted(37, 20) Source(32, 68) + SourceIndex(0) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(37, 6) Source(32, 71) + SourceIndex(0) +1 >Emitted(38, 6) Source(32, 71) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(38, 2) Source(32, 73) + SourceIndex(0) +1 >Emitted(39, 2) Source(32, 73) + SourceIndex(0) --- >>>declare namespace internalOther.something { 1-> @@ -527,12 +559,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(39, 1) Source(33, 16) + SourceIndex(0) -2 >Emitted(39, 19) Source(33, 26) + SourceIndex(0) -3 >Emitted(39, 32) Source(33, 39) + SourceIndex(0) -4 >Emitted(39, 33) Source(33, 40) + SourceIndex(0) -5 >Emitted(39, 42) Source(33, 49) + SourceIndex(0) -6 >Emitted(39, 43) Source(33, 50) + SourceIndex(0) +1->Emitted(40, 1) Source(33, 16) + SourceIndex(0) +2 >Emitted(40, 19) Source(33, 26) + SourceIndex(0) +3 >Emitted(40, 32) Source(33, 39) + SourceIndex(0) +4 >Emitted(40, 33) Source(33, 40) + SourceIndex(0) +5 >Emitted(40, 42) Source(33, 49) + SourceIndex(0) +6 >Emitted(40, 43) Source(33, 50) + SourceIndex(0) --- >>> class someClass { 1 >^^^^ @@ -541,20 +573,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(40, 5) Source(33, 52) + SourceIndex(0) -2 >Emitted(40, 11) Source(33, 65) + SourceIndex(0) -3 >Emitted(40, 20) Source(33, 74) + SourceIndex(0) +1 >Emitted(41, 5) Source(33, 52) + SourceIndex(0) +2 >Emitted(41, 11) Source(33, 65) + SourceIndex(0) +3 >Emitted(41, 20) Source(33, 74) + SourceIndex(0) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(41, 6) Source(33, 77) + SourceIndex(0) +1 >Emitted(42, 6) Source(33, 77) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(42, 2) Source(33, 79) + SourceIndex(0) +1 >Emitted(43, 2) Source(33, 79) + SourceIndex(0) --- >>>import internalImport = internalNamespace.someClass; 1-> @@ -574,14 +606,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > someClass 8 > ; -1->Emitted(43, 1) Source(34, 16) + SourceIndex(0) -2 >Emitted(43, 8) Source(34, 23) + SourceIndex(0) -3 >Emitted(43, 22) Source(34, 37) + SourceIndex(0) -4 >Emitted(43, 25) Source(34, 40) + SourceIndex(0) -5 >Emitted(43, 42) Source(34, 57) + SourceIndex(0) -6 >Emitted(43, 43) Source(34, 58) + SourceIndex(0) -7 >Emitted(43, 52) Source(34, 67) + SourceIndex(0) -8 >Emitted(43, 53) Source(34, 68) + SourceIndex(0) +1->Emitted(44, 1) Source(34, 16) + SourceIndex(0) +2 >Emitted(44, 8) Source(34, 23) + SourceIndex(0) +3 >Emitted(44, 22) Source(34, 37) + SourceIndex(0) +4 >Emitted(44, 25) Source(34, 40) + SourceIndex(0) +5 >Emitted(44, 42) Source(34, 57) + SourceIndex(0) +6 >Emitted(44, 43) Source(34, 58) + SourceIndex(0) +7 >Emitted(44, 52) Source(34, 67) + SourceIndex(0) +8 >Emitted(44, 53) Source(34, 68) + SourceIndex(0) --- >>>declare type internalType = internalC; 1 > @@ -597,12 +629,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(44, 1) Source(35, 16) + SourceIndex(0) -2 >Emitted(44, 14) Source(35, 21) + SourceIndex(0) -3 >Emitted(44, 26) Source(35, 33) + SourceIndex(0) -4 >Emitted(44, 29) Source(35, 36) + SourceIndex(0) -5 >Emitted(44, 38) Source(35, 45) + SourceIndex(0) -6 >Emitted(44, 39) Source(35, 46) + SourceIndex(0) +1 >Emitted(45, 1) Source(35, 16) + SourceIndex(0) +2 >Emitted(45, 14) Source(35, 21) + SourceIndex(0) +3 >Emitted(45, 26) Source(35, 33) + SourceIndex(0) +4 >Emitted(45, 29) Source(35, 36) + SourceIndex(0) +5 >Emitted(45, 38) Source(35, 45) + SourceIndex(0) +6 >Emitted(45, 39) Source(35, 46) + SourceIndex(0) --- >>>declare const internalConst = 10; 1 > @@ -618,12 +650,12 @@ sourceFile:../second/second_part1.ts 4 > internalConst 5 > = 10 6 > ; -1 >Emitted(45, 1) Source(36, 16) + SourceIndex(0) -2 >Emitted(45, 9) Source(36, 16) + SourceIndex(0) -3 >Emitted(45, 15) Source(36, 22) + SourceIndex(0) -4 >Emitted(45, 28) Source(36, 35) + SourceIndex(0) -5 >Emitted(45, 33) Source(36, 40) + SourceIndex(0) -6 >Emitted(45, 34) Source(36, 41) + SourceIndex(0) +1 >Emitted(46, 1) Source(36, 16) + SourceIndex(0) +2 >Emitted(46, 9) Source(36, 16) + SourceIndex(0) +3 >Emitted(46, 15) Source(36, 22) + SourceIndex(0) +4 >Emitted(46, 28) Source(36, 35) + SourceIndex(0) +5 >Emitted(46, 33) Source(36, 40) + SourceIndex(0) +6 >Emitted(46, 34) Source(36, 41) + SourceIndex(0) --- >>>declare enum internalEnum { 1 > @@ -633,9 +665,9 @@ sourceFile:../second/second_part1.ts >/**@internal*/ 2 >enum 3 > internalEnum -1 >Emitted(46, 1) Source(37, 16) + SourceIndex(0) -2 >Emitted(46, 14) Source(37, 21) + SourceIndex(0) -3 >Emitted(46, 26) Source(37, 33) + SourceIndex(0) +1 >Emitted(47, 1) Source(37, 16) + SourceIndex(0) +2 >Emitted(47, 14) Source(37, 21) + SourceIndex(0) +3 >Emitted(47, 26) Source(37, 33) + SourceIndex(0) --- >>> a = 0, 1 >^^^^ @@ -645,9 +677,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(47, 5) Source(37, 36) + SourceIndex(0) -2 >Emitted(47, 6) Source(37, 37) + SourceIndex(0) -3 >Emitted(47, 10) Source(37, 37) + SourceIndex(0) +1 >Emitted(48, 5) Source(37, 36) + SourceIndex(0) +2 >Emitted(48, 6) Source(37, 37) + SourceIndex(0) +3 >Emitted(48, 10) Source(37, 37) + SourceIndex(0) --- >>> b = 1, 1->^^^^ @@ -657,9 +689,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(48, 5) Source(37, 39) + SourceIndex(0) -2 >Emitted(48, 6) Source(37, 40) + SourceIndex(0) -3 >Emitted(48, 10) Source(37, 40) + SourceIndex(0) +1->Emitted(49, 5) Source(37, 39) + SourceIndex(0) +2 >Emitted(49, 6) Source(37, 40) + SourceIndex(0) +3 >Emitted(49, 10) Source(37, 40) + SourceIndex(0) --- >>> c = 2 1->^^^^ @@ -668,15 +700,15 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(49, 5) Source(37, 42) + SourceIndex(0) -2 >Emitted(49, 6) Source(37, 43) + SourceIndex(0) -3 >Emitted(49, 10) Source(37, 43) + SourceIndex(0) +1->Emitted(50, 5) Source(37, 42) + SourceIndex(0) +2 >Emitted(50, 6) Source(37, 43) + SourceIndex(0) +3 >Emitted(50, 10) Source(37, 43) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(50, 2) Source(37, 45) + SourceIndex(0) +1 >Emitted(51, 2) Source(37, 45) + SourceIndex(0) --- ------------------------------------------------------------------- emittedFile:/src/2/second-output.d.ts @@ -690,9 +722,9 @@ sourceFile:../second/second_part2.ts 1-> 2 >class 3 > C -1->Emitted(51, 1) Source(1, 1) + SourceIndex(1) -2 >Emitted(51, 15) Source(1, 7) + SourceIndex(1) -3 >Emitted(51, 16) Source(1, 8) + SourceIndex(1) +1->Emitted(52, 1) Source(1, 1) + SourceIndex(1) +2 >Emitted(52, 15) Source(1, 7) + SourceIndex(1) +3 >Emitted(52, 16) Source(1, 8) + SourceIndex(1) --- >>> doSomething(): void; 1->^^^^ @@ -700,8 +732,8 @@ sourceFile:../second/second_part2.ts 1-> { > 2 > doSomething -1->Emitted(52, 5) Source(2, 5) + SourceIndex(1) -2 >Emitted(52, 16) Source(2, 16) + SourceIndex(1) +1->Emitted(53, 5) Source(2, 5) + SourceIndex(1) +2 >Emitted(53, 16) Source(2, 16) + SourceIndex(1) --- >>>} 1 >^ @@ -710,7 +742,7 @@ sourceFile:../second/second_part2.ts > console.log("something got done"); > } >} -1 >Emitted(53, 2) Source(5, 2) + SourceIndex(1) +1 >Emitted(54, 2) Source(5, 2) + SourceIndex(1) --- >>>//# sourceMappingURL=second-output.d.ts.map @@ -2294,32 +2326,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 77, - "end": 151, + "end": 182, "kind": "internal" }, { - "pos": 153, - "end": 185, + "pos": 184, + "end": 216, "kind": "text" }, { - "pos": 185, - "end": 577, + "pos": 216, + "end": 608, "kind": "internal" }, { - "pos": 579, - "end": 582, + "pos": 610, + "end": 613, "kind": "text" }, { - "pos": 582, - "end": 995, + "pos": 613, + "end": 1026, "kind": "internal" }, { - "pos": 997, - "end": 1045, + "pos": 1028, + "end": 1076, "kind": "text" } ] @@ -2448,18 +2480,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (77-151) +internal: (77-182) constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (153-185) +text: (184-216) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (185-577) +internal: (216-608) class C { } function foo(): void; @@ -2480,11 +2513,11 @@ internal: (185-577) c = 2 } ---------------------------------------------------------------------- -text: (579-582) +text: (610-613) } ---------------------------------------------------------------------- -internal: (582-995) +internal: (613-1026) declare class internalC { } declare function internalfoo(): void; @@ -2505,7 +2538,7 @@ declare enum internalEnum { c = 2 } ---------------------------------------------------------------------- -text: (997-1045) +text: (1028-1076) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js index 0890b8d81889c..b2be036365b5d 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js @@ -15,7 +15,8 @@ declare class normalC { /**@internal*/ constructor(); /**@internal*/ prop: string; /**@internal*/ method(): void; - /**@internal*/ /**@internal*/ c: number; + /**@internal*/ get c(): number; + /**@internal*/ set c(val: number); } declare namespace normalN { /**@internal*/ class C { @@ -63,7 +64,7 @@ declare class C { //# sourceMappingURL=second-output.d.ts.map //// [/src/2/second-output.d.ts.map] -{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,cAAc,CAAC,UAAU,QAAQ;IAC7B,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;IACT,cAAc;IACd,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,MAAM;IACrB,cAAc,gBAAK,CAAC,EACM,MAAM;CACnC;AACD,kBAAU,OAAO,CAAC;IACd,cAAc,CAAC,MAAa,CAAC;KAAI;IACjC,cAAc,CAAC,SAAgB,GAAG,SAAK;IACvC,cAAc,CAAC,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACnE,cAAc,CAAC,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IACjF,cAAc,CAAC,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC1D,cAAc,CAAC,KAAY,YAAY,GAAG,SAAS,CAAC;IACpD,cAAc,CAAQ,MAAM,aAAa,KAAK,CAAC;IAC/C,cAAc,CAAC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACtD;AACD,cAAc,CAAC,cAAM,SAAS;CAAG;AACjC,cAAc,CAAC,iBAAS,WAAW,SAAK;AACxC,cAAc,CAAC,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACxE,cAAc,CAAC,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC9E,cAAc,CAAC,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACnE,cAAc,CAAC,aAAK,YAAY,GAAG,SAAS,CAAC;AAC7C,cAAc,CAAC,QAAA,MAAM,aAAa,KAAK,CAAC;AACxC,cAAc,CAAC,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC5C,cAAM,CAAC;IACH,WAAW;CAGd"} +{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,cAAc,CAAC,UAAU,QAAQ;IAC7B,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;IACT,cAAc;IACd,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,MAAM;IACrB,cAAc,CAAC,IAAI,CAAC,IACM,MAAM,CADK;IACrC,cAAc,CAAC,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;CACxC;AACD,kBAAU,OAAO,CAAC;IACd,cAAc,CAAC,MAAa,CAAC;KAAI;IACjC,cAAc,CAAC,SAAgB,GAAG,SAAK;IACvC,cAAc,CAAC,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACnE,cAAc,CAAC,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IACjF,cAAc,CAAC,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC1D,cAAc,CAAC,KAAY,YAAY,GAAG,SAAS,CAAC;IACpD,cAAc,CAAQ,MAAM,aAAa,KAAK,CAAC;IAC/C,cAAc,CAAC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACtD;AACD,cAAc,CAAC,cAAM,SAAS;CAAG;AACjC,cAAc,CAAC,iBAAS,WAAW,SAAK;AACxC,cAAc,CAAC,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACxE,cAAc,CAAC,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC9E,cAAc,CAAC,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACnE,cAAc,CAAC,aAAK,YAAY,GAAG,SAAS,CAAC;AAC7C,cAAc,CAAC,QAAA,MAAM,aAAa,KAAK,CAAC;AACxC,cAAc,CAAC,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC5C,cAAM,CAAC;IACH,WAAW;CAGd"} //// [/src/2/second-output.d.ts.map.baseline.txt] =================================================================== @@ -306,7 +307,7 @@ sourceFile:../second/second_part1.ts 2 > ^^^^^^^^^^^^^^ 3 > ^ 4 > ^^^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^-> +5 > ^^^^^^^^^^^-> 1-> > 2 > /**@internal*/ @@ -317,34 +318,71 @@ sourceFile:../second/second_part1.ts 3 >Emitted(16, 20) Source(16, 20) + SourceIndex(2) 4 >Emitted(16, 26) Source(16, 26) + SourceIndex(2) --- ->>> /**@internal*/ /**@internal*/ c: number; +>>> /**@internal*/ get c(): number; 1->^^^^ 2 > ^^^^^^^^^^^^^^ -3 > ^^^^^^^^^^^^^^^^ -4 > ^ -5 > ^^ -6 > ^^^^^^ +3 > ^ +4 > ^^^^ +5 > ^ +6 > ^^^^ +7 > ^^^^^^ +8 > ^ +9 > ^^^^-> 1->() { } > 2 > /**@internal*/ -3 > get -4 > c -5 > () { return 10; } - > /**@internal*/ set c(val: -6 > number +3 > +4 > get +5 > c +6 > () { return 10; } + > /**@internal*/ set c(val: +7 > number +8 > 1->Emitted(17, 5) Source(17, 5) + SourceIndex(2) 2 >Emitted(17, 19) Source(17, 19) + SourceIndex(2) -3 >Emitted(17, 35) Source(17, 24) + SourceIndex(2) -4 >Emitted(17, 36) Source(17, 25) + SourceIndex(2) -5 >Emitted(17, 38) Source(18, 31) + SourceIndex(2) -6 >Emitted(17, 44) Source(18, 37) + SourceIndex(2) +3 >Emitted(17, 20) Source(17, 20) + SourceIndex(2) +4 >Emitted(17, 24) Source(17, 24) + SourceIndex(2) +5 >Emitted(17, 25) Source(17, 25) + SourceIndex(2) +6 >Emitted(17, 29) Source(18, 31) + SourceIndex(2) +7 >Emitted(17, 35) Source(18, 37) + SourceIndex(2) +8 >Emitted(17, 36) Source(17, 42) + SourceIndex(2) +--- +>>> /**@internal*/ set c(val: number); +1->^^^^ +2 > ^^^^^^^^^^^^^^ +3 > ^ +4 > ^^^^ +5 > ^ +6 > ^ +7 > ^^^^^ +8 > ^^^^^^ +9 > ^^ +1-> + > +2 > /**@internal*/ +3 > +4 > set +5 > c +6 > ( +7 > val: +8 > number +9 > ) { } +1->Emitted(18, 5) Source(18, 5) + SourceIndex(2) +2 >Emitted(18, 19) Source(18, 19) + SourceIndex(2) +3 >Emitted(18, 20) Source(18, 20) + SourceIndex(2) +4 >Emitted(18, 24) Source(18, 24) + SourceIndex(2) +5 >Emitted(18, 25) Source(18, 25) + SourceIndex(2) +6 >Emitted(18, 26) Source(18, 26) + SourceIndex(2) +7 >Emitted(18, 31) Source(18, 31) + SourceIndex(2) +8 >Emitted(18, 37) Source(18, 37) + SourceIndex(2) +9 >Emitted(18, 39) Source(18, 42) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(18, 2) Source(19, 2) + SourceIndex(2) +1 >Emitted(19, 2) Source(19, 2) + SourceIndex(2) --- >>>declare namespace normalN { 1-> @@ -357,10 +395,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > normalN 4 > -1->Emitted(19, 1) Source(20, 1) + SourceIndex(2) -2 >Emitted(19, 19) Source(20, 11) + SourceIndex(2) -3 >Emitted(19, 26) Source(20, 18) + SourceIndex(2) -4 >Emitted(19, 27) Source(20, 19) + SourceIndex(2) +1->Emitted(20, 1) Source(20, 1) + SourceIndex(2) +2 >Emitted(20, 19) Source(20, 11) + SourceIndex(2) +3 >Emitted(20, 26) Source(20, 18) + SourceIndex(2) +4 >Emitted(20, 27) Source(20, 19) + SourceIndex(2) --- >>> /**@internal*/ class C { 1->^^^^ @@ -374,17 +412,17 @@ sourceFile:../second/second_part1.ts 3 > 4 > export class 5 > C -1->Emitted(20, 5) Source(21, 5) + SourceIndex(2) -2 >Emitted(20, 19) Source(21, 19) + SourceIndex(2) -3 >Emitted(20, 20) Source(21, 20) + SourceIndex(2) -4 >Emitted(20, 26) Source(21, 33) + SourceIndex(2) -5 >Emitted(20, 27) Source(21, 34) + SourceIndex(2) +1->Emitted(21, 5) Source(21, 5) + SourceIndex(2) +2 >Emitted(21, 19) Source(21, 19) + SourceIndex(2) +3 >Emitted(21, 20) Source(21, 20) + SourceIndex(2) +4 >Emitted(21, 26) Source(21, 33) + SourceIndex(2) +5 >Emitted(21, 27) Source(21, 34) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(21, 6) Source(21, 38) + SourceIndex(2) +1 >Emitted(22, 6) Source(21, 38) + SourceIndex(2) --- >>> /**@internal*/ function foo(): void; 1->^^^^ @@ -401,12 +439,12 @@ sourceFile:../second/second_part1.ts 4 > export function 5 > foo 6 > () {} -1->Emitted(22, 5) Source(22, 5) + SourceIndex(2) -2 >Emitted(22, 19) Source(22, 19) + SourceIndex(2) -3 >Emitted(22, 20) Source(22, 20) + SourceIndex(2) -4 >Emitted(22, 29) Source(22, 36) + SourceIndex(2) -5 >Emitted(22, 32) Source(22, 39) + SourceIndex(2) -6 >Emitted(22, 41) Source(22, 44) + SourceIndex(2) +1->Emitted(23, 5) Source(22, 5) + SourceIndex(2) +2 >Emitted(23, 19) Source(22, 19) + SourceIndex(2) +3 >Emitted(23, 20) Source(22, 20) + SourceIndex(2) +4 >Emitted(23, 29) Source(22, 36) + SourceIndex(2) +5 >Emitted(23, 32) Source(22, 39) + SourceIndex(2) +6 >Emitted(23, 41) Source(22, 44) + SourceIndex(2) --- >>> /**@internal*/ namespace someNamespace { 1->^^^^ @@ -422,12 +460,12 @@ sourceFile:../second/second_part1.ts 4 > export namespace 5 > someNamespace 6 > -1->Emitted(23, 5) Source(23, 5) + SourceIndex(2) -2 >Emitted(23, 19) Source(23, 19) + SourceIndex(2) -3 >Emitted(23, 20) Source(23, 20) + SourceIndex(2) -4 >Emitted(23, 30) Source(23, 37) + SourceIndex(2) -5 >Emitted(23, 43) Source(23, 50) + SourceIndex(2) -6 >Emitted(23, 44) Source(23, 51) + SourceIndex(2) +1->Emitted(24, 5) Source(23, 5) + SourceIndex(2) +2 >Emitted(24, 19) Source(23, 19) + SourceIndex(2) +3 >Emitted(24, 20) Source(23, 20) + SourceIndex(2) +4 >Emitted(24, 30) Source(23, 37) + SourceIndex(2) +5 >Emitted(24, 43) Source(23, 50) + SourceIndex(2) +6 >Emitted(24, 44) Source(23, 51) + SourceIndex(2) --- >>> class C { 1 >^^^^^^^^ @@ -436,20 +474,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(24, 9) Source(23, 53) + SourceIndex(2) -2 >Emitted(24, 15) Source(23, 66) + SourceIndex(2) -3 >Emitted(24, 16) Source(23, 67) + SourceIndex(2) +1 >Emitted(25, 9) Source(23, 53) + SourceIndex(2) +2 >Emitted(25, 15) Source(23, 66) + SourceIndex(2) +3 >Emitted(25, 16) Source(23, 67) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(25, 10) Source(23, 70) + SourceIndex(2) +1 >Emitted(26, 10) Source(23, 70) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(26, 6) Source(23, 72) + SourceIndex(2) +1 >Emitted(27, 6) Source(23, 72) + SourceIndex(2) --- >>> /**@internal*/ namespace someOther.something { 1->^^^^ @@ -469,14 +507,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > something 8 > -1->Emitted(27, 5) Source(24, 5) + SourceIndex(2) -2 >Emitted(27, 19) Source(24, 19) + SourceIndex(2) -3 >Emitted(27, 20) Source(24, 20) + SourceIndex(2) -4 >Emitted(27, 30) Source(24, 37) + SourceIndex(2) -5 >Emitted(27, 39) Source(24, 46) + SourceIndex(2) -6 >Emitted(27, 40) Source(24, 47) + SourceIndex(2) -7 >Emitted(27, 49) Source(24, 56) + SourceIndex(2) -8 >Emitted(27, 50) Source(24, 57) + SourceIndex(2) +1->Emitted(28, 5) Source(24, 5) + SourceIndex(2) +2 >Emitted(28, 19) Source(24, 19) + SourceIndex(2) +3 >Emitted(28, 20) Source(24, 20) + SourceIndex(2) +4 >Emitted(28, 30) Source(24, 37) + SourceIndex(2) +5 >Emitted(28, 39) Source(24, 46) + SourceIndex(2) +6 >Emitted(28, 40) Source(24, 47) + SourceIndex(2) +7 >Emitted(28, 49) Source(24, 56) + SourceIndex(2) +8 >Emitted(28, 50) Source(24, 57) + SourceIndex(2) --- >>> class someClass { 1 >^^^^^^^^ @@ -485,20 +523,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(28, 9) Source(24, 59) + SourceIndex(2) -2 >Emitted(28, 15) Source(24, 72) + SourceIndex(2) -3 >Emitted(28, 24) Source(24, 81) + SourceIndex(2) +1 >Emitted(29, 9) Source(24, 59) + SourceIndex(2) +2 >Emitted(29, 15) Source(24, 72) + SourceIndex(2) +3 >Emitted(29, 24) Source(24, 81) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(29, 10) Source(24, 84) + SourceIndex(2) +1 >Emitted(30, 10) Source(24, 84) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(30, 6) Source(24, 86) + SourceIndex(2) +1 >Emitted(31, 6) Source(24, 86) + SourceIndex(2) --- >>> /**@internal*/ export import someImport = someNamespace.C; 1->^^^^ @@ -524,17 +562,17 @@ sourceFile:../second/second_part1.ts 9 > . 10> C 11> ; -1->Emitted(31, 5) Source(25, 5) + SourceIndex(2) -2 >Emitted(31, 19) Source(25, 19) + SourceIndex(2) -3 >Emitted(31, 20) Source(25, 20) + SourceIndex(2) -4 >Emitted(31, 26) Source(25, 26) + SourceIndex(2) -5 >Emitted(31, 34) Source(25, 34) + SourceIndex(2) -6 >Emitted(31, 44) Source(25, 44) + SourceIndex(2) -7 >Emitted(31, 47) Source(25, 47) + SourceIndex(2) -8 >Emitted(31, 60) Source(25, 60) + SourceIndex(2) -9 >Emitted(31, 61) Source(25, 61) + SourceIndex(2) -10>Emitted(31, 62) Source(25, 62) + SourceIndex(2) -11>Emitted(31, 63) Source(25, 63) + SourceIndex(2) +1->Emitted(32, 5) Source(25, 5) + SourceIndex(2) +2 >Emitted(32, 19) Source(25, 19) + SourceIndex(2) +3 >Emitted(32, 20) Source(25, 20) + SourceIndex(2) +4 >Emitted(32, 26) Source(25, 26) + SourceIndex(2) +5 >Emitted(32, 34) Source(25, 34) + SourceIndex(2) +6 >Emitted(32, 44) Source(25, 44) + SourceIndex(2) +7 >Emitted(32, 47) Source(25, 47) + SourceIndex(2) +8 >Emitted(32, 60) Source(25, 60) + SourceIndex(2) +9 >Emitted(32, 61) Source(25, 61) + SourceIndex(2) +10>Emitted(32, 62) Source(25, 62) + SourceIndex(2) +11>Emitted(32, 63) Source(25, 63) + SourceIndex(2) --- >>> /**@internal*/ type internalType = internalC; 1 >^^^^ @@ -554,14 +592,14 @@ sourceFile:../second/second_part1.ts 6 > = 7 > internalC 8 > ; -1 >Emitted(32, 5) Source(26, 5) + SourceIndex(2) -2 >Emitted(32, 19) Source(26, 19) + SourceIndex(2) -3 >Emitted(32, 20) Source(26, 20) + SourceIndex(2) -4 >Emitted(32, 25) Source(26, 32) + SourceIndex(2) -5 >Emitted(32, 37) Source(26, 44) + SourceIndex(2) -6 >Emitted(32, 40) Source(26, 47) + SourceIndex(2) -7 >Emitted(32, 49) Source(26, 56) + SourceIndex(2) -8 >Emitted(32, 50) Source(26, 57) + SourceIndex(2) +1 >Emitted(33, 5) Source(26, 5) + SourceIndex(2) +2 >Emitted(33, 19) Source(26, 19) + SourceIndex(2) +3 >Emitted(33, 20) Source(26, 20) + SourceIndex(2) +4 >Emitted(33, 25) Source(26, 32) + SourceIndex(2) +5 >Emitted(33, 37) Source(26, 44) + SourceIndex(2) +6 >Emitted(33, 40) Source(26, 47) + SourceIndex(2) +7 >Emitted(33, 49) Source(26, 56) + SourceIndex(2) +8 >Emitted(33, 50) Source(26, 57) + SourceIndex(2) --- >>> /**@internal*/ const internalConst = 10; 1 >^^^^ @@ -579,13 +617,13 @@ sourceFile:../second/second_part1.ts 5 > internalConst 6 > = 10 7 > ; -1 >Emitted(33, 5) Source(27, 5) + SourceIndex(2) -2 >Emitted(33, 19) Source(27, 19) + SourceIndex(2) -3 >Emitted(33, 20) Source(27, 27) + SourceIndex(2) -4 >Emitted(33, 26) Source(27, 33) + SourceIndex(2) -5 >Emitted(33, 39) Source(27, 46) + SourceIndex(2) -6 >Emitted(33, 44) Source(27, 51) + SourceIndex(2) -7 >Emitted(33, 45) Source(27, 52) + SourceIndex(2) +1 >Emitted(34, 5) Source(27, 5) + SourceIndex(2) +2 >Emitted(34, 19) Source(27, 19) + SourceIndex(2) +3 >Emitted(34, 20) Source(27, 27) + SourceIndex(2) +4 >Emitted(34, 26) Source(27, 33) + SourceIndex(2) +5 >Emitted(34, 39) Source(27, 46) + SourceIndex(2) +6 >Emitted(34, 44) Source(27, 51) + SourceIndex(2) +7 >Emitted(34, 45) Source(27, 52) + SourceIndex(2) --- >>> /**@internal*/ enum internalEnum { 1 >^^^^ @@ -599,11 +637,11 @@ sourceFile:../second/second_part1.ts 3 > 4 > export enum 5 > internalEnum -1 >Emitted(34, 5) Source(28, 5) + SourceIndex(2) -2 >Emitted(34, 19) Source(28, 19) + SourceIndex(2) -3 >Emitted(34, 20) Source(28, 20) + SourceIndex(2) -4 >Emitted(34, 25) Source(28, 32) + SourceIndex(2) -5 >Emitted(34, 37) Source(28, 44) + SourceIndex(2) +1 >Emitted(35, 5) Source(28, 5) + SourceIndex(2) +2 >Emitted(35, 19) Source(28, 19) + SourceIndex(2) +3 >Emitted(35, 20) Source(28, 20) + SourceIndex(2) +4 >Emitted(35, 25) Source(28, 32) + SourceIndex(2) +5 >Emitted(35, 37) Source(28, 44) + SourceIndex(2) --- >>> a = 0, 1 >^^^^^^^^ @@ -613,9 +651,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(35, 9) Source(28, 47) + SourceIndex(2) -2 >Emitted(35, 10) Source(28, 48) + SourceIndex(2) -3 >Emitted(35, 14) Source(28, 48) + SourceIndex(2) +1 >Emitted(36, 9) Source(28, 47) + SourceIndex(2) +2 >Emitted(36, 10) Source(28, 48) + SourceIndex(2) +3 >Emitted(36, 14) Source(28, 48) + SourceIndex(2) --- >>> b = 1, 1->^^^^^^^^ @@ -625,9 +663,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(36, 9) Source(28, 50) + SourceIndex(2) -2 >Emitted(36, 10) Source(28, 51) + SourceIndex(2) -3 >Emitted(36, 14) Source(28, 51) + SourceIndex(2) +1->Emitted(37, 9) Source(28, 50) + SourceIndex(2) +2 >Emitted(37, 10) Source(28, 51) + SourceIndex(2) +3 >Emitted(37, 14) Source(28, 51) + SourceIndex(2) --- >>> c = 2 1->^^^^^^^^ @@ -636,21 +674,21 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(37, 9) Source(28, 53) + SourceIndex(2) -2 >Emitted(37, 10) Source(28, 54) + SourceIndex(2) -3 >Emitted(37, 14) Source(28, 54) + SourceIndex(2) +1->Emitted(38, 9) Source(28, 53) + SourceIndex(2) +2 >Emitted(38, 10) Source(28, 54) + SourceIndex(2) +3 >Emitted(38, 14) Source(28, 54) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(38, 6) Source(28, 56) + SourceIndex(2) +1 >Emitted(39, 6) Source(28, 56) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(39, 2) Source(29, 2) + SourceIndex(2) +1 >Emitted(40, 2) Source(29, 2) + SourceIndex(2) --- >>>/**@internal*/ declare class internalC { 1-> @@ -664,17 +702,17 @@ sourceFile:../second/second_part1.ts 3 > 4 > class 5 > internalC -1->Emitted(40, 1) Source(30, 1) + SourceIndex(2) -2 >Emitted(40, 15) Source(30, 15) + SourceIndex(2) -3 >Emitted(40, 16) Source(30, 16) + SourceIndex(2) -4 >Emitted(40, 30) Source(30, 22) + SourceIndex(2) -5 >Emitted(40, 39) Source(30, 31) + SourceIndex(2) +1->Emitted(41, 1) Source(30, 1) + SourceIndex(2) +2 >Emitted(41, 15) Source(30, 15) + SourceIndex(2) +3 >Emitted(41, 16) Source(30, 16) + SourceIndex(2) +4 >Emitted(41, 30) Source(30, 22) + SourceIndex(2) +5 >Emitted(41, 39) Source(30, 31) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(41, 2) Source(30, 34) + SourceIndex(2) +1 >Emitted(42, 2) Source(30, 34) + SourceIndex(2) --- >>>/**@internal*/ declare function internalfoo(): void; 1-> @@ -691,12 +729,12 @@ sourceFile:../second/second_part1.ts 4 > function 5 > internalfoo 6 > () {} -1->Emitted(42, 1) Source(31, 1) + SourceIndex(2) -2 >Emitted(42, 15) Source(31, 15) + SourceIndex(2) -3 >Emitted(42, 16) Source(31, 16) + SourceIndex(2) -4 >Emitted(42, 33) Source(31, 25) + SourceIndex(2) -5 >Emitted(42, 44) Source(31, 36) + SourceIndex(2) -6 >Emitted(42, 53) Source(31, 41) + SourceIndex(2) +1->Emitted(43, 1) Source(31, 1) + SourceIndex(2) +2 >Emitted(43, 15) Source(31, 15) + SourceIndex(2) +3 >Emitted(43, 16) Source(31, 16) + SourceIndex(2) +4 >Emitted(43, 33) Source(31, 25) + SourceIndex(2) +5 >Emitted(43, 44) Source(31, 36) + SourceIndex(2) +6 >Emitted(43, 53) Source(31, 41) + SourceIndex(2) --- >>>/**@internal*/ declare namespace internalNamespace { 1-> @@ -712,12 +750,12 @@ sourceFile:../second/second_part1.ts 4 > namespace 5 > internalNamespace 6 > -1->Emitted(43, 1) Source(32, 1) + SourceIndex(2) -2 >Emitted(43, 15) Source(32, 15) + SourceIndex(2) -3 >Emitted(43, 16) Source(32, 16) + SourceIndex(2) -4 >Emitted(43, 34) Source(32, 26) + SourceIndex(2) -5 >Emitted(43, 51) Source(32, 43) + SourceIndex(2) -6 >Emitted(43, 52) Source(32, 44) + SourceIndex(2) +1->Emitted(44, 1) Source(32, 1) + SourceIndex(2) +2 >Emitted(44, 15) Source(32, 15) + SourceIndex(2) +3 >Emitted(44, 16) Source(32, 16) + SourceIndex(2) +4 >Emitted(44, 34) Source(32, 26) + SourceIndex(2) +5 >Emitted(44, 51) Source(32, 43) + SourceIndex(2) +6 >Emitted(44, 52) Source(32, 44) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -726,20 +764,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(44, 5) Source(32, 46) + SourceIndex(2) -2 >Emitted(44, 11) Source(32, 59) + SourceIndex(2) -3 >Emitted(44, 20) Source(32, 68) + SourceIndex(2) +1 >Emitted(45, 5) Source(32, 46) + SourceIndex(2) +2 >Emitted(45, 11) Source(32, 59) + SourceIndex(2) +3 >Emitted(45, 20) Source(32, 68) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(45, 6) Source(32, 71) + SourceIndex(2) +1 >Emitted(46, 6) Source(32, 71) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(46, 2) Source(32, 73) + SourceIndex(2) +1 >Emitted(47, 2) Source(32, 73) + SourceIndex(2) --- >>>/**@internal*/ declare namespace internalOther.something { 1-> @@ -759,14 +797,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > something 8 > -1->Emitted(47, 1) Source(33, 1) + SourceIndex(2) -2 >Emitted(47, 15) Source(33, 15) + SourceIndex(2) -3 >Emitted(47, 16) Source(33, 16) + SourceIndex(2) -4 >Emitted(47, 34) Source(33, 26) + SourceIndex(2) -5 >Emitted(47, 47) Source(33, 39) + SourceIndex(2) -6 >Emitted(47, 48) Source(33, 40) + SourceIndex(2) -7 >Emitted(47, 57) Source(33, 49) + SourceIndex(2) -8 >Emitted(47, 58) Source(33, 50) + SourceIndex(2) +1->Emitted(48, 1) Source(33, 1) + SourceIndex(2) +2 >Emitted(48, 15) Source(33, 15) + SourceIndex(2) +3 >Emitted(48, 16) Source(33, 16) + SourceIndex(2) +4 >Emitted(48, 34) Source(33, 26) + SourceIndex(2) +5 >Emitted(48, 47) Source(33, 39) + SourceIndex(2) +6 >Emitted(48, 48) Source(33, 40) + SourceIndex(2) +7 >Emitted(48, 57) Source(33, 49) + SourceIndex(2) +8 >Emitted(48, 58) Source(33, 50) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -775,20 +813,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(48, 5) Source(33, 52) + SourceIndex(2) -2 >Emitted(48, 11) Source(33, 65) + SourceIndex(2) -3 >Emitted(48, 20) Source(33, 74) + SourceIndex(2) +1 >Emitted(49, 5) Source(33, 52) + SourceIndex(2) +2 >Emitted(49, 11) Source(33, 65) + SourceIndex(2) +3 >Emitted(49, 20) Source(33, 74) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(49, 6) Source(33, 77) + SourceIndex(2) +1 >Emitted(50, 6) Source(33, 77) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(50, 2) Source(33, 79) + SourceIndex(2) +1 >Emitted(51, 2) Source(33, 79) + SourceIndex(2) --- >>>/**@internal*/ import internalImport = internalNamespace.someClass; 1-> @@ -812,16 +850,16 @@ sourceFile:../second/second_part1.ts 8 > . 9 > someClass 10> ; -1->Emitted(51, 1) Source(34, 1) + SourceIndex(2) -2 >Emitted(51, 15) Source(34, 15) + SourceIndex(2) -3 >Emitted(51, 16) Source(34, 16) + SourceIndex(2) -4 >Emitted(51, 23) Source(34, 23) + SourceIndex(2) -5 >Emitted(51, 37) Source(34, 37) + SourceIndex(2) -6 >Emitted(51, 40) Source(34, 40) + SourceIndex(2) -7 >Emitted(51, 57) Source(34, 57) + SourceIndex(2) -8 >Emitted(51, 58) Source(34, 58) + SourceIndex(2) -9 >Emitted(51, 67) Source(34, 67) + SourceIndex(2) -10>Emitted(51, 68) Source(34, 68) + SourceIndex(2) +1->Emitted(52, 1) Source(34, 1) + SourceIndex(2) +2 >Emitted(52, 15) Source(34, 15) + SourceIndex(2) +3 >Emitted(52, 16) Source(34, 16) + SourceIndex(2) +4 >Emitted(52, 23) Source(34, 23) + SourceIndex(2) +5 >Emitted(52, 37) Source(34, 37) + SourceIndex(2) +6 >Emitted(52, 40) Source(34, 40) + SourceIndex(2) +7 >Emitted(52, 57) Source(34, 57) + SourceIndex(2) +8 >Emitted(52, 58) Source(34, 58) + SourceIndex(2) +9 >Emitted(52, 67) Source(34, 67) + SourceIndex(2) +10>Emitted(52, 68) Source(34, 68) + SourceIndex(2) --- >>>/**@internal*/ declare type internalType = internalC; 1 > @@ -841,14 +879,14 @@ sourceFile:../second/second_part1.ts 6 > = 7 > internalC 8 > ; -1 >Emitted(52, 1) Source(35, 1) + SourceIndex(2) -2 >Emitted(52, 15) Source(35, 15) + SourceIndex(2) -3 >Emitted(52, 16) Source(35, 16) + SourceIndex(2) -4 >Emitted(52, 29) Source(35, 21) + SourceIndex(2) -5 >Emitted(52, 41) Source(35, 33) + SourceIndex(2) -6 >Emitted(52, 44) Source(35, 36) + SourceIndex(2) -7 >Emitted(52, 53) Source(35, 45) + SourceIndex(2) -8 >Emitted(52, 54) Source(35, 46) + SourceIndex(2) +1 >Emitted(53, 1) Source(35, 1) + SourceIndex(2) +2 >Emitted(53, 15) Source(35, 15) + SourceIndex(2) +3 >Emitted(53, 16) Source(35, 16) + SourceIndex(2) +4 >Emitted(53, 29) Source(35, 21) + SourceIndex(2) +5 >Emitted(53, 41) Source(35, 33) + SourceIndex(2) +6 >Emitted(53, 44) Source(35, 36) + SourceIndex(2) +7 >Emitted(53, 53) Source(35, 45) + SourceIndex(2) +8 >Emitted(53, 54) Source(35, 46) + SourceIndex(2) --- >>>/**@internal*/ declare const internalConst = 10; 1 > @@ -868,14 +906,14 @@ sourceFile:../second/second_part1.ts 6 > internalConst 7 > = 10 8 > ; -1 >Emitted(53, 1) Source(36, 1) + SourceIndex(2) -2 >Emitted(53, 15) Source(36, 15) + SourceIndex(2) -3 >Emitted(53, 16) Source(36, 16) + SourceIndex(2) -4 >Emitted(53, 24) Source(36, 16) + SourceIndex(2) -5 >Emitted(53, 30) Source(36, 22) + SourceIndex(2) -6 >Emitted(53, 43) Source(36, 35) + SourceIndex(2) -7 >Emitted(53, 48) Source(36, 40) + SourceIndex(2) -8 >Emitted(53, 49) Source(36, 41) + SourceIndex(2) +1 >Emitted(54, 1) Source(36, 1) + SourceIndex(2) +2 >Emitted(54, 15) Source(36, 15) + SourceIndex(2) +3 >Emitted(54, 16) Source(36, 16) + SourceIndex(2) +4 >Emitted(54, 24) Source(36, 16) + SourceIndex(2) +5 >Emitted(54, 30) Source(36, 22) + SourceIndex(2) +6 >Emitted(54, 43) Source(36, 35) + SourceIndex(2) +7 >Emitted(54, 48) Source(36, 40) + SourceIndex(2) +8 >Emitted(54, 49) Source(36, 41) + SourceIndex(2) --- >>>/**@internal*/ declare enum internalEnum { 1 > @@ -889,11 +927,11 @@ sourceFile:../second/second_part1.ts 3 > 4 > enum 5 > internalEnum -1 >Emitted(54, 1) Source(37, 1) + SourceIndex(2) -2 >Emitted(54, 15) Source(37, 15) + SourceIndex(2) -3 >Emitted(54, 16) Source(37, 16) + SourceIndex(2) -4 >Emitted(54, 29) Source(37, 21) + SourceIndex(2) -5 >Emitted(54, 41) Source(37, 33) + SourceIndex(2) +1 >Emitted(55, 1) Source(37, 1) + SourceIndex(2) +2 >Emitted(55, 15) Source(37, 15) + SourceIndex(2) +3 >Emitted(55, 16) Source(37, 16) + SourceIndex(2) +4 >Emitted(55, 29) Source(37, 21) + SourceIndex(2) +5 >Emitted(55, 41) Source(37, 33) + SourceIndex(2) --- >>> a = 0, 1 >^^^^ @@ -903,9 +941,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(55, 5) Source(37, 36) + SourceIndex(2) -2 >Emitted(55, 6) Source(37, 37) + SourceIndex(2) -3 >Emitted(55, 10) Source(37, 37) + SourceIndex(2) +1 >Emitted(56, 5) Source(37, 36) + SourceIndex(2) +2 >Emitted(56, 6) Source(37, 37) + SourceIndex(2) +3 >Emitted(56, 10) Source(37, 37) + SourceIndex(2) --- >>> b = 1, 1->^^^^ @@ -915,9 +953,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(56, 5) Source(37, 39) + SourceIndex(2) -2 >Emitted(56, 6) Source(37, 40) + SourceIndex(2) -3 >Emitted(56, 10) Source(37, 40) + SourceIndex(2) +1->Emitted(57, 5) Source(37, 39) + SourceIndex(2) +2 >Emitted(57, 6) Source(37, 40) + SourceIndex(2) +3 >Emitted(57, 10) Source(37, 40) + SourceIndex(2) --- >>> c = 2 1->^^^^ @@ -926,15 +964,15 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(57, 5) Source(37, 42) + SourceIndex(2) -2 >Emitted(57, 6) Source(37, 43) + SourceIndex(2) -3 >Emitted(57, 10) Source(37, 43) + SourceIndex(2) +1->Emitted(58, 5) Source(37, 42) + SourceIndex(2) +2 >Emitted(58, 6) Source(37, 43) + SourceIndex(2) +3 >Emitted(58, 10) Source(37, 43) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(58, 2) Source(37, 45) + SourceIndex(2) +1 >Emitted(59, 2) Source(37, 45) + SourceIndex(2) --- ------------------------------------------------------------------- emittedFile:/src/2/second-output.d.ts @@ -948,9 +986,9 @@ sourceFile:../second/second_part2.ts 1-> 2 >class 3 > C -1->Emitted(59, 1) Source(1, 1) + SourceIndex(3) -2 >Emitted(59, 15) Source(1, 7) + SourceIndex(3) -3 >Emitted(59, 16) Source(1, 8) + SourceIndex(3) +1->Emitted(60, 1) Source(1, 1) + SourceIndex(3) +2 >Emitted(60, 15) Source(1, 7) + SourceIndex(3) +3 >Emitted(60, 16) Source(1, 8) + SourceIndex(3) --- >>> doSomething(): void; 1->^^^^ @@ -958,8 +996,8 @@ sourceFile:../second/second_part2.ts 1-> { > 2 > doSomething -1->Emitted(60, 5) Source(2, 5) + SourceIndex(3) -2 >Emitted(60, 16) Source(2, 16) + SourceIndex(3) +1->Emitted(61, 5) Source(2, 5) + SourceIndex(3) +2 >Emitted(61, 16) Source(2, 16) + SourceIndex(3) --- >>>} 1 >^ @@ -968,7 +1006,7 @@ sourceFile:../second/second_part2.ts > console.log("something got done"); > } >} -1 >Emitted(61, 2) Source(5, 2) + SourceIndex(3) +1 >Emitted(62, 2) Source(5, 2) + SourceIndex(3) --- >>>//# sourceMappingURL=second-output.d.ts.map @@ -2824,32 +2862,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 249, - "end": 398, + "end": 429, "kind": "internal" }, { - "pos": 400, - "end": 432, + "pos": 431, + "end": 463, "kind": "text" }, { - "pos": 432, - "end": 944, + "pos": 463, + "end": 975, "kind": "internal" }, { - "pos": 946, - "end": 949, + "pos": 977, + "end": 980, "kind": "text" }, { - "pos": 949, - "end": 1482, + "pos": 980, + "end": 1513, "kind": "internal" }, { - "pos": 1484, - "end": 1532, + "pos": 1515, + "end": 1563, "kind": "text" } ] @@ -3004,18 +3042,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (249-398) +internal: (249-429) /**@internal*/ constructor(); /**@internal*/ prop: string; /**@internal*/ method(): void; - /**@internal*/ /**@internal*/ c: number; + /**@internal*/ get c(): number; + /**@internal*/ set c(val: number); ---------------------------------------------------------------------- -text: (400-432) +text: (431-463) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (432-944) +internal: (463-975) /**@internal*/ class C { } /**@internal*/ function foo(): void; @@ -3036,11 +3075,11 @@ internal: (432-944) c = 2 } ---------------------------------------------------------------------- -text: (946-949) +text: (977-980) } ---------------------------------------------------------------------- -internal: (949-1482) +internal: (980-1513) /**@internal*/ declare class internalC { } /**@internal*/ declare function internalfoo(): void; @@ -3061,7 +3100,7 @@ internal: (949-1482) c = 2 } ---------------------------------------------------------------------- -text: (1484-1532) +text: (1515-1563) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-with-comments-emit-enabled.js b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-with-comments-emit-enabled.js index 87badd920395e..bba9f604bcf1c 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-with-comments-emit-enabled.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-jsdoc-style-with-comments-emit-enabled.js @@ -7,7 +7,8 @@ declare class normalC { /**@internal*/ constructor(); /**@internal*/ prop: string; /**@internal*/ method(): void; - /**@internal*/ /**@internal*/ c: number; + /**@internal*/ get c(): number; + /**@internal*/ set c(val: number); } declare namespace normalN { /**@internal*/ class C { @@ -55,7 +56,7 @@ declare class C { //# sourceMappingURL=second-output.d.ts.map //// [/src/2/second-output.d.ts.map] -{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;IACT,cAAc;IACd,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,MAAM;IACrB,cAAc,gBAAK,CAAC,EACM,MAAM;CACnC;AACD,kBAAU,OAAO,CAAC;IACd,cAAc,CAAC,MAAa,CAAC;KAAI;IACjC,cAAc,CAAC,SAAgB,GAAG,SAAK;IACvC,cAAc,CAAC,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACnE,cAAc,CAAC,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IACjF,cAAc,CAAC,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC1D,cAAc,CAAC,KAAY,YAAY,GAAG,SAAS,CAAC;IACpD,cAAc,CAAQ,MAAM,aAAa,KAAK,CAAC;IAC/C,cAAc,CAAC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACtD;AACD,cAAc,CAAC,cAAM,SAAS;CAAG;AACjC,cAAc,CAAC,iBAAS,WAAW,SAAK;AACxC,cAAc,CAAC,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACxE,cAAc,CAAC,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC9E,cAAc,CAAC,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACnE,cAAc,CAAC,aAAK,YAAY,GAAG,SAAS,CAAC;AAC7C,cAAc,CAAC,QAAA,MAAM,aAAa,KAAK,CAAC;AACxC,cAAc,CAAC,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC5C,cAAM,CAAC;IACH,WAAW;CAGd"} +{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;IACT,cAAc;IACd,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,MAAM;IACrB,cAAc,CAAC,IAAI,CAAC,IACM,MAAM,CADK;IACrC,cAAc,CAAC,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;CACxC;AACD,kBAAU,OAAO,CAAC;IACd,cAAc,CAAC,MAAa,CAAC;KAAI;IACjC,cAAc,CAAC,SAAgB,GAAG,SAAK;IACvC,cAAc,CAAC,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACnE,cAAc,CAAC,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IACjF,cAAc,CAAC,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC1D,cAAc,CAAC,KAAY,YAAY,GAAG,SAAS,CAAC;IACpD,cAAc,CAAQ,MAAM,aAAa,KAAK,CAAC;IAC/C,cAAc,CAAC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACtD;AACD,cAAc,CAAC,cAAM,SAAS;CAAG;AACjC,cAAc,CAAC,iBAAS,WAAW,SAAK;AACxC,cAAc,CAAC,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACxE,cAAc,CAAC,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC9E,cAAc,CAAC,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACnE,cAAc,CAAC,aAAK,YAAY,GAAG,SAAS,CAAC;AAC7C,cAAc,CAAC,QAAA,MAAM,aAAa,KAAK,CAAC;AACxC,cAAc,CAAC,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC5C,cAAM,CAAC;IACH,WAAW;CAGd"} //// [/src/2/second-output.d.ts.map.baseline.txt] =================================================================== @@ -172,7 +173,7 @@ sourceFile:../second/second_part1.ts 2 > ^^^^^^^^^^^^^^ 3 > ^ 4 > ^^^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^-> +5 > ^^^^^^^^^^^-> 1-> > 2 > /**@internal*/ @@ -183,34 +184,71 @@ sourceFile:../second/second_part1.ts 3 >Emitted(8, 20) Source(16, 20) + SourceIndex(0) 4 >Emitted(8, 26) Source(16, 26) + SourceIndex(0) --- ->>> /**@internal*/ /**@internal*/ c: number; +>>> /**@internal*/ get c(): number; 1->^^^^ 2 > ^^^^^^^^^^^^^^ -3 > ^^^^^^^^^^^^^^^^ -4 > ^ -5 > ^^ -6 > ^^^^^^ +3 > ^ +4 > ^^^^ +5 > ^ +6 > ^^^^ +7 > ^^^^^^ +8 > ^ +9 > ^^^^-> 1->() { } > 2 > /**@internal*/ -3 > get -4 > c -5 > () { return 10; } - > /**@internal*/ set c(val: -6 > number +3 > +4 > get +5 > c +6 > () { return 10; } + > /**@internal*/ set c(val: +7 > number +8 > 1->Emitted(9, 5) Source(17, 5) + SourceIndex(0) 2 >Emitted(9, 19) Source(17, 19) + SourceIndex(0) -3 >Emitted(9, 35) Source(17, 24) + SourceIndex(0) -4 >Emitted(9, 36) Source(17, 25) + SourceIndex(0) -5 >Emitted(9, 38) Source(18, 31) + SourceIndex(0) -6 >Emitted(9, 44) Source(18, 37) + SourceIndex(0) +3 >Emitted(9, 20) Source(17, 20) + SourceIndex(0) +4 >Emitted(9, 24) Source(17, 24) + SourceIndex(0) +5 >Emitted(9, 25) Source(17, 25) + SourceIndex(0) +6 >Emitted(9, 29) Source(18, 31) + SourceIndex(0) +7 >Emitted(9, 35) Source(18, 37) + SourceIndex(0) +8 >Emitted(9, 36) Source(17, 42) + SourceIndex(0) +--- +>>> /**@internal*/ set c(val: number); +1->^^^^ +2 > ^^^^^^^^^^^^^^ +3 > ^ +4 > ^^^^ +5 > ^ +6 > ^ +7 > ^^^^^ +8 > ^^^^^^ +9 > ^^ +1-> + > +2 > /**@internal*/ +3 > +4 > set +5 > c +6 > ( +7 > val: +8 > number +9 > ) { } +1->Emitted(10, 5) Source(18, 5) + SourceIndex(0) +2 >Emitted(10, 19) Source(18, 19) + SourceIndex(0) +3 >Emitted(10, 20) Source(18, 20) + SourceIndex(0) +4 >Emitted(10, 24) Source(18, 24) + SourceIndex(0) +5 >Emitted(10, 25) Source(18, 25) + SourceIndex(0) +6 >Emitted(10, 26) Source(18, 26) + SourceIndex(0) +7 >Emitted(10, 31) Source(18, 31) + SourceIndex(0) +8 >Emitted(10, 37) Source(18, 37) + SourceIndex(0) +9 >Emitted(10, 39) Source(18, 42) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(10, 2) Source(19, 2) + SourceIndex(0) +1 >Emitted(11, 2) Source(19, 2) + SourceIndex(0) --- >>>declare namespace normalN { 1-> @@ -223,10 +261,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > normalN 4 > -1->Emitted(11, 1) Source(20, 1) + SourceIndex(0) -2 >Emitted(11, 19) Source(20, 11) + SourceIndex(0) -3 >Emitted(11, 26) Source(20, 18) + SourceIndex(0) -4 >Emitted(11, 27) Source(20, 19) + SourceIndex(0) +1->Emitted(12, 1) Source(20, 1) + SourceIndex(0) +2 >Emitted(12, 19) Source(20, 11) + SourceIndex(0) +3 >Emitted(12, 26) Source(20, 18) + SourceIndex(0) +4 >Emitted(12, 27) Source(20, 19) + SourceIndex(0) --- >>> /**@internal*/ class C { 1->^^^^ @@ -240,17 +278,17 @@ sourceFile:../second/second_part1.ts 3 > 4 > export class 5 > C -1->Emitted(12, 5) Source(21, 5) + SourceIndex(0) -2 >Emitted(12, 19) Source(21, 19) + SourceIndex(0) -3 >Emitted(12, 20) Source(21, 20) + SourceIndex(0) -4 >Emitted(12, 26) Source(21, 33) + SourceIndex(0) -5 >Emitted(12, 27) Source(21, 34) + SourceIndex(0) +1->Emitted(13, 5) Source(21, 5) + SourceIndex(0) +2 >Emitted(13, 19) Source(21, 19) + SourceIndex(0) +3 >Emitted(13, 20) Source(21, 20) + SourceIndex(0) +4 >Emitted(13, 26) Source(21, 33) + SourceIndex(0) +5 >Emitted(13, 27) Source(21, 34) + SourceIndex(0) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(13, 6) Source(21, 38) + SourceIndex(0) +1 >Emitted(14, 6) Source(21, 38) + SourceIndex(0) --- >>> /**@internal*/ function foo(): void; 1->^^^^ @@ -267,12 +305,12 @@ sourceFile:../second/second_part1.ts 4 > export function 5 > foo 6 > () {} -1->Emitted(14, 5) Source(22, 5) + SourceIndex(0) -2 >Emitted(14, 19) Source(22, 19) + SourceIndex(0) -3 >Emitted(14, 20) Source(22, 20) + SourceIndex(0) -4 >Emitted(14, 29) Source(22, 36) + SourceIndex(0) -5 >Emitted(14, 32) Source(22, 39) + SourceIndex(0) -6 >Emitted(14, 41) Source(22, 44) + SourceIndex(0) +1->Emitted(15, 5) Source(22, 5) + SourceIndex(0) +2 >Emitted(15, 19) Source(22, 19) + SourceIndex(0) +3 >Emitted(15, 20) Source(22, 20) + SourceIndex(0) +4 >Emitted(15, 29) Source(22, 36) + SourceIndex(0) +5 >Emitted(15, 32) Source(22, 39) + SourceIndex(0) +6 >Emitted(15, 41) Source(22, 44) + SourceIndex(0) --- >>> /**@internal*/ namespace someNamespace { 1->^^^^ @@ -288,12 +326,12 @@ sourceFile:../second/second_part1.ts 4 > export namespace 5 > someNamespace 6 > -1->Emitted(15, 5) Source(23, 5) + SourceIndex(0) -2 >Emitted(15, 19) Source(23, 19) + SourceIndex(0) -3 >Emitted(15, 20) Source(23, 20) + SourceIndex(0) -4 >Emitted(15, 30) Source(23, 37) + SourceIndex(0) -5 >Emitted(15, 43) Source(23, 50) + SourceIndex(0) -6 >Emitted(15, 44) Source(23, 51) + SourceIndex(0) +1->Emitted(16, 5) Source(23, 5) + SourceIndex(0) +2 >Emitted(16, 19) Source(23, 19) + SourceIndex(0) +3 >Emitted(16, 20) Source(23, 20) + SourceIndex(0) +4 >Emitted(16, 30) Source(23, 37) + SourceIndex(0) +5 >Emitted(16, 43) Source(23, 50) + SourceIndex(0) +6 >Emitted(16, 44) Source(23, 51) + SourceIndex(0) --- >>> class C { 1 >^^^^^^^^ @@ -302,20 +340,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(16, 9) Source(23, 53) + SourceIndex(0) -2 >Emitted(16, 15) Source(23, 66) + SourceIndex(0) -3 >Emitted(16, 16) Source(23, 67) + SourceIndex(0) +1 >Emitted(17, 9) Source(23, 53) + SourceIndex(0) +2 >Emitted(17, 15) Source(23, 66) + SourceIndex(0) +3 >Emitted(17, 16) Source(23, 67) + SourceIndex(0) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(17, 10) Source(23, 70) + SourceIndex(0) +1 >Emitted(18, 10) Source(23, 70) + SourceIndex(0) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(18, 6) Source(23, 72) + SourceIndex(0) +1 >Emitted(19, 6) Source(23, 72) + SourceIndex(0) --- >>> /**@internal*/ namespace someOther.something { 1->^^^^ @@ -335,14 +373,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > something 8 > -1->Emitted(19, 5) Source(24, 5) + SourceIndex(0) -2 >Emitted(19, 19) Source(24, 19) + SourceIndex(0) -3 >Emitted(19, 20) Source(24, 20) + SourceIndex(0) -4 >Emitted(19, 30) Source(24, 37) + SourceIndex(0) -5 >Emitted(19, 39) Source(24, 46) + SourceIndex(0) -6 >Emitted(19, 40) Source(24, 47) + SourceIndex(0) -7 >Emitted(19, 49) Source(24, 56) + SourceIndex(0) -8 >Emitted(19, 50) Source(24, 57) + SourceIndex(0) +1->Emitted(20, 5) Source(24, 5) + SourceIndex(0) +2 >Emitted(20, 19) Source(24, 19) + SourceIndex(0) +3 >Emitted(20, 20) Source(24, 20) + SourceIndex(0) +4 >Emitted(20, 30) Source(24, 37) + SourceIndex(0) +5 >Emitted(20, 39) Source(24, 46) + SourceIndex(0) +6 >Emitted(20, 40) Source(24, 47) + SourceIndex(0) +7 >Emitted(20, 49) Source(24, 56) + SourceIndex(0) +8 >Emitted(20, 50) Source(24, 57) + SourceIndex(0) --- >>> class someClass { 1 >^^^^^^^^ @@ -351,20 +389,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(20, 9) Source(24, 59) + SourceIndex(0) -2 >Emitted(20, 15) Source(24, 72) + SourceIndex(0) -3 >Emitted(20, 24) Source(24, 81) + SourceIndex(0) +1 >Emitted(21, 9) Source(24, 59) + SourceIndex(0) +2 >Emitted(21, 15) Source(24, 72) + SourceIndex(0) +3 >Emitted(21, 24) Source(24, 81) + SourceIndex(0) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(21, 10) Source(24, 84) + SourceIndex(0) +1 >Emitted(22, 10) Source(24, 84) + SourceIndex(0) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(22, 6) Source(24, 86) + SourceIndex(0) +1 >Emitted(23, 6) Source(24, 86) + SourceIndex(0) --- >>> /**@internal*/ export import someImport = someNamespace.C; 1->^^^^ @@ -390,17 +428,17 @@ sourceFile:../second/second_part1.ts 9 > . 10> C 11> ; -1->Emitted(23, 5) Source(25, 5) + SourceIndex(0) -2 >Emitted(23, 19) Source(25, 19) + SourceIndex(0) -3 >Emitted(23, 20) Source(25, 20) + SourceIndex(0) -4 >Emitted(23, 26) Source(25, 26) + SourceIndex(0) -5 >Emitted(23, 34) Source(25, 34) + SourceIndex(0) -6 >Emitted(23, 44) Source(25, 44) + SourceIndex(0) -7 >Emitted(23, 47) Source(25, 47) + SourceIndex(0) -8 >Emitted(23, 60) Source(25, 60) + SourceIndex(0) -9 >Emitted(23, 61) Source(25, 61) + SourceIndex(0) -10>Emitted(23, 62) Source(25, 62) + SourceIndex(0) -11>Emitted(23, 63) Source(25, 63) + SourceIndex(0) +1->Emitted(24, 5) Source(25, 5) + SourceIndex(0) +2 >Emitted(24, 19) Source(25, 19) + SourceIndex(0) +3 >Emitted(24, 20) Source(25, 20) + SourceIndex(0) +4 >Emitted(24, 26) Source(25, 26) + SourceIndex(0) +5 >Emitted(24, 34) Source(25, 34) + SourceIndex(0) +6 >Emitted(24, 44) Source(25, 44) + SourceIndex(0) +7 >Emitted(24, 47) Source(25, 47) + SourceIndex(0) +8 >Emitted(24, 60) Source(25, 60) + SourceIndex(0) +9 >Emitted(24, 61) Source(25, 61) + SourceIndex(0) +10>Emitted(24, 62) Source(25, 62) + SourceIndex(0) +11>Emitted(24, 63) Source(25, 63) + SourceIndex(0) --- >>> /**@internal*/ type internalType = internalC; 1 >^^^^ @@ -420,14 +458,14 @@ sourceFile:../second/second_part1.ts 6 > = 7 > internalC 8 > ; -1 >Emitted(24, 5) Source(26, 5) + SourceIndex(0) -2 >Emitted(24, 19) Source(26, 19) + SourceIndex(0) -3 >Emitted(24, 20) Source(26, 20) + SourceIndex(0) -4 >Emitted(24, 25) Source(26, 32) + SourceIndex(0) -5 >Emitted(24, 37) Source(26, 44) + SourceIndex(0) -6 >Emitted(24, 40) Source(26, 47) + SourceIndex(0) -7 >Emitted(24, 49) Source(26, 56) + SourceIndex(0) -8 >Emitted(24, 50) Source(26, 57) + SourceIndex(0) +1 >Emitted(25, 5) Source(26, 5) + SourceIndex(0) +2 >Emitted(25, 19) Source(26, 19) + SourceIndex(0) +3 >Emitted(25, 20) Source(26, 20) + SourceIndex(0) +4 >Emitted(25, 25) Source(26, 32) + SourceIndex(0) +5 >Emitted(25, 37) Source(26, 44) + SourceIndex(0) +6 >Emitted(25, 40) Source(26, 47) + SourceIndex(0) +7 >Emitted(25, 49) Source(26, 56) + SourceIndex(0) +8 >Emitted(25, 50) Source(26, 57) + SourceIndex(0) --- >>> /**@internal*/ const internalConst = 10; 1 >^^^^ @@ -445,13 +483,13 @@ sourceFile:../second/second_part1.ts 5 > internalConst 6 > = 10 7 > ; -1 >Emitted(25, 5) Source(27, 5) + SourceIndex(0) -2 >Emitted(25, 19) Source(27, 19) + SourceIndex(0) -3 >Emitted(25, 20) Source(27, 27) + SourceIndex(0) -4 >Emitted(25, 26) Source(27, 33) + SourceIndex(0) -5 >Emitted(25, 39) Source(27, 46) + SourceIndex(0) -6 >Emitted(25, 44) Source(27, 51) + SourceIndex(0) -7 >Emitted(25, 45) Source(27, 52) + SourceIndex(0) +1 >Emitted(26, 5) Source(27, 5) + SourceIndex(0) +2 >Emitted(26, 19) Source(27, 19) + SourceIndex(0) +3 >Emitted(26, 20) Source(27, 27) + SourceIndex(0) +4 >Emitted(26, 26) Source(27, 33) + SourceIndex(0) +5 >Emitted(26, 39) Source(27, 46) + SourceIndex(0) +6 >Emitted(26, 44) Source(27, 51) + SourceIndex(0) +7 >Emitted(26, 45) Source(27, 52) + SourceIndex(0) --- >>> /**@internal*/ enum internalEnum { 1 >^^^^ @@ -465,11 +503,11 @@ sourceFile:../second/second_part1.ts 3 > 4 > export enum 5 > internalEnum -1 >Emitted(26, 5) Source(28, 5) + SourceIndex(0) -2 >Emitted(26, 19) Source(28, 19) + SourceIndex(0) -3 >Emitted(26, 20) Source(28, 20) + SourceIndex(0) -4 >Emitted(26, 25) Source(28, 32) + SourceIndex(0) -5 >Emitted(26, 37) Source(28, 44) + SourceIndex(0) +1 >Emitted(27, 5) Source(28, 5) + SourceIndex(0) +2 >Emitted(27, 19) Source(28, 19) + SourceIndex(0) +3 >Emitted(27, 20) Source(28, 20) + SourceIndex(0) +4 >Emitted(27, 25) Source(28, 32) + SourceIndex(0) +5 >Emitted(27, 37) Source(28, 44) + SourceIndex(0) --- >>> a = 0, 1 >^^^^^^^^ @@ -479,9 +517,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(27, 9) Source(28, 47) + SourceIndex(0) -2 >Emitted(27, 10) Source(28, 48) + SourceIndex(0) -3 >Emitted(27, 14) Source(28, 48) + SourceIndex(0) +1 >Emitted(28, 9) Source(28, 47) + SourceIndex(0) +2 >Emitted(28, 10) Source(28, 48) + SourceIndex(0) +3 >Emitted(28, 14) Source(28, 48) + SourceIndex(0) --- >>> b = 1, 1->^^^^^^^^ @@ -491,9 +529,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(28, 9) Source(28, 50) + SourceIndex(0) -2 >Emitted(28, 10) Source(28, 51) + SourceIndex(0) -3 >Emitted(28, 14) Source(28, 51) + SourceIndex(0) +1->Emitted(29, 9) Source(28, 50) + SourceIndex(0) +2 >Emitted(29, 10) Source(28, 51) + SourceIndex(0) +3 >Emitted(29, 14) Source(28, 51) + SourceIndex(0) --- >>> c = 2 1->^^^^^^^^ @@ -502,21 +540,21 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(29, 9) Source(28, 53) + SourceIndex(0) -2 >Emitted(29, 10) Source(28, 54) + SourceIndex(0) -3 >Emitted(29, 14) Source(28, 54) + SourceIndex(0) +1->Emitted(30, 9) Source(28, 53) + SourceIndex(0) +2 >Emitted(30, 10) Source(28, 54) + SourceIndex(0) +3 >Emitted(30, 14) Source(28, 54) + SourceIndex(0) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(30, 6) Source(28, 56) + SourceIndex(0) +1 >Emitted(31, 6) Source(28, 56) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(31, 2) Source(29, 2) + SourceIndex(0) +1 >Emitted(32, 2) Source(29, 2) + SourceIndex(0) --- >>>/**@internal*/ declare class internalC { 1-> @@ -530,17 +568,17 @@ sourceFile:../second/second_part1.ts 3 > 4 > class 5 > internalC -1->Emitted(32, 1) Source(30, 1) + SourceIndex(0) -2 >Emitted(32, 15) Source(30, 15) + SourceIndex(0) -3 >Emitted(32, 16) Source(30, 16) + SourceIndex(0) -4 >Emitted(32, 30) Source(30, 22) + SourceIndex(0) -5 >Emitted(32, 39) Source(30, 31) + SourceIndex(0) +1->Emitted(33, 1) Source(30, 1) + SourceIndex(0) +2 >Emitted(33, 15) Source(30, 15) + SourceIndex(0) +3 >Emitted(33, 16) Source(30, 16) + SourceIndex(0) +4 >Emitted(33, 30) Source(30, 22) + SourceIndex(0) +5 >Emitted(33, 39) Source(30, 31) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(33, 2) Source(30, 34) + SourceIndex(0) +1 >Emitted(34, 2) Source(30, 34) + SourceIndex(0) --- >>>/**@internal*/ declare function internalfoo(): void; 1-> @@ -557,12 +595,12 @@ sourceFile:../second/second_part1.ts 4 > function 5 > internalfoo 6 > () {} -1->Emitted(34, 1) Source(31, 1) + SourceIndex(0) -2 >Emitted(34, 15) Source(31, 15) + SourceIndex(0) -3 >Emitted(34, 16) Source(31, 16) + SourceIndex(0) -4 >Emitted(34, 33) Source(31, 25) + SourceIndex(0) -5 >Emitted(34, 44) Source(31, 36) + SourceIndex(0) -6 >Emitted(34, 53) Source(31, 41) + SourceIndex(0) +1->Emitted(35, 1) Source(31, 1) + SourceIndex(0) +2 >Emitted(35, 15) Source(31, 15) + SourceIndex(0) +3 >Emitted(35, 16) Source(31, 16) + SourceIndex(0) +4 >Emitted(35, 33) Source(31, 25) + SourceIndex(0) +5 >Emitted(35, 44) Source(31, 36) + SourceIndex(0) +6 >Emitted(35, 53) Source(31, 41) + SourceIndex(0) --- >>>/**@internal*/ declare namespace internalNamespace { 1-> @@ -578,12 +616,12 @@ sourceFile:../second/second_part1.ts 4 > namespace 5 > internalNamespace 6 > -1->Emitted(35, 1) Source(32, 1) + SourceIndex(0) -2 >Emitted(35, 15) Source(32, 15) + SourceIndex(0) -3 >Emitted(35, 16) Source(32, 16) + SourceIndex(0) -4 >Emitted(35, 34) Source(32, 26) + SourceIndex(0) -5 >Emitted(35, 51) Source(32, 43) + SourceIndex(0) -6 >Emitted(35, 52) Source(32, 44) + SourceIndex(0) +1->Emitted(36, 1) Source(32, 1) + SourceIndex(0) +2 >Emitted(36, 15) Source(32, 15) + SourceIndex(0) +3 >Emitted(36, 16) Source(32, 16) + SourceIndex(0) +4 >Emitted(36, 34) Source(32, 26) + SourceIndex(0) +5 >Emitted(36, 51) Source(32, 43) + SourceIndex(0) +6 >Emitted(36, 52) Source(32, 44) + SourceIndex(0) --- >>> class someClass { 1 >^^^^ @@ -592,20 +630,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(36, 5) Source(32, 46) + SourceIndex(0) -2 >Emitted(36, 11) Source(32, 59) + SourceIndex(0) -3 >Emitted(36, 20) Source(32, 68) + SourceIndex(0) +1 >Emitted(37, 5) Source(32, 46) + SourceIndex(0) +2 >Emitted(37, 11) Source(32, 59) + SourceIndex(0) +3 >Emitted(37, 20) Source(32, 68) + SourceIndex(0) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(37, 6) Source(32, 71) + SourceIndex(0) +1 >Emitted(38, 6) Source(32, 71) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(38, 2) Source(32, 73) + SourceIndex(0) +1 >Emitted(39, 2) Source(32, 73) + SourceIndex(0) --- >>>/**@internal*/ declare namespace internalOther.something { 1-> @@ -625,14 +663,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > something 8 > -1->Emitted(39, 1) Source(33, 1) + SourceIndex(0) -2 >Emitted(39, 15) Source(33, 15) + SourceIndex(0) -3 >Emitted(39, 16) Source(33, 16) + SourceIndex(0) -4 >Emitted(39, 34) Source(33, 26) + SourceIndex(0) -5 >Emitted(39, 47) Source(33, 39) + SourceIndex(0) -6 >Emitted(39, 48) Source(33, 40) + SourceIndex(0) -7 >Emitted(39, 57) Source(33, 49) + SourceIndex(0) -8 >Emitted(39, 58) Source(33, 50) + SourceIndex(0) +1->Emitted(40, 1) Source(33, 1) + SourceIndex(0) +2 >Emitted(40, 15) Source(33, 15) + SourceIndex(0) +3 >Emitted(40, 16) Source(33, 16) + SourceIndex(0) +4 >Emitted(40, 34) Source(33, 26) + SourceIndex(0) +5 >Emitted(40, 47) Source(33, 39) + SourceIndex(0) +6 >Emitted(40, 48) Source(33, 40) + SourceIndex(0) +7 >Emitted(40, 57) Source(33, 49) + SourceIndex(0) +8 >Emitted(40, 58) Source(33, 50) + SourceIndex(0) --- >>> class someClass { 1 >^^^^ @@ -641,20 +679,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(40, 5) Source(33, 52) + SourceIndex(0) -2 >Emitted(40, 11) Source(33, 65) + SourceIndex(0) -3 >Emitted(40, 20) Source(33, 74) + SourceIndex(0) +1 >Emitted(41, 5) Source(33, 52) + SourceIndex(0) +2 >Emitted(41, 11) Source(33, 65) + SourceIndex(0) +3 >Emitted(41, 20) Source(33, 74) + SourceIndex(0) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(41, 6) Source(33, 77) + SourceIndex(0) +1 >Emitted(42, 6) Source(33, 77) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(42, 2) Source(33, 79) + SourceIndex(0) +1 >Emitted(43, 2) Source(33, 79) + SourceIndex(0) --- >>>/**@internal*/ import internalImport = internalNamespace.someClass; 1-> @@ -678,16 +716,16 @@ sourceFile:../second/second_part1.ts 8 > . 9 > someClass 10> ; -1->Emitted(43, 1) Source(34, 1) + SourceIndex(0) -2 >Emitted(43, 15) Source(34, 15) + SourceIndex(0) -3 >Emitted(43, 16) Source(34, 16) + SourceIndex(0) -4 >Emitted(43, 23) Source(34, 23) + SourceIndex(0) -5 >Emitted(43, 37) Source(34, 37) + SourceIndex(0) -6 >Emitted(43, 40) Source(34, 40) + SourceIndex(0) -7 >Emitted(43, 57) Source(34, 57) + SourceIndex(0) -8 >Emitted(43, 58) Source(34, 58) + SourceIndex(0) -9 >Emitted(43, 67) Source(34, 67) + SourceIndex(0) -10>Emitted(43, 68) Source(34, 68) + SourceIndex(0) +1->Emitted(44, 1) Source(34, 1) + SourceIndex(0) +2 >Emitted(44, 15) Source(34, 15) + SourceIndex(0) +3 >Emitted(44, 16) Source(34, 16) + SourceIndex(0) +4 >Emitted(44, 23) Source(34, 23) + SourceIndex(0) +5 >Emitted(44, 37) Source(34, 37) + SourceIndex(0) +6 >Emitted(44, 40) Source(34, 40) + SourceIndex(0) +7 >Emitted(44, 57) Source(34, 57) + SourceIndex(0) +8 >Emitted(44, 58) Source(34, 58) + SourceIndex(0) +9 >Emitted(44, 67) Source(34, 67) + SourceIndex(0) +10>Emitted(44, 68) Source(34, 68) + SourceIndex(0) --- >>>/**@internal*/ declare type internalType = internalC; 1 > @@ -707,14 +745,14 @@ sourceFile:../second/second_part1.ts 6 > = 7 > internalC 8 > ; -1 >Emitted(44, 1) Source(35, 1) + SourceIndex(0) -2 >Emitted(44, 15) Source(35, 15) + SourceIndex(0) -3 >Emitted(44, 16) Source(35, 16) + SourceIndex(0) -4 >Emitted(44, 29) Source(35, 21) + SourceIndex(0) -5 >Emitted(44, 41) Source(35, 33) + SourceIndex(0) -6 >Emitted(44, 44) Source(35, 36) + SourceIndex(0) -7 >Emitted(44, 53) Source(35, 45) + SourceIndex(0) -8 >Emitted(44, 54) Source(35, 46) + SourceIndex(0) +1 >Emitted(45, 1) Source(35, 1) + SourceIndex(0) +2 >Emitted(45, 15) Source(35, 15) + SourceIndex(0) +3 >Emitted(45, 16) Source(35, 16) + SourceIndex(0) +4 >Emitted(45, 29) Source(35, 21) + SourceIndex(0) +5 >Emitted(45, 41) Source(35, 33) + SourceIndex(0) +6 >Emitted(45, 44) Source(35, 36) + SourceIndex(0) +7 >Emitted(45, 53) Source(35, 45) + SourceIndex(0) +8 >Emitted(45, 54) Source(35, 46) + SourceIndex(0) --- >>>/**@internal*/ declare const internalConst = 10; 1 > @@ -734,14 +772,14 @@ sourceFile:../second/second_part1.ts 6 > internalConst 7 > = 10 8 > ; -1 >Emitted(45, 1) Source(36, 1) + SourceIndex(0) -2 >Emitted(45, 15) Source(36, 15) + SourceIndex(0) -3 >Emitted(45, 16) Source(36, 16) + SourceIndex(0) -4 >Emitted(45, 24) Source(36, 16) + SourceIndex(0) -5 >Emitted(45, 30) Source(36, 22) + SourceIndex(0) -6 >Emitted(45, 43) Source(36, 35) + SourceIndex(0) -7 >Emitted(45, 48) Source(36, 40) + SourceIndex(0) -8 >Emitted(45, 49) Source(36, 41) + SourceIndex(0) +1 >Emitted(46, 1) Source(36, 1) + SourceIndex(0) +2 >Emitted(46, 15) Source(36, 15) + SourceIndex(0) +3 >Emitted(46, 16) Source(36, 16) + SourceIndex(0) +4 >Emitted(46, 24) Source(36, 16) + SourceIndex(0) +5 >Emitted(46, 30) Source(36, 22) + SourceIndex(0) +6 >Emitted(46, 43) Source(36, 35) + SourceIndex(0) +7 >Emitted(46, 48) Source(36, 40) + SourceIndex(0) +8 >Emitted(46, 49) Source(36, 41) + SourceIndex(0) --- >>>/**@internal*/ declare enum internalEnum { 1 > @@ -755,11 +793,11 @@ sourceFile:../second/second_part1.ts 3 > 4 > enum 5 > internalEnum -1 >Emitted(46, 1) Source(37, 1) + SourceIndex(0) -2 >Emitted(46, 15) Source(37, 15) + SourceIndex(0) -3 >Emitted(46, 16) Source(37, 16) + SourceIndex(0) -4 >Emitted(46, 29) Source(37, 21) + SourceIndex(0) -5 >Emitted(46, 41) Source(37, 33) + SourceIndex(0) +1 >Emitted(47, 1) Source(37, 1) + SourceIndex(0) +2 >Emitted(47, 15) Source(37, 15) + SourceIndex(0) +3 >Emitted(47, 16) Source(37, 16) + SourceIndex(0) +4 >Emitted(47, 29) Source(37, 21) + SourceIndex(0) +5 >Emitted(47, 41) Source(37, 33) + SourceIndex(0) --- >>> a = 0, 1 >^^^^ @@ -769,9 +807,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(47, 5) Source(37, 36) + SourceIndex(0) -2 >Emitted(47, 6) Source(37, 37) + SourceIndex(0) -3 >Emitted(47, 10) Source(37, 37) + SourceIndex(0) +1 >Emitted(48, 5) Source(37, 36) + SourceIndex(0) +2 >Emitted(48, 6) Source(37, 37) + SourceIndex(0) +3 >Emitted(48, 10) Source(37, 37) + SourceIndex(0) --- >>> b = 1, 1->^^^^ @@ -781,9 +819,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(48, 5) Source(37, 39) + SourceIndex(0) -2 >Emitted(48, 6) Source(37, 40) + SourceIndex(0) -3 >Emitted(48, 10) Source(37, 40) + SourceIndex(0) +1->Emitted(49, 5) Source(37, 39) + SourceIndex(0) +2 >Emitted(49, 6) Source(37, 40) + SourceIndex(0) +3 >Emitted(49, 10) Source(37, 40) + SourceIndex(0) --- >>> c = 2 1->^^^^ @@ -792,15 +830,15 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(49, 5) Source(37, 42) + SourceIndex(0) -2 >Emitted(49, 6) Source(37, 43) + SourceIndex(0) -3 >Emitted(49, 10) Source(37, 43) + SourceIndex(0) +1->Emitted(50, 5) Source(37, 42) + SourceIndex(0) +2 >Emitted(50, 6) Source(37, 43) + SourceIndex(0) +3 >Emitted(50, 10) Source(37, 43) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(50, 2) Source(37, 45) + SourceIndex(0) +1 >Emitted(51, 2) Source(37, 45) + SourceIndex(0) --- ------------------------------------------------------------------- emittedFile:/src/2/second-output.d.ts @@ -814,9 +852,9 @@ sourceFile:../second/second_part2.ts 1-> 2 >class 3 > C -1->Emitted(51, 1) Source(1, 1) + SourceIndex(1) -2 >Emitted(51, 15) Source(1, 7) + SourceIndex(1) -3 >Emitted(51, 16) Source(1, 8) + SourceIndex(1) +1->Emitted(52, 1) Source(1, 1) + SourceIndex(1) +2 >Emitted(52, 15) Source(1, 7) + SourceIndex(1) +3 >Emitted(52, 16) Source(1, 8) + SourceIndex(1) --- >>> doSomething(): void; 1->^^^^ @@ -824,8 +862,8 @@ sourceFile:../second/second_part2.ts 1-> { > 2 > doSomething -1->Emitted(52, 5) Source(2, 5) + SourceIndex(1) -2 >Emitted(52, 16) Source(2, 16) + SourceIndex(1) +1->Emitted(53, 5) Source(2, 5) + SourceIndex(1) +2 >Emitted(53, 16) Source(2, 16) + SourceIndex(1) --- >>>} 1 >^ @@ -834,7 +872,7 @@ sourceFile:../second/second_part2.ts > console.log("something got done"); > } >} -1 >Emitted(53, 2) Source(5, 2) + SourceIndex(1) +1 >Emitted(54, 2) Source(5, 2) + SourceIndex(1) --- >>>//# sourceMappingURL=second-output.d.ts.map @@ -2518,32 +2556,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 77, - "end": 226, + "end": 257, "kind": "internal" }, { - "pos": 228, - "end": 260, + "pos": 259, + "end": 291, "kind": "text" }, { - "pos": 260, - "end": 772, + "pos": 291, + "end": 803, "kind": "internal" }, { - "pos": 774, - "end": 777, + "pos": 805, + "end": 808, "kind": "text" }, { - "pos": 777, - "end": 1310, + "pos": 808, + "end": 1341, "kind": "internal" }, { - "pos": 1312, - "end": 1360, + "pos": 1343, + "end": 1391, "kind": "text" } ] @@ -2672,18 +2710,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (77-226) +internal: (77-257) /**@internal*/ constructor(); /**@internal*/ prop: string; /**@internal*/ method(): void; - /**@internal*/ /**@internal*/ c: number; + /**@internal*/ get c(): number; + /**@internal*/ set c(val: number); ---------------------------------------------------------------------- -text: (228-260) +text: (259-291) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (260-772) +internal: (291-803) /**@internal*/ class C { } /**@internal*/ function foo(): void; @@ -2704,11 +2743,11 @@ internal: (260-772) c = 2 } ---------------------------------------------------------------------- -text: (774-777) +text: (805-808) } ---------------------------------------------------------------------- -internal: (777-1310) +internal: (808-1341) /**@internal*/ declare class internalC { } /**@internal*/ declare function internalfoo(): void; @@ -2729,7 +2768,7 @@ internal: (777-1310) c = 2 } ---------------------------------------------------------------------- -text: (1312-1360) +text: (1343-1391) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-when-one-two-three-are-prepended-in-order.js b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-when-one-two-three-are-prepended-in-order.js index 8986286317040..04743ac6f97dd 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-when-one-two-three-are-prepended-in-order.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-when-one-two-three-are-prepended-in-order.js @@ -15,7 +15,8 @@ declare class normalC { constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); } declare namespace normalN { class C { @@ -63,7 +64,7 @@ declare class C { //# sourceMappingURL=second-output.d.ts.map //// [/src/2/second-output.d.ts.map] -{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAc,UAAU,QAAQ;IAC5B,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACF,CAAC,EACM,MAAM;CAClC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} +{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAc,UAAU,QAAQ;IAC5B,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACN,IAAI,CAAC,IACM,MAAM,CADK;IACtB,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;CACvC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} //// [/src/2/second-output.d.ts.map.baseline.txt] =================================================================== @@ -283,35 +284,66 @@ sourceFile:../second/second_part1.ts >>> method(): void; 1->^^^^ 2 > ^^^^^^ -3 > ^^^^^-> +3 > ^^^^^^^^^^^-> 1-> > /*@internal*/ 2 > method 1->Emitted(16, 5) Source(16, 19) + SourceIndex(2) 2 >Emitted(16, 11) Source(16, 25) + SourceIndex(2) --- ->>> c: number; +>>> get c(): number; 1->^^^^ -2 > ^ -3 > ^^ -4 > ^^^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^^ +5 > ^^^^^^ +6 > ^ +7 > ^^^^-> 1->() { } - > /*@internal*/ get -2 > c -3 > () { return 10; } - > /*@internal*/ set c(val: -4 > number -1->Emitted(17, 5) Source(17, 23) + SourceIndex(2) -2 >Emitted(17, 6) Source(17, 24) + SourceIndex(2) -3 >Emitted(17, 8) Source(18, 30) + SourceIndex(2) -4 >Emitted(17, 14) Source(18, 36) + SourceIndex(2) + > /*@internal*/ +2 > get +3 > c +4 > () { return 10; } + > /*@internal*/ set c(val: +5 > number +6 > +1->Emitted(17, 5) Source(17, 19) + SourceIndex(2) +2 >Emitted(17, 9) Source(17, 23) + SourceIndex(2) +3 >Emitted(17, 10) Source(17, 24) + SourceIndex(2) +4 >Emitted(17, 14) Source(18, 30) + SourceIndex(2) +5 >Emitted(17, 20) Source(18, 36) + SourceIndex(2) +6 >Emitted(17, 21) Source(17, 41) + SourceIndex(2) +--- +>>> set c(val: number); +1->^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^ +6 > ^^^^^^ +7 > ^^ +1-> + > /*@internal*/ +2 > set +3 > c +4 > ( +5 > val: +6 > number +7 > ) { } +1->Emitted(18, 5) Source(18, 19) + SourceIndex(2) +2 >Emitted(18, 9) Source(18, 23) + SourceIndex(2) +3 >Emitted(18, 10) Source(18, 24) + SourceIndex(2) +4 >Emitted(18, 11) Source(18, 25) + SourceIndex(2) +5 >Emitted(18, 16) Source(18, 30) + SourceIndex(2) +6 >Emitted(18, 22) Source(18, 36) + SourceIndex(2) +7 >Emitted(18, 24) Source(18, 41) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(18, 2) Source(19, 2) + SourceIndex(2) +1 >Emitted(19, 2) Source(19, 2) + SourceIndex(2) --- >>>declare namespace normalN { 1-> @@ -323,10 +355,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > normalN 4 > -1->Emitted(19, 1) Source(20, 1) + SourceIndex(2) -2 >Emitted(19, 19) Source(20, 11) + SourceIndex(2) -3 >Emitted(19, 26) Source(20, 18) + SourceIndex(2) -4 >Emitted(19, 27) Source(20, 19) + SourceIndex(2) +1->Emitted(20, 1) Source(20, 1) + SourceIndex(2) +2 >Emitted(20, 19) Source(20, 11) + SourceIndex(2) +3 >Emitted(20, 26) Source(20, 18) + SourceIndex(2) +4 >Emitted(20, 27) Source(20, 19) + SourceIndex(2) --- >>> class C { 1 >^^^^ @@ -336,15 +368,15 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export class 3 > C -1 >Emitted(20, 5) Source(21, 19) + SourceIndex(2) -2 >Emitted(20, 11) Source(21, 32) + SourceIndex(2) -3 >Emitted(20, 12) Source(21, 33) + SourceIndex(2) +1 >Emitted(21, 5) Source(21, 19) + SourceIndex(2) +2 >Emitted(21, 11) Source(21, 32) + SourceIndex(2) +3 >Emitted(21, 12) Source(21, 33) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(21, 6) Source(21, 37) + SourceIndex(2) +1 >Emitted(22, 6) Source(21, 37) + SourceIndex(2) --- >>> function foo(): void; 1->^^^^ @@ -357,10 +389,10 @@ sourceFile:../second/second_part1.ts 2 > export function 3 > foo 4 > () {} -1->Emitted(22, 5) Source(22, 19) + SourceIndex(2) -2 >Emitted(22, 14) Source(22, 35) + SourceIndex(2) -3 >Emitted(22, 17) Source(22, 38) + SourceIndex(2) -4 >Emitted(22, 26) Source(22, 43) + SourceIndex(2) +1->Emitted(23, 5) Source(22, 19) + SourceIndex(2) +2 >Emitted(23, 14) Source(22, 35) + SourceIndex(2) +3 >Emitted(23, 17) Source(22, 38) + SourceIndex(2) +4 >Emitted(23, 26) Source(22, 43) + SourceIndex(2) --- >>> namespace someNamespace { 1->^^^^ @@ -372,10 +404,10 @@ sourceFile:../second/second_part1.ts 2 > export namespace 3 > someNamespace 4 > -1->Emitted(23, 5) Source(23, 19) + SourceIndex(2) -2 >Emitted(23, 15) Source(23, 36) + SourceIndex(2) -3 >Emitted(23, 28) Source(23, 49) + SourceIndex(2) -4 >Emitted(23, 29) Source(23, 50) + SourceIndex(2) +1->Emitted(24, 5) Source(23, 19) + SourceIndex(2) +2 >Emitted(24, 15) Source(23, 36) + SourceIndex(2) +3 >Emitted(24, 28) Source(23, 49) + SourceIndex(2) +4 >Emitted(24, 29) Source(23, 50) + SourceIndex(2) --- >>> class C { 1 >^^^^^^^^ @@ -384,20 +416,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(24, 9) Source(23, 52) + SourceIndex(2) -2 >Emitted(24, 15) Source(23, 65) + SourceIndex(2) -3 >Emitted(24, 16) Source(23, 66) + SourceIndex(2) +1 >Emitted(25, 9) Source(23, 52) + SourceIndex(2) +2 >Emitted(25, 15) Source(23, 65) + SourceIndex(2) +3 >Emitted(25, 16) Source(23, 66) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(25, 10) Source(23, 69) + SourceIndex(2) +1 >Emitted(26, 10) Source(23, 69) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(26, 6) Source(23, 71) + SourceIndex(2) +1 >Emitted(27, 6) Source(23, 71) + SourceIndex(2) --- >>> namespace someOther.something { 1->^^^^ @@ -413,12 +445,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(27, 5) Source(24, 19) + SourceIndex(2) -2 >Emitted(27, 15) Source(24, 36) + SourceIndex(2) -3 >Emitted(27, 24) Source(24, 45) + SourceIndex(2) -4 >Emitted(27, 25) Source(24, 46) + SourceIndex(2) -5 >Emitted(27, 34) Source(24, 55) + SourceIndex(2) -6 >Emitted(27, 35) Source(24, 56) + SourceIndex(2) +1->Emitted(28, 5) Source(24, 19) + SourceIndex(2) +2 >Emitted(28, 15) Source(24, 36) + SourceIndex(2) +3 >Emitted(28, 24) Source(24, 45) + SourceIndex(2) +4 >Emitted(28, 25) Source(24, 46) + SourceIndex(2) +5 >Emitted(28, 34) Source(24, 55) + SourceIndex(2) +6 >Emitted(28, 35) Source(24, 56) + SourceIndex(2) --- >>> class someClass { 1 >^^^^^^^^ @@ -427,20 +459,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(28, 9) Source(24, 58) + SourceIndex(2) -2 >Emitted(28, 15) Source(24, 71) + SourceIndex(2) -3 >Emitted(28, 24) Source(24, 80) + SourceIndex(2) +1 >Emitted(29, 9) Source(24, 58) + SourceIndex(2) +2 >Emitted(29, 15) Source(24, 71) + SourceIndex(2) +3 >Emitted(29, 24) Source(24, 80) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(29, 10) Source(24, 83) + SourceIndex(2) +1 >Emitted(30, 10) Source(24, 83) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(30, 6) Source(24, 85) + SourceIndex(2) +1 >Emitted(31, 6) Source(24, 85) + SourceIndex(2) --- >>> export import someImport = someNamespace.C; 1->^^^^ @@ -462,15 +494,15 @@ sourceFile:../second/second_part1.ts 7 > . 8 > C 9 > ; -1->Emitted(31, 5) Source(25, 19) + SourceIndex(2) -2 >Emitted(31, 11) Source(25, 25) + SourceIndex(2) -3 >Emitted(31, 19) Source(25, 33) + SourceIndex(2) -4 >Emitted(31, 29) Source(25, 43) + SourceIndex(2) -5 >Emitted(31, 32) Source(25, 46) + SourceIndex(2) -6 >Emitted(31, 45) Source(25, 59) + SourceIndex(2) -7 >Emitted(31, 46) Source(25, 60) + SourceIndex(2) -8 >Emitted(31, 47) Source(25, 61) + SourceIndex(2) -9 >Emitted(31, 48) Source(25, 62) + SourceIndex(2) +1->Emitted(32, 5) Source(25, 19) + SourceIndex(2) +2 >Emitted(32, 11) Source(25, 25) + SourceIndex(2) +3 >Emitted(32, 19) Source(25, 33) + SourceIndex(2) +4 >Emitted(32, 29) Source(25, 43) + SourceIndex(2) +5 >Emitted(32, 32) Source(25, 46) + SourceIndex(2) +6 >Emitted(32, 45) Source(25, 59) + SourceIndex(2) +7 >Emitted(32, 46) Source(25, 60) + SourceIndex(2) +8 >Emitted(32, 47) Source(25, 61) + SourceIndex(2) +9 >Emitted(32, 48) Source(25, 62) + SourceIndex(2) --- >>> type internalType = internalC; 1 >^^^^ @@ -486,12 +518,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(32, 5) Source(26, 19) + SourceIndex(2) -2 >Emitted(32, 10) Source(26, 31) + SourceIndex(2) -3 >Emitted(32, 22) Source(26, 43) + SourceIndex(2) -4 >Emitted(32, 25) Source(26, 46) + SourceIndex(2) -5 >Emitted(32, 34) Source(26, 55) + SourceIndex(2) -6 >Emitted(32, 35) Source(26, 56) + SourceIndex(2) +1 >Emitted(33, 5) Source(26, 19) + SourceIndex(2) +2 >Emitted(33, 10) Source(26, 31) + SourceIndex(2) +3 >Emitted(33, 22) Source(26, 43) + SourceIndex(2) +4 >Emitted(33, 25) Source(26, 46) + SourceIndex(2) +5 >Emitted(33, 34) Source(26, 55) + SourceIndex(2) +6 >Emitted(33, 35) Source(26, 56) + SourceIndex(2) --- >>> const internalConst = 10; 1 >^^^^ @@ -505,11 +537,11 @@ sourceFile:../second/second_part1.ts 3 > internalConst 4 > = 10 5 > ; -1 >Emitted(33, 5) Source(27, 26) + SourceIndex(2) -2 >Emitted(33, 11) Source(27, 32) + SourceIndex(2) -3 >Emitted(33, 24) Source(27, 45) + SourceIndex(2) -4 >Emitted(33, 29) Source(27, 50) + SourceIndex(2) -5 >Emitted(33, 30) Source(27, 51) + SourceIndex(2) +1 >Emitted(34, 5) Source(27, 26) + SourceIndex(2) +2 >Emitted(34, 11) Source(27, 32) + SourceIndex(2) +3 >Emitted(34, 24) Source(27, 45) + SourceIndex(2) +4 >Emitted(34, 29) Source(27, 50) + SourceIndex(2) +5 >Emitted(34, 30) Source(27, 51) + SourceIndex(2) --- >>> enum internalEnum { 1 >^^^^ @@ -519,9 +551,9 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export enum 3 > internalEnum -1 >Emitted(34, 5) Source(28, 19) + SourceIndex(2) -2 >Emitted(34, 10) Source(28, 31) + SourceIndex(2) -3 >Emitted(34, 22) Source(28, 43) + SourceIndex(2) +1 >Emitted(35, 5) Source(28, 19) + SourceIndex(2) +2 >Emitted(35, 10) Source(28, 31) + SourceIndex(2) +3 >Emitted(35, 22) Source(28, 43) + SourceIndex(2) --- >>> a = 0, 1 >^^^^^^^^ @@ -531,9 +563,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(35, 9) Source(28, 46) + SourceIndex(2) -2 >Emitted(35, 10) Source(28, 47) + SourceIndex(2) -3 >Emitted(35, 14) Source(28, 47) + SourceIndex(2) +1 >Emitted(36, 9) Source(28, 46) + SourceIndex(2) +2 >Emitted(36, 10) Source(28, 47) + SourceIndex(2) +3 >Emitted(36, 14) Source(28, 47) + SourceIndex(2) --- >>> b = 1, 1->^^^^^^^^ @@ -543,9 +575,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(36, 9) Source(28, 49) + SourceIndex(2) -2 >Emitted(36, 10) Source(28, 50) + SourceIndex(2) -3 >Emitted(36, 14) Source(28, 50) + SourceIndex(2) +1->Emitted(37, 9) Source(28, 49) + SourceIndex(2) +2 >Emitted(37, 10) Source(28, 50) + SourceIndex(2) +3 >Emitted(37, 14) Source(28, 50) + SourceIndex(2) --- >>> c = 2 1->^^^^^^^^ @@ -554,21 +586,21 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(37, 9) Source(28, 52) + SourceIndex(2) -2 >Emitted(37, 10) Source(28, 53) + SourceIndex(2) -3 >Emitted(37, 14) Source(28, 53) + SourceIndex(2) +1->Emitted(38, 9) Source(28, 52) + SourceIndex(2) +2 >Emitted(38, 10) Source(28, 53) + SourceIndex(2) +3 >Emitted(38, 14) Source(28, 53) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(38, 6) Source(28, 55) + SourceIndex(2) +1 >Emitted(39, 6) Source(28, 55) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(39, 2) Source(29, 2) + SourceIndex(2) +1 >Emitted(40, 2) Source(29, 2) + SourceIndex(2) --- >>>declare class internalC { 1-> @@ -578,15 +610,15 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >class 3 > internalC -1->Emitted(40, 1) Source(30, 15) + SourceIndex(2) -2 >Emitted(40, 15) Source(30, 21) + SourceIndex(2) -3 >Emitted(40, 24) Source(30, 30) + SourceIndex(2) +1->Emitted(41, 1) Source(30, 15) + SourceIndex(2) +2 >Emitted(41, 15) Source(30, 21) + SourceIndex(2) +3 >Emitted(41, 24) Source(30, 30) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(41, 2) Source(30, 33) + SourceIndex(2) +1 >Emitted(42, 2) Source(30, 33) + SourceIndex(2) --- >>>declare function internalfoo(): void; 1-> @@ -599,10 +631,10 @@ sourceFile:../second/second_part1.ts 2 >function 3 > internalfoo 4 > () {} -1->Emitted(42, 1) Source(31, 15) + SourceIndex(2) -2 >Emitted(42, 18) Source(31, 24) + SourceIndex(2) -3 >Emitted(42, 29) Source(31, 35) + SourceIndex(2) -4 >Emitted(42, 38) Source(31, 40) + SourceIndex(2) +1->Emitted(43, 1) Source(31, 15) + SourceIndex(2) +2 >Emitted(43, 18) Source(31, 24) + SourceIndex(2) +3 >Emitted(43, 29) Source(31, 35) + SourceIndex(2) +4 >Emitted(43, 38) Source(31, 40) + SourceIndex(2) --- >>>declare namespace internalNamespace { 1-> @@ -614,10 +646,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > internalNamespace 4 > -1->Emitted(43, 1) Source(32, 15) + SourceIndex(2) -2 >Emitted(43, 19) Source(32, 25) + SourceIndex(2) -3 >Emitted(43, 36) Source(32, 42) + SourceIndex(2) -4 >Emitted(43, 37) Source(32, 43) + SourceIndex(2) +1->Emitted(44, 1) Source(32, 15) + SourceIndex(2) +2 >Emitted(44, 19) Source(32, 25) + SourceIndex(2) +3 >Emitted(44, 36) Source(32, 42) + SourceIndex(2) +4 >Emitted(44, 37) Source(32, 43) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -626,20 +658,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(44, 5) Source(32, 45) + SourceIndex(2) -2 >Emitted(44, 11) Source(32, 58) + SourceIndex(2) -3 >Emitted(44, 20) Source(32, 67) + SourceIndex(2) +1 >Emitted(45, 5) Source(32, 45) + SourceIndex(2) +2 >Emitted(45, 11) Source(32, 58) + SourceIndex(2) +3 >Emitted(45, 20) Source(32, 67) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(45, 6) Source(32, 70) + SourceIndex(2) +1 >Emitted(46, 6) Source(32, 70) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(46, 2) Source(32, 72) + SourceIndex(2) +1 >Emitted(47, 2) Source(32, 72) + SourceIndex(2) --- >>>declare namespace internalOther.something { 1-> @@ -655,12 +687,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(47, 1) Source(33, 15) + SourceIndex(2) -2 >Emitted(47, 19) Source(33, 25) + SourceIndex(2) -3 >Emitted(47, 32) Source(33, 38) + SourceIndex(2) -4 >Emitted(47, 33) Source(33, 39) + SourceIndex(2) -5 >Emitted(47, 42) Source(33, 48) + SourceIndex(2) -6 >Emitted(47, 43) Source(33, 49) + SourceIndex(2) +1->Emitted(48, 1) Source(33, 15) + SourceIndex(2) +2 >Emitted(48, 19) Source(33, 25) + SourceIndex(2) +3 >Emitted(48, 32) Source(33, 38) + SourceIndex(2) +4 >Emitted(48, 33) Source(33, 39) + SourceIndex(2) +5 >Emitted(48, 42) Source(33, 48) + SourceIndex(2) +6 >Emitted(48, 43) Source(33, 49) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -669,20 +701,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(48, 5) Source(33, 51) + SourceIndex(2) -2 >Emitted(48, 11) Source(33, 64) + SourceIndex(2) -3 >Emitted(48, 20) Source(33, 73) + SourceIndex(2) +1 >Emitted(49, 5) Source(33, 51) + SourceIndex(2) +2 >Emitted(49, 11) Source(33, 64) + SourceIndex(2) +3 >Emitted(49, 20) Source(33, 73) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(49, 6) Source(33, 76) + SourceIndex(2) +1 >Emitted(50, 6) Source(33, 76) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(50, 2) Source(33, 78) + SourceIndex(2) +1 >Emitted(51, 2) Source(33, 78) + SourceIndex(2) --- >>>import internalImport = internalNamespace.someClass; 1-> @@ -702,14 +734,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > someClass 8 > ; -1->Emitted(51, 1) Source(34, 15) + SourceIndex(2) -2 >Emitted(51, 8) Source(34, 22) + SourceIndex(2) -3 >Emitted(51, 22) Source(34, 36) + SourceIndex(2) -4 >Emitted(51, 25) Source(34, 39) + SourceIndex(2) -5 >Emitted(51, 42) Source(34, 56) + SourceIndex(2) -6 >Emitted(51, 43) Source(34, 57) + SourceIndex(2) -7 >Emitted(51, 52) Source(34, 66) + SourceIndex(2) -8 >Emitted(51, 53) Source(34, 67) + SourceIndex(2) +1->Emitted(52, 1) Source(34, 15) + SourceIndex(2) +2 >Emitted(52, 8) Source(34, 22) + SourceIndex(2) +3 >Emitted(52, 22) Source(34, 36) + SourceIndex(2) +4 >Emitted(52, 25) Source(34, 39) + SourceIndex(2) +5 >Emitted(52, 42) Source(34, 56) + SourceIndex(2) +6 >Emitted(52, 43) Source(34, 57) + SourceIndex(2) +7 >Emitted(52, 52) Source(34, 66) + SourceIndex(2) +8 >Emitted(52, 53) Source(34, 67) + SourceIndex(2) --- >>>declare type internalType = internalC; 1 > @@ -725,12 +757,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(52, 1) Source(35, 15) + SourceIndex(2) -2 >Emitted(52, 14) Source(35, 20) + SourceIndex(2) -3 >Emitted(52, 26) Source(35, 32) + SourceIndex(2) -4 >Emitted(52, 29) Source(35, 35) + SourceIndex(2) -5 >Emitted(52, 38) Source(35, 44) + SourceIndex(2) -6 >Emitted(52, 39) Source(35, 45) + SourceIndex(2) +1 >Emitted(53, 1) Source(35, 15) + SourceIndex(2) +2 >Emitted(53, 14) Source(35, 20) + SourceIndex(2) +3 >Emitted(53, 26) Source(35, 32) + SourceIndex(2) +4 >Emitted(53, 29) Source(35, 35) + SourceIndex(2) +5 >Emitted(53, 38) Source(35, 44) + SourceIndex(2) +6 >Emitted(53, 39) Source(35, 45) + SourceIndex(2) --- >>>declare const internalConst = 10; 1 > @@ -746,12 +778,12 @@ sourceFile:../second/second_part1.ts 4 > internalConst 5 > = 10 6 > ; -1 >Emitted(53, 1) Source(36, 15) + SourceIndex(2) -2 >Emitted(53, 9) Source(36, 15) + SourceIndex(2) -3 >Emitted(53, 15) Source(36, 21) + SourceIndex(2) -4 >Emitted(53, 28) Source(36, 34) + SourceIndex(2) -5 >Emitted(53, 33) Source(36, 39) + SourceIndex(2) -6 >Emitted(53, 34) Source(36, 40) + SourceIndex(2) +1 >Emitted(54, 1) Source(36, 15) + SourceIndex(2) +2 >Emitted(54, 9) Source(36, 15) + SourceIndex(2) +3 >Emitted(54, 15) Source(36, 21) + SourceIndex(2) +4 >Emitted(54, 28) Source(36, 34) + SourceIndex(2) +5 >Emitted(54, 33) Source(36, 39) + SourceIndex(2) +6 >Emitted(54, 34) Source(36, 40) + SourceIndex(2) --- >>>declare enum internalEnum { 1 > @@ -761,9 +793,9 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >enum 3 > internalEnum -1 >Emitted(54, 1) Source(37, 15) + SourceIndex(2) -2 >Emitted(54, 14) Source(37, 20) + SourceIndex(2) -3 >Emitted(54, 26) Source(37, 32) + SourceIndex(2) +1 >Emitted(55, 1) Source(37, 15) + SourceIndex(2) +2 >Emitted(55, 14) Source(37, 20) + SourceIndex(2) +3 >Emitted(55, 26) Source(37, 32) + SourceIndex(2) --- >>> a = 0, 1 >^^^^ @@ -773,9 +805,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(55, 5) Source(37, 35) + SourceIndex(2) -2 >Emitted(55, 6) Source(37, 36) + SourceIndex(2) -3 >Emitted(55, 10) Source(37, 36) + SourceIndex(2) +1 >Emitted(56, 5) Source(37, 35) + SourceIndex(2) +2 >Emitted(56, 6) Source(37, 36) + SourceIndex(2) +3 >Emitted(56, 10) Source(37, 36) + SourceIndex(2) --- >>> b = 1, 1->^^^^ @@ -785,9 +817,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(56, 5) Source(37, 38) + SourceIndex(2) -2 >Emitted(56, 6) Source(37, 39) + SourceIndex(2) -3 >Emitted(56, 10) Source(37, 39) + SourceIndex(2) +1->Emitted(57, 5) Source(37, 38) + SourceIndex(2) +2 >Emitted(57, 6) Source(37, 39) + SourceIndex(2) +3 >Emitted(57, 10) Source(37, 39) + SourceIndex(2) --- >>> c = 2 1->^^^^ @@ -796,15 +828,15 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(57, 5) Source(37, 41) + SourceIndex(2) -2 >Emitted(57, 6) Source(37, 42) + SourceIndex(2) -3 >Emitted(57, 10) Source(37, 42) + SourceIndex(2) +1->Emitted(58, 5) Source(37, 41) + SourceIndex(2) +2 >Emitted(58, 6) Source(37, 42) + SourceIndex(2) +3 >Emitted(58, 10) Source(37, 42) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(58, 2) Source(37, 44) + SourceIndex(2) +1 >Emitted(59, 2) Source(37, 44) + SourceIndex(2) --- ------------------------------------------------------------------- emittedFile:/src/2/second-output.d.ts @@ -818,9 +850,9 @@ sourceFile:../second/second_part2.ts 1-> 2 >class 3 > C -1->Emitted(59, 1) Source(1, 1) + SourceIndex(3) -2 >Emitted(59, 15) Source(1, 7) + SourceIndex(3) -3 >Emitted(59, 16) Source(1, 8) + SourceIndex(3) +1->Emitted(60, 1) Source(1, 1) + SourceIndex(3) +2 >Emitted(60, 15) Source(1, 7) + SourceIndex(3) +3 >Emitted(60, 16) Source(1, 8) + SourceIndex(3) --- >>> doSomething(): void; 1->^^^^ @@ -828,8 +860,8 @@ sourceFile:../second/second_part2.ts 1-> { > 2 > doSomething -1->Emitted(60, 5) Source(2, 5) + SourceIndex(3) -2 >Emitted(60, 16) Source(2, 16) + SourceIndex(3) +1->Emitted(61, 5) Source(2, 5) + SourceIndex(3) +2 >Emitted(61, 16) Source(2, 16) + SourceIndex(3) --- >>>} 1 >^ @@ -838,7 +870,7 @@ sourceFile:../second/second_part2.ts > console.log("something got done"); > } >} -1 >Emitted(61, 2) Source(5, 2) + SourceIndex(3) +1 >Emitted(62, 2) Source(5, 2) + SourceIndex(3) --- >>>//# sourceMappingURL=second-output.d.ts.map @@ -2594,32 +2626,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 234, - "end": 308, + "end": 339, "kind": "internal" }, { - "pos": 310, - "end": 342, + "pos": 341, + "end": 373, "kind": "text" }, { - "pos": 342, - "end": 734, + "pos": 373, + "end": 765, "kind": "internal" }, { - "pos": 736, - "end": 739, + "pos": 767, + "end": 770, "kind": "text" }, { - "pos": 739, - "end": 1152, + "pos": 770, + "end": 1183, "kind": "internal" }, { - "pos": 1154, - "end": 1202, + "pos": 1185, + "end": 1233, "kind": "text" } ] @@ -2774,18 +2806,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (234-308) +internal: (234-339) constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (310-342) +text: (341-373) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (342-734) +internal: (373-765) class C { } function foo(): void; @@ -2806,11 +2839,11 @@ internal: (342-734) c = 2 } ---------------------------------------------------------------------- -text: (736-739) +text: (767-770) } ---------------------------------------------------------------------- -internal: (739-1152) +internal: (770-1183) declare class internalC { } declare function internalfoo(): void; @@ -2831,7 +2864,7 @@ declare enum internalEnum { c = 2 } ---------------------------------------------------------------------- -text: (1154-1202) +text: (1185-1233) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js index 5d2941abca299..c8f5cd986136c 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-with-comments-emit-enabled-when-one-two-three-are-prepended-in-order.js @@ -15,7 +15,8 @@ declare class normalC { constructor(); prop: string; method(): void; - /*@internal*/ c: number; + get c(): number; + set c(val: number); } declare namespace normalN { class C { @@ -63,7 +64,7 @@ declare class C { //# sourceMappingURL=second-output.d.ts.map //// [/src/2/second-output.d.ts.map] -{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAc,UAAU,QAAQ;IAC5B,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;kBACF,CAAC,EACM,MAAM;CAClC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} +{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../first/first_PART1.ts","../first/first_part3.ts","../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAc,UAAU,QAAQ;IAC5B,IAAI,EAAE,GAAG,CAAC;CACb;AAED,QAAA,MAAM,CAAC,iBAAiB,CAAC;AAEzB,UAAU,iBAAiB;IACvB,IAAI,EAAE,GAAG,CAAC;CACb;ACRD,iBAAS,CAAC,WAET;ACFD,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACN,IAAI,CAAC,IACM,MAAM,CADK;IACtB,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;CACvC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} //// [/src/2/second-output.d.ts.map.baseline.txt] =================================================================== @@ -283,35 +284,66 @@ sourceFile:../second/second_part1.ts >>> method(): void; 1->^^^^ 2 > ^^^^^^ -3 > ^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^-> 1-> > /*@internal*/ 2 > method 1->Emitted(16, 5) Source(16, 19) + SourceIndex(2) 2 >Emitted(16, 11) Source(16, 25) + SourceIndex(2) --- ->>> /*@internal*/ c: number; -1->^^^^^^^^^^^^^^^^^^ -2 > ^ -3 > ^^ -4 > ^^^^^^ +>>> get c(): number; +1->^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^^ +5 > ^^^^^^ +6 > ^ +7 > ^^^^-> 1->() { } - > /*@internal*/ get -2 > c -3 > () { return 10; } - > /*@internal*/ set c(val: -4 > number -1->Emitted(17, 19) Source(17, 23) + SourceIndex(2) -2 >Emitted(17, 20) Source(17, 24) + SourceIndex(2) -3 >Emitted(17, 22) Source(18, 30) + SourceIndex(2) -4 >Emitted(17, 28) Source(18, 36) + SourceIndex(2) + > /*@internal*/ +2 > get +3 > c +4 > () { return 10; } + > /*@internal*/ set c(val: +5 > number +6 > +1->Emitted(17, 5) Source(17, 19) + SourceIndex(2) +2 >Emitted(17, 9) Source(17, 23) + SourceIndex(2) +3 >Emitted(17, 10) Source(17, 24) + SourceIndex(2) +4 >Emitted(17, 14) Source(18, 30) + SourceIndex(2) +5 >Emitted(17, 20) Source(18, 36) + SourceIndex(2) +6 >Emitted(17, 21) Source(17, 41) + SourceIndex(2) +--- +>>> set c(val: number); +1->^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^ +6 > ^^^^^^ +7 > ^^ +1-> + > /*@internal*/ +2 > set +3 > c +4 > ( +5 > val: +6 > number +7 > ) { } +1->Emitted(18, 5) Source(18, 19) + SourceIndex(2) +2 >Emitted(18, 9) Source(18, 23) + SourceIndex(2) +3 >Emitted(18, 10) Source(18, 24) + SourceIndex(2) +4 >Emitted(18, 11) Source(18, 25) + SourceIndex(2) +5 >Emitted(18, 16) Source(18, 30) + SourceIndex(2) +6 >Emitted(18, 22) Source(18, 36) + SourceIndex(2) +7 >Emitted(18, 24) Source(18, 41) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(18, 2) Source(19, 2) + SourceIndex(2) +1 >Emitted(19, 2) Source(19, 2) + SourceIndex(2) --- >>>declare namespace normalN { 1-> @@ -323,10 +355,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > normalN 4 > -1->Emitted(19, 1) Source(20, 1) + SourceIndex(2) -2 >Emitted(19, 19) Source(20, 11) + SourceIndex(2) -3 >Emitted(19, 26) Source(20, 18) + SourceIndex(2) -4 >Emitted(19, 27) Source(20, 19) + SourceIndex(2) +1->Emitted(20, 1) Source(20, 1) + SourceIndex(2) +2 >Emitted(20, 19) Source(20, 11) + SourceIndex(2) +3 >Emitted(20, 26) Source(20, 18) + SourceIndex(2) +4 >Emitted(20, 27) Source(20, 19) + SourceIndex(2) --- >>> class C { 1 >^^^^ @@ -336,15 +368,15 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export class 3 > C -1 >Emitted(20, 5) Source(21, 19) + SourceIndex(2) -2 >Emitted(20, 11) Source(21, 32) + SourceIndex(2) -3 >Emitted(20, 12) Source(21, 33) + SourceIndex(2) +1 >Emitted(21, 5) Source(21, 19) + SourceIndex(2) +2 >Emitted(21, 11) Source(21, 32) + SourceIndex(2) +3 >Emitted(21, 12) Source(21, 33) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(21, 6) Source(21, 37) + SourceIndex(2) +1 >Emitted(22, 6) Source(21, 37) + SourceIndex(2) --- >>> function foo(): void; 1->^^^^ @@ -357,10 +389,10 @@ sourceFile:../second/second_part1.ts 2 > export function 3 > foo 4 > () {} -1->Emitted(22, 5) Source(22, 19) + SourceIndex(2) -2 >Emitted(22, 14) Source(22, 35) + SourceIndex(2) -3 >Emitted(22, 17) Source(22, 38) + SourceIndex(2) -4 >Emitted(22, 26) Source(22, 43) + SourceIndex(2) +1->Emitted(23, 5) Source(22, 19) + SourceIndex(2) +2 >Emitted(23, 14) Source(22, 35) + SourceIndex(2) +3 >Emitted(23, 17) Source(22, 38) + SourceIndex(2) +4 >Emitted(23, 26) Source(22, 43) + SourceIndex(2) --- >>> namespace someNamespace { 1->^^^^ @@ -372,10 +404,10 @@ sourceFile:../second/second_part1.ts 2 > export namespace 3 > someNamespace 4 > -1->Emitted(23, 5) Source(23, 19) + SourceIndex(2) -2 >Emitted(23, 15) Source(23, 36) + SourceIndex(2) -3 >Emitted(23, 28) Source(23, 49) + SourceIndex(2) -4 >Emitted(23, 29) Source(23, 50) + SourceIndex(2) +1->Emitted(24, 5) Source(23, 19) + SourceIndex(2) +2 >Emitted(24, 15) Source(23, 36) + SourceIndex(2) +3 >Emitted(24, 28) Source(23, 49) + SourceIndex(2) +4 >Emitted(24, 29) Source(23, 50) + SourceIndex(2) --- >>> class C { 1 >^^^^^^^^ @@ -384,20 +416,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(24, 9) Source(23, 52) + SourceIndex(2) -2 >Emitted(24, 15) Source(23, 65) + SourceIndex(2) -3 >Emitted(24, 16) Source(23, 66) + SourceIndex(2) +1 >Emitted(25, 9) Source(23, 52) + SourceIndex(2) +2 >Emitted(25, 15) Source(23, 65) + SourceIndex(2) +3 >Emitted(25, 16) Source(23, 66) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(25, 10) Source(23, 69) + SourceIndex(2) +1 >Emitted(26, 10) Source(23, 69) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(26, 6) Source(23, 71) + SourceIndex(2) +1 >Emitted(27, 6) Source(23, 71) + SourceIndex(2) --- >>> namespace someOther.something { 1->^^^^ @@ -413,12 +445,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(27, 5) Source(24, 19) + SourceIndex(2) -2 >Emitted(27, 15) Source(24, 36) + SourceIndex(2) -3 >Emitted(27, 24) Source(24, 45) + SourceIndex(2) -4 >Emitted(27, 25) Source(24, 46) + SourceIndex(2) -5 >Emitted(27, 34) Source(24, 55) + SourceIndex(2) -6 >Emitted(27, 35) Source(24, 56) + SourceIndex(2) +1->Emitted(28, 5) Source(24, 19) + SourceIndex(2) +2 >Emitted(28, 15) Source(24, 36) + SourceIndex(2) +3 >Emitted(28, 24) Source(24, 45) + SourceIndex(2) +4 >Emitted(28, 25) Source(24, 46) + SourceIndex(2) +5 >Emitted(28, 34) Source(24, 55) + SourceIndex(2) +6 >Emitted(28, 35) Source(24, 56) + SourceIndex(2) --- >>> class someClass { 1 >^^^^^^^^ @@ -427,20 +459,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(28, 9) Source(24, 58) + SourceIndex(2) -2 >Emitted(28, 15) Source(24, 71) + SourceIndex(2) -3 >Emitted(28, 24) Source(24, 80) + SourceIndex(2) +1 >Emitted(29, 9) Source(24, 58) + SourceIndex(2) +2 >Emitted(29, 15) Source(24, 71) + SourceIndex(2) +3 >Emitted(29, 24) Source(24, 80) + SourceIndex(2) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(29, 10) Source(24, 83) + SourceIndex(2) +1 >Emitted(30, 10) Source(24, 83) + SourceIndex(2) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(30, 6) Source(24, 85) + SourceIndex(2) +1 >Emitted(31, 6) Source(24, 85) + SourceIndex(2) --- >>> export import someImport = someNamespace.C; 1->^^^^ @@ -462,15 +494,15 @@ sourceFile:../second/second_part1.ts 7 > . 8 > C 9 > ; -1->Emitted(31, 5) Source(25, 19) + SourceIndex(2) -2 >Emitted(31, 11) Source(25, 25) + SourceIndex(2) -3 >Emitted(31, 19) Source(25, 33) + SourceIndex(2) -4 >Emitted(31, 29) Source(25, 43) + SourceIndex(2) -5 >Emitted(31, 32) Source(25, 46) + SourceIndex(2) -6 >Emitted(31, 45) Source(25, 59) + SourceIndex(2) -7 >Emitted(31, 46) Source(25, 60) + SourceIndex(2) -8 >Emitted(31, 47) Source(25, 61) + SourceIndex(2) -9 >Emitted(31, 48) Source(25, 62) + SourceIndex(2) +1->Emitted(32, 5) Source(25, 19) + SourceIndex(2) +2 >Emitted(32, 11) Source(25, 25) + SourceIndex(2) +3 >Emitted(32, 19) Source(25, 33) + SourceIndex(2) +4 >Emitted(32, 29) Source(25, 43) + SourceIndex(2) +5 >Emitted(32, 32) Source(25, 46) + SourceIndex(2) +6 >Emitted(32, 45) Source(25, 59) + SourceIndex(2) +7 >Emitted(32, 46) Source(25, 60) + SourceIndex(2) +8 >Emitted(32, 47) Source(25, 61) + SourceIndex(2) +9 >Emitted(32, 48) Source(25, 62) + SourceIndex(2) --- >>> type internalType = internalC; 1 >^^^^ @@ -486,12 +518,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(32, 5) Source(26, 19) + SourceIndex(2) -2 >Emitted(32, 10) Source(26, 31) + SourceIndex(2) -3 >Emitted(32, 22) Source(26, 43) + SourceIndex(2) -4 >Emitted(32, 25) Source(26, 46) + SourceIndex(2) -5 >Emitted(32, 34) Source(26, 55) + SourceIndex(2) -6 >Emitted(32, 35) Source(26, 56) + SourceIndex(2) +1 >Emitted(33, 5) Source(26, 19) + SourceIndex(2) +2 >Emitted(33, 10) Source(26, 31) + SourceIndex(2) +3 >Emitted(33, 22) Source(26, 43) + SourceIndex(2) +4 >Emitted(33, 25) Source(26, 46) + SourceIndex(2) +5 >Emitted(33, 34) Source(26, 55) + SourceIndex(2) +6 >Emitted(33, 35) Source(26, 56) + SourceIndex(2) --- >>> const internalConst = 10; 1 >^^^^ @@ -505,11 +537,11 @@ sourceFile:../second/second_part1.ts 3 > internalConst 4 > = 10 5 > ; -1 >Emitted(33, 5) Source(27, 26) + SourceIndex(2) -2 >Emitted(33, 11) Source(27, 32) + SourceIndex(2) -3 >Emitted(33, 24) Source(27, 45) + SourceIndex(2) -4 >Emitted(33, 29) Source(27, 50) + SourceIndex(2) -5 >Emitted(33, 30) Source(27, 51) + SourceIndex(2) +1 >Emitted(34, 5) Source(27, 26) + SourceIndex(2) +2 >Emitted(34, 11) Source(27, 32) + SourceIndex(2) +3 >Emitted(34, 24) Source(27, 45) + SourceIndex(2) +4 >Emitted(34, 29) Source(27, 50) + SourceIndex(2) +5 >Emitted(34, 30) Source(27, 51) + SourceIndex(2) --- >>> enum internalEnum { 1 >^^^^ @@ -519,9 +551,9 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export enum 3 > internalEnum -1 >Emitted(34, 5) Source(28, 19) + SourceIndex(2) -2 >Emitted(34, 10) Source(28, 31) + SourceIndex(2) -3 >Emitted(34, 22) Source(28, 43) + SourceIndex(2) +1 >Emitted(35, 5) Source(28, 19) + SourceIndex(2) +2 >Emitted(35, 10) Source(28, 31) + SourceIndex(2) +3 >Emitted(35, 22) Source(28, 43) + SourceIndex(2) --- >>> a = 0, 1 >^^^^^^^^ @@ -531,9 +563,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(35, 9) Source(28, 46) + SourceIndex(2) -2 >Emitted(35, 10) Source(28, 47) + SourceIndex(2) -3 >Emitted(35, 14) Source(28, 47) + SourceIndex(2) +1 >Emitted(36, 9) Source(28, 46) + SourceIndex(2) +2 >Emitted(36, 10) Source(28, 47) + SourceIndex(2) +3 >Emitted(36, 14) Source(28, 47) + SourceIndex(2) --- >>> b = 1, 1->^^^^^^^^ @@ -543,9 +575,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(36, 9) Source(28, 49) + SourceIndex(2) -2 >Emitted(36, 10) Source(28, 50) + SourceIndex(2) -3 >Emitted(36, 14) Source(28, 50) + SourceIndex(2) +1->Emitted(37, 9) Source(28, 49) + SourceIndex(2) +2 >Emitted(37, 10) Source(28, 50) + SourceIndex(2) +3 >Emitted(37, 14) Source(28, 50) + SourceIndex(2) --- >>> c = 2 1->^^^^^^^^ @@ -554,21 +586,21 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(37, 9) Source(28, 52) + SourceIndex(2) -2 >Emitted(37, 10) Source(28, 53) + SourceIndex(2) -3 >Emitted(37, 14) Source(28, 53) + SourceIndex(2) +1->Emitted(38, 9) Source(28, 52) + SourceIndex(2) +2 >Emitted(38, 10) Source(28, 53) + SourceIndex(2) +3 >Emitted(38, 14) Source(28, 53) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(38, 6) Source(28, 55) + SourceIndex(2) +1 >Emitted(39, 6) Source(28, 55) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(39, 2) Source(29, 2) + SourceIndex(2) +1 >Emitted(40, 2) Source(29, 2) + SourceIndex(2) --- >>>declare class internalC { 1-> @@ -578,15 +610,15 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >class 3 > internalC -1->Emitted(40, 1) Source(30, 15) + SourceIndex(2) -2 >Emitted(40, 15) Source(30, 21) + SourceIndex(2) -3 >Emitted(40, 24) Source(30, 30) + SourceIndex(2) +1->Emitted(41, 1) Source(30, 15) + SourceIndex(2) +2 >Emitted(41, 15) Source(30, 21) + SourceIndex(2) +3 >Emitted(41, 24) Source(30, 30) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(41, 2) Source(30, 33) + SourceIndex(2) +1 >Emitted(42, 2) Source(30, 33) + SourceIndex(2) --- >>>declare function internalfoo(): void; 1-> @@ -599,10 +631,10 @@ sourceFile:../second/second_part1.ts 2 >function 3 > internalfoo 4 > () {} -1->Emitted(42, 1) Source(31, 15) + SourceIndex(2) -2 >Emitted(42, 18) Source(31, 24) + SourceIndex(2) -3 >Emitted(42, 29) Source(31, 35) + SourceIndex(2) -4 >Emitted(42, 38) Source(31, 40) + SourceIndex(2) +1->Emitted(43, 1) Source(31, 15) + SourceIndex(2) +2 >Emitted(43, 18) Source(31, 24) + SourceIndex(2) +3 >Emitted(43, 29) Source(31, 35) + SourceIndex(2) +4 >Emitted(43, 38) Source(31, 40) + SourceIndex(2) --- >>>declare namespace internalNamespace { 1-> @@ -614,10 +646,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > internalNamespace 4 > -1->Emitted(43, 1) Source(32, 15) + SourceIndex(2) -2 >Emitted(43, 19) Source(32, 25) + SourceIndex(2) -3 >Emitted(43, 36) Source(32, 42) + SourceIndex(2) -4 >Emitted(43, 37) Source(32, 43) + SourceIndex(2) +1->Emitted(44, 1) Source(32, 15) + SourceIndex(2) +2 >Emitted(44, 19) Source(32, 25) + SourceIndex(2) +3 >Emitted(44, 36) Source(32, 42) + SourceIndex(2) +4 >Emitted(44, 37) Source(32, 43) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -626,20 +658,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(44, 5) Source(32, 45) + SourceIndex(2) -2 >Emitted(44, 11) Source(32, 58) + SourceIndex(2) -3 >Emitted(44, 20) Source(32, 67) + SourceIndex(2) +1 >Emitted(45, 5) Source(32, 45) + SourceIndex(2) +2 >Emitted(45, 11) Source(32, 58) + SourceIndex(2) +3 >Emitted(45, 20) Source(32, 67) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(45, 6) Source(32, 70) + SourceIndex(2) +1 >Emitted(46, 6) Source(32, 70) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(46, 2) Source(32, 72) + SourceIndex(2) +1 >Emitted(47, 2) Source(32, 72) + SourceIndex(2) --- >>>declare namespace internalOther.something { 1-> @@ -655,12 +687,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(47, 1) Source(33, 15) + SourceIndex(2) -2 >Emitted(47, 19) Source(33, 25) + SourceIndex(2) -3 >Emitted(47, 32) Source(33, 38) + SourceIndex(2) -4 >Emitted(47, 33) Source(33, 39) + SourceIndex(2) -5 >Emitted(47, 42) Source(33, 48) + SourceIndex(2) -6 >Emitted(47, 43) Source(33, 49) + SourceIndex(2) +1->Emitted(48, 1) Source(33, 15) + SourceIndex(2) +2 >Emitted(48, 19) Source(33, 25) + SourceIndex(2) +3 >Emitted(48, 32) Source(33, 38) + SourceIndex(2) +4 >Emitted(48, 33) Source(33, 39) + SourceIndex(2) +5 >Emitted(48, 42) Source(33, 48) + SourceIndex(2) +6 >Emitted(48, 43) Source(33, 49) + SourceIndex(2) --- >>> class someClass { 1 >^^^^ @@ -669,20 +701,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(48, 5) Source(33, 51) + SourceIndex(2) -2 >Emitted(48, 11) Source(33, 64) + SourceIndex(2) -3 >Emitted(48, 20) Source(33, 73) + SourceIndex(2) +1 >Emitted(49, 5) Source(33, 51) + SourceIndex(2) +2 >Emitted(49, 11) Source(33, 64) + SourceIndex(2) +3 >Emitted(49, 20) Source(33, 73) + SourceIndex(2) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(49, 6) Source(33, 76) + SourceIndex(2) +1 >Emitted(50, 6) Source(33, 76) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(50, 2) Source(33, 78) + SourceIndex(2) +1 >Emitted(51, 2) Source(33, 78) + SourceIndex(2) --- >>>import internalImport = internalNamespace.someClass; 1-> @@ -702,14 +734,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > someClass 8 > ; -1->Emitted(51, 1) Source(34, 15) + SourceIndex(2) -2 >Emitted(51, 8) Source(34, 22) + SourceIndex(2) -3 >Emitted(51, 22) Source(34, 36) + SourceIndex(2) -4 >Emitted(51, 25) Source(34, 39) + SourceIndex(2) -5 >Emitted(51, 42) Source(34, 56) + SourceIndex(2) -6 >Emitted(51, 43) Source(34, 57) + SourceIndex(2) -7 >Emitted(51, 52) Source(34, 66) + SourceIndex(2) -8 >Emitted(51, 53) Source(34, 67) + SourceIndex(2) +1->Emitted(52, 1) Source(34, 15) + SourceIndex(2) +2 >Emitted(52, 8) Source(34, 22) + SourceIndex(2) +3 >Emitted(52, 22) Source(34, 36) + SourceIndex(2) +4 >Emitted(52, 25) Source(34, 39) + SourceIndex(2) +5 >Emitted(52, 42) Source(34, 56) + SourceIndex(2) +6 >Emitted(52, 43) Source(34, 57) + SourceIndex(2) +7 >Emitted(52, 52) Source(34, 66) + SourceIndex(2) +8 >Emitted(52, 53) Source(34, 67) + SourceIndex(2) --- >>>declare type internalType = internalC; 1 > @@ -725,12 +757,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(52, 1) Source(35, 15) + SourceIndex(2) -2 >Emitted(52, 14) Source(35, 20) + SourceIndex(2) -3 >Emitted(52, 26) Source(35, 32) + SourceIndex(2) -4 >Emitted(52, 29) Source(35, 35) + SourceIndex(2) -5 >Emitted(52, 38) Source(35, 44) + SourceIndex(2) -6 >Emitted(52, 39) Source(35, 45) + SourceIndex(2) +1 >Emitted(53, 1) Source(35, 15) + SourceIndex(2) +2 >Emitted(53, 14) Source(35, 20) + SourceIndex(2) +3 >Emitted(53, 26) Source(35, 32) + SourceIndex(2) +4 >Emitted(53, 29) Source(35, 35) + SourceIndex(2) +5 >Emitted(53, 38) Source(35, 44) + SourceIndex(2) +6 >Emitted(53, 39) Source(35, 45) + SourceIndex(2) --- >>>declare const internalConst = 10; 1 > @@ -746,12 +778,12 @@ sourceFile:../second/second_part1.ts 4 > internalConst 5 > = 10 6 > ; -1 >Emitted(53, 1) Source(36, 15) + SourceIndex(2) -2 >Emitted(53, 9) Source(36, 15) + SourceIndex(2) -3 >Emitted(53, 15) Source(36, 21) + SourceIndex(2) -4 >Emitted(53, 28) Source(36, 34) + SourceIndex(2) -5 >Emitted(53, 33) Source(36, 39) + SourceIndex(2) -6 >Emitted(53, 34) Source(36, 40) + SourceIndex(2) +1 >Emitted(54, 1) Source(36, 15) + SourceIndex(2) +2 >Emitted(54, 9) Source(36, 15) + SourceIndex(2) +3 >Emitted(54, 15) Source(36, 21) + SourceIndex(2) +4 >Emitted(54, 28) Source(36, 34) + SourceIndex(2) +5 >Emitted(54, 33) Source(36, 39) + SourceIndex(2) +6 >Emitted(54, 34) Source(36, 40) + SourceIndex(2) --- >>>declare enum internalEnum { 1 > @@ -761,9 +793,9 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >enum 3 > internalEnum -1 >Emitted(54, 1) Source(37, 15) + SourceIndex(2) -2 >Emitted(54, 14) Source(37, 20) + SourceIndex(2) -3 >Emitted(54, 26) Source(37, 32) + SourceIndex(2) +1 >Emitted(55, 1) Source(37, 15) + SourceIndex(2) +2 >Emitted(55, 14) Source(37, 20) + SourceIndex(2) +3 >Emitted(55, 26) Source(37, 32) + SourceIndex(2) --- >>> a = 0, 1 >^^^^ @@ -773,9 +805,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(55, 5) Source(37, 35) + SourceIndex(2) -2 >Emitted(55, 6) Source(37, 36) + SourceIndex(2) -3 >Emitted(55, 10) Source(37, 36) + SourceIndex(2) +1 >Emitted(56, 5) Source(37, 35) + SourceIndex(2) +2 >Emitted(56, 6) Source(37, 36) + SourceIndex(2) +3 >Emitted(56, 10) Source(37, 36) + SourceIndex(2) --- >>> b = 1, 1->^^^^ @@ -785,9 +817,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(56, 5) Source(37, 38) + SourceIndex(2) -2 >Emitted(56, 6) Source(37, 39) + SourceIndex(2) -3 >Emitted(56, 10) Source(37, 39) + SourceIndex(2) +1->Emitted(57, 5) Source(37, 38) + SourceIndex(2) +2 >Emitted(57, 6) Source(37, 39) + SourceIndex(2) +3 >Emitted(57, 10) Source(37, 39) + SourceIndex(2) --- >>> c = 2 1->^^^^ @@ -796,15 +828,15 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(57, 5) Source(37, 41) + SourceIndex(2) -2 >Emitted(57, 6) Source(37, 42) + SourceIndex(2) -3 >Emitted(57, 10) Source(37, 42) + SourceIndex(2) +1->Emitted(58, 5) Source(37, 41) + SourceIndex(2) +2 >Emitted(58, 6) Source(37, 42) + SourceIndex(2) +3 >Emitted(58, 10) Source(37, 42) + SourceIndex(2) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(58, 2) Source(37, 44) + SourceIndex(2) +1 >Emitted(59, 2) Source(37, 44) + SourceIndex(2) --- ------------------------------------------------------------------- emittedFile:/src/2/second-output.d.ts @@ -818,9 +850,9 @@ sourceFile:../second/second_part2.ts 1-> 2 >class 3 > C -1->Emitted(59, 1) Source(1, 1) + SourceIndex(3) -2 >Emitted(59, 15) Source(1, 7) + SourceIndex(3) -3 >Emitted(59, 16) Source(1, 8) + SourceIndex(3) +1->Emitted(60, 1) Source(1, 1) + SourceIndex(3) +2 >Emitted(60, 15) Source(1, 7) + SourceIndex(3) +3 >Emitted(60, 16) Source(1, 8) + SourceIndex(3) --- >>> doSomething(): void; 1->^^^^ @@ -828,8 +860,8 @@ sourceFile:../second/second_part2.ts 1-> { > 2 > doSomething -1->Emitted(60, 5) Source(2, 5) + SourceIndex(3) -2 >Emitted(60, 16) Source(2, 16) + SourceIndex(3) +1->Emitted(61, 5) Source(2, 5) + SourceIndex(3) +2 >Emitted(61, 16) Source(2, 16) + SourceIndex(3) --- >>>} 1 >^ @@ -838,7 +870,7 @@ sourceFile:../second/second_part2.ts > console.log("something got done"); > } >} -1 >Emitted(61, 2) Source(5, 2) + SourceIndex(3) +1 >Emitted(62, 2) Source(5, 2) + SourceIndex(3) --- >>>//# sourceMappingURL=second-output.d.ts.map @@ -2694,32 +2726,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 234, - "end": 322, + "end": 339, "kind": "internal" }, { - "pos": 324, - "end": 356, + "pos": 341, + "end": 373, "kind": "text" }, { - "pos": 356, - "end": 748, + "pos": 373, + "end": 765, "kind": "internal" }, { - "pos": 750, - "end": 753, + "pos": 767, + "end": 770, "kind": "text" }, { - "pos": 753, - "end": 1166, + "pos": 770, + "end": 1183, "kind": "internal" }, { - "pos": 1168, - "end": 1216, + "pos": 1185, + "end": 1233, "kind": "text" } ] @@ -2874,18 +2906,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (234-322) +internal: (234-339) constructor(); prop: string; method(): void; - /*@internal*/ c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (324-356) +text: (341-373) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (356-748) +internal: (373-765) class C { } function foo(): void; @@ -2906,11 +2939,11 @@ internal: (356-748) c = 2 } ---------------------------------------------------------------------- -text: (750-753) +text: (767-770) } ---------------------------------------------------------------------- -internal: (753-1166) +internal: (770-1183) declare class internalC { } declare function internalfoo(): void; @@ -2931,7 +2964,7 @@ declare enum internalEnum { c = 2 } ---------------------------------------------------------------------- -text: (1168-1216) +text: (1185-1233) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-with-comments-emit-enabled.js b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-with-comments-emit-enabled.js index 2475d4e4eda78..a54c5109af8b6 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-with-comments-emit-enabled.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal-with-comments-emit-enabled.js @@ -7,7 +7,8 @@ declare class normalC { constructor(); prop: string; method(): void; - /*@internal*/ c: number; + get c(): number; + set c(val: number); } declare namespace normalN { class C { @@ -55,7 +56,7 @@ declare class C { //# sourceMappingURL=second-output.d.ts.map //// [/src/2/second-output.d.ts.map] -{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;kBACF,CAAC,EACM,MAAM;CAClC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} +{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACN,IAAI,CAAC,IACM,MAAM,CADK;IACtB,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;CACvC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} //// [/src/2/second-output.d.ts.map.baseline.txt] =================================================================== @@ -155,35 +156,66 @@ sourceFile:../second/second_part1.ts >>> method(): void; 1->^^^^ 2 > ^^^^^^ -3 > ^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^-> 1-> > /*@internal*/ 2 > method 1->Emitted(8, 5) Source(16, 19) + SourceIndex(0) 2 >Emitted(8, 11) Source(16, 25) + SourceIndex(0) --- ->>> /*@internal*/ c: number; -1->^^^^^^^^^^^^^^^^^^ -2 > ^ -3 > ^^ -4 > ^^^^^^ +>>> get c(): number; +1->^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^^ +5 > ^^^^^^ +6 > ^ +7 > ^^^^-> 1->() { } - > /*@internal*/ get -2 > c -3 > () { return 10; } - > /*@internal*/ set c(val: -4 > number -1->Emitted(9, 19) Source(17, 23) + SourceIndex(0) -2 >Emitted(9, 20) Source(17, 24) + SourceIndex(0) -3 >Emitted(9, 22) Source(18, 30) + SourceIndex(0) -4 >Emitted(9, 28) Source(18, 36) + SourceIndex(0) + > /*@internal*/ +2 > get +3 > c +4 > () { return 10; } + > /*@internal*/ set c(val: +5 > number +6 > +1->Emitted(9, 5) Source(17, 19) + SourceIndex(0) +2 >Emitted(9, 9) Source(17, 23) + SourceIndex(0) +3 >Emitted(9, 10) Source(17, 24) + SourceIndex(0) +4 >Emitted(9, 14) Source(18, 30) + SourceIndex(0) +5 >Emitted(9, 20) Source(18, 36) + SourceIndex(0) +6 >Emitted(9, 21) Source(17, 41) + SourceIndex(0) +--- +>>> set c(val: number); +1->^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^ +6 > ^^^^^^ +7 > ^^ +1-> + > /*@internal*/ +2 > set +3 > c +4 > ( +5 > val: +6 > number +7 > ) { } +1->Emitted(10, 5) Source(18, 19) + SourceIndex(0) +2 >Emitted(10, 9) Source(18, 23) + SourceIndex(0) +3 >Emitted(10, 10) Source(18, 24) + SourceIndex(0) +4 >Emitted(10, 11) Source(18, 25) + SourceIndex(0) +5 >Emitted(10, 16) Source(18, 30) + SourceIndex(0) +6 >Emitted(10, 22) Source(18, 36) + SourceIndex(0) +7 >Emitted(10, 24) Source(18, 41) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(10, 2) Source(19, 2) + SourceIndex(0) +1 >Emitted(11, 2) Source(19, 2) + SourceIndex(0) --- >>>declare namespace normalN { 1-> @@ -195,10 +227,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > normalN 4 > -1->Emitted(11, 1) Source(20, 1) + SourceIndex(0) -2 >Emitted(11, 19) Source(20, 11) + SourceIndex(0) -3 >Emitted(11, 26) Source(20, 18) + SourceIndex(0) -4 >Emitted(11, 27) Source(20, 19) + SourceIndex(0) +1->Emitted(12, 1) Source(20, 1) + SourceIndex(0) +2 >Emitted(12, 19) Source(20, 11) + SourceIndex(0) +3 >Emitted(12, 26) Source(20, 18) + SourceIndex(0) +4 >Emitted(12, 27) Source(20, 19) + SourceIndex(0) --- >>> class C { 1 >^^^^ @@ -208,15 +240,15 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export class 3 > C -1 >Emitted(12, 5) Source(21, 19) + SourceIndex(0) -2 >Emitted(12, 11) Source(21, 32) + SourceIndex(0) -3 >Emitted(12, 12) Source(21, 33) + SourceIndex(0) +1 >Emitted(13, 5) Source(21, 19) + SourceIndex(0) +2 >Emitted(13, 11) Source(21, 32) + SourceIndex(0) +3 >Emitted(13, 12) Source(21, 33) + SourceIndex(0) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(13, 6) Source(21, 37) + SourceIndex(0) +1 >Emitted(14, 6) Source(21, 37) + SourceIndex(0) --- >>> function foo(): void; 1->^^^^ @@ -229,10 +261,10 @@ sourceFile:../second/second_part1.ts 2 > export function 3 > foo 4 > () {} -1->Emitted(14, 5) Source(22, 19) + SourceIndex(0) -2 >Emitted(14, 14) Source(22, 35) + SourceIndex(0) -3 >Emitted(14, 17) Source(22, 38) + SourceIndex(0) -4 >Emitted(14, 26) Source(22, 43) + SourceIndex(0) +1->Emitted(15, 5) Source(22, 19) + SourceIndex(0) +2 >Emitted(15, 14) Source(22, 35) + SourceIndex(0) +3 >Emitted(15, 17) Source(22, 38) + SourceIndex(0) +4 >Emitted(15, 26) Source(22, 43) + SourceIndex(0) --- >>> namespace someNamespace { 1->^^^^ @@ -244,10 +276,10 @@ sourceFile:../second/second_part1.ts 2 > export namespace 3 > someNamespace 4 > -1->Emitted(15, 5) Source(23, 19) + SourceIndex(0) -2 >Emitted(15, 15) Source(23, 36) + SourceIndex(0) -3 >Emitted(15, 28) Source(23, 49) + SourceIndex(0) -4 >Emitted(15, 29) Source(23, 50) + SourceIndex(0) +1->Emitted(16, 5) Source(23, 19) + SourceIndex(0) +2 >Emitted(16, 15) Source(23, 36) + SourceIndex(0) +3 >Emitted(16, 28) Source(23, 49) + SourceIndex(0) +4 >Emitted(16, 29) Source(23, 50) + SourceIndex(0) --- >>> class C { 1 >^^^^^^^^ @@ -256,20 +288,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(16, 9) Source(23, 52) + SourceIndex(0) -2 >Emitted(16, 15) Source(23, 65) + SourceIndex(0) -3 >Emitted(16, 16) Source(23, 66) + SourceIndex(0) +1 >Emitted(17, 9) Source(23, 52) + SourceIndex(0) +2 >Emitted(17, 15) Source(23, 65) + SourceIndex(0) +3 >Emitted(17, 16) Source(23, 66) + SourceIndex(0) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(17, 10) Source(23, 69) + SourceIndex(0) +1 >Emitted(18, 10) Source(23, 69) + SourceIndex(0) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(18, 6) Source(23, 71) + SourceIndex(0) +1 >Emitted(19, 6) Source(23, 71) + SourceIndex(0) --- >>> namespace someOther.something { 1->^^^^ @@ -285,12 +317,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(19, 5) Source(24, 19) + SourceIndex(0) -2 >Emitted(19, 15) Source(24, 36) + SourceIndex(0) -3 >Emitted(19, 24) Source(24, 45) + SourceIndex(0) -4 >Emitted(19, 25) Source(24, 46) + SourceIndex(0) -5 >Emitted(19, 34) Source(24, 55) + SourceIndex(0) -6 >Emitted(19, 35) Source(24, 56) + SourceIndex(0) +1->Emitted(20, 5) Source(24, 19) + SourceIndex(0) +2 >Emitted(20, 15) Source(24, 36) + SourceIndex(0) +3 >Emitted(20, 24) Source(24, 45) + SourceIndex(0) +4 >Emitted(20, 25) Source(24, 46) + SourceIndex(0) +5 >Emitted(20, 34) Source(24, 55) + SourceIndex(0) +6 >Emitted(20, 35) Source(24, 56) + SourceIndex(0) --- >>> class someClass { 1 >^^^^^^^^ @@ -299,20 +331,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(20, 9) Source(24, 58) + SourceIndex(0) -2 >Emitted(20, 15) Source(24, 71) + SourceIndex(0) -3 >Emitted(20, 24) Source(24, 80) + SourceIndex(0) +1 >Emitted(21, 9) Source(24, 58) + SourceIndex(0) +2 >Emitted(21, 15) Source(24, 71) + SourceIndex(0) +3 >Emitted(21, 24) Source(24, 80) + SourceIndex(0) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(21, 10) Source(24, 83) + SourceIndex(0) +1 >Emitted(22, 10) Source(24, 83) + SourceIndex(0) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(22, 6) Source(24, 85) + SourceIndex(0) +1 >Emitted(23, 6) Source(24, 85) + SourceIndex(0) --- >>> export import someImport = someNamespace.C; 1->^^^^ @@ -334,15 +366,15 @@ sourceFile:../second/second_part1.ts 7 > . 8 > C 9 > ; -1->Emitted(23, 5) Source(25, 19) + SourceIndex(0) -2 >Emitted(23, 11) Source(25, 25) + SourceIndex(0) -3 >Emitted(23, 19) Source(25, 33) + SourceIndex(0) -4 >Emitted(23, 29) Source(25, 43) + SourceIndex(0) -5 >Emitted(23, 32) Source(25, 46) + SourceIndex(0) -6 >Emitted(23, 45) Source(25, 59) + SourceIndex(0) -7 >Emitted(23, 46) Source(25, 60) + SourceIndex(0) -8 >Emitted(23, 47) Source(25, 61) + SourceIndex(0) -9 >Emitted(23, 48) Source(25, 62) + SourceIndex(0) +1->Emitted(24, 5) Source(25, 19) + SourceIndex(0) +2 >Emitted(24, 11) Source(25, 25) + SourceIndex(0) +3 >Emitted(24, 19) Source(25, 33) + SourceIndex(0) +4 >Emitted(24, 29) Source(25, 43) + SourceIndex(0) +5 >Emitted(24, 32) Source(25, 46) + SourceIndex(0) +6 >Emitted(24, 45) Source(25, 59) + SourceIndex(0) +7 >Emitted(24, 46) Source(25, 60) + SourceIndex(0) +8 >Emitted(24, 47) Source(25, 61) + SourceIndex(0) +9 >Emitted(24, 48) Source(25, 62) + SourceIndex(0) --- >>> type internalType = internalC; 1 >^^^^ @@ -358,12 +390,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(24, 5) Source(26, 19) + SourceIndex(0) -2 >Emitted(24, 10) Source(26, 31) + SourceIndex(0) -3 >Emitted(24, 22) Source(26, 43) + SourceIndex(0) -4 >Emitted(24, 25) Source(26, 46) + SourceIndex(0) -5 >Emitted(24, 34) Source(26, 55) + SourceIndex(0) -6 >Emitted(24, 35) Source(26, 56) + SourceIndex(0) +1 >Emitted(25, 5) Source(26, 19) + SourceIndex(0) +2 >Emitted(25, 10) Source(26, 31) + SourceIndex(0) +3 >Emitted(25, 22) Source(26, 43) + SourceIndex(0) +4 >Emitted(25, 25) Source(26, 46) + SourceIndex(0) +5 >Emitted(25, 34) Source(26, 55) + SourceIndex(0) +6 >Emitted(25, 35) Source(26, 56) + SourceIndex(0) --- >>> const internalConst = 10; 1 >^^^^ @@ -377,11 +409,11 @@ sourceFile:../second/second_part1.ts 3 > internalConst 4 > = 10 5 > ; -1 >Emitted(25, 5) Source(27, 26) + SourceIndex(0) -2 >Emitted(25, 11) Source(27, 32) + SourceIndex(0) -3 >Emitted(25, 24) Source(27, 45) + SourceIndex(0) -4 >Emitted(25, 29) Source(27, 50) + SourceIndex(0) -5 >Emitted(25, 30) Source(27, 51) + SourceIndex(0) +1 >Emitted(26, 5) Source(27, 26) + SourceIndex(0) +2 >Emitted(26, 11) Source(27, 32) + SourceIndex(0) +3 >Emitted(26, 24) Source(27, 45) + SourceIndex(0) +4 >Emitted(26, 29) Source(27, 50) + SourceIndex(0) +5 >Emitted(26, 30) Source(27, 51) + SourceIndex(0) --- >>> enum internalEnum { 1 >^^^^ @@ -391,9 +423,9 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export enum 3 > internalEnum -1 >Emitted(26, 5) Source(28, 19) + SourceIndex(0) -2 >Emitted(26, 10) Source(28, 31) + SourceIndex(0) -3 >Emitted(26, 22) Source(28, 43) + SourceIndex(0) +1 >Emitted(27, 5) Source(28, 19) + SourceIndex(0) +2 >Emitted(27, 10) Source(28, 31) + SourceIndex(0) +3 >Emitted(27, 22) Source(28, 43) + SourceIndex(0) --- >>> a = 0, 1 >^^^^^^^^ @@ -403,9 +435,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(27, 9) Source(28, 46) + SourceIndex(0) -2 >Emitted(27, 10) Source(28, 47) + SourceIndex(0) -3 >Emitted(27, 14) Source(28, 47) + SourceIndex(0) +1 >Emitted(28, 9) Source(28, 46) + SourceIndex(0) +2 >Emitted(28, 10) Source(28, 47) + SourceIndex(0) +3 >Emitted(28, 14) Source(28, 47) + SourceIndex(0) --- >>> b = 1, 1->^^^^^^^^ @@ -415,9 +447,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(28, 9) Source(28, 49) + SourceIndex(0) -2 >Emitted(28, 10) Source(28, 50) + SourceIndex(0) -3 >Emitted(28, 14) Source(28, 50) + SourceIndex(0) +1->Emitted(29, 9) Source(28, 49) + SourceIndex(0) +2 >Emitted(29, 10) Source(28, 50) + SourceIndex(0) +3 >Emitted(29, 14) Source(28, 50) + SourceIndex(0) --- >>> c = 2 1->^^^^^^^^ @@ -426,21 +458,21 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(29, 9) Source(28, 52) + SourceIndex(0) -2 >Emitted(29, 10) Source(28, 53) + SourceIndex(0) -3 >Emitted(29, 14) Source(28, 53) + SourceIndex(0) +1->Emitted(30, 9) Source(28, 52) + SourceIndex(0) +2 >Emitted(30, 10) Source(28, 53) + SourceIndex(0) +3 >Emitted(30, 14) Source(28, 53) + SourceIndex(0) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(30, 6) Source(28, 55) + SourceIndex(0) +1 >Emitted(31, 6) Source(28, 55) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(31, 2) Source(29, 2) + SourceIndex(0) +1 >Emitted(32, 2) Source(29, 2) + SourceIndex(0) --- >>>declare class internalC { 1-> @@ -450,15 +482,15 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >class 3 > internalC -1->Emitted(32, 1) Source(30, 15) + SourceIndex(0) -2 >Emitted(32, 15) Source(30, 21) + SourceIndex(0) -3 >Emitted(32, 24) Source(30, 30) + SourceIndex(0) +1->Emitted(33, 1) Source(30, 15) + SourceIndex(0) +2 >Emitted(33, 15) Source(30, 21) + SourceIndex(0) +3 >Emitted(33, 24) Source(30, 30) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(33, 2) Source(30, 33) + SourceIndex(0) +1 >Emitted(34, 2) Source(30, 33) + SourceIndex(0) --- >>>declare function internalfoo(): void; 1-> @@ -471,10 +503,10 @@ sourceFile:../second/second_part1.ts 2 >function 3 > internalfoo 4 > () {} -1->Emitted(34, 1) Source(31, 15) + SourceIndex(0) -2 >Emitted(34, 18) Source(31, 24) + SourceIndex(0) -3 >Emitted(34, 29) Source(31, 35) + SourceIndex(0) -4 >Emitted(34, 38) Source(31, 40) + SourceIndex(0) +1->Emitted(35, 1) Source(31, 15) + SourceIndex(0) +2 >Emitted(35, 18) Source(31, 24) + SourceIndex(0) +3 >Emitted(35, 29) Source(31, 35) + SourceIndex(0) +4 >Emitted(35, 38) Source(31, 40) + SourceIndex(0) --- >>>declare namespace internalNamespace { 1-> @@ -486,10 +518,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > internalNamespace 4 > -1->Emitted(35, 1) Source(32, 15) + SourceIndex(0) -2 >Emitted(35, 19) Source(32, 25) + SourceIndex(0) -3 >Emitted(35, 36) Source(32, 42) + SourceIndex(0) -4 >Emitted(35, 37) Source(32, 43) + SourceIndex(0) +1->Emitted(36, 1) Source(32, 15) + SourceIndex(0) +2 >Emitted(36, 19) Source(32, 25) + SourceIndex(0) +3 >Emitted(36, 36) Source(32, 42) + SourceIndex(0) +4 >Emitted(36, 37) Source(32, 43) + SourceIndex(0) --- >>> class someClass { 1 >^^^^ @@ -498,20 +530,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(36, 5) Source(32, 45) + SourceIndex(0) -2 >Emitted(36, 11) Source(32, 58) + SourceIndex(0) -3 >Emitted(36, 20) Source(32, 67) + SourceIndex(0) +1 >Emitted(37, 5) Source(32, 45) + SourceIndex(0) +2 >Emitted(37, 11) Source(32, 58) + SourceIndex(0) +3 >Emitted(37, 20) Source(32, 67) + SourceIndex(0) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(37, 6) Source(32, 70) + SourceIndex(0) +1 >Emitted(38, 6) Source(32, 70) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(38, 2) Source(32, 72) + SourceIndex(0) +1 >Emitted(39, 2) Source(32, 72) + SourceIndex(0) --- >>>declare namespace internalOther.something { 1-> @@ -527,12 +559,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(39, 1) Source(33, 15) + SourceIndex(0) -2 >Emitted(39, 19) Source(33, 25) + SourceIndex(0) -3 >Emitted(39, 32) Source(33, 38) + SourceIndex(0) -4 >Emitted(39, 33) Source(33, 39) + SourceIndex(0) -5 >Emitted(39, 42) Source(33, 48) + SourceIndex(0) -6 >Emitted(39, 43) Source(33, 49) + SourceIndex(0) +1->Emitted(40, 1) Source(33, 15) + SourceIndex(0) +2 >Emitted(40, 19) Source(33, 25) + SourceIndex(0) +3 >Emitted(40, 32) Source(33, 38) + SourceIndex(0) +4 >Emitted(40, 33) Source(33, 39) + SourceIndex(0) +5 >Emitted(40, 42) Source(33, 48) + SourceIndex(0) +6 >Emitted(40, 43) Source(33, 49) + SourceIndex(0) --- >>> class someClass { 1 >^^^^ @@ -541,20 +573,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(40, 5) Source(33, 51) + SourceIndex(0) -2 >Emitted(40, 11) Source(33, 64) + SourceIndex(0) -3 >Emitted(40, 20) Source(33, 73) + SourceIndex(0) +1 >Emitted(41, 5) Source(33, 51) + SourceIndex(0) +2 >Emitted(41, 11) Source(33, 64) + SourceIndex(0) +3 >Emitted(41, 20) Source(33, 73) + SourceIndex(0) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(41, 6) Source(33, 76) + SourceIndex(0) +1 >Emitted(42, 6) Source(33, 76) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(42, 2) Source(33, 78) + SourceIndex(0) +1 >Emitted(43, 2) Source(33, 78) + SourceIndex(0) --- >>>import internalImport = internalNamespace.someClass; 1-> @@ -574,14 +606,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > someClass 8 > ; -1->Emitted(43, 1) Source(34, 15) + SourceIndex(0) -2 >Emitted(43, 8) Source(34, 22) + SourceIndex(0) -3 >Emitted(43, 22) Source(34, 36) + SourceIndex(0) -4 >Emitted(43, 25) Source(34, 39) + SourceIndex(0) -5 >Emitted(43, 42) Source(34, 56) + SourceIndex(0) -6 >Emitted(43, 43) Source(34, 57) + SourceIndex(0) -7 >Emitted(43, 52) Source(34, 66) + SourceIndex(0) -8 >Emitted(43, 53) Source(34, 67) + SourceIndex(0) +1->Emitted(44, 1) Source(34, 15) + SourceIndex(0) +2 >Emitted(44, 8) Source(34, 22) + SourceIndex(0) +3 >Emitted(44, 22) Source(34, 36) + SourceIndex(0) +4 >Emitted(44, 25) Source(34, 39) + SourceIndex(0) +5 >Emitted(44, 42) Source(34, 56) + SourceIndex(0) +6 >Emitted(44, 43) Source(34, 57) + SourceIndex(0) +7 >Emitted(44, 52) Source(34, 66) + SourceIndex(0) +8 >Emitted(44, 53) Source(34, 67) + SourceIndex(0) --- >>>declare type internalType = internalC; 1 > @@ -597,12 +629,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(44, 1) Source(35, 15) + SourceIndex(0) -2 >Emitted(44, 14) Source(35, 20) + SourceIndex(0) -3 >Emitted(44, 26) Source(35, 32) + SourceIndex(0) -4 >Emitted(44, 29) Source(35, 35) + SourceIndex(0) -5 >Emitted(44, 38) Source(35, 44) + SourceIndex(0) -6 >Emitted(44, 39) Source(35, 45) + SourceIndex(0) +1 >Emitted(45, 1) Source(35, 15) + SourceIndex(0) +2 >Emitted(45, 14) Source(35, 20) + SourceIndex(0) +3 >Emitted(45, 26) Source(35, 32) + SourceIndex(0) +4 >Emitted(45, 29) Source(35, 35) + SourceIndex(0) +5 >Emitted(45, 38) Source(35, 44) + SourceIndex(0) +6 >Emitted(45, 39) Source(35, 45) + SourceIndex(0) --- >>>declare const internalConst = 10; 1 > @@ -618,12 +650,12 @@ sourceFile:../second/second_part1.ts 4 > internalConst 5 > = 10 6 > ; -1 >Emitted(45, 1) Source(36, 15) + SourceIndex(0) -2 >Emitted(45, 9) Source(36, 15) + SourceIndex(0) -3 >Emitted(45, 15) Source(36, 21) + SourceIndex(0) -4 >Emitted(45, 28) Source(36, 34) + SourceIndex(0) -5 >Emitted(45, 33) Source(36, 39) + SourceIndex(0) -6 >Emitted(45, 34) Source(36, 40) + SourceIndex(0) +1 >Emitted(46, 1) Source(36, 15) + SourceIndex(0) +2 >Emitted(46, 9) Source(36, 15) + SourceIndex(0) +3 >Emitted(46, 15) Source(36, 21) + SourceIndex(0) +4 >Emitted(46, 28) Source(36, 34) + SourceIndex(0) +5 >Emitted(46, 33) Source(36, 39) + SourceIndex(0) +6 >Emitted(46, 34) Source(36, 40) + SourceIndex(0) --- >>>declare enum internalEnum { 1 > @@ -633,9 +665,9 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >enum 3 > internalEnum -1 >Emitted(46, 1) Source(37, 15) + SourceIndex(0) -2 >Emitted(46, 14) Source(37, 20) + SourceIndex(0) -3 >Emitted(46, 26) Source(37, 32) + SourceIndex(0) +1 >Emitted(47, 1) Source(37, 15) + SourceIndex(0) +2 >Emitted(47, 14) Source(37, 20) + SourceIndex(0) +3 >Emitted(47, 26) Source(37, 32) + SourceIndex(0) --- >>> a = 0, 1 >^^^^ @@ -645,9 +677,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(47, 5) Source(37, 35) + SourceIndex(0) -2 >Emitted(47, 6) Source(37, 36) + SourceIndex(0) -3 >Emitted(47, 10) Source(37, 36) + SourceIndex(0) +1 >Emitted(48, 5) Source(37, 35) + SourceIndex(0) +2 >Emitted(48, 6) Source(37, 36) + SourceIndex(0) +3 >Emitted(48, 10) Source(37, 36) + SourceIndex(0) --- >>> b = 1, 1->^^^^ @@ -657,9 +689,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(48, 5) Source(37, 38) + SourceIndex(0) -2 >Emitted(48, 6) Source(37, 39) + SourceIndex(0) -3 >Emitted(48, 10) Source(37, 39) + SourceIndex(0) +1->Emitted(49, 5) Source(37, 38) + SourceIndex(0) +2 >Emitted(49, 6) Source(37, 39) + SourceIndex(0) +3 >Emitted(49, 10) Source(37, 39) + SourceIndex(0) --- >>> c = 2 1->^^^^ @@ -668,15 +700,15 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(49, 5) Source(37, 41) + SourceIndex(0) -2 >Emitted(49, 6) Source(37, 42) + SourceIndex(0) -3 >Emitted(49, 10) Source(37, 42) + SourceIndex(0) +1->Emitted(50, 5) Source(37, 41) + SourceIndex(0) +2 >Emitted(50, 6) Source(37, 42) + SourceIndex(0) +3 >Emitted(50, 10) Source(37, 42) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(50, 2) Source(37, 44) + SourceIndex(0) +1 >Emitted(51, 2) Source(37, 44) + SourceIndex(0) --- ------------------------------------------------------------------- emittedFile:/src/2/second-output.d.ts @@ -690,9 +722,9 @@ sourceFile:../second/second_part2.ts 1-> 2 >class 3 > C -1->Emitted(51, 1) Source(1, 1) + SourceIndex(1) -2 >Emitted(51, 15) Source(1, 7) + SourceIndex(1) -3 >Emitted(51, 16) Source(1, 8) + SourceIndex(1) +1->Emitted(52, 1) Source(1, 1) + SourceIndex(1) +2 >Emitted(52, 15) Source(1, 7) + SourceIndex(1) +3 >Emitted(52, 16) Source(1, 8) + SourceIndex(1) --- >>> doSomething(): void; 1->^^^^ @@ -700,8 +732,8 @@ sourceFile:../second/second_part2.ts 1-> { > 2 > doSomething -1->Emitted(52, 5) Source(2, 5) + SourceIndex(1) -2 >Emitted(52, 16) Source(2, 16) + SourceIndex(1) +1->Emitted(53, 5) Source(2, 5) + SourceIndex(1) +2 >Emitted(53, 16) Source(2, 16) + SourceIndex(1) --- >>>} 1 >^ @@ -710,7 +742,7 @@ sourceFile:../second/second_part2.ts > console.log("something got done"); > } >} -1 >Emitted(53, 2) Source(5, 2) + SourceIndex(1) +1 >Emitted(54, 2) Source(5, 2) + SourceIndex(1) --- >>>//# sourceMappingURL=second-output.d.ts.map @@ -2394,32 +2426,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 77, - "end": 165, + "end": 182, "kind": "internal" }, { - "pos": 167, - "end": 199, + "pos": 184, + "end": 216, "kind": "text" }, { - "pos": 199, - "end": 591, + "pos": 216, + "end": 608, "kind": "internal" }, { - "pos": 593, - "end": 596, + "pos": 610, + "end": 613, "kind": "text" }, { - "pos": 596, - "end": 1009, + "pos": 613, + "end": 1026, "kind": "internal" }, { - "pos": 1011, - "end": 1059, + "pos": 1028, + "end": 1076, "kind": "text" } ] @@ -2548,18 +2580,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (77-165) +internal: (77-182) constructor(); prop: string; method(): void; - /*@internal*/ c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (167-199) +text: (184-216) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (199-591) +internal: (216-608) class C { } function foo(): void; @@ -2580,11 +2613,11 @@ internal: (199-591) c = 2 } ---------------------------------------------------------------------- -text: (593-596) +text: (610-613) } ---------------------------------------------------------------------- -internal: (596-1009) +internal: (613-1026) declare class internalC { } declare function internalfoo(): void; @@ -2605,7 +2638,7 @@ declare enum internalEnum { c = 2 } ---------------------------------------------------------------------- -text: (1011-1059) +text: (1028-1076) declare class C { doSomething(): void; } diff --git a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal.js b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal.js index 7ac42063f7d1a..6dfe54632feff 100644 --- a/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal.js +++ b/tests/baselines/reference/tsbuild/outfile-concat/initial-Build/stripInternal.js @@ -7,7 +7,8 @@ declare class normalC { constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); } declare namespace normalN { class C { @@ -55,7 +56,7 @@ declare class C { //# sourceMappingURL=second-output.d.ts.map //// [/src/2/second-output.d.ts.map] -{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACF,CAAC,EACM,MAAM;CAClC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} +{"version":3,"file":"second-output.d.ts","sourceRoot":"","sources":["../second/second_part1.ts","../second/second_part2.ts"],"names":[],"mappings":"AAAA,kBAAU,CAAC,CAAC;CAEX;AAED,kBAAU,CAAC,CAAC;CAMX;AAED,cAAM,OAAO;;IAEK,IAAI,EAAE,MAAM,CAAC;IACb,MAAM;IACN,IAAI,CAAC,IACM,MAAM,CADK;IACtB,IAAI,CAAC,CAAC,KAAK,MAAM,EAAK;CACvC;AACD,kBAAU,OAAO,CAAC;IACA,MAAa,CAAC;KAAI;IAClB,SAAgB,GAAG,SAAK;IACxB,UAAiB,aAAa,CAAC;QAAE,MAAa,CAAC;SAAG;KAAE;IACpD,UAAiB,SAAS,CAAC,SAAS,CAAC;QAAE,MAAa,SAAS;SAAG;KAAE;IAClE,MAAM,QAAQ,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC;IAC3C,KAAY,YAAY,GAAG,SAAS,CAAC;IAC9B,MAAM,aAAa,KAAK,CAAC;IAChC,KAAY,YAAY;QAAG,CAAC,IAAA;QAAE,CAAC,IAAA;QAAE,CAAC,IAAA;KAAE;CACrD;AACa,cAAM,SAAS;CAAG;AAClB,iBAAS,WAAW,SAAK;AACzB,kBAAU,iBAAiB,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AACzD,kBAAU,aAAa,CAAC,SAAS,CAAC;IAAE,MAAa,SAAS;KAAG;CAAE;AAC/D,OAAO,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC;AACpD,aAAK,YAAY,GAAG,SAAS,CAAC;AAC9B,QAAA,MAAM,aAAa,KAAK,CAAC;AACzB,aAAK,YAAY;IAAG,CAAC,IAAA;IAAE,CAAC,IAAA;IAAE,CAAC,IAAA;CAAE;ACpC3C,cAAM,CAAC;IACH,WAAW;CAGd"} //// [/src/2/second-output.d.ts.map.baseline.txt] =================================================================== @@ -155,35 +156,66 @@ sourceFile:../second/second_part1.ts >>> method(): void; 1->^^^^ 2 > ^^^^^^ -3 > ^^^^^-> +3 > ^^^^^^^^^^^-> 1-> > /*@internal*/ 2 > method 1->Emitted(8, 5) Source(16, 19) + SourceIndex(0) 2 >Emitted(8, 11) Source(16, 25) + SourceIndex(0) --- ->>> c: number; +>>> get c(): number; 1->^^^^ -2 > ^ -3 > ^^ -4 > ^^^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^^ +5 > ^^^^^^ +6 > ^ +7 > ^^^^-> 1->() { } - > /*@internal*/ get -2 > c -3 > () { return 10; } - > /*@internal*/ set c(val: -4 > number -1->Emitted(9, 5) Source(17, 23) + SourceIndex(0) -2 >Emitted(9, 6) Source(17, 24) + SourceIndex(0) -3 >Emitted(9, 8) Source(18, 30) + SourceIndex(0) -4 >Emitted(9, 14) Source(18, 36) + SourceIndex(0) + > /*@internal*/ +2 > get +3 > c +4 > () { return 10; } + > /*@internal*/ set c(val: +5 > number +6 > +1->Emitted(9, 5) Source(17, 19) + SourceIndex(0) +2 >Emitted(9, 9) Source(17, 23) + SourceIndex(0) +3 >Emitted(9, 10) Source(17, 24) + SourceIndex(0) +4 >Emitted(9, 14) Source(18, 30) + SourceIndex(0) +5 >Emitted(9, 20) Source(18, 36) + SourceIndex(0) +6 >Emitted(9, 21) Source(17, 41) + SourceIndex(0) +--- +>>> set c(val: number); +1->^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^ +6 > ^^^^^^ +7 > ^^ +1-> + > /*@internal*/ +2 > set +3 > c +4 > ( +5 > val: +6 > number +7 > ) { } +1->Emitted(10, 5) Source(18, 19) + SourceIndex(0) +2 >Emitted(10, 9) Source(18, 23) + SourceIndex(0) +3 >Emitted(10, 10) Source(18, 24) + SourceIndex(0) +4 >Emitted(10, 11) Source(18, 25) + SourceIndex(0) +5 >Emitted(10, 16) Source(18, 30) + SourceIndex(0) +6 >Emitted(10, 22) Source(18, 36) + SourceIndex(0) +7 >Emitted(10, 24) Source(18, 41) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >) { } +1 > >} -1 >Emitted(10, 2) Source(19, 2) + SourceIndex(0) +1 >Emitted(11, 2) Source(19, 2) + SourceIndex(0) --- >>>declare namespace normalN { 1-> @@ -195,10 +227,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > normalN 4 > -1->Emitted(11, 1) Source(20, 1) + SourceIndex(0) -2 >Emitted(11, 19) Source(20, 11) + SourceIndex(0) -3 >Emitted(11, 26) Source(20, 18) + SourceIndex(0) -4 >Emitted(11, 27) Source(20, 19) + SourceIndex(0) +1->Emitted(12, 1) Source(20, 1) + SourceIndex(0) +2 >Emitted(12, 19) Source(20, 11) + SourceIndex(0) +3 >Emitted(12, 26) Source(20, 18) + SourceIndex(0) +4 >Emitted(12, 27) Source(20, 19) + SourceIndex(0) --- >>> class C { 1 >^^^^ @@ -208,15 +240,15 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export class 3 > C -1 >Emitted(12, 5) Source(21, 19) + SourceIndex(0) -2 >Emitted(12, 11) Source(21, 32) + SourceIndex(0) -3 >Emitted(12, 12) Source(21, 33) + SourceIndex(0) +1 >Emitted(13, 5) Source(21, 19) + SourceIndex(0) +2 >Emitted(13, 11) Source(21, 32) + SourceIndex(0) +3 >Emitted(13, 12) Source(21, 33) + SourceIndex(0) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > { } -1 >Emitted(13, 6) Source(21, 37) + SourceIndex(0) +1 >Emitted(14, 6) Source(21, 37) + SourceIndex(0) --- >>> function foo(): void; 1->^^^^ @@ -229,10 +261,10 @@ sourceFile:../second/second_part1.ts 2 > export function 3 > foo 4 > () {} -1->Emitted(14, 5) Source(22, 19) + SourceIndex(0) -2 >Emitted(14, 14) Source(22, 35) + SourceIndex(0) -3 >Emitted(14, 17) Source(22, 38) + SourceIndex(0) -4 >Emitted(14, 26) Source(22, 43) + SourceIndex(0) +1->Emitted(15, 5) Source(22, 19) + SourceIndex(0) +2 >Emitted(15, 14) Source(22, 35) + SourceIndex(0) +3 >Emitted(15, 17) Source(22, 38) + SourceIndex(0) +4 >Emitted(15, 26) Source(22, 43) + SourceIndex(0) --- >>> namespace someNamespace { 1->^^^^ @@ -244,10 +276,10 @@ sourceFile:../second/second_part1.ts 2 > export namespace 3 > someNamespace 4 > -1->Emitted(15, 5) Source(23, 19) + SourceIndex(0) -2 >Emitted(15, 15) Source(23, 36) + SourceIndex(0) -3 >Emitted(15, 28) Source(23, 49) + SourceIndex(0) -4 >Emitted(15, 29) Source(23, 50) + SourceIndex(0) +1->Emitted(16, 5) Source(23, 19) + SourceIndex(0) +2 >Emitted(16, 15) Source(23, 36) + SourceIndex(0) +3 >Emitted(16, 28) Source(23, 49) + SourceIndex(0) +4 >Emitted(16, 29) Source(23, 50) + SourceIndex(0) --- >>> class C { 1 >^^^^^^^^ @@ -256,20 +288,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > C -1 >Emitted(16, 9) Source(23, 52) + SourceIndex(0) -2 >Emitted(16, 15) Source(23, 65) + SourceIndex(0) -3 >Emitted(16, 16) Source(23, 66) + SourceIndex(0) +1 >Emitted(17, 9) Source(23, 52) + SourceIndex(0) +2 >Emitted(17, 15) Source(23, 65) + SourceIndex(0) +3 >Emitted(17, 16) Source(23, 66) + SourceIndex(0) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(17, 10) Source(23, 69) + SourceIndex(0) +1 >Emitted(18, 10) Source(23, 69) + SourceIndex(0) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(18, 6) Source(23, 71) + SourceIndex(0) +1 >Emitted(19, 6) Source(23, 71) + SourceIndex(0) --- >>> namespace someOther.something { 1->^^^^ @@ -285,12 +317,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(19, 5) Source(24, 19) + SourceIndex(0) -2 >Emitted(19, 15) Source(24, 36) + SourceIndex(0) -3 >Emitted(19, 24) Source(24, 45) + SourceIndex(0) -4 >Emitted(19, 25) Source(24, 46) + SourceIndex(0) -5 >Emitted(19, 34) Source(24, 55) + SourceIndex(0) -6 >Emitted(19, 35) Source(24, 56) + SourceIndex(0) +1->Emitted(20, 5) Source(24, 19) + SourceIndex(0) +2 >Emitted(20, 15) Source(24, 36) + SourceIndex(0) +3 >Emitted(20, 24) Source(24, 45) + SourceIndex(0) +4 >Emitted(20, 25) Source(24, 46) + SourceIndex(0) +5 >Emitted(20, 34) Source(24, 55) + SourceIndex(0) +6 >Emitted(20, 35) Source(24, 56) + SourceIndex(0) --- >>> class someClass { 1 >^^^^^^^^ @@ -299,20 +331,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(20, 9) Source(24, 58) + SourceIndex(0) -2 >Emitted(20, 15) Source(24, 71) + SourceIndex(0) -3 >Emitted(20, 24) Source(24, 80) + SourceIndex(0) +1 >Emitted(21, 9) Source(24, 58) + SourceIndex(0) +2 >Emitted(21, 15) Source(24, 71) + SourceIndex(0) +3 >Emitted(21, 24) Source(24, 80) + SourceIndex(0) --- >>> } 1 >^^^^^^^^^ 1 > {} -1 >Emitted(21, 10) Source(24, 83) + SourceIndex(0) +1 >Emitted(22, 10) Source(24, 83) + SourceIndex(0) --- >>> } 1 >^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(22, 6) Source(24, 85) + SourceIndex(0) +1 >Emitted(23, 6) Source(24, 85) + SourceIndex(0) --- >>> export import someImport = someNamespace.C; 1->^^^^ @@ -334,15 +366,15 @@ sourceFile:../second/second_part1.ts 7 > . 8 > C 9 > ; -1->Emitted(23, 5) Source(25, 19) + SourceIndex(0) -2 >Emitted(23, 11) Source(25, 25) + SourceIndex(0) -3 >Emitted(23, 19) Source(25, 33) + SourceIndex(0) -4 >Emitted(23, 29) Source(25, 43) + SourceIndex(0) -5 >Emitted(23, 32) Source(25, 46) + SourceIndex(0) -6 >Emitted(23, 45) Source(25, 59) + SourceIndex(0) -7 >Emitted(23, 46) Source(25, 60) + SourceIndex(0) -8 >Emitted(23, 47) Source(25, 61) + SourceIndex(0) -9 >Emitted(23, 48) Source(25, 62) + SourceIndex(0) +1->Emitted(24, 5) Source(25, 19) + SourceIndex(0) +2 >Emitted(24, 11) Source(25, 25) + SourceIndex(0) +3 >Emitted(24, 19) Source(25, 33) + SourceIndex(0) +4 >Emitted(24, 29) Source(25, 43) + SourceIndex(0) +5 >Emitted(24, 32) Source(25, 46) + SourceIndex(0) +6 >Emitted(24, 45) Source(25, 59) + SourceIndex(0) +7 >Emitted(24, 46) Source(25, 60) + SourceIndex(0) +8 >Emitted(24, 47) Source(25, 61) + SourceIndex(0) +9 >Emitted(24, 48) Source(25, 62) + SourceIndex(0) --- >>> type internalType = internalC; 1 >^^^^ @@ -358,12 +390,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(24, 5) Source(26, 19) + SourceIndex(0) -2 >Emitted(24, 10) Source(26, 31) + SourceIndex(0) -3 >Emitted(24, 22) Source(26, 43) + SourceIndex(0) -4 >Emitted(24, 25) Source(26, 46) + SourceIndex(0) -5 >Emitted(24, 34) Source(26, 55) + SourceIndex(0) -6 >Emitted(24, 35) Source(26, 56) + SourceIndex(0) +1 >Emitted(25, 5) Source(26, 19) + SourceIndex(0) +2 >Emitted(25, 10) Source(26, 31) + SourceIndex(0) +3 >Emitted(25, 22) Source(26, 43) + SourceIndex(0) +4 >Emitted(25, 25) Source(26, 46) + SourceIndex(0) +5 >Emitted(25, 34) Source(26, 55) + SourceIndex(0) +6 >Emitted(25, 35) Source(26, 56) + SourceIndex(0) --- >>> const internalConst = 10; 1 >^^^^ @@ -377,11 +409,11 @@ sourceFile:../second/second_part1.ts 3 > internalConst 4 > = 10 5 > ; -1 >Emitted(25, 5) Source(27, 26) + SourceIndex(0) -2 >Emitted(25, 11) Source(27, 32) + SourceIndex(0) -3 >Emitted(25, 24) Source(27, 45) + SourceIndex(0) -4 >Emitted(25, 29) Source(27, 50) + SourceIndex(0) -5 >Emitted(25, 30) Source(27, 51) + SourceIndex(0) +1 >Emitted(26, 5) Source(27, 26) + SourceIndex(0) +2 >Emitted(26, 11) Source(27, 32) + SourceIndex(0) +3 >Emitted(26, 24) Source(27, 45) + SourceIndex(0) +4 >Emitted(26, 29) Source(27, 50) + SourceIndex(0) +5 >Emitted(26, 30) Source(27, 51) + SourceIndex(0) --- >>> enum internalEnum { 1 >^^^^ @@ -391,9 +423,9 @@ sourceFile:../second/second_part1.ts > /*@internal*/ 2 > export enum 3 > internalEnum -1 >Emitted(26, 5) Source(28, 19) + SourceIndex(0) -2 >Emitted(26, 10) Source(28, 31) + SourceIndex(0) -3 >Emitted(26, 22) Source(28, 43) + SourceIndex(0) +1 >Emitted(27, 5) Source(28, 19) + SourceIndex(0) +2 >Emitted(27, 10) Source(28, 31) + SourceIndex(0) +3 >Emitted(27, 22) Source(28, 43) + SourceIndex(0) --- >>> a = 0, 1 >^^^^^^^^ @@ -403,9 +435,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(27, 9) Source(28, 46) + SourceIndex(0) -2 >Emitted(27, 10) Source(28, 47) + SourceIndex(0) -3 >Emitted(27, 14) Source(28, 47) + SourceIndex(0) +1 >Emitted(28, 9) Source(28, 46) + SourceIndex(0) +2 >Emitted(28, 10) Source(28, 47) + SourceIndex(0) +3 >Emitted(28, 14) Source(28, 47) + SourceIndex(0) --- >>> b = 1, 1->^^^^^^^^ @@ -415,9 +447,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(28, 9) Source(28, 49) + SourceIndex(0) -2 >Emitted(28, 10) Source(28, 50) + SourceIndex(0) -3 >Emitted(28, 14) Source(28, 50) + SourceIndex(0) +1->Emitted(29, 9) Source(28, 49) + SourceIndex(0) +2 >Emitted(29, 10) Source(28, 50) + SourceIndex(0) +3 >Emitted(29, 14) Source(28, 50) + SourceIndex(0) --- >>> c = 2 1->^^^^^^^^ @@ -426,21 +458,21 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(29, 9) Source(28, 52) + SourceIndex(0) -2 >Emitted(29, 10) Source(28, 53) + SourceIndex(0) -3 >Emitted(29, 14) Source(28, 53) + SourceIndex(0) +1->Emitted(30, 9) Source(28, 52) + SourceIndex(0) +2 >Emitted(30, 10) Source(28, 53) + SourceIndex(0) +3 >Emitted(30, 14) Source(28, 53) + SourceIndex(0) --- >>> } 1 >^^^^^ 1 > } -1 >Emitted(30, 6) Source(28, 55) + SourceIndex(0) +1 >Emitted(31, 6) Source(28, 55) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > >} -1 >Emitted(31, 2) Source(29, 2) + SourceIndex(0) +1 >Emitted(32, 2) Source(29, 2) + SourceIndex(0) --- >>>declare class internalC { 1-> @@ -450,15 +482,15 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >class 3 > internalC -1->Emitted(32, 1) Source(30, 15) + SourceIndex(0) -2 >Emitted(32, 15) Source(30, 21) + SourceIndex(0) -3 >Emitted(32, 24) Source(30, 30) + SourceIndex(0) +1->Emitted(33, 1) Source(30, 15) + SourceIndex(0) +2 >Emitted(33, 15) Source(30, 21) + SourceIndex(0) +3 >Emitted(33, 24) Source(30, 30) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > {} -1 >Emitted(33, 2) Source(30, 33) + SourceIndex(0) +1 >Emitted(34, 2) Source(30, 33) + SourceIndex(0) --- >>>declare function internalfoo(): void; 1-> @@ -471,10 +503,10 @@ sourceFile:../second/second_part1.ts 2 >function 3 > internalfoo 4 > () {} -1->Emitted(34, 1) Source(31, 15) + SourceIndex(0) -2 >Emitted(34, 18) Source(31, 24) + SourceIndex(0) -3 >Emitted(34, 29) Source(31, 35) + SourceIndex(0) -4 >Emitted(34, 38) Source(31, 40) + SourceIndex(0) +1->Emitted(35, 1) Source(31, 15) + SourceIndex(0) +2 >Emitted(35, 18) Source(31, 24) + SourceIndex(0) +3 >Emitted(35, 29) Source(31, 35) + SourceIndex(0) +4 >Emitted(35, 38) Source(31, 40) + SourceIndex(0) --- >>>declare namespace internalNamespace { 1-> @@ -486,10 +518,10 @@ sourceFile:../second/second_part1.ts 2 >namespace 3 > internalNamespace 4 > -1->Emitted(35, 1) Source(32, 15) + SourceIndex(0) -2 >Emitted(35, 19) Source(32, 25) + SourceIndex(0) -3 >Emitted(35, 36) Source(32, 42) + SourceIndex(0) -4 >Emitted(35, 37) Source(32, 43) + SourceIndex(0) +1->Emitted(36, 1) Source(32, 15) + SourceIndex(0) +2 >Emitted(36, 19) Source(32, 25) + SourceIndex(0) +3 >Emitted(36, 36) Source(32, 42) + SourceIndex(0) +4 >Emitted(36, 37) Source(32, 43) + SourceIndex(0) --- >>> class someClass { 1 >^^^^ @@ -498,20 +530,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(36, 5) Source(32, 45) + SourceIndex(0) -2 >Emitted(36, 11) Source(32, 58) + SourceIndex(0) -3 >Emitted(36, 20) Source(32, 67) + SourceIndex(0) +1 >Emitted(37, 5) Source(32, 45) + SourceIndex(0) +2 >Emitted(37, 11) Source(32, 58) + SourceIndex(0) +3 >Emitted(37, 20) Source(32, 67) + SourceIndex(0) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(37, 6) Source(32, 70) + SourceIndex(0) +1 >Emitted(38, 6) Source(32, 70) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(38, 2) Source(32, 72) + SourceIndex(0) +1 >Emitted(39, 2) Source(32, 72) + SourceIndex(0) --- >>>declare namespace internalOther.something { 1-> @@ -527,12 +559,12 @@ sourceFile:../second/second_part1.ts 4 > . 5 > something 6 > -1->Emitted(39, 1) Source(33, 15) + SourceIndex(0) -2 >Emitted(39, 19) Source(33, 25) + SourceIndex(0) -3 >Emitted(39, 32) Source(33, 38) + SourceIndex(0) -4 >Emitted(39, 33) Source(33, 39) + SourceIndex(0) -5 >Emitted(39, 42) Source(33, 48) + SourceIndex(0) -6 >Emitted(39, 43) Source(33, 49) + SourceIndex(0) +1->Emitted(40, 1) Source(33, 15) + SourceIndex(0) +2 >Emitted(40, 19) Source(33, 25) + SourceIndex(0) +3 >Emitted(40, 32) Source(33, 38) + SourceIndex(0) +4 >Emitted(40, 33) Source(33, 39) + SourceIndex(0) +5 >Emitted(40, 42) Source(33, 48) + SourceIndex(0) +6 >Emitted(40, 43) Source(33, 49) + SourceIndex(0) --- >>> class someClass { 1 >^^^^ @@ -541,20 +573,20 @@ sourceFile:../second/second_part1.ts 1 >{ 2 > export class 3 > someClass -1 >Emitted(40, 5) Source(33, 51) + SourceIndex(0) -2 >Emitted(40, 11) Source(33, 64) + SourceIndex(0) -3 >Emitted(40, 20) Source(33, 73) + SourceIndex(0) +1 >Emitted(41, 5) Source(33, 51) + SourceIndex(0) +2 >Emitted(41, 11) Source(33, 64) + SourceIndex(0) +3 >Emitted(41, 20) Source(33, 73) + SourceIndex(0) --- >>> } 1 >^^^^^ 1 > {} -1 >Emitted(41, 6) Source(33, 76) + SourceIndex(0) +1 >Emitted(42, 6) Source(33, 76) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(42, 2) Source(33, 78) + SourceIndex(0) +1 >Emitted(43, 2) Source(33, 78) + SourceIndex(0) --- >>>import internalImport = internalNamespace.someClass; 1-> @@ -574,14 +606,14 @@ sourceFile:../second/second_part1.ts 6 > . 7 > someClass 8 > ; -1->Emitted(43, 1) Source(34, 15) + SourceIndex(0) -2 >Emitted(43, 8) Source(34, 22) + SourceIndex(0) -3 >Emitted(43, 22) Source(34, 36) + SourceIndex(0) -4 >Emitted(43, 25) Source(34, 39) + SourceIndex(0) -5 >Emitted(43, 42) Source(34, 56) + SourceIndex(0) -6 >Emitted(43, 43) Source(34, 57) + SourceIndex(0) -7 >Emitted(43, 52) Source(34, 66) + SourceIndex(0) -8 >Emitted(43, 53) Source(34, 67) + SourceIndex(0) +1->Emitted(44, 1) Source(34, 15) + SourceIndex(0) +2 >Emitted(44, 8) Source(34, 22) + SourceIndex(0) +3 >Emitted(44, 22) Source(34, 36) + SourceIndex(0) +4 >Emitted(44, 25) Source(34, 39) + SourceIndex(0) +5 >Emitted(44, 42) Source(34, 56) + SourceIndex(0) +6 >Emitted(44, 43) Source(34, 57) + SourceIndex(0) +7 >Emitted(44, 52) Source(34, 66) + SourceIndex(0) +8 >Emitted(44, 53) Source(34, 67) + SourceIndex(0) --- >>>declare type internalType = internalC; 1 > @@ -597,12 +629,12 @@ sourceFile:../second/second_part1.ts 4 > = 5 > internalC 6 > ; -1 >Emitted(44, 1) Source(35, 15) + SourceIndex(0) -2 >Emitted(44, 14) Source(35, 20) + SourceIndex(0) -3 >Emitted(44, 26) Source(35, 32) + SourceIndex(0) -4 >Emitted(44, 29) Source(35, 35) + SourceIndex(0) -5 >Emitted(44, 38) Source(35, 44) + SourceIndex(0) -6 >Emitted(44, 39) Source(35, 45) + SourceIndex(0) +1 >Emitted(45, 1) Source(35, 15) + SourceIndex(0) +2 >Emitted(45, 14) Source(35, 20) + SourceIndex(0) +3 >Emitted(45, 26) Source(35, 32) + SourceIndex(0) +4 >Emitted(45, 29) Source(35, 35) + SourceIndex(0) +5 >Emitted(45, 38) Source(35, 44) + SourceIndex(0) +6 >Emitted(45, 39) Source(35, 45) + SourceIndex(0) --- >>>declare const internalConst = 10; 1 > @@ -618,12 +650,12 @@ sourceFile:../second/second_part1.ts 4 > internalConst 5 > = 10 6 > ; -1 >Emitted(45, 1) Source(36, 15) + SourceIndex(0) -2 >Emitted(45, 9) Source(36, 15) + SourceIndex(0) -3 >Emitted(45, 15) Source(36, 21) + SourceIndex(0) -4 >Emitted(45, 28) Source(36, 34) + SourceIndex(0) -5 >Emitted(45, 33) Source(36, 39) + SourceIndex(0) -6 >Emitted(45, 34) Source(36, 40) + SourceIndex(0) +1 >Emitted(46, 1) Source(36, 15) + SourceIndex(0) +2 >Emitted(46, 9) Source(36, 15) + SourceIndex(0) +3 >Emitted(46, 15) Source(36, 21) + SourceIndex(0) +4 >Emitted(46, 28) Source(36, 34) + SourceIndex(0) +5 >Emitted(46, 33) Source(36, 39) + SourceIndex(0) +6 >Emitted(46, 34) Source(36, 40) + SourceIndex(0) --- >>>declare enum internalEnum { 1 > @@ -633,9 +665,9 @@ sourceFile:../second/second_part1.ts >/*@internal*/ 2 >enum 3 > internalEnum -1 >Emitted(46, 1) Source(37, 15) + SourceIndex(0) -2 >Emitted(46, 14) Source(37, 20) + SourceIndex(0) -3 >Emitted(46, 26) Source(37, 32) + SourceIndex(0) +1 >Emitted(47, 1) Source(37, 15) + SourceIndex(0) +2 >Emitted(47, 14) Source(37, 20) + SourceIndex(0) +3 >Emitted(47, 26) Source(37, 32) + SourceIndex(0) --- >>> a = 0, 1 >^^^^ @@ -645,9 +677,9 @@ sourceFile:../second/second_part1.ts 1 > { 2 > a 3 > -1 >Emitted(47, 5) Source(37, 35) + SourceIndex(0) -2 >Emitted(47, 6) Source(37, 36) + SourceIndex(0) -3 >Emitted(47, 10) Source(37, 36) + SourceIndex(0) +1 >Emitted(48, 5) Source(37, 35) + SourceIndex(0) +2 >Emitted(48, 6) Source(37, 36) + SourceIndex(0) +3 >Emitted(48, 10) Source(37, 36) + SourceIndex(0) --- >>> b = 1, 1->^^^^ @@ -657,9 +689,9 @@ sourceFile:../second/second_part1.ts 1->, 2 > b 3 > -1->Emitted(48, 5) Source(37, 38) + SourceIndex(0) -2 >Emitted(48, 6) Source(37, 39) + SourceIndex(0) -3 >Emitted(48, 10) Source(37, 39) + SourceIndex(0) +1->Emitted(49, 5) Source(37, 38) + SourceIndex(0) +2 >Emitted(49, 6) Source(37, 39) + SourceIndex(0) +3 >Emitted(49, 10) Source(37, 39) + SourceIndex(0) --- >>> c = 2 1->^^^^ @@ -668,15 +700,15 @@ sourceFile:../second/second_part1.ts 1->, 2 > c 3 > -1->Emitted(49, 5) Source(37, 41) + SourceIndex(0) -2 >Emitted(49, 6) Source(37, 42) + SourceIndex(0) -3 >Emitted(49, 10) Source(37, 42) + SourceIndex(0) +1->Emitted(50, 5) Source(37, 41) + SourceIndex(0) +2 >Emitted(50, 6) Source(37, 42) + SourceIndex(0) +3 >Emitted(50, 10) Source(37, 42) + SourceIndex(0) --- >>>} 1 >^ 2 > ^^^^^^^^^^^^^^^^^-> 1 > } -1 >Emitted(50, 2) Source(37, 44) + SourceIndex(0) +1 >Emitted(51, 2) Source(37, 44) + SourceIndex(0) --- ------------------------------------------------------------------- emittedFile:/src/2/second-output.d.ts @@ -690,9 +722,9 @@ sourceFile:../second/second_part2.ts 1-> 2 >class 3 > C -1->Emitted(51, 1) Source(1, 1) + SourceIndex(1) -2 >Emitted(51, 15) Source(1, 7) + SourceIndex(1) -3 >Emitted(51, 16) Source(1, 8) + SourceIndex(1) +1->Emitted(52, 1) Source(1, 1) + SourceIndex(1) +2 >Emitted(52, 15) Source(1, 7) + SourceIndex(1) +3 >Emitted(52, 16) Source(1, 8) + SourceIndex(1) --- >>> doSomething(): void; 1->^^^^ @@ -700,8 +732,8 @@ sourceFile:../second/second_part2.ts 1-> { > 2 > doSomething -1->Emitted(52, 5) Source(2, 5) + SourceIndex(1) -2 >Emitted(52, 16) Source(2, 16) + SourceIndex(1) +1->Emitted(53, 5) Source(2, 5) + SourceIndex(1) +2 >Emitted(53, 16) Source(2, 16) + SourceIndex(1) --- >>>} 1 >^ @@ -710,7 +742,7 @@ sourceFile:../second/second_part2.ts > console.log("something got done"); > } >} -1 >Emitted(53, 2) Source(5, 2) + SourceIndex(1) +1 >Emitted(54, 2) Source(5, 2) + SourceIndex(1) --- >>>//# sourceMappingURL=second-output.d.ts.map @@ -2294,32 +2326,32 @@ sourceFile:../second/second_part2.ts }, { "pos": 77, - "end": 151, + "end": 182, "kind": "internal" }, { - "pos": 153, - "end": 185, + "pos": 184, + "end": 216, "kind": "text" }, { - "pos": 185, - "end": 577, + "pos": 216, + "end": 608, "kind": "internal" }, { - "pos": 579, - "end": 582, + "pos": 610, + "end": 613, "kind": "text" }, { - "pos": 582, - "end": 995, + "pos": 613, + "end": 1026, "kind": "internal" }, { - "pos": 997, - "end": 1045, + "pos": 1028, + "end": 1076, "kind": "text" } ] @@ -2448,18 +2480,19 @@ declare namespace N { declare class normalC { ---------------------------------------------------------------------- -internal: (77-151) +internal: (77-182) constructor(); prop: string; method(): void; - c: number; + get c(): number; + set c(val: number); ---------------------------------------------------------------------- -text: (153-185) +text: (184-216) } declare namespace normalN { ---------------------------------------------------------------------- -internal: (185-577) +internal: (216-608) class C { } function foo(): void; @@ -2480,11 +2513,11 @@ internal: (185-577) c = 2 } ---------------------------------------------------------------------- -text: (579-582) +text: (610-613) } ---------------------------------------------------------------------- -internal: (582-995) +internal: (613-1026) declare class internalC { } declare function internalfoo(): void; @@ -2505,7 +2538,7 @@ declare enum internalEnum { c = 2 } ---------------------------------------------------------------------- -text: (997-1045) +text: (1028-1076) declare class C { doSomething(): void; } From d46a0dbbc22688c2e82def5eb09b01eb5d732d6a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 17 Sep 2019 15:25:24 -0700 Subject: [PATCH 18/44] Update baselines --- .../reference/commentsInheritance.errors.txt | 8 +- .../reference/parserAstSpans1.errors.txt | 8 +- .../reference/parserRealSource11.errors.txt | 8 +- .../reference/parserharness.errors.txt | 16 +-- ...AccessibleWithinNestedSubclass1.errors.txt | 4 +- ...opertyAccessibleWithinSubclass2.errors.txt | 4 +- ...sOfTypeParameterWithConstraints.errors.txt | 116 +++++++++--------- 7 files changed, 82 insertions(+), 82 deletions(-) diff --git a/tests/baselines/reference/commentsInheritance.errors.txt b/tests/baselines/reference/commentsInheritance.errors.txt index 2a9a5eff5dca7..08e02a19b2dcb 100644 --- a/tests/baselines/reference/commentsInheritance.errors.txt +++ b/tests/baselines/reference/commentsInheritance.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/commentsInheritance.ts(90,12): error TS2610: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/compiler/commentsInheritance.ts(98,12): error TS2610: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/compiler/commentsInheritance.ts(90,12): error TS2612: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/compiler/commentsInheritance.ts(98,12): error TS2612: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/compiler/commentsInheritance.ts (2 errors) ==== @@ -94,7 +94,7 @@ tests/cases/compiler/commentsInheritance.ts(98,12): error TS2610: Property 'nc_p /** c3 p1*/ public p1: number; ~~ -!!! error TS2610: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. /** c3 f1*/ public f1() { } @@ -104,7 +104,7 @@ tests/cases/compiler/commentsInheritance.ts(98,12): error TS2610: Property 'nc_p } public nc_p1: number; ~~~~~ -!!! error TS2610: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. public nc_f1() { } public get nc_prop() { diff --git a/tests/baselines/reference/parserAstSpans1.errors.txt b/tests/baselines/reference/parserAstSpans1.errors.txt index 6fa8715a8f6ea..e97f2f249f8c1 100644 --- a/tests/baselines/reference/parserAstSpans1.errors.txt +++ b/tests/baselines/reference/parserAstSpans1.errors.txt @@ -3,9 +3,9 @@ tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(85,16): error TS10 tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(94,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(100,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(111,25): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. -tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(114,12): error TS2610: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(114,12): error TS2612: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(119,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(122,12): error TS2610: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(122,12): error TS2612: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(125,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(217,24): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. @@ -136,7 +136,7 @@ tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(217,24): error TS2 /** c3 p1*/ public p1: number; ~~ -!!! error TS2610: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. /** c3 f1*/ public f1() { } @@ -148,7 +148,7 @@ tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(217,24): error TS2 } public nc_p1: number; ~~~~~ -!!! error TS2610: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. public nc_f1() { } public get nc_prop() { diff --git a/tests/baselines/reference/parserRealSource11.errors.txt b/tests/baselines/reference/parserRealSource11.errors.txt index fdfb15759460e..af217668adef1 100644 --- a/tests/baselines/reference/parserRealSource11.errors.txt +++ b/tests/baselines/reference/parserRealSource11.errors.txt @@ -288,8 +288,8 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1095,29): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1098,56): error TS2304: Cannot find name 'FncFlags'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1098,79): error TS2304: Cannot find name 'FncFlags'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1111,33): error TS2304: Cannot find name 'IFileReference'. -tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1120,16): error TS2610: Property 'vars' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1121,16): error TS2610: Property 'scopes' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1120,16): error TS2612: Property 'vars' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1121,16): error TS2612: Property 'scopes' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1127,84): error TS2304: Cannot find name 'NodeType'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1132,36): error TS2304: Cannot find name 'TypeFlow'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1144,42): error TS2304: Cannot find name 'NodeType'. @@ -2215,10 +2215,10 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error public rightCurlyCount = 0; public vars: ASTList; ~~~~ -!!! error TS2610: Property 'vars' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'vars' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. public scopes: ASTList; ~~~~~~ -!!! error TS2610: Property 'scopes' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'scopes' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. // Remember if the script contains Unicode chars, that is needed when generating code for this script object to decide the output file correct encoding. public containsUnicodeChar = false; public containsUnicodeCharInComment = false; diff --git a/tests/baselines/reference/parserharness.errors.txt b/tests/baselines/reference/parserharness.errors.txt index 9c00868b16d22..a62a8cc718884 100644 --- a/tests/baselines/reference/parserharness.errors.txt +++ b/tests/baselines/reference/parserharness.errors.txt @@ -12,10 +12,10 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(347,13): e tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(351,17): error TS2662: Cannot find name 'errorHandlerStack'. Did you mean the static member 'Runnable.errorHandlerStack'? tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(354,17): error TS2662: Cannot find name 'errorHandlerStack'. Did you mean the static member 'Runnable.errorHandlerStack'? tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(354,35): error TS2662: Cannot find name 'errorHandlerStack'. Did you mean the static member 'Runnable.errorHandlerStack'? -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(359,16): error TS2610: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(360,16): error TS2610: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(402,16): error TS2610: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(403,16): error TS2610: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(359,16): error TS2612: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(360,16): error TS2612: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(402,16): error TS2612: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(403,16): error TS2612: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(691,50): error TS2304: Cannot find name 'ITextWriter'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(716,47): error TS2503: Cannot find namespace 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(721,62): error TS2304: Cannot find name 'ITextWriter'. @@ -503,10 +503,10 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): export class TestCase extends Runnable { public description: string; ~~~~~~~~~~~ -!!! error TS2610: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. public block; ~~~~~ -!!! error TS2610: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. constructor(description: string, block: any) { super(description, block); @@ -550,10 +550,10 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): export class Scenario extends Runnable { public description: string; ~~~~~~~~~~~ -!!! error TS2610: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. public block; ~~~~~ -!!! error TS2610: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. constructor(description: string, block: any) { super(description, block); diff --git a/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt b/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt index dd395b2a2a4a2..5ea3f18aa0cfa 100644 --- a/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt +++ b/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt @@ -6,7 +6,7 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(52,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(53,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(55,20): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. -tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(63,15): error TS2610: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(63,15): error TS2612: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(73,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(74,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(75,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. @@ -103,7 +103,7 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce class Derived3 extends Derived1 { protected x: string; ~ -!!! error TS2610: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. method3() { class D { method3d() { diff --git a/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass2.errors.txt b/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass2.errors.txt index 2d43267ed419e..9ea7fbed191c4 100644 --- a/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass2.errors.txt +++ b/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass2.errors.txt @@ -6,7 +6,7 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(42,11): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(43,12): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(45,12): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. -tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(51,15): error TS2610: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(51,15): error TS2612: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(59,11): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(60,12): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(61,12): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. @@ -91,7 +91,7 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce class Derived3 extends Derived1 { protected x: string; ~ -!!! error TS2610: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. method3() { var b: Base; var d1: Derived1; diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt index 37ae8137c5a2b..6376af99434dd 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt @@ -1,39 +1,39 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(9,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(14,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(9,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(14,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(24,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(33,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(38,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(43,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(24,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(33,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(38,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(43,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. Type 'V' is not assignable to type 'T'. 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(55,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(60,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(55,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(60,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2416: Property 'foo' in type 'D11' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'T'. 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2416: Property 'foo' in type 'D12' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'U'. 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint '{}'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(77,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(85,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(90,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(95,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(100,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(107,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(77,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(85,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(90,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(95,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(100,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(107,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2416: Property 'foo' in type 'D19' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. @@ -42,41 +42,41 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. Type 'Date' is not assignable to type 'T'. 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(117,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(122,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(129,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(117,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(122,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(129,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2416: Property 'foo' in type 'D23' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'T'. 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. Type 'Date' is not assignable to type 'T'. 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2416: Property 'foo' in type 'D24' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'U'. 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. Type 'Date' is not assignable to type 'U'. 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(144,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(151,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(144,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(151,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2416: Property 'foo' in type 'D27' is not assignable to the same property in base type 'C3'. Type 'Date' is not assignable to type 'T'. 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2416: Property 'foo' in type 'D28' is not assignable to the same property in base type 'C3'. Type 'Date' is not assignable to type 'U'. 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2416: Property 'foo' in type 'D29' is not assignable to the same property in base type 'C3'. Type 'Date' is not assignable to type 'V'. 'Date' is assignable to the constraint of type 'V', but 'V' could be instantiated with a different subtype of constraint 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts (49 errors) ==== @@ -90,14 +90,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: T; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D2 extends C3 { [x: string]: U; foo: T; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D3 extends C3 { @@ -110,14 +110,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D4 extends C3 { [x: string]: U; foo: U; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } @@ -128,21 +128,21 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: T; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D6 extends C3 { [x: string]: U; foo: T; ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D7 extends C3 { [x: string]: V; foo: T; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if U is a subtype of T, U, V @@ -159,21 +159,21 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D9 extends C3 { [x: string]: U; foo: U; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D10 extends C3 { [x: string]: V; foo: U; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if V is a subtype of T, U, V @@ -188,7 +188,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D12 extends C3 { @@ -201,14 +201,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'V' is not assignable to type 'U'. !!! error TS2416: 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint '{}'. ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D13 extends C3 { [x: string]: V; foo: V; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // Date > V > U > T @@ -218,28 +218,28 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: Date; foo: T; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D15 extends C3 { [x: string]: T; foo: T; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D16 extends C3 { [x: string]: U; foo: T; ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D17 extends C3 { [x: string]: V; foo: T; ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if U is a subtype of T, U, V, Date @@ -248,7 +248,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: Date; foo: T; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D19 extends C3 { @@ -265,21 +265,21 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Date' is not assignable to type 'T'. !!! error TS2416: 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D20 extends C3 { [x: string]: U; foo: U; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D21 extends C3 { [x: string]: V; foo: U; ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if V is a subtype of T, U, V, Date @@ -288,7 +288,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: Date; foo: T; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D23 extends C3 { @@ -303,7 +303,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Date' is not assignable to type 'T'. !!! error TS2416: 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D24 extends C3 { @@ -318,14 +318,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Date' is not assignable to type 'U'. !!! error TS2416: 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D25 extends C3 { [x: string]: V; foo: V; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if Date is a subtype of T, U, V, Date @@ -334,7 +334,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: Date; foo: Date; // ok ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D27 extends C3 { @@ -347,7 +347,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Date' is not assignable to type 'T'. !!! error TS2416: 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D28 extends C3 { @@ -360,7 +360,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Date' is not assignable to type 'U'. !!! error TS2416: 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D29 extends C3 { @@ -373,5 +373,5 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Date' is not assignable to type 'V'. !!! error TS2416: 'Date' is assignable to the constraint of type 'V', but 'V' could be instantiated with a different subtype of constraint 'Date'. ~~~ -!!! error TS2610: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. +!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file From 58e17462045651933fce591f1579f519b2750f4c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 19 Sep 2019 07:40:34 -0700 Subject: [PATCH 19/44] Ignore this-property assignments --- src/compiler/checker.ts | 4 ++- .../thisPropertyOverridesAccessors.symbols | 28 ++++++++++++++++ .../thisPropertyOverridesAccessors.types | 32 +++++++++++++++++++ .../thisPropertyOverridesAccessors.ts | 17 ++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/thisPropertyOverridesAccessors.symbols create mode 100644 tests/baselines/reference/thisPropertyOverridesAccessors.types create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/thisPropertyOverridesAccessors.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e38b631df4f9c..a2f69261c3c84 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29519,8 +29519,10 @@ namespace ts { if (basePropertyFlags && derivedPropertyFlags) { // property/accessor is overridden with property/accessor if (baseDeclarationFlags & ModifierFlags.Abstract - || getObjectFlags(getTargetType(baseType)) & ObjectFlags.Interface) { + || getObjectFlags(getTargetType(baseType)) & ObjectFlags.Interface + || derived.valueDeclaration && isBinaryExpression(derived.valueDeclaration)) { // when the base property is abstract or from an interface, base/derived flags don't need to match + // same when the derived property is from an assignment continue; } if (basePropertyFlags !== SymbolFlags.Property && derivedPropertyFlags === SymbolFlags.Property) { diff --git a/tests/baselines/reference/thisPropertyOverridesAccessors.symbols b/tests/baselines/reference/thisPropertyOverridesAccessors.symbols new file mode 100644 index 0000000000000..40cec9f184709 --- /dev/null +++ b/tests/baselines/reference/thisPropertyOverridesAccessors.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/foo.ts === +class Foo { +>Foo : Symbol(Foo, Decl(foo.ts, 0, 0)) + + get p() { return 1 } +>p : Symbol(Foo.p, Decl(foo.ts, 0, 11), Decl(foo.ts, 1, 24)) + + set p(value) { } +>p : Symbol(Foo.p, Decl(foo.ts, 0, 11), Decl(foo.ts, 1, 24)) +>value : Symbol(value, Decl(foo.ts, 2, 10)) +} + +=== tests/cases/conformance/classes/propertyMemberDeclarations/bar.js === +class Bar extends Foo { +>Bar : Symbol(Bar, Decl(bar.js, 0, 0)) +>Foo : Symbol(Foo, Decl(foo.ts, 0, 0)) + + constructor() { + super() +>super : Symbol(Foo, Decl(foo.ts, 0, 0)) + + this.p = 2 +>this.p : Symbol(Bar.p, Decl(bar.js, 2, 15)) +>this : Symbol(Bar, Decl(bar.js, 0, 0)) +>p : Symbol(Bar.p, Decl(bar.js, 2, 15)) + } +} + diff --git a/tests/baselines/reference/thisPropertyOverridesAccessors.types b/tests/baselines/reference/thisPropertyOverridesAccessors.types new file mode 100644 index 0000000000000..c242351dbd2b2 --- /dev/null +++ b/tests/baselines/reference/thisPropertyOverridesAccessors.types @@ -0,0 +1,32 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/foo.ts === +class Foo { +>Foo : Foo + + get p() { return 1 } +>p : number +>1 : 1 + + set p(value) { } +>p : number +>value : number +} + +=== tests/cases/conformance/classes/propertyMemberDeclarations/bar.js === +class Bar extends Foo { +>Bar : Bar +>Foo : Foo + + constructor() { + super() +>super() : void +>super : typeof Foo + + this.p = 2 +>this.p = 2 : 2 +>this.p : number +>this : this +>p : number +>2 : 2 + } +} + diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/thisPropertyOverridesAccessors.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/thisPropertyOverridesAccessors.ts new file mode 100644 index 0000000000000..779d326fa6f3b --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/thisPropertyOverridesAccessors.ts @@ -0,0 +1,17 @@ +// @target: esnext +// @allowjs: true +// @noemit: true +// @checkjs: true +// @Filename: foo.ts +class Foo { + get p() { return 1 } + set p(value) { } +} + +// @Filename: bar.js +class Bar extends Foo { + constructor() { + super() + this.p = 2 + } +} From 832d51f62981c23fcf66d6ac67cf44dfb86e5d81 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 19 Sep 2019 10:28:06 -0700 Subject: [PATCH 20/44] Fix base-in-interface check --- src/compiler/checker.ts | 3 ++- .../reference/accessorsOverrideProperty5.js | 19 ++++++++++++++ .../accessorsOverrideProperty5.symbols | 26 +++++++++++++++++++ .../accessorsOverrideProperty5.types | 22 ++++++++++++++++ .../accessorsOverrideProperty5.ts | 10 +++++++ 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/accessorsOverrideProperty5.js create mode 100644 tests/baselines/reference/accessorsOverrideProperty5.symbols create mode 100644 tests/baselines/reference/accessorsOverrideProperty5.types create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a2f69261c3c84..11291fb869369 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29518,8 +29518,9 @@ namespace ts { const derivedPropertyFlags = derived.flags & SymbolFlags.PropertyOrAccessor; if (basePropertyFlags && derivedPropertyFlags) { // property/accessor is overridden with property/accessor + const baseParent = getParentOfSymbol(base); if (baseDeclarationFlags & ModifierFlags.Abstract - || getObjectFlags(getTargetType(baseType)) & ObjectFlags.Interface + || baseParent && baseParent.flags & SymbolFlags.Interface || derived.valueDeclaration && isBinaryExpression(derived.valueDeclaration)) { // when the base property is abstract or from an interface, base/derived flags don't need to match // same when the derived property is from an assignment diff --git a/tests/baselines/reference/accessorsOverrideProperty5.js b/tests/baselines/reference/accessorsOverrideProperty5.js new file mode 100644 index 0000000000000..fb7cee0630b67 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty5.js @@ -0,0 +1,19 @@ +//// [accessorsOverrideProperty5.ts] +interface I { + p: number +} +interface B extends I { } +class B { } +class C extends B { + get p() { return 1 } + set p(value) { } +} + + +//// [accessorsOverrideProperty5.js] +class B { +} +class C extends B { + get p() { return 1; } + set p(value) { } +} diff --git a/tests/baselines/reference/accessorsOverrideProperty5.symbols b/tests/baselines/reference/accessorsOverrideProperty5.symbols new file mode 100644 index 0000000000000..b048d8bbc928d --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty5.symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts === +interface I { +>I : Symbol(I, Decl(accessorsOverrideProperty5.ts, 0, 0)) + + p: number +>p : Symbol(I.p, Decl(accessorsOverrideProperty5.ts, 0, 13)) +} +interface B extends I { } +>B : Symbol(B, Decl(accessorsOverrideProperty5.ts, 2, 1), Decl(accessorsOverrideProperty5.ts, 3, 25)) +>I : Symbol(I, Decl(accessorsOverrideProperty5.ts, 0, 0)) + +class B { } +>B : Symbol(B, Decl(accessorsOverrideProperty5.ts, 2, 1), Decl(accessorsOverrideProperty5.ts, 3, 25)) + +class C extends B { +>C : Symbol(C, Decl(accessorsOverrideProperty5.ts, 4, 11)) +>B : Symbol(B, Decl(accessorsOverrideProperty5.ts, 2, 1), Decl(accessorsOverrideProperty5.ts, 3, 25)) + + get p() { return 1 } +>p : Symbol(C.p, Decl(accessorsOverrideProperty5.ts, 5, 19), Decl(accessorsOverrideProperty5.ts, 6, 24)) + + set p(value) { } +>p : Symbol(C.p, Decl(accessorsOverrideProperty5.ts, 5, 19), Decl(accessorsOverrideProperty5.ts, 6, 24)) +>value : Symbol(value, Decl(accessorsOverrideProperty5.ts, 7, 10)) +} + diff --git a/tests/baselines/reference/accessorsOverrideProperty5.types b/tests/baselines/reference/accessorsOverrideProperty5.types new file mode 100644 index 0000000000000..2032d3fa6ae50 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty5.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts === +interface I { + p: number +>p : number +} +interface B extends I { } +class B { } +>B : B + +class C extends B { +>C : C +>B : B + + get p() { return 1 } +>p : number +>1 : 1 + + set p(value) { } +>p : number +>value : number +} + diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts new file mode 100644 index 0000000000000..3bf85e9ddd2c1 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts @@ -0,0 +1,10 @@ +// @target: esnext +interface I { + p: number +} +interface B extends I { } +class B { } +class C extends B { + get p() { return 1 } + set p(value) { } +} From a645ca9839005137d824622d245a16055092458e Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 19 Sep 2019 10:51:09 -0700 Subject: [PATCH 21/44] Do not error when base parent is interface --- src/compiler/checker.ts | 2 ++ ...ninitializedPropertyDeclaration.errors.txt | 14 ++++++++++++- ...derivedUninitializedPropertyDeclaration.js | 21 +++++++++++++++++++ ...edUninitializedPropertyDeclaration.symbols | 21 +++++++++++++++++++ ...ivedUninitializedPropertyDeclaration.types | 16 ++++++++++++++ ...derivedUninitializedPropertyDeclaration.ts | 9 ++++++++ 6 files changed, 82 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 308ddaac6427f..5b81f34370369 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29518,7 +29518,9 @@ namespace ts { } if (base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) { const uninitialized = find(derived.declarations, d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer); + const baseParent = getParentOfSymbol(base); if (uninitialized + && !(baseParent && baseParent.flags & SymbolFlags.Interface) && !(derived.flags & SymbolFlags.Transient) && !(baseDeclarationFlags & ModifierFlags.Abstract) && !(derivedDeclarationFlags & ModifierFlags.Abstract) diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt index 62c7aedfbbea7..b2365be06bca4 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt @@ -7,9 +7,10 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2610: Property 'p' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(39,5): error TS2610: Property 'p1' will overwrite the base property in 'E'. Add a 'declare' modifier or an initializer to avoid this. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(62,5): error TS2564: Property 'q' has no initializer and is not definitely assigned in the constructor. -==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (9 errors) ==== +==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (10 errors) ==== class A { property = 'x'; m() { return 1 } @@ -82,4 +83,15 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP abstract p1: 'a' | 'b' | 'c' declare abstract p2: 'a' | 'b' | 'c' } + + interface I { + q: number + } + interface J extends I { } + class K { } + class L extends K { + q: 1 | 2 | 3 // ok, extends a property from an interface + ~ +!!! error TS2564: Property 'q' has no initializer and is not definitely assigned in the constructor. + } \ No newline at end of file diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js index decc56a4867c2..4849a443fd145 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js @@ -53,6 +53,15 @@ abstract class H extends E { abstract p1: 'a' | 'b' | 'c' declare abstract p2: 'a' | 'b' | 'c' } + +interface I { + q: number +} +interface J extends I { } +class K { } +class L extends K { + q: 1 | 2 | 3 // ok, extends a property from an interface +} //// [derivedUninitializedPropertyDeclaration.js] @@ -155,3 +164,15 @@ var H = /** @class */ (function (_super) { } return H; }(E)); +var K = /** @class */ (function () { + function K() { + } + return K; +}()); +var L = /** @class */ (function (_super) { + __extends(L, _super); + function L() { + return _super !== null && _super.apply(this, arguments) || this; + } + return L; +}(K)); diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols index 2ed91c2c2d172..668a0053ed579 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols @@ -120,3 +120,24 @@ abstract class H extends E { >p2 : Symbol(H.p2, Decl(derivedUninitializedPropertyDeclaration.ts, 51, 32)) } +interface I { +>I : Symbol(I, Decl(derivedUninitializedPropertyDeclaration.ts, 53, 1)) + + q: number +>q : Symbol(I.q, Decl(derivedUninitializedPropertyDeclaration.ts, 55, 13)) +} +interface J extends I { } +>J : Symbol(J, Decl(derivedUninitializedPropertyDeclaration.ts, 57, 1)) +>I : Symbol(I, Decl(derivedUninitializedPropertyDeclaration.ts, 53, 1)) + +class K { } +>K : Symbol(K, Decl(derivedUninitializedPropertyDeclaration.ts, 58, 25)) + +class L extends K { +>L : Symbol(L, Decl(derivedUninitializedPropertyDeclaration.ts, 59, 11)) +>K : Symbol(K, Decl(derivedUninitializedPropertyDeclaration.ts, 58, 25)) + + q: 1 | 2 | 3 // ok, extends a property from an interface +>q : Symbol(L.q, Decl(derivedUninitializedPropertyDeclaration.ts, 60, 19)) +} + diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types index aa4e7ba501e42..63cc5d59ec47c 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types @@ -127,3 +127,19 @@ abstract class H extends E { >p2 : "a" | "b" | "c" } +interface I { + q: number +>q : number +} +interface J extends I { } +class K { } +>K : K + +class L extends K { +>L : L +>K : K + + q: 1 | 2 | 3 // ok, extends a property from an interface +>q : 1 | 2 | 3 +} + diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts index a3f126c10aec8..a590d667a4a81 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts @@ -53,3 +53,12 @@ abstract class H extends E { abstract p1: 'a' | 'b' | 'c' declare abstract p2: 'a' | 'b' | 'c' } + +interface I { + q: number +} +interface J extends I { } +class K { } +class L extends K { + q: 1 | 2 | 3 // ok, extends a property from an interface +} From 030c768d91d4dfc61b2ca60fa94836098a64ddb1 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 19 Sep 2019 11:58:46 -0700 Subject: [PATCH 22/44] Fix base interface check --- src/compiler/checker.ts | 3 +-- ...ninitializedPropertyDeclaration.errors.txt | 13 ++++++---- ...derivedUninitializedPropertyDeclaration.js | 26 +++++++++++-------- ...edUninitializedPropertyDeclaration.symbols | 22 ++++++++++------ ...ivedUninitializedPropertyDeclaration.types | 17 ++++++++---- ...derivedUninitializedPropertyDeclaration.ts | 9 ++++--- 6 files changed, 56 insertions(+), 34 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5b81f34370369..30d671748c74c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29518,9 +29518,8 @@ namespace ts { } if (base.flags & SymbolFlags.PropertyOrAccessor && derived.flags & SymbolFlags.PropertyOrAccessor) { const uninitialized = find(derived.declarations, d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer); - const baseParent = getParentOfSymbol(base); if (uninitialized - && !(baseParent && baseParent.flags & SymbolFlags.Interface) + && !(base.valueDeclaration && base.valueDeclaration.parent.kind === SyntaxKind.InterfaceDeclaration) && !(derived.flags & SymbolFlags.Transient) && !(baseDeclarationFlags & ModifierFlags.Abstract) && !(derivedDeclarationFlags & ModifierFlags.Abstract) diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt index b2365be06bca4..0c0fda3415616 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt @@ -7,7 +7,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2610: Property 'p' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(39,5): error TS2610: Property 'p1' will overwrite the base property in 'E'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(62,5): error TS2564: Property 'q' has no initializer and is not definitely assigned in the constructor. +tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(65,5): error TS2610: Property 'r' will overwrite the base property in 'J'. Add a 'declare' modifier or an initializer to avoid this. ==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (10 errors) ==== @@ -88,10 +88,13 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP q: number } interface J extends I { } - class K { } - class L extends K { - q: 1 | 2 | 3 // ok, extends a property from an interface + class J { + r = 5 + } + class K extends J { + q!: 1 | 2 | 3 // ok, extends a property from an interface + r!: 4 | 5 // error, from class ~ -!!! error TS2564: Property 'q' has no initializer and is not definitely assigned in the constructor. +!!! error TS2610: Property 'r' will overwrite the base property in 'J'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js index 4849a443fd145..471cd5bbf1d18 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.js @@ -58,9 +58,12 @@ interface I { q: number } interface J extends I { } -class K { } -class L extends K { - q: 1 | 2 | 3 // ok, extends a property from an interface +class J { + r = 5 +} +class K extends J { + q!: 1 | 2 | 3 // ok, extends a property from an interface + r!: 4 | 5 // error, from class } @@ -164,15 +167,16 @@ var H = /** @class */ (function (_super) { } return H; }(E)); -var K = /** @class */ (function () { - function K() { +var J = /** @class */ (function () { + function J() { + this.r = 5; } - return K; + return J; }()); -var L = /** @class */ (function (_super) { - __extends(L, _super); - function L() { +var K = /** @class */ (function (_super) { + __extends(K, _super); + function K() { return _super !== null && _super.apply(this, arguments) || this; } - return L; -}(K)); + return K; +}(J)); diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols index 668a0053ed579..87e912887042a 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.symbols @@ -127,17 +127,23 @@ interface I { >q : Symbol(I.q, Decl(derivedUninitializedPropertyDeclaration.ts, 55, 13)) } interface J extends I { } ->J : Symbol(J, Decl(derivedUninitializedPropertyDeclaration.ts, 57, 1)) +>J : Symbol(J, Decl(derivedUninitializedPropertyDeclaration.ts, 57, 1), Decl(derivedUninitializedPropertyDeclaration.ts, 58, 25)) >I : Symbol(I, Decl(derivedUninitializedPropertyDeclaration.ts, 53, 1)) -class K { } ->K : Symbol(K, Decl(derivedUninitializedPropertyDeclaration.ts, 58, 25)) +class J { +>J : Symbol(J, Decl(derivedUninitializedPropertyDeclaration.ts, 57, 1), Decl(derivedUninitializedPropertyDeclaration.ts, 58, 25)) -class L extends K { ->L : Symbol(L, Decl(derivedUninitializedPropertyDeclaration.ts, 59, 11)) ->K : Symbol(K, Decl(derivedUninitializedPropertyDeclaration.ts, 58, 25)) + r = 5 +>r : Symbol(J.r, Decl(derivedUninitializedPropertyDeclaration.ts, 59, 9)) +} +class K extends J { +>K : Symbol(K, Decl(derivedUninitializedPropertyDeclaration.ts, 61, 1)) +>J : Symbol(J, Decl(derivedUninitializedPropertyDeclaration.ts, 57, 1), Decl(derivedUninitializedPropertyDeclaration.ts, 58, 25)) + + q!: 1 | 2 | 3 // ok, extends a property from an interface +>q : Symbol(K.q, Decl(derivedUninitializedPropertyDeclaration.ts, 62, 19)) - q: 1 | 2 | 3 // ok, extends a property from an interface ->q : Symbol(L.q, Decl(derivedUninitializedPropertyDeclaration.ts, 60, 19)) + r!: 4 | 5 // error, from class +>r : Symbol(K.r, Decl(derivedUninitializedPropertyDeclaration.ts, 63, 17)) } diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types index 63cc5d59ec47c..d9c96f0c9fc07 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.types @@ -132,14 +132,21 @@ interface I { >q : number } interface J extends I { } -class K { } ->K : K +class J { +>J : J -class L extends K { ->L : L + r = 5 +>r : number +>5 : 5 +} +class K extends J { >K : K +>J : J - q: 1 | 2 | 3 // ok, extends a property from an interface + q!: 1 | 2 | 3 // ok, extends a property from an interface >q : 1 | 2 | 3 + + r!: 4 | 5 // error, from class +>r : 5 | 4 } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts index a590d667a4a81..e2d7494dd6891 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts @@ -58,7 +58,10 @@ interface I { q: number } interface J extends I { } -class K { } -class L extends K { - q: 1 | 2 | 3 // ok, extends a property from an interface +class J { + r = 5 +} +class K extends J { + q!: 1 | 2 | 3 // ok, extends a property from an interface + r!: 4 | 5 // error, from class } From 003d04151547cc14d6e613ff6b25c737fd730534 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 19 Sep 2019 12:40:12 -0700 Subject: [PATCH 23/44] Add missed baselines --- ...erfaceExtendsObjectIntersection.errors.txt | 78 ------------------- ...ExtendsObjectIntersectionErrors.errors.txt | 5 +- 2 files changed, 1 insertion(+), 82 deletions(-) delete mode 100644 tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt diff --git a/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt b/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt deleted file mode 100644 index f23383cda97cc..0000000000000 --- a/tests/baselines/reference/interfaceExtendsObjectIntersection.errors.txt +++ /dev/null @@ -1,78 +0,0 @@ -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(20,38): error TS2610: Property 'x' will overwrite the base property in 'I1'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(21,38): error TS2610: Property 'x' will overwrite the base property in 'I2'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(22,38): error TS2610: Property 'x' will overwrite the base property in 'I3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(23,38): error TS2610: Property 'x' will overwrite the base property in 'I4'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(24,38): error TS2610: Property 'x' will overwrite the base property in 'I5'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(25,38): error TS2610: Property 'x' will overwrite the base property in 'I6'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts(26,38): error TS2610: Property 'x' will overwrite the base property in 'I7'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersection.ts (7 errors) ==== - type T1 = { a: number }; - type T2 = T1 & { b: number }; - type T3 = () => void; - type T4 = new () => { a: number }; - type T5 = number[]; - type T6 = [string, number]; - type T7 = { [P in 'a' | 'b' | 'c']: string }; - - interface I1 extends T1 { x: string } - interface I2 extends T2 { x: string } - interface I3 extends T3 { x: string } - interface I4 extends T4 { x: string } - interface I5 extends T5 { x: string } - interface I6 extends T6 { x: string } - interface I7 extends T7 { x: string } - - type Constructor = new () => T; - declare function Constructor(): Constructor; - - class C1 extends Constructor() { x: string } - ~ -!!! error TS2610: Property 'x' will overwrite the base property in 'I1'. Add a 'declare' modifier or an initializer to avoid this. - class C2 extends Constructor() { x: string } - ~ -!!! error TS2610: Property 'x' will overwrite the base property in 'I2'. Add a 'declare' modifier or an initializer to avoid this. - class C3 extends Constructor() { x: string } - ~ -!!! error TS2610: Property 'x' will overwrite the base property in 'I3'. Add a 'declare' modifier or an initializer to avoid this. - class C4 extends Constructor() { x: string } - ~ -!!! error TS2610: Property 'x' will overwrite the base property in 'I4'. Add a 'declare' modifier or an initializer to avoid this. - class C5 extends Constructor() { x: string } - ~ -!!! error TS2610: Property 'x' will overwrite the base property in 'I5'. Add a 'declare' modifier or an initializer to avoid this. - class C6 extends Constructor() { x: string } - ~ -!!! error TS2610: Property 'x' will overwrite the base property in 'I6'. Add a 'declare' modifier or an initializer to avoid this. - class C7 extends Constructor() { x: string } - ~ -!!! error TS2610: Property 'x' will overwrite the base property in 'I7'. Add a 'declare' modifier or an initializer to avoid this. - - declare function fx(x: string): string; - declare class CX { a: number } - declare enum EX { A, B, C } - declare namespace NX { export const a = 1 } - - type T10 = typeof fx; - type T11 = typeof CX; - type T12 = typeof EX; - type T13 = typeof NX; - - interface I10 extends T10 { x: string } - interface I11 extends T11 { x: string } - interface I12 extends T12 { x: string } - interface I13 extends T13 { x: string } - - type Identifiable = { _id: string } & T; - - interface I20 extends Partial { x: string } - interface I21 extends Readonly { x: string } - interface I22 extends Identifiable { x: string } - interface I23 extends Identifiable { x: string } - - class C20 extends Constructor>() { x: string } - class C21 extends Constructor>() { x: string } - class C22 extends Constructor>() { x: string } - class C23 extends Constructor>() { x: string } - \ No newline at end of file diff --git a/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt b/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt index 88f9150adc11d..cf04e9cbc4221 100644 --- a/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt +++ b/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt @@ -22,7 +22,6 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2610: Property 'b' will overwrite the base property in 'T2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2610: Property 'length' will overwrite the base property in 'number[]'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'. Type 'number' is not assignable to type 'string'. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2610: Property '0' will overwrite the base property in '[string, number]'. Add a 'declare' modifier or an initializer to avoid this. @@ -60,7 +59,7 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(47,26): error TS2312: An interface can only extend an object type or intersection of object types with statically known members. -==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts (28 errors) ==== +==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts (27 errors) ==== type T1 = { a: number }; type T2 = T1 & { b: number }; type T3 = number[]; @@ -113,8 +112,6 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI ~~~~~~ !!! error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'. !!! error TS2416: Type 'string' is not assignable to type 'number'. - ~~~~~~ -!!! error TS2610: Property 'length' will overwrite the base property in 'number[]'. Add a 'declare' modifier or an initializer to avoid this. class C4 extends Constructor() { 0: number } ~ !!! error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'. From 6ec445f9d512e63b8f3d76de7eb73235b1bdec40 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 19 Sep 2019 12:46:20 -0700 Subject: [PATCH 24/44] Fix check --- src/compiler/checker.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 11291fb869369..03365d106e638 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29518,9 +29518,8 @@ namespace ts { const derivedPropertyFlags = derived.flags & SymbolFlags.PropertyOrAccessor; if (basePropertyFlags && derivedPropertyFlags) { // property/accessor is overridden with property/accessor - const baseParent = getParentOfSymbol(base); if (baseDeclarationFlags & ModifierFlags.Abstract - || baseParent && baseParent.flags & SymbolFlags.Interface + || base.valueDeclaration && base.valueDeclaration.parent.kind === SyntaxKind.InterfaceDeclaration || derived.valueDeclaration && isBinaryExpression(derived.valueDeclaration)) { // when the base property is abstract or from an interface, base/derived flags don't need to match // same when the derived property is from an assignment From c283574123686bba0e860fe2818b29050b244d74 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 19 Sep 2019 14:04:25 -0700 Subject: [PATCH 25/44] Fix new errors in services --- src/services/services.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 644629ce2af4f..ebf63d246a6e2 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -339,7 +339,6 @@ namespace ts { } class TokenObject extends TokenOrIdentifierObject implements Token { - public symbol!: Symbol; public kind: TKind; constructor(kind: TKind, pos: number, end: number) { @@ -349,9 +348,8 @@ namespace ts { } class IdentifierObject extends TokenOrIdentifierObject implements Identifier { - public kind!: SyntaxKind.Identifier; + public kind: SyntaxKind.Identifier = SyntaxKind.Identifier; public escapedText!: __String; - public symbol!: Symbol; public autoGenerateFlags!: GeneratedIdentifierFlags; _primaryExpressionBrand: any; _memberExpressionBrand: any; @@ -541,7 +539,7 @@ namespace ts { } class SourceFileObject extends NodeObject implements SourceFile { - public kind!: SyntaxKind.SourceFile; + public kind: SyntaxKind.SourceFile = SyntaxKind.SourceFile; public _declarationBrand: any; public fileName!: string; public path!: Path; From 1c5f699994332a5cd6fbb22507b1535aca884b84 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 19 Sep 2019 14:04:25 -0700 Subject: [PATCH 26/44] Fix new errors in services --- src/services/services.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 644629ce2af4f..ebf63d246a6e2 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -339,7 +339,6 @@ namespace ts { } class TokenObject extends TokenOrIdentifierObject implements Token { - public symbol!: Symbol; public kind: TKind; constructor(kind: TKind, pos: number, end: number) { @@ -349,9 +348,8 @@ namespace ts { } class IdentifierObject extends TokenOrIdentifierObject implements Identifier { - public kind!: SyntaxKind.Identifier; + public kind: SyntaxKind.Identifier = SyntaxKind.Identifier; public escapedText!: __String; - public symbol!: Symbol; public autoGenerateFlags!: GeneratedIdentifierFlags; _primaryExpressionBrand: any; _memberExpressionBrand: any; @@ -541,7 +539,7 @@ namespace ts { } class SourceFileObject extends NodeObject implements SourceFile { - public kind!: SyntaxKind.SourceFile; + public kind: SyntaxKind.SourceFile = SyntaxKind.SourceFile; public _declarationBrand: any; public fileName!: string; public path!: Path; From 8d99856ee9d423763122a00524a6dec136ec5ea7 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 19 Sep 2019 16:16:15 -0700 Subject: [PATCH 27/44] Fix errors in testRunner --- src/testRunner/parallel/host.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/testRunner/parallel/host.ts b/src/testRunner/parallel/host.ts index 56fa17dd9e1ce..89264224c13a6 100644 --- a/src/testRunner/parallel/host.ts +++ b/src/testRunner/parallel/host.ts @@ -24,9 +24,7 @@ namespace Harness.Parallel.Host { let totalCost = 0; class RemoteSuite extends Mocha.Suite { - suites!: RemoteSuite[]; suiteMap = ts.createMap(); - tests!: RemoteTest[]; constructor(title: string) { super(title); this.pending = false; @@ -529,10 +527,10 @@ namespace Harness.Parallel.Host { function replaySuite(runner: Mocha.Runner, suite: RemoteSuite) { runner.emit("suite", suite); for (const test of suite.tests) { - replayTest(runner, test); + replayTest(runner, test as RemoteTest); } for (const child of suite.suites) { - replaySuite(runner, child); + replaySuite(runner, child as RemoteSuite); } runner.emit("suite end", suite); } From f400822a609a7a3b5cc2341232e974d281a4cd0b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 19 Sep 2019 16:19:30 -0700 Subject: [PATCH 28/44] Add flag and turn off errors when on --- src/compiler/checker.ts | 3 ++- src/compiler/commandLineParser.ts | 7 +++++++ src/compiler/diagnosticMessages.json | 13 +++++++++---- src/server/protocol.ts | 1 + 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a9ad3b2d70c93..d6b35244bdf1e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29517,7 +29517,8 @@ namespace ts { const derivedPropertyFlags = derived.flags & SymbolFlags.PropertyOrAccessor; if (basePropertyFlags && derivedPropertyFlags) { // property/accessor is overridden with property/accessor - if (baseDeclarationFlags & ModifierFlags.Abstract + if (compilerOptions.legacyClassFields + || baseDeclarationFlags & ModifierFlags.Abstract || base.valueDeclaration && base.valueDeclaration.parent.kind === SyntaxKind.InterfaceDeclaration || derived.valueDeclaration && isBinaryExpression(derived.valueDeclaration)) { // when the base property is abstract or from an interface, base/derived flags don't need to match diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 009c04fbb8c5f..c834a937c9661 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -867,6 +867,13 @@ namespace ts { category: Diagnostics.Advanced_Options, description: Diagnostics.Disable_strict_checking_of_generic_signatures_in_function_types, }, + { + name: "legacyClassFields", + type: "boolean", + affectsSemanticDiagnostics: true, + category: Diagnostics.Advanced_Options, + description: Diagnostics.Emit_legacy_class_fields, + }, { name: "keyofStringsOnly", type: "boolean", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 80d50cd90dd65..9b3f8e0ed6f4e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3947,6 +3947,10 @@ "Conflicts are in this file.": { "category": "Message", "code": 6201 + }, + "Project references may not form a circular graph. Cycle detected: {0}": { + "category": "Error", + "code": 6202 }, "'{0}' was also declared here.": { "category": "Message", @@ -4020,6 +4024,10 @@ "category": "Message", "code": 6220 }, + "Emit legacy class fields.": { + "category": "Message", + "code": 6221 + }, "Projects to reference": { "category": "Message", @@ -4029,10 +4037,7 @@ "category": "Message", "code": 6302 }, - "Project references may not form a circular graph. Cycle detected: {0}": { - "category": "Error", - "code": 6202 - }, + "Composite projects may not disable declaration emit.": { "category": "Error", "code": 6304 diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 0674f1c142de3..57c947409b2be 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -3067,6 +3067,7 @@ namespace ts.server.protocol { strictNullChecks?: boolean; suppressExcessPropertyErrors?: boolean; suppressImplicitAnyIndexErrors?: boolean; + legacyClassFields?: boolean; target?: ScriptTarget | ts.ScriptTarget; traceResolution?: boolean; resolveJsonModule?: boolean; From 1f68bea377f0220b79dd508ff86a88101acbdef1 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 20 Sep 2019 08:16:22 -0700 Subject: [PATCH 29/44] Structure of new emit is correct, fake content It is 'hi'. --- src/compiler/transformers/classFields.ts | 1037 +-- src/compiler/transformers/ts.ts | 6716 ++++++++--------- src/compiler/transformers/utilities.ts | 662 +- src/compiler/types.ts | 3 +- .../reference/accessorsOverrideProperty6.js | 39 + .../accessorsOverrideProperty6.symbols | 42 + .../accessorsOverrideProperty6.types | 47 + .../accessorsOverrideProperty5.ts | 21 +- .../accessorsOverrideProperty6.ts | 16 + .../propertyOverridesAccessors.ts | 2 +- 10 files changed, 4367 insertions(+), 4218 deletions(-) create mode 100644 tests/baselines/reference/accessorsOverrideProperty6.js create mode 100644 tests/baselines/reference/accessorsOverrideProperty6.symbols create mode 100644 tests/baselines/reference/accessorsOverrideProperty6.types create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty6.ts diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 37473d9bb20ec..716e196f3b87a 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -1,511 +1,526 @@ -/*@internal*/ -namespace ts { - const enum ClassPropertySubstitutionFlags { - /** - * Enables substitutions for class expressions with static fields - * which have initializers that reference the class name. - */ - ClassAliases = 1 << 0, - } - /** - * Transforms ECMAScript Class Syntax. - * TypeScript parameter property syntax is transformed in the TypeScript transformer. - * For now, this transforms public field declarations using TypeScript class semantics - * (where the declarations get elided and initializers are transformed as assignments in the constructor). - * Eventually, this transform will change to the ECMAScript semantics (with Object.defineProperty). - */ - export function transformClassFields(context: TransformationContext) { - const { - hoistVariableDeclaration, - endLexicalEnvironment, - resumeLexicalEnvironment - } = context; - const resolver = context.getEmitResolver(); - - const previousOnSubstituteNode = context.onSubstituteNode; - context.onSubstituteNode = onSubstituteNode; - - let enabledSubstitutions: ClassPropertySubstitutionFlags; - - let classAliases: Identifier[]; - - /** - * Tracks what computed name expressions originating from elided names must be inlined - * at the next execution site, in document order - */ - let pendingExpressions: Expression[] | undefined; - - /** - * Tracks what computed name expression statements and static property initializers must be - * emitted at the next execution site, in document order (for decorated classes). - */ - let pendingStatements: Statement[] | undefined; - - return chainBundle(transformSourceFile); - - function transformSourceFile(node: SourceFile) { - if (node.isDeclarationFile) { - return node; - } - const visited = visitEachChild(node, visitor, context); - addEmitHelpers(visited, context.readEmitHelpers()); - return visited; - } - - function visitor(node: Node): VisitResult { - if (!(node.transformFlags & TransformFlags.ContainsClassFields)) return node; - - switch (node.kind) { - case SyntaxKind.ClassExpression: - return visitClassExpression(node as ClassExpression); - case SyntaxKind.ClassDeclaration: - return visitClassDeclaration(node as ClassDeclaration); - case SyntaxKind.VariableStatement: - return visitVariableStatement(node as VariableStatement); - } - return visitEachChild(node, visitor, context); - } - - /** - * Visits the members of a class that has fields. - * - * @param node The node to visit. - */ - function classElementVisitor(node: Node): VisitResult { - switch (node.kind) { - case SyntaxKind.Constructor: - // Constructors for classes using class fields are transformed in - // `visitClassDeclaration` or `visitClassExpression`. - return undefined; - - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.MethodDeclaration: - // Visit the name of the member (if it's a computed property name). - return visitEachChild(node, classElementVisitor, context); - - case SyntaxKind.PropertyDeclaration: - return visitPropertyDeclaration(node as PropertyDeclaration); - - case SyntaxKind.ComputedPropertyName: - return visitComputedPropertyName(node as ComputedPropertyName); - - case SyntaxKind.SemicolonClassElement: - return node; - - default: - return visitor(node); - } - } - - function visitVariableStatement(node: VariableStatement) { - const savedPendingStatements = pendingStatements; - pendingStatements = []; - - const visitedNode = visitEachChild(node, visitor, context); - const statement = some(pendingStatements) ? - [visitedNode, ...pendingStatements] : - visitedNode; - - pendingStatements = savedPendingStatements; - return statement; - } - - function visitComputedPropertyName(name: ComputedPropertyName) { - let node = visitEachChild(name, visitor, context); - if (some(pendingExpressions)) { - const expressions = pendingExpressions; - expressions.push(name.expression); - pendingExpressions = []; - node = updateComputedPropertyName( - node, - inlineExpressions(expressions) - ); - } - return node; - } - - function visitPropertyDeclaration(node: PropertyDeclaration) { - Debug.assert(!some(node.decorators)); - // Create a temporary variable to store a computed property name (if necessary). - // If it's not inlineable, then we emit an expression after the class which assigns - // the property name to the temporary variable. - const expr = getPropertyNameExpressionIfNeeded(node.name, !!node.initializer); - if (expr && !isSimpleInlineableExpression(expr)) { - (pendingExpressions || (pendingExpressions = [])).push(expr); - } - return undefined; - } - - function visitClassDeclaration(node: ClassDeclaration) { - if (!forEach(node.members, isPropertyDeclaration)) { - return visitEachChild(node, visitor, context); - } - - const savedPendingExpressions = pendingExpressions; - pendingExpressions = undefined!; - - const extendsClauseElement = getEffectiveBaseTypeNode(node); - const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword); - - const statements: Statement[] = [ - updateClassDeclaration( - node, - /*decorators*/ undefined, - node.modifiers, - node.name, - /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, visitor, isHeritageClause), - transformClassMembers(node, isDerivedClass) - ) - ]; - - // Write any pending expressions from elided or moved computed property names - if (some(pendingExpressions)) { - statements.push(createExpressionStatement(inlineExpressions(pendingExpressions))); - } - - pendingExpressions = savedPendingExpressions; - - // Emit static property assignment. Because classDeclaration is lexically evaluated, - // it is safe to emit static property assignment after classDeclaration - // From ES6 specification: - // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using - // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. - const staticProperties = getInitializedProperties(node, /*isStatic*/ true); - if (some(staticProperties)) { - addInitializedPropertyStatements(statements, staticProperties, getInternalName(node)); - } - - return statements; - } - - function visitClassExpression(node: ClassExpression): Expression { - if (!forEach(node.members, isPropertyDeclaration)) { - return visitEachChild(node, visitor, context); - } - const savedPendingExpressions = pendingExpressions; - pendingExpressions = undefined; - - // If this class expression is a transformation of a decorated class declaration, - // then we want to output the pendingExpressions as statements, not as inlined - // expressions with the class statement. - // - // In this case, we use pendingStatements to produce the same output as the - // class declaration transformation. The VariableStatement visitor will insert - // these statements after the class expression variable statement. - const isDecoratedClassDeclaration = isClassDeclaration(getOriginalNode(node)); - - const staticProperties = getInitializedProperties(node, /*isStatic*/ true); - const extendsClauseElement = getEffectiveBaseTypeNode(node); - const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword); - - const classExpression = updateClassExpression( - node, - node.modifiers, - node.name, - /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, visitor, isHeritageClause), - transformClassMembers(node, isDerivedClass) - ); - - if (some(staticProperties) || some(pendingExpressions)) { - if (isDecoratedClassDeclaration) { - Debug.assertDefined(pendingStatements, "Decorated classes transformed by TypeScript are expected to be within a variable declaration."); - - // Write any pending expressions from elided or moved computed property names - if (pendingStatements && pendingExpressions && some(pendingExpressions)) { - pendingStatements.push(createExpressionStatement(inlineExpressions(pendingExpressions))); - } - pendingExpressions = savedPendingExpressions; - - if (pendingStatements && some(staticProperties)) { - addInitializedPropertyStatements(pendingStatements, staticProperties, getInternalName(node)); - } - return classExpression; - } - else { - const expressions: Expression[] = []; - const isClassWithConstructorReference = resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithConstructorReference; - const temp = createTempVariable(hoistVariableDeclaration, !!isClassWithConstructorReference); - if (isClassWithConstructorReference) { - // record an alias as the class name is not in scope for statics. - enableSubstitutionForClassAliases(); - const alias = getSynthesizedClone(temp); - alias.autoGenerateFlags &= ~GeneratedIdentifierFlags.ReservedInNestedScopes; - classAliases[getOriginalNodeId(node)] = alias; - } - - // To preserve the behavior of the old emitter, we explicitly indent - // the body of a class with static initializers. - setEmitFlags(classExpression, EmitFlags.Indented | getEmitFlags(classExpression)); - expressions.push(startOnNewLine(createAssignment(temp, classExpression))); - // Add any pending expressions leftover from elided or relocated computed property names - addRange(expressions, map(pendingExpressions, startOnNewLine)); - addRange(expressions, generateInitializedPropertyExpressions(staticProperties, temp)); - expressions.push(startOnNewLine(temp)); - - pendingExpressions = savedPendingExpressions; - return inlineExpressions(expressions); - } - } - - pendingExpressions = savedPendingExpressions; - return classExpression; - } - - function transformClassMembers(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { - const members: ClassElement[] = []; - const constructor = transformConstructor(node, isDerivedClass); - if (constructor) { - members.push(constructor); - } - addRange(members, visitNodes(node.members, classElementVisitor, isClassElement)); - return setTextRange(createNodeArray(members), /*location*/ node.members); - } - - function transformConstructor(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { - const constructor = visitNode(getFirstConstructorWithBody(node), visitor, isConstructorDeclaration); - const containsPropertyInitializer = forEach(node.members, isInitializedProperty); - if (!containsPropertyInitializer) { - return constructor; - } - const parameters = visitParameterList(constructor ? constructor.parameters : undefined, visitor, context); - const body = transformConstructorBody(node, constructor, isDerivedClass); - if (!body) { - return undefined; - } - return startOnNewLine( - setOriginalNode( - setTextRange( - createConstructor( - /*decorators*/ undefined, - /*modifiers*/ undefined, - parameters, - body - ), - constructor || node - ), - constructor - ) - ); - } - - function transformConstructorBody(node: ClassDeclaration | ClassExpression, constructor: ConstructorDeclaration | undefined, isDerivedClass: boolean) { - const properties = getInitializedProperties(node, /*isStatic*/ false); - - // Only generate synthetic constructor when there are property initializers to move. - if (!constructor && !some(properties)) { - return visitFunctionBody(/*node*/ undefined, visitor, context); - } - - resumeLexicalEnvironment(); - - let indexOfFirstStatement = 0; - let statements: Statement[] = []; - - if (!constructor && isDerivedClass) { - // Add a synthetic `super` call: - // - // super(...arguments); - // - statements.push( - createExpressionStatement( - createCall( - createSuper(), - /*typeArguments*/ undefined, - [createSpread(createIdentifier("arguments"))] - ) - ) - ); - } - - if (constructor) { - indexOfFirstStatement = addPrologueDirectivesAndInitialSuperCall(constructor, statements, visitor); - } - - // Add the property initializers. Transforms this: - // - // public x = 1; - // - // Into this: - // - // constructor() { - // this.x = 1; - // } - // - if (constructor && constructor.body) { - let parameterPropertyDeclarationCount = 0; - for (let i = indexOfFirstStatement; i < constructor.body.statements.length; i++) { - if (isParameterPropertyDeclaration(getOriginalNode(constructor.body.statements[i]), constructor)) { - parameterPropertyDeclarationCount++; - } - else { - break; - } - } - if (parameterPropertyDeclarationCount > 0) { - addRange(statements, visitNodes(constructor.body.statements, visitor, isStatement, indexOfFirstStatement, parameterPropertyDeclarationCount)); - indexOfFirstStatement += parameterPropertyDeclarationCount; - } - } - addInitializedPropertyStatements(statements, properties, createThis()); - - // Add existing statements, skipping the initial super call. - if (constructor) { - addRange(statements, visitNodes(constructor.body!.statements, visitor, isStatement, indexOfFirstStatement)); - } - - statements = mergeLexicalEnvironment(statements, endLexicalEnvironment()); - - return setTextRange( - createBlock( - setTextRange( - createNodeArray(statements), - /*location*/ constructor ? constructor.body!.statements : node.members - ), - /*multiLine*/ true - ), - /*location*/ constructor ? constructor.body : undefined - ); - } - - /** - * Generates assignment statements for property initializers. - * - * @param properties An array of property declarations to transform. - * @param receiver The receiver on which each property should be assigned. - */ - function addInitializedPropertyStatements(statements: Statement[], properties: readonly PropertyDeclaration[], receiver: LeftHandSideExpression) { - for (const property of properties) { - const statement = createExpressionStatement(transformInitializedProperty(property, receiver)); - setSourceMapRange(statement, moveRangePastModifiers(property)); - setCommentRange(statement, property); - setOriginalNode(statement, property); - statements.push(statement); - } - } - - /** - * Generates assignment expressions for property initializers. - * - * @param properties An array of property declarations to transform. - * @param receiver The receiver on which each property should be assigned. - */ - function generateInitializedPropertyExpressions(properties: readonly PropertyDeclaration[], receiver: LeftHandSideExpression) { - const expressions: Expression[] = []; - for (const property of properties) { - const expression = transformInitializedProperty(property, receiver); - startOnNewLine(expression); - setSourceMapRange(expression, moveRangePastModifiers(property)); - setCommentRange(expression, property); - setOriginalNode(expression, property); - expressions.push(expression); - } - - return expressions; - } - - /** - * Transforms a property initializer into an assignment statement. - * - * @param property The property declaration. - * @param receiver The object receiving the property assignment. - */ - function transformInitializedProperty(property: PropertyDeclaration, receiver: LeftHandSideExpression) { - // We generate a name here in order to reuse the value cached by the relocated computed name expression (which uses the same generated name) - const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) - ? updateComputedPropertyName(property.name, getGeneratedNameForNode(property.name)) - : property.name; - const initializer = visitNode(property.initializer, visitor, isExpression); - const memberAccess = createMemberAccessForPropertyName(receiver, propertyName, /*location*/ propertyName); - - return createAssignment(memberAccess, initializer); - } - - function enableSubstitutionForClassAliases() { - if ((enabledSubstitutions & ClassPropertySubstitutionFlags.ClassAliases) === 0) { - enabledSubstitutions |= ClassPropertySubstitutionFlags.ClassAliases; - - // We need to enable substitutions for identifiers. This allows us to - // substitute class names inside of a class declaration. - context.enableSubstitution(SyntaxKind.Identifier); - - // Keep track of class aliases. - classAliases = []; - } - } - - /** - * Hooks node substitutions. - * - * @param hint The context for the emitter. - * @param node The node to substitute. - */ - function onSubstituteNode(hint: EmitHint, node: Node) { - node = previousOnSubstituteNode(hint, node); - if (hint === EmitHint.Expression) { - return substituteExpression(node as Expression); - } - return node; - } - - function substituteExpression(node: Expression) { - switch (node.kind) { - case SyntaxKind.Identifier: - return substituteExpressionIdentifier(node as Identifier); - } - return node; - } - - function substituteExpressionIdentifier(node: Identifier): Expression { - return trySubstituteClassAlias(node) || node; - } - - function trySubstituteClassAlias(node: Identifier): Expression | undefined { - if (enabledSubstitutions & ClassPropertySubstitutionFlags.ClassAliases) { - if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ConstructorReferenceInClass) { - // Due to the emit for class decorators, any reference to the class from inside of the class body - // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind - // behavior of class names in ES6. - // Also, when emitting statics for class expressions, we must substitute a class alias for - // constructor references in static property initializers. - const declaration = resolver.getReferencedValueDeclaration(node); - if (declaration) { - const classAlias = classAliases[declaration.id!]; // TODO: GH#18217 - if (classAlias) { - const clone = getSynthesizedClone(classAlias); - setSourceMapRange(clone, node); - setCommentRange(clone, node); - return clone; - } - } - } - } - - return undefined; - } - - - /** - * If the name is a computed property, this function transforms it, then either returns an expression which caches the - * value of the result or the expression itself if the value is either unused or safe to inline into multiple locations - * @param shouldHoist Does the expression need to be reused? (ie, for an initializer or a decorator) - */ - function getPropertyNameExpressionIfNeeded(name: PropertyName, shouldHoist: boolean): Expression | undefined { - if (isComputedPropertyName(name)) { - const expression = visitNode(name.expression, visitor, isExpression); - const innerExpression = skipPartiallyEmittedExpressions(expression); - const inlinable = isSimpleInlineableExpression(innerExpression); - const alreadyTransformed = isAssignmentExpression(innerExpression) && isGeneratedIdentifier(innerExpression.left); - if (!alreadyTransformed && !inlinable && shouldHoist) { - const generatedName = getGeneratedNameForNode(name); - hoistVariableDeclaration(generatedName); - return createAssignment(generatedName, expression); - } - return (inlinable || isIdentifier(innerExpression)) ? undefined : expression; - } - } - } - -} +/*@internal*/ +namespace ts { + const enum ClassPropertySubstitutionFlags { + /** + * Enables substitutions for class expressions with static fields + * which have initializers that reference the class name. + */ + ClassAliases = 1 << 0, + } + /** + * Transforms ECMAScript Class Syntax. + * TypeScript parameter property syntax is transformed in the TypeScript transformer. + * For now, this transforms public field declarations using TypeScript class semantics + * (where the declarations get elided and initializers are transformed as assignments in the constructor). + * Eventually, this transform will change to the ECMAScript semantics (with Object.defineProperty). + */ + export function transformClassFields(context: TransformationContext) { + const { + hoistVariableDeclaration, + endLexicalEnvironment, + resumeLexicalEnvironment + } = context; + const resolver = context.getEmitResolver(); + + const previousOnSubstituteNode = context.onSubstituteNode; + context.onSubstituteNode = onSubstituteNode; + + let enabledSubstitutions: ClassPropertySubstitutionFlags; + + let classAliases: Identifier[]; + + /** + * Tracks what computed name expressions originating from elided names must be inlined + * at the next execution site, in document order + */ + let pendingExpressions: Expression[] | undefined; + + /** + * Tracks what computed name expression statements and static property initializers must be + * emitted at the next execution site, in document order (for decorated classes). + */ + let pendingStatements: Statement[] | undefined; + + return chainBundle(transformSourceFile); + + function transformSourceFile(node: SourceFile) { + const options = context.getCompilerOptions(); + if (node.isDeclarationFile + // TODO: ES3 target will still need to emit set semantics probably + // TODO: Need to test computed proeprties too + // [x] = 1 => Object.defineProperty(this, x, ...) + // -vs- + // [x] = 1 -> this[x] = 1 + // TODO: Unininitialised properties need to be emitted too. + || !options.legacyClassFields && options.target === ScriptTarget.ESNext) { + return node; + } + const visited = visitEachChild(node, visitor, context); + addEmitHelpers(visited, context.readEmitHelpers()); + return visited; + } + + function visitor(node: Node): VisitResult { + if (!(node.transformFlags & TransformFlags.ContainsClassFields)) return node; + + switch (node.kind) { + case SyntaxKind.ClassExpression: + return visitClassExpression(node as ClassExpression); + case SyntaxKind.ClassDeclaration: + return visitClassDeclaration(node as ClassDeclaration); + case SyntaxKind.VariableStatement: + return visitVariableStatement(node as VariableStatement); + } + return visitEachChild(node, visitor, context); + } + + /** + * Visits the members of a class that has fields. + * + * @param node The node to visit. + */ + function classElementVisitor(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.Constructor: + // Constructors for classes using class fields are transformed in + // `visitClassDeclaration` or `visitClassExpression`. + return undefined; + + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.MethodDeclaration: + // Visit the name of the member (if it's a computed property name). + return visitEachChild(node, classElementVisitor, context); + + case SyntaxKind.PropertyDeclaration: + return visitPropertyDeclaration(node as PropertyDeclaration); + + case SyntaxKind.ComputedPropertyName: + return visitComputedPropertyName(node as ComputedPropertyName); + + case SyntaxKind.SemicolonClassElement: + return node; + + default: + return visitor(node); + } + } + + function visitVariableStatement(node: VariableStatement) { + const savedPendingStatements = pendingStatements; + pendingStatements = []; + + const visitedNode = visitEachChild(node, visitor, context); + const statement = some(pendingStatements) ? + [visitedNode, ...pendingStatements] : + visitedNode; + + pendingStatements = savedPendingStatements; + return statement; + } + + function visitComputedPropertyName(name: ComputedPropertyName) { + let node = visitEachChild(name, visitor, context); + if (some(pendingExpressions)) { + const expressions = pendingExpressions; + expressions.push(name.expression); + pendingExpressions = []; + node = updateComputedPropertyName( + node, + inlineExpressions(expressions) + ); + } + return node; + } + + function visitPropertyDeclaration(node: PropertyDeclaration) { + Debug.assert(!some(node.decorators)); + // Create a temporary variable to store a computed property name (if necessary). + // If it's not inlineable, then we emit an expression after the class which assigns + // the property name to the temporary variable. + const expr = getPropertyNameExpressionIfNeeded(node.name, !!node.initializer); + if (expr && !isSimpleInlineableExpression(expr)) { + (pendingExpressions || (pendingExpressions = [])).push(expr); + } + return undefined; + } + + function visitClassDeclaration(node: ClassDeclaration) { + if (!forEach(node.members, isPropertyDeclaration)) { + return visitEachChild(node, visitor, context); + } + + const savedPendingExpressions = pendingExpressions; + pendingExpressions = undefined!; + + const extendsClauseElement = getEffectiveBaseTypeNode(node); + const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword); + + const statements: Statement[] = [ + updateClassDeclaration( + node, + /*decorators*/ undefined, + node.modifiers, + node.name, + /*typeParameters*/ undefined, + visitNodes(node.heritageClauses, visitor, isHeritageClause), + transformClassMembers(node, isDerivedClass) + ) + ]; + + // Write any pending expressions from elided or moved computed property names + if (some(pendingExpressions)) { + statements.push(createExpressionStatement(inlineExpressions(pendingExpressions))); + } + + pendingExpressions = savedPendingExpressions; + + // Emit static property assignment. Because classDeclaration is lexically evaluated, + // it is safe to emit static property assignment after classDeclaration + // From ES6 specification: + // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using + // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. + const staticProperties = getProperties(node, /*requireInitializer*/ true, /*isStatic*/ true); + if (some(staticProperties)) { + addPropertyStatements(statements, staticProperties, getInternalName(node)); + } + + return statements; + } + + function visitClassExpression(node: ClassExpression): Expression { + if (!forEach(node.members, isPropertyDeclaration)) { + return visitEachChild(node, visitor, context); + } + const savedPendingExpressions = pendingExpressions; + pendingExpressions = undefined; + + // If this class expression is a transformation of a decorated class declaration, + // then we want to output the pendingExpressions as statements, not as inlined + // expressions with the class statement. + // + // In this case, we use pendingStatements to produce the same output as the + // class declaration transformation. The VariableStatement visitor will insert + // these statements after the class expression variable statement. + const isDecoratedClassDeclaration = isClassDeclaration(getOriginalNode(node)); + + const staticProperties = getProperties(node, /*requireInitializer*/ true, /*isStatic*/ true); + const extendsClauseElement = getEffectiveBaseTypeNode(node); + const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword); + + const classExpression = updateClassExpression( + node, + node.modifiers, + node.name, + /*typeParameters*/ undefined, + visitNodes(node.heritageClauses, visitor, isHeritageClause), + transformClassMembers(node, isDerivedClass) + ); + + if (some(staticProperties) || some(pendingExpressions)) { + if (isDecoratedClassDeclaration) { + Debug.assertDefined(pendingStatements, "Decorated classes transformed by TypeScript are expected to be within a variable declaration."); + + // Write any pending expressions from elided or moved computed property names + if (pendingStatements && pendingExpressions && some(pendingExpressions)) { + pendingStatements.push(createExpressionStatement(inlineExpressions(pendingExpressions))); + } + pendingExpressions = savedPendingExpressions; + + if (pendingStatements && some(staticProperties)) { + addPropertyStatements(pendingStatements, staticProperties, getInternalName(node)); + } + return classExpression; + } + else { + const expressions: Expression[] = []; + const isClassWithConstructorReference = resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithConstructorReference; + const temp = createTempVariable(hoistVariableDeclaration, !!isClassWithConstructorReference); + if (isClassWithConstructorReference) { + // record an alias as the class name is not in scope for statics. + enableSubstitutionForClassAliases(); + const alias = getSynthesizedClone(temp); + alias.autoGenerateFlags &= ~GeneratedIdentifierFlags.ReservedInNestedScopes; + classAliases[getOriginalNodeId(node)] = alias; + } + + // To preserve the behavior of the old emitter, we explicitly indent + // the body of a class with static initializers. + setEmitFlags(classExpression, EmitFlags.Indented | getEmitFlags(classExpression)); + expressions.push(startOnNewLine(createAssignment(temp, classExpression))); + // Add any pending expressions leftover from elided or relocated computed property names + addRange(expressions, map(pendingExpressions, startOnNewLine)); + addRange(expressions, generateInitializedPropertyExpressions(staticProperties, temp)); + expressions.push(startOnNewLine(temp)); + + pendingExpressions = savedPendingExpressions; + return inlineExpressions(expressions); + } + } + + pendingExpressions = savedPendingExpressions; + return classExpression; + } + + function transformClassMembers(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { + const members: ClassElement[] = []; + const constructor = transformConstructor(node, isDerivedClass); + if (constructor) { + members.push(constructor); + } + addRange(members, visitNodes(node.members, classElementVisitor, isClassElement)); + return setTextRange(createNodeArray(members), /*location*/ node.members); + } + + function transformConstructor(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { + const constructor = visitNode(getFirstConstructorWithBody(node), visitor, isConstructorDeclaration); + const containsProperty = forEach(node.members, m => isInitializedProperty(m, !!context.getCompilerOptions().legacyClassFields)); + if (!containsProperty) { + return constructor; + } + const parameters = visitParameterList(constructor ? constructor.parameters : undefined, visitor, context); + const body = transformConstructorBody(node, constructor, isDerivedClass); + if (!body) { + return undefined; + } + return startOnNewLine( + setOriginalNode( + setTextRange( + createConstructor( + /*decorators*/ undefined, + /*modifiers*/ undefined, + parameters, + body + ), + constructor || node + ), + constructor + ) + ); + } + + function transformConstructorBody(node: ClassDeclaration | ClassExpression, constructor: ConstructorDeclaration | undefined, isDerivedClass: boolean) { + const properties = getProperties(node, /*requireInitializer*/ !!context.getCompilerOptions().legacyClassFields, /*isStatic*/ false); + + // Only generate synthetic constructor when there are property initializers to move. + if (!constructor && !some(properties)) { + return visitFunctionBody(/*node*/ undefined, visitor, context); + } + + resumeLexicalEnvironment(); + + let indexOfFirstStatement = 0; + let statements: Statement[] = []; + + if (!constructor && isDerivedClass) { + // Add a synthetic `super` call: + // + // super(...arguments); + // + statements.push( + createExpressionStatement( + createCall( + createSuper(), + /*typeArguments*/ undefined, + [createSpread(createIdentifier("arguments"))] + ) + ) + ); + } + + if (constructor) { + indexOfFirstStatement = addPrologueDirectivesAndInitialSuperCall(constructor, statements, visitor); + } + + // Add the property initializers. Transforms this: + // + // public x = 1; + // + // Into this: + // + // constructor() { + // this.x = 1; + // } + // + if (constructor && constructor.body) { + // TODO: Need to think about parameter property declarations + let parameterPropertyDeclarationCount = 0; + for (let i = indexOfFirstStatement; i < constructor.body.statements.length; i++) { + if (isParameterPropertyDeclaration(getOriginalNode(constructor.body.statements[i]), constructor)) { + parameterPropertyDeclarationCount++; + } + else { + break; + } + } + if (parameterPropertyDeclarationCount > 0) { + addRange(statements, visitNodes(constructor.body.statements, visitor, isStatement, indexOfFirstStatement, parameterPropertyDeclarationCount)); + indexOfFirstStatement += parameterPropertyDeclarationCount; + } + } + addPropertyStatements(statements, properties, createThis()); + + // Add existing statements, skipping the initial super call. + if (constructor) { + addRange(statements, visitNodes(constructor.body!.statements, visitor, isStatement, indexOfFirstStatement)); + } + + statements = mergeLexicalEnvironment(statements, endLexicalEnvironment()); + + return setTextRange( + createBlock( + setTextRange( + createNodeArray(statements), + /*location*/ constructor ? constructor.body!.statements : node.members + ), + /*multiLine*/ true + ), + /*location*/ constructor ? constructor.body : undefined + ); + } + + /** + * Generates assignment statements for property initializers. + * + * @param properties An array of property declarations to transform. + * @param receiver The receiver on which each property should be assigned. + */ + function addPropertyStatements(statements: Statement[], properties: readonly PropertyDeclaration[], receiver: LeftHandSideExpression) { + for (const property of properties) { + const statement = createExpressionStatement(transformInitializedProperty(property, receiver)); + setSourceMapRange(statement, moveRangePastModifiers(property)); + setCommentRange(statement, property); + setOriginalNode(statement, property); + statements.push(statement); + } + } + + /** + * Generates assignment expressions for property initializers. + * + * @param properties An array of property declarations to transform. + * @param receiver The receiver on which each property should be assigned. + */ + function generateInitializedPropertyExpressions(properties: readonly PropertyDeclaration[], receiver: LeftHandSideExpression) { + const expressions: Expression[] = []; + for (const property of properties) { + const expression = transformInitializedProperty(property, receiver); + startOnNewLine(expression); + setSourceMapRange(expression, moveRangePastModifiers(property)); + setCommentRange(expression, property); + setOriginalNode(expression, property); + expressions.push(expression); + } + + return expressions; + } + + /** + * Transforms a property initializer into an assignment statement. + * + * @param property The property declaration. + * @param receiver The object receiving the property assignment. + */ + function transformInitializedProperty(property: PropertyDeclaration, receiver: LeftHandSideExpression) { + if (context.getCompilerOptions().legacyClassFields) { + // We generate a name here in order to reuse the value cached by the relocated computed name expression (which uses the same generated name) + const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) + ? updateComputedPropertyName(property.name, getGeneratedNameForNode(property.name)) + : property.name; + const initializer = visitNode(property.initializer, visitor, isExpression); + const memberAccess = createMemberAccessForPropertyName(receiver, propertyName, /*location*/ propertyName); + + return createAssignment(memberAccess, initializer); + } + else { + return createIdentifier('hi'); + // return createCall(); + } + } + + function enableSubstitutionForClassAliases() { + if ((enabledSubstitutions & ClassPropertySubstitutionFlags.ClassAliases) === 0) { + enabledSubstitutions |= ClassPropertySubstitutionFlags.ClassAliases; + + // We need to enable substitutions for identifiers. This allows us to + // substitute class names inside of a class declaration. + context.enableSubstitution(SyntaxKind.Identifier); + + // Keep track of class aliases. + classAliases = []; + } + } + + /** + * Hooks node substitutions. + * + * @param hint The context for the emitter. + * @param node The node to substitute. + */ + function onSubstituteNode(hint: EmitHint, node: Node) { + node = previousOnSubstituteNode(hint, node); + if (hint === EmitHint.Expression) { + return substituteExpression(node as Expression); + } + return node; + } + + function substituteExpression(node: Expression) { + switch (node.kind) { + case SyntaxKind.Identifier: + return substituteExpressionIdentifier(node as Identifier); + } + return node; + } + + function substituteExpressionIdentifier(node: Identifier): Expression { + return trySubstituteClassAlias(node) || node; + } + + function trySubstituteClassAlias(node: Identifier): Expression | undefined { + if (enabledSubstitutions & ClassPropertySubstitutionFlags.ClassAliases) { + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ConstructorReferenceInClass) { + // Due to the emit for class decorators, any reference to the class from inside of the class body + // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind + // behavior of class names in ES6. + // Also, when emitting statics for class expressions, we must substitute a class alias for + // constructor references in static property initializers. + const declaration = resolver.getReferencedValueDeclaration(node); + if (declaration) { + const classAlias = classAliases[declaration.id!]; // TODO: GH#18217 + if (classAlias) { + const clone = getSynthesizedClone(classAlias); + setSourceMapRange(clone, node); + setCommentRange(clone, node); + return clone; + } + } + } + } + + return undefined; + } + + + /** + * If the name is a computed property, this function transforms it, then either returns an expression which caches the + * value of the result or the expression itself if the value is either unused or safe to inline into multiple locations + * @param shouldHoist Does the expression need to be reused? (ie, for an initializer or a decorator) + */ + function getPropertyNameExpressionIfNeeded(name: PropertyName, shouldHoist: boolean): Expression | undefined { + if (isComputedPropertyName(name)) { + const expression = visitNode(name.expression, visitor, isExpression); + const innerExpression = skipPartiallyEmittedExpressions(expression); + const inlinable = isSimpleInlineableExpression(innerExpression); + const alreadyTransformed = isAssignmentExpression(innerExpression) && isGeneratedIdentifier(innerExpression.left); + if (!alreadyTransformed && !inlinable && shouldHoist) { + const generatedName = getGeneratedNameForNode(name); + hoistVariableDeclaration(generatedName); + return createAssignment(generatedName, expression); + } + return (inlinable || isIdentifier(innerExpression)) ? undefined : expression; + } + } + } + +} diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 06b3fb53ec180..16f436c95a406 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -1,3358 +1,3358 @@ -/*@internal*/ -namespace ts { - /** - * Indicates whether to emit type metadata in the new format. - */ - const USE_NEW_TYPE_METADATA_FORMAT = false; - - const enum TypeScriptSubstitutionFlags { - /** Enables substitutions for decorated classes. */ - ClassAliases = 1 << 0, - /** Enables substitutions for namespace exports. */ - NamespaceExports = 1 << 1, - /* Enables substitutions for unqualified enum members */ - NonQualifiedEnumMembers = 1 << 3 - } - - const enum ClassFacts { - None = 0, - HasStaticInitializedProperties = 1 << 0, - HasConstructorDecorators = 1 << 1, - HasMemberDecorators = 1 << 2, - IsExportOfNamespace = 1 << 3, - IsNamedExternalExport = 1 << 4, - IsDefaultExternalExport = 1 << 5, - IsDerivedClass = 1 << 6, - UseImmediatelyInvokedFunctionExpression = 1 << 7, - - HasAnyDecorators = HasConstructorDecorators | HasMemberDecorators, - NeedsName = HasStaticInitializedProperties | HasMemberDecorators, - MayNeedImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties, - IsExported = IsExportOfNamespace | IsDefaultExternalExport | IsNamedExternalExport, - } - - export function transformTypeScript(context: TransformationContext) { - const { - startLexicalEnvironment, - resumeLexicalEnvironment, - endLexicalEnvironment, - hoistVariableDeclaration, - } = context; - - const resolver = context.getEmitResolver(); - const compilerOptions = context.getCompilerOptions(); - const strictNullChecks = getStrictOptionValue(compilerOptions, "strictNullChecks"); - const languageVersion = getEmitScriptTarget(compilerOptions); - const moduleKind = getEmitModuleKind(compilerOptions); - - // Save the previous transformation hooks. - const previousOnEmitNode = context.onEmitNode; - const previousOnSubstituteNode = context.onSubstituteNode; - - // Set new transformation hooks. - context.onEmitNode = onEmitNode; - context.onSubstituteNode = onSubstituteNode; - - // Enable substitution for property/element access to emit const enum values. - context.enableSubstitution(SyntaxKind.PropertyAccessExpression); - context.enableSubstitution(SyntaxKind.ElementAccessExpression); - - // These variables contain state that changes as we descend into the tree. - let currentSourceFile: SourceFile; - let currentNamespace: ModuleDeclaration; - let currentNamespaceContainerName: Identifier; - let currentLexicalScope: SourceFile | Block | ModuleBlock | CaseBlock; - let currentNameScope: ClassDeclaration | undefined; - let currentScopeFirstDeclarationsOfName: UnderscoreEscapedMap | undefined; - let currentClassHasParameterProperties: boolean | undefined; - - /** - * Keeps track of whether expression substitution has been enabled for specific edge cases. - * They are persisted between each SourceFile transformation and should not be reset. - */ - let enabledSubstitutions: TypeScriptSubstitutionFlags; - - /** - * A map that keeps track of aliases created for classes with decorators to avoid issues - * with the double-binding behavior of classes. - */ - let classAliases: Identifier[]; - - /** - * Keeps track of whether we are within any containing namespaces when performing - * just-in-time substitution while printing an expression identifier. - */ - let applicableSubstitutions: TypeScriptSubstitutionFlags; - - return transformSourceFileOrBundle; - - function transformSourceFileOrBundle(node: SourceFile | Bundle) { - if (node.kind === SyntaxKind.Bundle) { - return transformBundle(node); - } - return transformSourceFile(node); - } - - function transformBundle(node: Bundle) { - return createBundle(node.sourceFiles.map(transformSourceFile), mapDefined(node.prepends, prepend => { - if (prepend.kind === SyntaxKind.InputFiles) { - return createUnparsedSourceFile(prepend, "js"); - } - return prepend; - })); - } - - /** - * Transform TypeScript-specific syntax in a SourceFile. - * - * @param node A SourceFile node. - */ - function transformSourceFile(node: SourceFile) { - if (node.isDeclarationFile) { - return node; - } - - currentSourceFile = node; - - const visited = saveStateAndInvoke(node, visitSourceFile); - addEmitHelpers(visited, context.readEmitHelpers()); - - currentSourceFile = undefined!; - return visited; - } - - /** - * Visits a node, saving and restoring state variables on the stack. - * - * @param node The node to visit. - */ - function saveStateAndInvoke(node: Node, f: (node: Node) => T): T { - // Save state - const savedCurrentScope = currentLexicalScope; - const savedCurrentNameScope = currentNameScope; - const savedCurrentScopeFirstDeclarationsOfName = currentScopeFirstDeclarationsOfName; - const savedCurrentClassHasParameterProperties = currentClassHasParameterProperties; - - // Handle state changes before visiting a node. - onBeforeVisitNode(node); - - const visited = f(node); - - // Restore state - if (currentLexicalScope !== savedCurrentScope) { - currentScopeFirstDeclarationsOfName = savedCurrentScopeFirstDeclarationsOfName; - } - - currentLexicalScope = savedCurrentScope; - currentNameScope = savedCurrentNameScope; - currentClassHasParameterProperties = savedCurrentClassHasParameterProperties; - return visited; - } - - /** - * Performs actions that should always occur immediately before visiting a node. - * - * @param node The node to visit. - */ - function onBeforeVisitNode(node: Node) { - switch (node.kind) { - case SyntaxKind.SourceFile: - case SyntaxKind.CaseBlock: - case SyntaxKind.ModuleBlock: - case SyntaxKind.Block: - currentLexicalScope = node; - currentNameScope = undefined; - currentScopeFirstDeclarationsOfName = undefined; - break; - - case SyntaxKind.ClassDeclaration: - case SyntaxKind.FunctionDeclaration: - if (hasModifier(node, ModifierFlags.Ambient)) { - break; - } - - // Record these declarations provided that they have a name. - if ((node as ClassDeclaration | FunctionDeclaration).name) { - recordEmittedDeclarationInScope(node as ClassDeclaration | FunctionDeclaration); - } - else { - // These nodes should always have names unless they are default-exports; - // however, class declaration parsing allows for undefined names, so syntactically invalid - // programs may also have an undefined name. - Debug.assert(node.kind === SyntaxKind.ClassDeclaration || hasModifier(node, ModifierFlags.Default)); - } - if (isClassDeclaration(node)) { - // XXX: should probably also cover interfaces and type aliases that can have type variables? - currentNameScope = node; - } - - break; - } - } - - /** - * General-purpose node visitor. - * - * @param node The node to visit. - */ - function visitor(node: Node): VisitResult { - return saveStateAndInvoke(node, visitorWorker); - } - - /** - * Visits and possibly transforms any node. - * - * @param node The node to visit. - */ - function visitorWorker(node: Node): VisitResult { - if (node.transformFlags & TransformFlags.ContainsTypeScript) { - return visitTypeScript(node); - } - return node; - } - - /** - * Specialized visitor that visits the immediate children of a SourceFile. - * - * @param node The node to visit. - */ - function sourceElementVisitor(node: Node): VisitResult { - return saveStateAndInvoke(node, sourceElementVisitorWorker); - } - - /** - * Specialized visitor that visits the immediate children of a SourceFile. - * - * @param node The node to visit. - */ - function sourceElementVisitorWorker(node: Node): VisitResult { - switch (node.kind) { - case SyntaxKind.ImportDeclaration: - case SyntaxKind.ImportEqualsDeclaration: - case SyntaxKind.ExportAssignment: - case SyntaxKind.ExportDeclaration: - return visitEllidableStatement(node); - default: - return visitorWorker(node); - } - } - - function visitEllidableStatement(node: ImportDeclaration | ImportEqualsDeclaration | ExportAssignment | ExportDeclaration): VisitResult { - const parsed = getParseTreeNode(node); - if (parsed !== node) { - // If the node has been transformed by a `before` transformer, perform no ellision on it - // As the type information we would attempt to lookup to perform ellision is potentially unavailable for the synthesized nodes - // We do not reuse `visitorWorker`, as the ellidable statement syntax kinds are technically unrecognized by the switch-case in `visitTypeScript`, - // and will trigger debug failures when debug verbosity is turned up - if (node.transformFlags & TransformFlags.ContainsTypeScript) { - // This node contains TypeScript, so we should visit its children. - return visitEachChild(node, visitor, context); - } - // Otherwise, we can just return the node - return node; - } - switch (node.kind) { - case SyntaxKind.ImportDeclaration: - return visitImportDeclaration(node); - case SyntaxKind.ImportEqualsDeclaration: - return visitImportEqualsDeclaration(node); - case SyntaxKind.ExportAssignment: - return visitExportAssignment(node); - case SyntaxKind.ExportDeclaration: - return visitExportDeclaration(node); - default: - Debug.fail("Unhandled ellided statement"); - } - } - - /** - * Specialized visitor that visits the immediate children of a namespace. - * - * @param node The node to visit. - */ - function namespaceElementVisitor(node: Node): VisitResult { - return saveStateAndInvoke(node, namespaceElementVisitorWorker); - } - - /** - * Specialized visitor that visits the immediate children of a namespace. - * - * @param node The node to visit. - */ - function namespaceElementVisitorWorker(node: Node): VisitResult { - if (node.kind === SyntaxKind.ExportDeclaration || - node.kind === SyntaxKind.ImportDeclaration || - node.kind === SyntaxKind.ImportClause || - (node.kind === SyntaxKind.ImportEqualsDeclaration && - (node).moduleReference.kind === SyntaxKind.ExternalModuleReference)) { - // do not emit ES6 imports and exports since they are illegal inside a namespace - return undefined; - } - else if (node.transformFlags & TransformFlags.ContainsTypeScript || hasModifier(node, ModifierFlags.Export)) { - return visitTypeScript(node); - } - - return node; - } - - /** - * Specialized visitor that visits the immediate children of a class with TypeScript syntax. - * - * @param node The node to visit. - */ - function classElementVisitor(node: Node): VisitResult { - return saveStateAndInvoke(node, classElementVisitorWorker); - } - - /** - * Specialized visitor that visits the immediate children of a class with TypeScript syntax. - * - * @param node The node to visit. - */ - function classElementVisitorWorker(node: Node): VisitResult { - switch (node.kind) { - case SyntaxKind.Constructor: - return visitConstructor(node as ConstructorDeclaration); - - case SyntaxKind.PropertyDeclaration: - // Property declarations are not TypeScript syntax, but they must be visited - // for the decorator transformation. - return visitPropertyDeclaration(node as PropertyDeclaration); - case SyntaxKind.IndexSignature: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.MethodDeclaration: - // Fallback to the default visit behavior. - return visitorWorker(node); - - case SyntaxKind.SemicolonClassElement: - return node; - - default: - return Debug.failBadSyntaxKind(node); - } - } - - function modifierVisitor(node: Node): VisitResult { - if (modifierToFlag(node.kind) & ModifierFlags.TypeScriptModifier) { - return undefined; - } - else if (currentNamespace && node.kind === SyntaxKind.ExportKeyword) { - return undefined; - } - - return node; - } - - /** - * Branching visitor, visits a TypeScript syntax node. - * - * @param node The node to visit. - */ - function visitTypeScript(node: Node): VisitResult { - if (isStatement(node) && hasModifier(node, ModifierFlags.Ambient)) { - // TypeScript ambient declarations are elided, but some comments may be preserved. - // See the implementation of `getLeadingComments` in comments.ts for more details. - return createNotEmittedStatement(node); - } - - switch (node.kind) { - case SyntaxKind.ExportKeyword: - case SyntaxKind.DefaultKeyword: - // ES6 export and default modifiers are elided when inside a namespace. - return currentNamespace ? undefined : node; - - case SyntaxKind.PublicKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.ProtectedKeyword: - case SyntaxKind.AbstractKeyword: - case SyntaxKind.ConstKeyword: - case SyntaxKind.DeclareKeyword: - case SyntaxKind.ReadonlyKeyword: - // TypeScript accessibility and readonly modifiers are elided - // falls through - case SyntaxKind.ArrayType: - case SyntaxKind.TupleType: - case SyntaxKind.OptionalType: - case SyntaxKind.RestType: - case SyntaxKind.TypeLiteral: - case SyntaxKind.TypePredicate: - case SyntaxKind.TypeParameter: - case SyntaxKind.AnyKeyword: - case SyntaxKind.UnknownKeyword: - case SyntaxKind.BooleanKeyword: - case SyntaxKind.StringKeyword: - case SyntaxKind.NumberKeyword: - case SyntaxKind.NeverKeyword: - case SyntaxKind.VoidKeyword: - case SyntaxKind.SymbolKeyword: - case SyntaxKind.ConstructorType: - case SyntaxKind.FunctionType: - case SyntaxKind.TypeQuery: - case SyntaxKind.TypeReference: - case SyntaxKind.UnionType: - case SyntaxKind.IntersectionType: - case SyntaxKind.ConditionalType: - case SyntaxKind.ParenthesizedType: - case SyntaxKind.ThisType: - case SyntaxKind.TypeOperator: - case SyntaxKind.IndexedAccessType: - case SyntaxKind.MappedType: - case SyntaxKind.LiteralType: - // TypeScript type nodes are elided. - // falls through - - case SyntaxKind.IndexSignature: - // TypeScript index signatures are elided. - // falls through - - case SyntaxKind.Decorator: - // TypeScript decorators are elided. They will be emitted as part of visitClassDeclaration. - // falls through - - case SyntaxKind.TypeAliasDeclaration: - // TypeScript type-only declarations are elided. - return undefined; - - case SyntaxKind.PropertyDeclaration: - // TypeScript property declarations are elided. However their names are still visited, and can potentially be retained if they could have sideeffects - return visitPropertyDeclaration(node as PropertyDeclaration); - - case SyntaxKind.NamespaceExportDeclaration: - // TypeScript namespace export declarations are elided. - return undefined; - - case SyntaxKind.Constructor: - return visitConstructor(node); - - case SyntaxKind.InterfaceDeclaration: - // TypeScript interfaces are elided, but some comments may be preserved. - // See the implementation of `getLeadingComments` in comments.ts for more details. - return createNotEmittedStatement(node); - - case SyntaxKind.ClassDeclaration: - // This may be a class declaration with TypeScript syntax extensions. - // - // TypeScript class syntax extensions include: - // - decorators - // - optional `implements` heritage clause - // - parameter property assignments in the constructor - // - index signatures - // - method overload signatures - return visitClassDeclaration(node); - - case SyntaxKind.ClassExpression: - // This may be a class expression with TypeScript syntax extensions. - // - // TypeScript class syntax extensions include: - // - decorators - // - optional `implements` heritage clause - // - parameter property assignments in the constructor - // - index signatures - // - method overload signatures - return visitClassExpression(node); - - case SyntaxKind.HeritageClause: - // This may be a heritage clause with TypeScript syntax extensions. - // - // TypeScript heritage clause extensions include: - // - `implements` clause - return visitHeritageClause(node); - - case SyntaxKind.ExpressionWithTypeArguments: - // TypeScript supports type arguments on an expression in an `extends` heritage clause. - return visitExpressionWithTypeArguments(node); - - case SyntaxKind.MethodDeclaration: - // TypeScript method declarations may have decorators, modifiers - // or type annotations. - return visitMethodDeclaration(node); - - case SyntaxKind.GetAccessor: - // Get Accessors can have TypeScript modifiers, decorators, and type annotations. - return visitGetAccessor(node); - - case SyntaxKind.SetAccessor: - // Set Accessors can have TypeScript modifiers and type annotations. - return visitSetAccessor(node); - - case SyntaxKind.FunctionDeclaration: - // Typescript function declarations can have modifiers, decorators, and type annotations. - return visitFunctionDeclaration(node); - - case SyntaxKind.FunctionExpression: - // TypeScript function expressions can have modifiers and type annotations. - return visitFunctionExpression(node); - - case SyntaxKind.ArrowFunction: - // TypeScript arrow functions can have modifiers and type annotations. - return visitArrowFunction(node); - - case SyntaxKind.Parameter: - // This may be a parameter declaration with TypeScript syntax extensions. - // - // TypeScript parameter declaration syntax extensions include: - // - decorators - // - accessibility modifiers - // - the question mark (?) token for optional parameters - // - type annotations - // - this parameters - return visitParameter(node); - - case SyntaxKind.ParenthesizedExpression: - // ParenthesizedExpressions are TypeScript if their expression is a - // TypeAssertion or AsExpression - return visitParenthesizedExpression(node); - - case SyntaxKind.TypeAssertionExpression: - case SyntaxKind.AsExpression: - // TypeScript type assertions are removed, but their subtrees are preserved. - return visitAssertionExpression(node); - - case SyntaxKind.CallExpression: - return visitCallExpression(node); - - case SyntaxKind.NewExpression: - return visitNewExpression(node); - - case SyntaxKind.TaggedTemplateExpression: - return visitTaggedTemplateExpression(node); - - case SyntaxKind.NonNullExpression: - // TypeScript non-null expressions are removed, but their subtrees are preserved. - return visitNonNullExpression(node); - - case SyntaxKind.EnumDeclaration: - // TypeScript enum declarations do not exist in ES6 and must be rewritten. - return visitEnumDeclaration(node); - - case SyntaxKind.VariableStatement: - // TypeScript namespace exports for variable statements must be transformed. - return visitVariableStatement(node); - - case SyntaxKind.VariableDeclaration: - return visitVariableDeclaration(node); - - case SyntaxKind.ModuleDeclaration: - // TypeScript namespace declarations must be transformed. - return visitModuleDeclaration(node); - - case SyntaxKind.ImportEqualsDeclaration: - // TypeScript namespace or external module import. - return visitImportEqualsDeclaration(node); - - default: - // node contains some other TypeScript syntax - return visitEachChild(node, visitor, context); - } - } - - function visitSourceFile(node: SourceFile) { - const alwaysStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") && - !(isExternalModule(node) && moduleKind >= ModuleKind.ES2015) && - !isJsonSourceFile(node); - - return updateSourceFileNode( - node, - visitLexicalEnvironment(node.statements, sourceElementVisitor, context, /*start*/ 0, alwaysStrict)); - } - - /** - * Tests whether we should emit a __decorate call for a class declaration. - */ - function shouldEmitDecorateCallForClass(node: ClassDeclaration) { - if (node.decorators && node.decorators.length > 0) { - return true; - } - - const constructor = getFirstConstructorWithBody(node); - if (constructor) { - return forEach(constructor.parameters, shouldEmitDecorateCallForParameter); - } - - return false; - } - - /** - * Tests whether we should emit a __decorate call for a parameter declaration. - */ - function shouldEmitDecorateCallForParameter(parameter: ParameterDeclaration) { - return parameter.decorators !== undefined && parameter.decorators.length > 0; - } - - function getClassFacts(node: ClassDeclaration, staticProperties: readonly PropertyDeclaration[]) { - let facts = ClassFacts.None; - if (some(staticProperties)) facts |= ClassFacts.HasStaticInitializedProperties; - const extendsClauseElement = getEffectiveBaseTypeNode(node); - if (extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword) facts |= ClassFacts.IsDerivedClass; - if (shouldEmitDecorateCallForClass(node)) facts |= ClassFacts.HasConstructorDecorators; - if (childIsDecorated(node)) facts |= ClassFacts.HasMemberDecorators; - if (isExportOfNamespace(node)) facts |= ClassFacts.IsExportOfNamespace; - else if (isDefaultExternalModuleExport(node)) facts |= ClassFacts.IsDefaultExternalExport; - else if (isNamedExternalModuleExport(node)) facts |= ClassFacts.IsNamedExternalExport; - if (languageVersion <= ScriptTarget.ES5 && (facts & ClassFacts.MayNeedImmediatelyInvokedFunctionExpression)) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression; - return facts; - } - - function hasTypeScriptClassSyntax(node: Node) { - return !!(node.transformFlags & TransformFlags.ContainsTypeScriptClassSyntax); - } - - function isClassLikeDeclarationWithTypeScriptSyntax(node: ClassLikeDeclaration) { - return some(node.decorators) - || some(node.typeParameters) - || some(node.heritageClauses, hasTypeScriptClassSyntax) - || some(node.members, hasTypeScriptClassSyntax); - } - - function visitClassDeclaration(node: ClassDeclaration): VisitResult { - if (!isClassLikeDeclarationWithTypeScriptSyntax(node) && !(currentNamespace && hasModifier(node, ModifierFlags.Export))) { - return visitEachChild(node, visitor, context); - } - - const staticProperties = getInitializedProperties(node, /*isStatic*/ true); - const facts = getClassFacts(node, staticProperties); - - if (facts & ClassFacts.UseImmediatelyInvokedFunctionExpression) { - context.startLexicalEnvironment(); - } - - const name = node.name || (facts & ClassFacts.NeedsName ? getGeneratedNameForNode(node) : undefined); - const classStatement = facts & ClassFacts.HasConstructorDecorators - ? createClassDeclarationHeadWithDecorators(node, name) - : createClassDeclarationHeadWithoutDecorators(node, name, facts); - - let statements: Statement[] = [classStatement]; - - - // Write any decorators of the node. - addClassElementDecorationStatements(statements, node, /*isStatic*/ false); - addClassElementDecorationStatements(statements, node, /*isStatic*/ true); - addConstructorDecorationStatement(statements, node); - - if (facts & ClassFacts.UseImmediatelyInvokedFunctionExpression) { - // When we emit a TypeScript class down to ES5, we must wrap it in an IIFE so that the - // 'es2015' transformer can properly nest static initializers and decorators. The result - // looks something like: - // - // var C = function () { - // class C { - // } - // C.static_prop = 1; - // return C; - // }(); - // - const closingBraceLocation = createTokenRange(skipTrivia(currentSourceFile.text, node.members.end), SyntaxKind.CloseBraceToken); - const localName = getInternalName(node); - - // The following partially-emitted expression exists purely to align our sourcemap - // emit with the original emitter. - const outer = createPartiallyEmittedExpression(localName); - outer.end = closingBraceLocation.end; - setEmitFlags(outer, EmitFlags.NoComments); - - const statement = createReturn(outer); - statement.pos = closingBraceLocation.pos; - setEmitFlags(statement, EmitFlags.NoComments | EmitFlags.NoTokenSourceMaps); - statements.push(statement); - - insertStatementsAfterStandardPrologue(statements, context.endLexicalEnvironment()); - - const iife = createImmediatelyInvokedArrowFunction(statements); - setEmitFlags(iife, EmitFlags.TypeScriptClassWrapper); - - const varStatement = createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList([ - createVariableDeclaration( - getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ false), - /*type*/ undefined, - iife - ) - ]) - ); - - setOriginalNode(varStatement, node); - setCommentRange(varStatement, node); - setSourceMapRange(varStatement, moveRangePastDecorators(node)); - startOnNewLine(varStatement); - statements = [varStatement]; - } - - // If the class is exported as part of a TypeScript namespace, emit the namespace export. - // Otherwise, if the class was exported at the top level and was decorated, emit an export - // declaration or export default for the class. - if (facts & ClassFacts.IsExportOfNamespace) { - addExportMemberAssignment(statements, node); - } - else if (facts & ClassFacts.UseImmediatelyInvokedFunctionExpression || facts & ClassFacts.HasConstructorDecorators) { - if (facts & ClassFacts.IsDefaultExternalExport) { - statements.push(createExportDefault(getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true))); - } - else if (facts & ClassFacts.IsNamedExternalExport) { - statements.push(createExternalModuleExport(getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true))); - } - } - - if (statements.length > 1) { - // Add a DeclarationMarker as a marker for the end of the declaration - statements.push(createEndOfDeclarationMarker(node)); - setEmitFlags(classStatement, getEmitFlags(classStatement) | EmitFlags.HasEndOfDeclarationMarker); - } - - return singleOrMany(statements); - } - - /** - * Transforms a non-decorated class declaration and appends the resulting statements. - * - * @param node A ClassDeclaration node. - * @param name The name of the class. - * @param facts Precomputed facts about the class. - */ - function createClassDeclarationHeadWithoutDecorators(node: ClassDeclaration, name: Identifier | undefined, facts: ClassFacts) { - // ${modifiers} class ${name} ${heritageClauses} { - // ${members} - // } - - // we do not emit modifiers on the declaration if we are emitting an IIFE - const modifiers = !(facts & ClassFacts.UseImmediatelyInvokedFunctionExpression) - ? visitNodes(node.modifiers, modifierVisitor, isModifier) - : undefined; - - const classDeclaration = createClassDeclaration( - /*decorators*/ undefined, - modifiers, - name, - /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, visitor, isHeritageClause), - transformClassMembers(node) - ); - - // To better align with the old emitter, we should not emit a trailing source map - // entry if the class has static properties. - let emitFlags = getEmitFlags(node); - if (facts & ClassFacts.HasStaticInitializedProperties) { - emitFlags |= EmitFlags.NoTrailingSourceMap; - } - - aggregateTransformFlags(classDeclaration); - setTextRange(classDeclaration, node); - setOriginalNode(classDeclaration, node); - setEmitFlags(classDeclaration, emitFlags); - return classDeclaration; - } - - /** - * Transforms a decorated class declaration and appends the resulting statements. If - * the class requires an alias to avoid issues with double-binding, the alias is returned. - */ - function createClassDeclarationHeadWithDecorators(node: ClassDeclaration, name: Identifier | undefined) { - // When we emit an ES6 class that has a class decorator, we must tailor the - // emit to certain specific cases. - // - // In the simplest case, we emit the class declaration as a let declaration, and - // evaluate decorators after the close of the class body: - // - // [Example 1] - // --------------------------------------------------------------------- - // TypeScript | Javascript - // --------------------------------------------------------------------- - // @dec | let C = class C { - // class C { | } - // } | C = __decorate([dec], C); - // --------------------------------------------------------------------- - // @dec | let C = class C { - // export class C { | } - // } | C = __decorate([dec], C); - // | export { C }; - // --------------------------------------------------------------------- - // - // If a class declaration contains a reference to itself *inside* of the class body, - // this introduces two bindings to the class: One outside of the class body, and one - // inside of the class body. If we apply decorators as in [Example 1] above, there - // is the possibility that the decorator `dec` will return a new value for the - // constructor, which would result in the binding inside of the class no longer - // pointing to the same reference as the binding outside of the class. - // - // As a result, we must instead rewrite all references to the class *inside* of the - // class body to instead point to a local temporary alias for the class: - // - // [Example 2] - // --------------------------------------------------------------------- - // TypeScript | Javascript - // --------------------------------------------------------------------- - // @dec | let C = C_1 = class C { - // class C { | static x() { return C_1.y; } - // static x() { return C.y; } | } - // static y = 1; | C.y = 1; - // } | C = C_1 = __decorate([dec], C); - // | var C_1; - // --------------------------------------------------------------------- - // @dec | let C = class C { - // export class C { | static x() { return C_1.y; } - // static x() { return C.y; } | } - // static y = 1; | C.y = 1; - // } | C = C_1 = __decorate([dec], C); - // | export { C }; - // | var C_1; - // --------------------------------------------------------------------- - // - // If a class declaration is the default export of a module, we instead emit - // the export after the decorated declaration: - // - // [Example 3] - // --------------------------------------------------------------------- - // TypeScript | Javascript - // --------------------------------------------------------------------- - // @dec | let default_1 = class { - // export default class { | } - // } | default_1 = __decorate([dec], default_1); - // | export default default_1; - // --------------------------------------------------------------------- - // @dec | let C = class C { - // export default class C { | } - // } | C = __decorate([dec], C); - // | export default C; - // --------------------------------------------------------------------- - // - // If the class declaration is the default export and a reference to itself - // inside of the class body, we must emit both an alias for the class *and* - // move the export after the declaration: - // - // [Example 4] - // --------------------------------------------------------------------- - // TypeScript | Javascript - // --------------------------------------------------------------------- - // @dec | let C = class C { - // export default class C { | static x() { return C_1.y; } - // static x() { return C.y; } | } - // static y = 1; | C.y = 1; - // } | C = C_1 = __decorate([dec], C); - // | export default C; - // | var C_1; - // --------------------------------------------------------------------- - // - - const location = moveRangePastDecorators(node); - const classAlias = getClassAliasIfNeeded(node); - const declName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); - - // ... = class ${name} ${heritageClauses} { - // ${members} - // } - const heritageClauses = visitNodes(node.heritageClauses, visitor, isHeritageClause); - const members = transformClassMembers(node); - const classExpression = createClassExpression(/*modifiers*/ undefined, name, /*typeParameters*/ undefined, heritageClauses, members); - aggregateTransformFlags(classExpression); - setOriginalNode(classExpression, node); - setTextRange(classExpression, location); - - // let ${name} = ${classExpression} where name is either declaredName if the class doesn't contain self-reference - // or decoratedClassAlias if the class contain self-reference. - const statement = createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList([ - createVariableDeclaration( - declName, - /*type*/ undefined, - classAlias ? createAssignment(classAlias, classExpression) : classExpression - ) - ], NodeFlags.Let) - ); - setOriginalNode(statement, node); - setTextRange(statement, location); - setCommentRange(statement, node); - return statement; - } - - function visitClassExpression(node: ClassExpression): Expression { - if (!isClassLikeDeclarationWithTypeScriptSyntax(node)) { - return visitEachChild(node, visitor, context); - } - - const classExpression = createClassExpression( - /*modifiers*/ undefined, - node.name, - /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, visitor, isHeritageClause), - transformClassMembers(node) - ); - - aggregateTransformFlags(classExpression); - setOriginalNode(classExpression, node); - setTextRange(classExpression, node); - - return classExpression; - } - - /** - * Transforms the members of a class. - * - * @param node The current class. - */ - function transformClassMembers(node: ClassDeclaration | ClassExpression) { - const members: ClassElement[] = []; - const constructor = getFirstConstructorWithBody(node); - const parametersWithPropertyAssignments = constructor && - filter(constructor.parameters, p => isParameterPropertyDeclaration(p, constructor)); - - if (parametersWithPropertyAssignments) { - for (const parameter of parametersWithPropertyAssignments) { - if (isIdentifier(parameter.name)) { - members.push(aggregateTransformFlags(createProperty( - /*decorators*/ undefined, - /*modifiers*/ undefined, - parameter.name, - /*questionOrExclamationToken*/ undefined, - /*type*/ undefined, - /*initializer*/ undefined))); - } - } - } - - addRange(members, visitNodes(node.members, classElementVisitor, isClassElement)); - return setTextRange(createNodeArray(members), /*location*/ node.members); - } - - - /** - * Gets either the static or instance members of a class that are decorated, or have - * parameters that are decorated. - * - * @param node The class containing the member. - * @param isStatic A value indicating whether to retrieve static or instance members of - * the class. - */ - function getDecoratedClassElements(node: ClassExpression | ClassDeclaration, isStatic: boolean): readonly ClassElement[] { - return filter(node.members, isStatic ? m => isStaticDecoratedClassElement(m, node) : m => isInstanceDecoratedClassElement(m, node)); - } - - /** - * Determines whether a class member is a static member of a class that is decorated, or - * has parameters that are decorated. - * - * @param member The class member. - */ - function isStaticDecoratedClassElement(member: ClassElement, parent: ClassLikeDeclaration) { - return isDecoratedClassElement(member, /*isStatic*/ true, parent); - } - - /** - * Determines whether a class member is an instance member of a class that is decorated, - * or has parameters that are decorated. - * - * @param member The class member. - */ - function isInstanceDecoratedClassElement(member: ClassElement, parent: ClassLikeDeclaration) { - return isDecoratedClassElement(member, /*isStatic*/ false, parent); - } - - /** - * Determines whether a class member is either a static or an instance member of a class - * that is decorated, or has parameters that are decorated. - * - * @param member The class member. - */ - function isDecoratedClassElement(member: ClassElement, isStatic: boolean, parent: ClassLikeDeclaration) { - return nodeOrChildIsDecorated(member, parent) - && isStatic === hasModifier(member, ModifierFlags.Static); - } - - /** - * A structure describing the decorators for a class element. - */ - interface AllDecorators { - decorators: readonly Decorator[] | undefined; - parameters?: readonly (readonly Decorator[] | undefined)[]; - } - - /** - * Gets an array of arrays of decorators for the parameters of a function-like node. - * The offset into the result array should correspond to the offset of the parameter. - * - * @param node The function-like node. - */ - function getDecoratorsOfParameters(node: FunctionLikeDeclaration | undefined) { - let decorators: (readonly Decorator[] | undefined)[] | undefined; - if (node) { - const parameters = node.parameters; - const firstParameterIsThis = parameters.length > 0 && parameterIsThisKeyword(parameters[0]); - const firstParameterOffset = firstParameterIsThis ? 1 : 0; - const numParameters = firstParameterIsThis ? parameters.length - 1 : parameters.length; - for (let i = 0; i < numParameters; i++) { - const parameter = parameters[i + firstParameterOffset]; - if (decorators || parameter.decorators) { - if (!decorators) { - decorators = new Array(numParameters); - } - - decorators[i] = parameter.decorators; - } - } - } - - return decorators; - } - - /** - * Gets an AllDecorators object containing the decorators for the class and the decorators for the - * parameters of the constructor of the class. - * - * @param node The class node. - */ - function getAllDecoratorsOfConstructor(node: ClassExpression | ClassDeclaration): AllDecorators | undefined { - const decorators = node.decorators; - const parameters = getDecoratorsOfParameters(getFirstConstructorWithBody(node)); - if (!decorators && !parameters) { - return undefined; - } - - return { - decorators, - parameters - }; - } - - /** - * Gets an AllDecorators object containing the decorators for the member and its parameters. - * - * @param node The class node that contains the member. - * @param member The class member. - */ - function getAllDecoratorsOfClassElement(node: ClassExpression | ClassDeclaration, member: ClassElement): AllDecorators | undefined { - switch (member.kind) { - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return getAllDecoratorsOfAccessors(node, member); - - case SyntaxKind.MethodDeclaration: - return getAllDecoratorsOfMethod(member); - - case SyntaxKind.PropertyDeclaration: - return getAllDecoratorsOfProperty(member); - - default: - return undefined; - } - } - - /** - * Gets an AllDecorators object containing the decorators for the accessor and its parameters. - * - * @param node The class node that contains the accessor. - * @param accessor The class accessor member. - */ - function getAllDecoratorsOfAccessors(node: ClassExpression | ClassDeclaration, accessor: AccessorDeclaration): AllDecorators | undefined { - if (!accessor.body) { - return undefined; - } - - const { firstAccessor, secondAccessor, setAccessor } = getAllAccessorDeclarations(node.members, accessor); - const firstAccessorWithDecorators = firstAccessor.decorators ? firstAccessor : secondAccessor && secondAccessor.decorators ? secondAccessor : undefined; - if (!firstAccessorWithDecorators || accessor !== firstAccessorWithDecorators) { - return undefined; - } - - const decorators = firstAccessorWithDecorators.decorators; - const parameters = getDecoratorsOfParameters(setAccessor); - if (!decorators && !parameters) { - return undefined; - } - - return { decorators, parameters }; - } - - /** - * Gets an AllDecorators object containing the decorators for the method and its parameters. - * - * @param method The class method member. - */ - function getAllDecoratorsOfMethod(method: MethodDeclaration): AllDecorators | undefined { - if (!method.body) { - return undefined; - } - - const decorators = method.decorators; - const parameters = getDecoratorsOfParameters(method); - if (!decorators && !parameters) { - return undefined; - } - - return { decorators, parameters }; - } - - /** - * Gets an AllDecorators object containing the decorators for the property. - * - * @param property The class property member. - */ - function getAllDecoratorsOfProperty(property: PropertyDeclaration): AllDecorators | undefined { - const decorators = property.decorators; - if (!decorators) { - return undefined; - - } - - return { decorators }; - } - - /** - * Transforms all of the decorators for a declaration into an array of expressions. - * - * @param node The declaration node. - * @param allDecorators An object containing all of the decorators for the declaration. - */ - function transformAllDecoratorsOfDeclaration(node: Declaration, container: ClassLikeDeclaration, allDecorators: AllDecorators | undefined) { - if (!allDecorators) { - return undefined; - } - - const decoratorExpressions: Expression[] = []; - addRange(decoratorExpressions, map(allDecorators.decorators, transformDecorator)); - addRange(decoratorExpressions, flatMap(allDecorators.parameters, transformDecoratorsOfParameter)); - addTypeMetadata(node, container, decoratorExpressions); - return decoratorExpressions; - } - - /** - * Generates statements used to apply decorators to either the static or instance members - * of a class. - * - * @param node The class node. - * @param isStatic A value indicating whether to generate statements for static or - * instance members. - */ - function addClassElementDecorationStatements(statements: Statement[], node: ClassDeclaration, isStatic: boolean) { - addRange(statements, map(generateClassElementDecorationExpressions(node, isStatic), expressionToStatement)); - } - - /** - * Generates expressions used to apply decorators to either the static or instance members - * of a class. - * - * @param node The class node. - * @param isStatic A value indicating whether to generate expressions for static or - * instance members. - */ - function generateClassElementDecorationExpressions(node: ClassExpression | ClassDeclaration, isStatic: boolean) { - const members = getDecoratedClassElements(node, isStatic); - let expressions: Expression[] | undefined; - for (const member of members) { - const expression = generateClassElementDecorationExpression(node, member); - if (expression) { - if (!expressions) { - expressions = [expression]; - } - else { - expressions.push(expression); - } - } - } - return expressions; - } - - /** - * Generates an expression used to evaluate class element decorators at runtime. - * - * @param node The class node that contains the member. - * @param member The class member. - */ - function generateClassElementDecorationExpression(node: ClassExpression | ClassDeclaration, member: ClassElement) { - const allDecorators = getAllDecoratorsOfClassElement(node, member); - const decoratorExpressions = transformAllDecoratorsOfDeclaration(member, node, allDecorators); - if (!decoratorExpressions) { - return undefined; - } - - // Emit the call to __decorate. Given the following: - // - // class C { - // @dec method(@dec2 x) {} - // @dec get accessor() {} - // @dec prop; - // } - // - // The emit for a method is: - // - // __decorate([ - // dec, - // __param(0, dec2), - // __metadata("design:type", Function), - // __metadata("design:paramtypes", [Object]), - // __metadata("design:returntype", void 0) - // ], C.prototype, "method", null); - // - // The emit for an accessor is: - // - // __decorate([ - // dec - // ], C.prototype, "accessor", null); - // - // The emit for a property is: - // - // __decorate([ - // dec - // ], C.prototype, "prop"); - // - - const prefix = getClassMemberPrefix(node, member); - const memberName = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ true); - const descriptor = languageVersion > ScriptTarget.ES3 - ? member.kind === SyntaxKind.PropertyDeclaration - // We emit `void 0` here to indicate to `__decorate` that it can invoke `Object.defineProperty` directly, but that it - // should not invoke `Object.getOwnPropertyDescriptor`. - ? createVoidZero() - - // We emit `null` here to indicate to `__decorate` that it can invoke `Object.getOwnPropertyDescriptor` directly. - // We have this extra argument here so that we can inject an explicit property descriptor at a later date. - : createNull() - : undefined; - - const helper = createDecorateHelper( - context, - decoratorExpressions, - prefix, - memberName, - descriptor, - moveRangePastDecorators(member) - ); - - setEmitFlags(helper, EmitFlags.NoComments); - return helper; - } - - /** - * Generates a __decorate helper call for a class constructor. - * - * @param node The class node. - */ - function addConstructorDecorationStatement(statements: Statement[], node: ClassDeclaration) { - const expression = generateConstructorDecorationExpression(node); - if (expression) { - statements.push(setOriginalNode(createExpressionStatement(expression), node)); - } - } - - /** - * Generates a __decorate helper call for a class constructor. - * - * @param node The class node. - */ - function generateConstructorDecorationExpression(node: ClassExpression | ClassDeclaration) { - const allDecorators = getAllDecoratorsOfConstructor(node); - const decoratorExpressions = transformAllDecoratorsOfDeclaration(node, node, allDecorators); - if (!decoratorExpressions) { - return undefined; - } - - const classAlias = classAliases && classAliases[getOriginalNodeId(node)]; - const localName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); - const decorate = createDecorateHelper(context, decoratorExpressions, localName); - const expression = createAssignment(localName, classAlias ? createAssignment(classAlias, decorate) : decorate); - setEmitFlags(expression, EmitFlags.NoComments); - setSourceMapRange(expression, moveRangePastDecorators(node)); - return expression; - } - - /** - * Transforms a decorator into an expression. - * - * @param decorator The decorator node. - */ - function transformDecorator(decorator: Decorator) { - return visitNode(decorator.expression, visitor, isExpression); - } - - /** - * Transforms the decorators of a parameter. - * - * @param decorators The decorators for the parameter at the provided offset. - * @param parameterOffset The offset of the parameter. - */ - function transformDecoratorsOfParameter(decorators: Decorator[], parameterOffset: number) { - let expressions: Expression[] | undefined; - if (decorators) { - expressions = []; - for (const decorator of decorators) { - const helper = createParamHelper( - context, - transformDecorator(decorator), - parameterOffset, - /*location*/ decorator.expression); - setEmitFlags(helper, EmitFlags.NoComments); - expressions.push(helper); - } - } - - return expressions; - } - - /** - * Adds optional type metadata for a declaration. - * - * @param node The declaration node. - * @param decoratorExpressions The destination array to which to add new decorator expressions. - */ - function addTypeMetadata(node: Declaration, container: ClassLikeDeclaration, decoratorExpressions: Expression[]) { - if (USE_NEW_TYPE_METADATA_FORMAT) { - addNewTypeMetadata(node, container, decoratorExpressions); - } - else { - addOldTypeMetadata(node, container, decoratorExpressions); - } - } - - function addOldTypeMetadata(node: Declaration, container: ClassLikeDeclaration, decoratorExpressions: Expression[]) { - if (compilerOptions.emitDecoratorMetadata) { - if (shouldAddTypeMetadata(node)) { - decoratorExpressions.push(createMetadataHelper(context, "design:type", serializeTypeOfNode(node))); - } - if (shouldAddParamTypesMetadata(node)) { - decoratorExpressions.push(createMetadataHelper(context, "design:paramtypes", serializeParameterTypesOfNode(node, container))); - } - if (shouldAddReturnTypeMetadata(node)) { - decoratorExpressions.push(createMetadataHelper(context, "design:returntype", serializeReturnTypeOfNode(node))); - } - } - } - - function addNewTypeMetadata(node: Declaration, container: ClassLikeDeclaration, decoratorExpressions: Expression[]) { - if (compilerOptions.emitDecoratorMetadata) { - let properties: ObjectLiteralElementLike[] | undefined; - if (shouldAddTypeMetadata(node)) { - (properties || (properties = [])).push(createPropertyAssignment("type", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeTypeOfNode(node)))); - } - if (shouldAddParamTypesMetadata(node)) { - (properties || (properties = [])).push(createPropertyAssignment("paramTypes", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeParameterTypesOfNode(node, container)))); - } - if (shouldAddReturnTypeMetadata(node)) { - (properties || (properties = [])).push(createPropertyAssignment("returnType", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeReturnTypeOfNode(node)))); - } - if (properties) { - decoratorExpressions.push(createMetadataHelper(context, "design:typeinfo", createObjectLiteral(properties, /*multiLine*/ true))); - } - } - } - - /** - * Determines whether to emit the "design:type" metadata based on the node's kind. - * The caller should have already tested whether the node has decorators and whether the - * emitDecoratorMetadata compiler option is set. - * - * @param node The node to test. - */ - function shouldAddTypeMetadata(node: Declaration): boolean { - const kind = node.kind; - return kind === SyntaxKind.MethodDeclaration - || kind === SyntaxKind.GetAccessor - || kind === SyntaxKind.SetAccessor - || kind === SyntaxKind.PropertyDeclaration; - } - - /** - * Determines whether to emit the "design:returntype" metadata based on the node's kind. - * The caller should have already tested whether the node has decorators and whether the - * emitDecoratorMetadata compiler option is set. - * - * @param node The node to test. - */ - function shouldAddReturnTypeMetadata(node: Declaration): boolean { - return node.kind === SyntaxKind.MethodDeclaration; - } - - /** - * Determines whether to emit the "design:paramtypes" metadata based on the node's kind. - * The caller should have already tested whether the node has decorators and whether the - * emitDecoratorMetadata compiler option is set. - * - * @param node The node to test. - */ - function shouldAddParamTypesMetadata(node: Declaration): boolean { - switch (node.kind) { - case SyntaxKind.ClassDeclaration: - case SyntaxKind.ClassExpression: - return getFirstConstructorWithBody(node) !== undefined; - case SyntaxKind.MethodDeclaration: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return true; - } - return false; - } - - type SerializedEntityNameAsExpression = Identifier | BinaryExpression | PropertyAccessExpression; - type SerializedTypeNode = SerializedEntityNameAsExpression | VoidExpression | ConditionalExpression; - - function getAccessorTypeNode(node: AccessorDeclaration) { - const accessors = resolver.getAllAccessorDeclarations(node); - return accessors.setAccessor && getSetAccessorTypeAnnotationNode(accessors.setAccessor) - || accessors.getAccessor && getEffectiveReturnTypeNode(accessors.getAccessor); - } - - /** - * Serializes the type of a node for use with decorator type metadata. - * - * @param node The node that should have its type serialized. - */ - function serializeTypeOfNode(node: Node): SerializedTypeNode { - switch (node.kind) { - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.Parameter: - return serializeTypeNode((node).type); - case SyntaxKind.SetAccessor: - case SyntaxKind.GetAccessor: - return serializeTypeNode(getAccessorTypeNode(node as AccessorDeclaration)); - case SyntaxKind.ClassDeclaration: - case SyntaxKind.ClassExpression: - case SyntaxKind.MethodDeclaration: - return createIdentifier("Function"); - default: - return createVoidZero(); - } - } - - /** - * Serializes the types of the parameters of a node for use with decorator type metadata. - * - * @param node The node that should have its parameter types serialized. - */ - function serializeParameterTypesOfNode(node: Node, container: ClassLikeDeclaration): ArrayLiteralExpression { - const valueDeclaration = - isClassLike(node) - ? getFirstConstructorWithBody(node) - : isFunctionLike(node) && nodeIsPresent((node as FunctionLikeDeclaration).body) - ? node - : undefined; - - const expressions: SerializedTypeNode[] = []; - if (valueDeclaration) { - const parameters = getParametersOfDecoratedDeclaration(valueDeclaration, container); - const numParameters = parameters.length; - for (let i = 0; i < numParameters; i++) { - const parameter = parameters[i]; - if (i === 0 && isIdentifier(parameter.name) && parameter.name.escapedText === "this") { - continue; - } - if (parameter.dotDotDotToken) { - expressions.push(serializeTypeNode(getRestParameterElementType(parameter.type))); - } - else { - expressions.push(serializeTypeOfNode(parameter)); - } - } - } - - return createArrayLiteral(expressions); - } - - function getParametersOfDecoratedDeclaration(node: SignatureDeclaration, container: ClassLikeDeclaration) { - if (container && node.kind === SyntaxKind.GetAccessor) { - const { setAccessor } = getAllAccessorDeclarations(container.members, node); - if (setAccessor) { - return setAccessor.parameters; - } - } - return node.parameters; - } - - /** - * Serializes the return type of a node for use with decorator type metadata. - * - * @param node The node that should have its return type serialized. - */ - function serializeReturnTypeOfNode(node: Node): SerializedTypeNode { - if (isFunctionLike(node) && node.type) { - return serializeTypeNode(node.type); - } - else if (isAsyncFunction(node)) { - return createIdentifier("Promise"); - } - - return createVoidZero(); - } - - /** - * Serializes a type node for use with decorator type metadata. - * - * Types are serialized in the following fashion: - * - Void types point to "undefined" (e.g. "void 0") - * - Function and Constructor types point to the global "Function" constructor. - * - Interface types with a call or construct signature types point to the global - * "Function" constructor. - * - Array and Tuple types point to the global "Array" constructor. - * - Type predicates and booleans point to the global "Boolean" constructor. - * - String literal types and strings point to the global "String" constructor. - * - Enum and number types point to the global "Number" constructor. - * - Symbol types point to the global "Symbol" constructor. - * - Type references to classes (or class-like variables) point to the constructor for the class. - * - Anything else points to the global "Object" constructor. - * - * @param node The type node to serialize. - */ - function serializeTypeNode(node: TypeNode | undefined): SerializedTypeNode { - if (node === undefined) { - return createIdentifier("Object"); - } - - switch (node.kind) { - case SyntaxKind.VoidKeyword: - case SyntaxKind.UndefinedKeyword: - case SyntaxKind.NullKeyword: - case SyntaxKind.NeverKeyword: - return createVoidZero(); - - case SyntaxKind.ParenthesizedType: - return serializeTypeNode((node).type); - - case SyntaxKind.FunctionType: - case SyntaxKind.ConstructorType: - return createIdentifier("Function"); - - case SyntaxKind.ArrayType: - case SyntaxKind.TupleType: - return createIdentifier("Array"); - - case SyntaxKind.TypePredicate: - case SyntaxKind.BooleanKeyword: - return createIdentifier("Boolean"); - - case SyntaxKind.StringKeyword: - return createIdentifier("String"); - - case SyntaxKind.ObjectKeyword: - return createIdentifier("Object"); - - case SyntaxKind.LiteralType: - switch ((node).literal.kind) { - case SyntaxKind.StringLiteral: - return createIdentifier("String"); - - case SyntaxKind.PrefixUnaryExpression: - case SyntaxKind.NumericLiteral: - return createIdentifier("Number"); - - case SyntaxKind.BigIntLiteral: - return getGlobalBigIntNameWithFallback(); - - case SyntaxKind.TrueKeyword: - case SyntaxKind.FalseKeyword: - return createIdentifier("Boolean"); - - default: - return Debug.failBadSyntaxKind((node).literal); - } - - case SyntaxKind.NumberKeyword: - return createIdentifier("Number"); - - case SyntaxKind.BigIntKeyword: - return getGlobalBigIntNameWithFallback(); - - case SyntaxKind.SymbolKeyword: - return languageVersion < ScriptTarget.ES2015 - ? getGlobalSymbolNameWithFallback() - : createIdentifier("Symbol"); - - case SyntaxKind.TypeReference: - return serializeTypeReferenceNode(node); - - case SyntaxKind.IntersectionType: - case SyntaxKind.UnionType: - return serializeTypeList((node).types); - - case SyntaxKind.ConditionalType: - return serializeTypeList([(node).trueType, (node).falseType]); - - case SyntaxKind.TypeOperator: - if ((node).operator === SyntaxKind.ReadonlyKeyword) { - return serializeTypeNode((node).type); - } - break; - - case SyntaxKind.TypeQuery: - case SyntaxKind.IndexedAccessType: - case SyntaxKind.MappedType: - case SyntaxKind.TypeLiteral: - case SyntaxKind.AnyKeyword: - case SyntaxKind.UnknownKeyword: - case SyntaxKind.ThisType: - case SyntaxKind.ImportType: - break; - - - default: - return Debug.failBadSyntaxKind(node); - } - - return createIdentifier("Object"); - } - - function serializeTypeList(types: readonly TypeNode[]): SerializedTypeNode { - // Note when updating logic here also update getEntityNameForDecoratorMetadata - // so that aliases can be marked as referenced - let serializedUnion: SerializedTypeNode | undefined; - for (let typeNode of types) { - while (typeNode.kind === SyntaxKind.ParenthesizedType) { - typeNode = (typeNode as ParenthesizedTypeNode).type; // Skip parens if need be - } - if (typeNode.kind === SyntaxKind.NeverKeyword) { - continue; // Always elide `never` from the union/intersection if possible - } - if (!strictNullChecks && (typeNode.kind === SyntaxKind.NullKeyword || typeNode.kind === SyntaxKind.UndefinedKeyword)) { - continue; // Elide null and undefined from unions for metadata, just like what we did prior to the implementation of strict null checks - } - const serializedIndividual = serializeTypeNode(typeNode); - - if (isIdentifier(serializedIndividual) && serializedIndividual.escapedText === "Object") { - // One of the individual is global object, return immediately - return serializedIndividual; - } - // If there exists union that is not void 0 expression, check if the the common type is identifier. - // anything more complex and we will just default to Object - else if (serializedUnion) { - // Different types - if (!isIdentifier(serializedUnion) || - !isIdentifier(serializedIndividual) || - serializedUnion.escapedText !== serializedIndividual.escapedText) { - return createIdentifier("Object"); - } - } - else { - // Initialize the union type - serializedUnion = serializedIndividual; - } - } - - // If we were able to find common type, use it - return serializedUnion || createVoidZero(); // Fallback is only hit if all union constituients are null/undefined/never - } - - /** - * Serializes a TypeReferenceNode to an appropriate JS constructor value for use with - * decorator type metadata. - * - * @param node The type reference node. - */ - function serializeTypeReferenceNode(node: TypeReferenceNode): SerializedTypeNode { - const kind = resolver.getTypeReferenceSerializationKind(node.typeName, currentNameScope || currentLexicalScope); - switch (kind) { - case TypeReferenceSerializationKind.Unknown: - // From conditional type type reference that cannot be resolved is Similar to any or unknown - if (findAncestor(node, n => n.parent && isConditionalTypeNode(n.parent) && (n.parent.trueType === n || n.parent.falseType === n))) { - return createIdentifier("Object"); - } - - const serialized = serializeEntityNameAsExpressionFallback(node.typeName); - const temp = createTempVariable(hoistVariableDeclaration); - return createConditional( - createTypeCheck(createAssignment(temp, serialized), "function"), - temp, - createIdentifier("Object") - ); - - case TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: - return serializeEntityNameAsExpression(node.typeName); - - case TypeReferenceSerializationKind.VoidNullableOrNeverType: - return createVoidZero(); - - case TypeReferenceSerializationKind.BigIntLikeType: - return getGlobalBigIntNameWithFallback(); - - case TypeReferenceSerializationKind.BooleanType: - return createIdentifier("Boolean"); - - case TypeReferenceSerializationKind.NumberLikeType: - return createIdentifier("Number"); - - case TypeReferenceSerializationKind.StringLikeType: - return createIdentifier("String"); - - case TypeReferenceSerializationKind.ArrayLikeType: - return createIdentifier("Array"); - - case TypeReferenceSerializationKind.ESSymbolType: - return languageVersion < ScriptTarget.ES2015 - ? getGlobalSymbolNameWithFallback() - : createIdentifier("Symbol"); - - case TypeReferenceSerializationKind.TypeWithCallSignature: - return createIdentifier("Function"); - - case TypeReferenceSerializationKind.Promise: - return createIdentifier("Promise"); - - case TypeReferenceSerializationKind.ObjectType: - return createIdentifier("Object"); - default: - return Debug.assertNever(kind); - } - } - - function createCheckedValue(left: Expression, right: Expression) { - return createLogicalAnd( - createStrictInequality(createTypeOf(left), createLiteral("undefined")), - right - ); - } - - /** - * Serializes an entity name which may not exist at runtime, but whose access shouldn't throw - * - * @param node The entity name to serialize. - */ - function serializeEntityNameAsExpressionFallback(node: EntityName): BinaryExpression { - if (node.kind === SyntaxKind.Identifier) { - // A -> typeof A !== undefined && A - const copied = serializeEntityNameAsExpression(node); - return createCheckedValue(copied, copied); - } - if (node.left.kind === SyntaxKind.Identifier) { - // A.B -> typeof A !== undefined && A.B - return createCheckedValue(serializeEntityNameAsExpression(node.left), serializeEntityNameAsExpression(node)); - } - // A.B.C -> typeof A !== undefined && (_a = A.B) !== void 0 && _a.C - const left = serializeEntityNameAsExpressionFallback(node.left); - const temp = createTempVariable(hoistVariableDeclaration); - return createLogicalAnd( - createLogicalAnd( - left.left, - createStrictInequality(createAssignment(temp, left.right), createVoidZero()) - ), - createPropertyAccess(temp, node.right) - ); - } - - /** - * Serializes an entity name as an expression for decorator type metadata. - * - * @param node The entity name to serialize. - */ - function serializeEntityNameAsExpression(node: EntityName): SerializedEntityNameAsExpression { - switch (node.kind) { - case SyntaxKind.Identifier: - // Create a clone of the name with a new parent, and treat it as if it were - // a source tree node for the purposes of the checker. - const name = getMutableClone(node); - name.flags &= ~NodeFlags.Synthesized; - name.original = undefined; - name.parent = getParseTreeNode(currentLexicalScope); // ensure the parent is set to a parse tree node. - - return name; - - case SyntaxKind.QualifiedName: - return serializeQualifiedNameAsExpression(node); - } - } - - /** - * Serializes an qualified name as an expression for decorator type metadata. - * - * @param node The qualified name to serialize. - * @param useFallback A value indicating whether to use logical operators to test for the - * qualified name at runtime. - */ - function serializeQualifiedNameAsExpression(node: QualifiedName): SerializedEntityNameAsExpression { - return createPropertyAccess(serializeEntityNameAsExpression(node.left), node.right); - } - - /** - * Gets an expression that points to the global "Symbol" constructor at runtime if it is - * available. - */ - function getGlobalSymbolNameWithFallback(): ConditionalExpression { - return createConditional( - createTypeCheck(createIdentifier("Symbol"), "function"), - createIdentifier("Symbol"), - createIdentifier("Object") - ); - } - - /** - * Gets an expression that points to the global "BigInt" constructor at runtime if it is - * available. - */ - function getGlobalBigIntNameWithFallback(): SerializedTypeNode { - return languageVersion < ScriptTarget.ESNext - ? createConditional( - createTypeCheck(createIdentifier("BigInt"), "function"), - createIdentifier("BigInt"), - createIdentifier("Object") - ) - : createIdentifier("BigInt"); - } - - /** - * Gets an expression that represents a property name. For a computed property, a - * name is generated for the node. - * - * @param member The member whose name should be converted into an expression. - */ - function getExpressionForPropertyName(member: ClassElement | EnumMember, generateNameForComputedPropertyName: boolean): Expression { - const name = member.name!; - if (isComputedPropertyName(name)) { - return generateNameForComputedPropertyName && !isSimpleInlineableExpression(name.expression) - ? getGeneratedNameForNode(name) - : name.expression; - } - else if (isIdentifier(name)) { - return createLiteral(idText(name)); - } - else { - return getSynthesizedClone(name); - } - } - - /** - * Visits the property name of a class element, for use when emitting property - * initializers. For a computed property on a node with decorators, a temporary - * value is stored for later use. - * - * @param member The member whose name should be visited. - */ - function visitPropertyNameOfClassElement(member: ClassElement): PropertyName { - const name = member.name!; - // Computed property names need to be transformed into a hoisted variable when they are used more than once. - // The names are used more than once when: - // - the property is non-static and its initializer is moved to the constructor (when there are parameter property assignments). - // - the property has a decorator. - if (isComputedPropertyName(name) && ((!hasStaticModifier(member) && currentClassHasParameterProperties) || some(member.decorators))) { - const expression = visitNode(name.expression, visitor, isExpression); - const innerExpression = skipPartiallyEmittedExpressions(expression); - if (!isSimpleInlineableExpression(innerExpression)) { - const generatedName = getGeneratedNameForNode(name); - hoistVariableDeclaration(generatedName); - return updateComputedPropertyName(name, createAssignment(generatedName, expression)); - } - } - return visitNode(name, visitor, isPropertyName); - } - - /** - * Transforms a HeritageClause with TypeScript syntax. - * - * This function will only be called when one of the following conditions are met: - * - The node is a non-`extends` heritage clause that should be elided. - * - The node is an `extends` heritage clause that should be visited, but only allow a single type. - * - * @param node The HeritageClause to transform. - */ - function visitHeritageClause(node: HeritageClause): HeritageClause | undefined { - if (node.token === SyntaxKind.ImplementsKeyword) { - // implements clauses are elided - return undefined; - } - return visitEachChild(node, visitor, context); - } - - /** - * Transforms an ExpressionWithTypeArguments with TypeScript syntax. - * - * This function will only be called when one of the following conditions are met: - * - The node contains type arguments that should be elided. - * - * @param node The ExpressionWithTypeArguments to transform. - */ - function visitExpressionWithTypeArguments(node: ExpressionWithTypeArguments): ExpressionWithTypeArguments { - return updateExpressionWithTypeArguments( - node, - /*typeArguments*/ undefined, - visitNode(node.expression, visitor, isLeftHandSideExpression) - ); - } - - /** - * Determines whether to emit a function-like declaration. We should not emit the - * declaration if it does not have a body. - * - * @param node The declaration node. - */ - function shouldEmitFunctionLikeDeclaration(node: T): node is T & { body: NonNullable } { - return !nodeIsMissing(node.body); - } - - function visitPropertyDeclaration(node: PropertyDeclaration) { - const updated = updateProperty( - node, - /*decorators*/ undefined, - visitNodes(node.modifiers, visitor, isModifier), - visitPropertyNameOfClassElement(node), - /*questionOrExclamationToken*/ undefined, - /*type*/ undefined, - visitNode(node.initializer, visitor) - ); - if (updated !== node) { - // While we emit the source map for the node after skipping decorators and modifiers, - // we need to emit the comments for the original range. - setCommentRange(updated, node); - setSourceMapRange(updated, moveRangePastDecorators(node)); - } - return updated; - } - - function visitConstructor(node: ConstructorDeclaration) { - if (!shouldEmitFunctionLikeDeclaration(node)) { - return undefined; - } - - return updateConstructor( - node, - /*decorators*/ undefined, - /*modifiers*/ undefined, - visitParameterList(node.parameters, visitor, context), - transformConstructorBody(node.body, node) - ); - } - - function transformConstructorBody(body: Block, constructor: ConstructorDeclaration) { - const parametersWithPropertyAssignments = constructor && - filter(constructor.parameters, p => isParameterPropertyDeclaration(p, constructor)); - if (!some(parametersWithPropertyAssignments)) { - return visitFunctionBody(body, visitor, context); - } - - let statements: Statement[] = []; - let indexOfFirstStatement = 0; - - resumeLexicalEnvironment(); - - indexOfFirstStatement = addPrologueDirectivesAndInitialSuperCall(constructor, statements, visitor); - - // Add parameters with property assignments. Transforms this: - // - // constructor (public x, public y) { - // } - // - // Into this: - // - // constructor (x, y) { - // this.x = x; - // this.y = y; - // } - // - addRange(statements, map(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment)); - - // Add the existing statements, skipping the initial super call. - addRange(statements, visitNodes(body.statements, visitor, isStatement, indexOfFirstStatement)); - - // End the lexical environment. - statements = mergeLexicalEnvironment(statements, endLexicalEnvironment()); - const block = createBlock(setTextRange(createNodeArray(statements), body.statements), /*multiLine*/ true); - setTextRange(block, /*location*/ body); - setOriginalNode(block, body); - return block; - } - - /** - * Transforms a parameter into a property assignment statement. - * - * @param node The parameter declaration. - */ - function transformParameterWithPropertyAssignment(node: ParameterPropertyDeclaration) { - const name = node.name; - if (!isIdentifier(name)) { - return undefined; - } - - const propertyName = getMutableClone(name); - setEmitFlags(propertyName, EmitFlags.NoComments | EmitFlags.NoSourceMap); - - const localName = getMutableClone(name); - setEmitFlags(localName, EmitFlags.NoComments); - - return startOnNewLine( - removeAllComments( - setTextRange( - setOriginalNode( - createExpressionStatement( - createAssignment( - setTextRange( - createPropertyAccess( - createThis(), - propertyName - ), - node.name - ), - localName - ) - ), - node - ), - moveRangePos(node, -1) - ) - ) - ); - } - - function visitMethodDeclaration(node: MethodDeclaration) { - if (!shouldEmitFunctionLikeDeclaration(node)) { - return undefined; - } - const updated = updateMethod( - node, - /*decorators*/ undefined, - visitNodes(node.modifiers, modifierVisitor, isModifier), - node.asteriskToken, - visitPropertyNameOfClassElement(node), - /*questionToken*/ undefined, - /*typeParameters*/ undefined, - visitParameterList(node.parameters, visitor, context), - /*type*/ undefined, - visitFunctionBody(node.body, visitor, context) - ); - if (updated !== node) { - // While we emit the source map for the node after skipping decorators and modifiers, - // we need to emit the comments for the original range. - setCommentRange(updated, node); - setSourceMapRange(updated, moveRangePastDecorators(node)); - } - return updated; - } - - /** - * Determines whether to emit an accessor declaration. We should not emit the - * declaration if it does not have a body and is abstract. - * - * @param node The declaration node. - */ - function shouldEmitAccessorDeclaration(node: AccessorDeclaration) { - return !(nodeIsMissing(node.body) && hasModifier(node, ModifierFlags.Abstract)); - } - - function visitGetAccessor(node: GetAccessorDeclaration) { - if (!shouldEmitAccessorDeclaration(node)) { - return undefined; - } - const updated = updateGetAccessor( - node, - /*decorators*/ undefined, - visitNodes(node.modifiers, modifierVisitor, isModifier), - visitPropertyNameOfClassElement(node), - visitParameterList(node.parameters, visitor, context), - /*type*/ undefined, - visitFunctionBody(node.body, visitor, context) || createBlock([]) - ); - if (updated !== node) { - // While we emit the source map for the node after skipping decorators and modifiers, - // we need to emit the comments for the original range. - setCommentRange(updated, node); - setSourceMapRange(updated, moveRangePastDecorators(node)); - } - return updated; - } - - function visitSetAccessor(node: SetAccessorDeclaration) { - if (!shouldEmitAccessorDeclaration(node)) { - return undefined; - } - const updated = updateSetAccessor( - node, - /*decorators*/ undefined, - visitNodes(node.modifiers, modifierVisitor, isModifier), - visitPropertyNameOfClassElement(node), - visitParameterList(node.parameters, visitor, context), - visitFunctionBody(node.body, visitor, context) || createBlock([]) - ); - if (updated !== node) { - // While we emit the source map for the node after skipping decorators and modifiers, - // we need to emit the comments for the original range. - setCommentRange(updated, node); - setSourceMapRange(updated, moveRangePastDecorators(node)); - } - return updated; - } - - function visitFunctionDeclaration(node: FunctionDeclaration): VisitResult { - if (!shouldEmitFunctionLikeDeclaration(node)) { - return createNotEmittedStatement(node); - } - const updated = updateFunctionDeclaration( - node, - /*decorators*/ undefined, - visitNodes(node.modifiers, modifierVisitor, isModifier), - node.asteriskToken, - node.name, - /*typeParameters*/ undefined, - visitParameterList(node.parameters, visitor, context), - /*type*/ undefined, - visitFunctionBody(node.body, visitor, context) || createBlock([]) - ); - if (isExportOfNamespace(node)) { - const statements: Statement[] = [updated]; - addExportMemberAssignment(statements, node); - return statements; - } - return updated; - } - - function visitFunctionExpression(node: FunctionExpression): Expression { - if (!shouldEmitFunctionLikeDeclaration(node)) { - return createOmittedExpression(); - } - const updated = updateFunctionExpression( - node, - visitNodes(node.modifiers, modifierVisitor, isModifier), - node.asteriskToken, - node.name, - /*typeParameters*/ undefined, - visitParameterList(node.parameters, visitor, context), - /*type*/ undefined, - visitFunctionBody(node.body, visitor, context) || createBlock([]) - ); - return updated; - } - - function visitArrowFunction(node: ArrowFunction) { - const updated = updateArrowFunction( - node, - visitNodes(node.modifiers, modifierVisitor, isModifier), - /*typeParameters*/ undefined, - visitParameterList(node.parameters, visitor, context), - /*type*/ undefined, - node.equalsGreaterThanToken, - visitFunctionBody(node.body, visitor, context), - ); - return updated; - } - - function visitParameter(node: ParameterDeclaration) { - if (parameterIsThisKeyword(node)) { - return undefined; - } - - const updated = updateParameter( - node, - /*decorators*/ undefined, - /*modifiers*/ undefined, - node.dotDotDotToken, - visitNode(node.name, visitor, isBindingName), - /*questionToken*/ undefined, - /*type*/ undefined, - visitNode(node.initializer, visitor, isExpression) - ); - if (updated !== node) { - // While we emit the source map for the node after skipping decorators and modifiers, - // we need to emit the comments for the original range. - setCommentRange(updated, node); - setTextRange(updated, moveRangePastModifiers(node)); - setSourceMapRange(updated, moveRangePastModifiers(node)); - setEmitFlags(updated.name, EmitFlags.NoTrailingSourceMap); - } - return updated; - } - - function visitVariableStatement(node: VariableStatement): Statement | undefined { - if (isExportOfNamespace(node)) { - const variables = getInitializedVariables(node.declarationList); - if (variables.length === 0) { - // elide statement if there are no initialized variables. - return undefined; - } - - return setTextRange( - createExpressionStatement( - inlineExpressions( - map(variables, transformInitializedVariable) - ) - ), - node - ); - } - else { - return visitEachChild(node, visitor, context); - } - } - - function transformInitializedVariable(node: VariableDeclaration): Expression { - const name = node.name; - if (isBindingPattern(name)) { - return flattenDestructuringAssignment( - node, - visitor, - context, - FlattenLevel.All, - /*needsValue*/ false, - createNamespaceExportExpression - ); - } - else { - return setTextRange( - createAssignment( - getNamespaceMemberNameWithSourceMapsAndWithoutComments(name), - visitNode(node.initializer, visitor, isExpression) - ), - /*location*/ node - ); - } - } - - function visitVariableDeclaration(node: VariableDeclaration) { - return updateVariableDeclaration( - node, - visitNode(node.name, visitor, isBindingName), - /*type*/ undefined, - visitNode(node.initializer, visitor, isExpression)); - } - - function visitParenthesizedExpression(node: ParenthesizedExpression): Expression { - const innerExpression = skipOuterExpressions(node.expression, ~OuterExpressionKinds.Assertions); - if (isAssertionExpression(innerExpression)) { - // Make sure we consider all nested cast expressions, e.g.: - // (-A).x; - const expression = visitNode(node.expression, visitor, isExpression); - - // We have an expression of the form: (SubExpr). Emitting this as (SubExpr) - // is really not desirable. We would like to emit the subexpression as-is. Omitting - // the parentheses, however, could cause change in the semantics of the generated - // code if the casted expression has a lower precedence than the rest of the - // expression. - // - // To preserve comments, we return a "PartiallyEmittedExpression" here which will - // preserve the position information of the original expression. - // - // Due to the auto-parenthesization rules used by the visitor and factory functions - // we can safely elide the parentheses here, as a new synthetic - // ParenthesizedExpression will be inserted if we remove parentheses too - // aggressively. - // HOWEVER - if there are leading comments on the expression itself, to handle ASI - // correctly for return and throw, we must keep the parenthesis - if (length(getLeadingCommentRangesOfNode(expression, currentSourceFile))) { - return updateParen(node, expression); - } - return createPartiallyEmittedExpression(expression, node); - } - - return visitEachChild(node, visitor, context); - } - - function visitAssertionExpression(node: AssertionExpression): Expression { - const expression = visitNode(node.expression, visitor, isExpression); - return createPartiallyEmittedExpression(expression, node); - } - - function visitNonNullExpression(node: NonNullExpression): Expression { - const expression = visitNode(node.expression, visitor, isLeftHandSideExpression); - return createPartiallyEmittedExpression(expression, node); - } - - function visitCallExpression(node: CallExpression) { - return updateCall( - node, - visitNode(node.expression, visitor, isExpression), - /*typeArguments*/ undefined, - visitNodes(node.arguments, visitor, isExpression)); - } - - function visitNewExpression(node: NewExpression) { - return updateNew( - node, - visitNode(node.expression, visitor, isExpression), - /*typeArguments*/ undefined, - visitNodes(node.arguments, visitor, isExpression)); - } - - function visitTaggedTemplateExpression(node: TaggedTemplateExpression) { - return updateTaggedTemplate( - node, - visitNode(node.tag, visitor, isExpression), - /*typeArguments*/ undefined, - visitNode(node.template, visitor, isExpression)); - } - - /** - * Determines whether to emit an enum declaration. - * - * @param node The enum declaration node. - */ - function shouldEmitEnumDeclaration(node: EnumDeclaration) { - return !isEnumConst(node) - || compilerOptions.preserveConstEnums - || compilerOptions.isolatedModules; - } - - /** - * Visits an enum declaration. - * - * This function will be called any time a TypeScript enum is encountered. - * - * @param node The enum declaration node. - */ - function visitEnumDeclaration(node: EnumDeclaration): VisitResult { - if (!shouldEmitEnumDeclaration(node)) { - return createNotEmittedStatement(node); - } - - const statements: Statement[] = []; - - // We request to be advised when the printer is about to print this node. This allows - // us to set up the correct state for later substitutions. - let emitFlags = EmitFlags.AdviseOnEmitNode; - - // If needed, we should emit a variable declaration for the enum. If we emit - // a leading variable declaration, we should not emit leading comments for the - // enum body. - const varAdded = addVarForEnumOrModuleDeclaration(statements, node); - if (varAdded) { - // We should still emit the comments if we are emitting a system module. - if (moduleKind !== ModuleKind.System || currentLexicalScope !== currentSourceFile) { - emitFlags |= EmitFlags.NoLeadingComments; - } - } - - // `parameterName` is the declaration name used inside of the enum. - const parameterName = getNamespaceParameterName(node); - - // `containerName` is the expression used inside of the enum for assignments. - const containerName = getNamespaceContainerName(node); - - // `exportName` is the expression used within this node's container for any exported references. - const exportName = hasModifier(node, ModifierFlags.Export) - ? getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true) - : getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); - - // x || (x = {}) - // exports.x || (exports.x = {}) - let moduleArg = - createLogicalOr( - exportName, - createAssignment( - exportName, - createObjectLiteral() - ) - ); - - if (hasNamespaceQualifiedExportName(node)) { - // `localName` is the expression used within this node's containing scope for any local references. - const localName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); - - // x = (exports.x || (exports.x = {})) - moduleArg = createAssignment(localName, moduleArg); - } - - // (function (x) { - // x[x["y"] = 0] = "y"; - // ... - // })(x || (x = {})); - const enumStatement = createExpressionStatement( - createCall( - createFunctionExpression( - /*modifiers*/ undefined, - /*asteriskToken*/ undefined, - /*name*/ undefined, - /*typeParameters*/ undefined, - [createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, parameterName)], - /*type*/ undefined, - transformEnumBody(node, containerName) - ), - /*typeArguments*/ undefined, - [moduleArg] - ) - ); - - setOriginalNode(enumStatement, node); - if (varAdded) { - // If a variable was added, synthetic comments are emitted on it, not on the moduleStatement. - setSyntheticLeadingComments(enumStatement, undefined); - setSyntheticTrailingComments(enumStatement, undefined); - } - setTextRange(enumStatement, node); - addEmitFlags(enumStatement, emitFlags); - statements.push(enumStatement); - - // Add a DeclarationMarker for the enum to preserve trailing comments and mark - // the end of the declaration. - statements.push(createEndOfDeclarationMarker(node)); - return statements; - } - - /** - * Transforms the body of an enum declaration. - * - * @param node The enum declaration node. - */ - function transformEnumBody(node: EnumDeclaration, localName: Identifier): Block { - const savedCurrentNamespaceLocalName = currentNamespaceContainerName; - currentNamespaceContainerName = localName; - - const statements: Statement[] = []; - startLexicalEnvironment(); - const members = map(node.members, transformEnumMember); - insertStatementsAfterStandardPrologue(statements, endLexicalEnvironment()); - addRange(statements, members); - - currentNamespaceContainerName = savedCurrentNamespaceLocalName; - return createBlock( - setTextRange(createNodeArray(statements), /*location*/ node.members), - /*multiLine*/ true - ); - } - - /** - * Transforms an enum member into a statement. - * - * @param member The enum member node. - */ - function transformEnumMember(member: EnumMember): Statement { - // enums don't support computed properties - // we pass false as 'generateNameForComputedPropertyName' for a backward compatibility purposes - // old emitter always generate 'expression' part of the name as-is. - const name = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ false); - const valueExpression = transformEnumMemberDeclarationValue(member); - const innerAssignment = createAssignment( - createElementAccess( - currentNamespaceContainerName, - name - ), - valueExpression - ); - const outerAssignment = valueExpression.kind === SyntaxKind.StringLiteral ? - innerAssignment : - createAssignment( - createElementAccess( - currentNamespaceContainerName, - innerAssignment - ), - name - ); - return setTextRange( - createExpressionStatement( - setTextRange( - outerAssignment, - member - ) - ), - member - ); - } - - /** - * Transforms the value of an enum member. - * - * @param member The enum member node. - */ - function transformEnumMemberDeclarationValue(member: EnumMember): Expression { - const value = resolver.getConstantValue(member); - if (value !== undefined) { - return createLiteral(value); - } - else { - enableSubstitutionForNonQualifiedEnumMembers(); - if (member.initializer) { - return visitNode(member.initializer, visitor, isExpression); - } - else { - return createVoidZero(); - } - } - } - - /** - * Determines whether to elide a module declaration. - * - * @param node The module declaration node. - */ - function shouldEmitModuleDeclaration(node: ModuleDeclaration) { - return isInstantiatedModule(node, !!compilerOptions.preserveConstEnums || !!compilerOptions.isolatedModules); - } - - /** - * Determines whether an exported declaration will have a qualified export name (e.g. `f.x` - * or `exports.x`). - */ - function hasNamespaceQualifiedExportName(node: Node) { - return isExportOfNamespace(node) - || (isExternalModuleExport(node) - && moduleKind !== ModuleKind.ES2015 - && moduleKind !== ModuleKind.ESNext - && moduleKind !== ModuleKind.System); - } - - /** - * Records that a declaration was emitted in the current scope, if it was the first - * declaration for the provided symbol. - */ - function recordEmittedDeclarationInScope(node: FunctionDeclaration | ClassDeclaration | ModuleDeclaration | EnumDeclaration) { - if (!currentScopeFirstDeclarationsOfName) { - currentScopeFirstDeclarationsOfName = createUnderscoreEscapedMap(); - } - - const name = declaredNameInScope(node); - if (!currentScopeFirstDeclarationsOfName.has(name)) { - currentScopeFirstDeclarationsOfName.set(name, node); - } - } - - /** - * Determines whether a declaration is the first declaration with - * the same name emitted in the current scope. - */ - function isFirstEmittedDeclarationInScope(node: ModuleDeclaration | EnumDeclaration) { - if (currentScopeFirstDeclarationsOfName) { - const name = declaredNameInScope(node); - return currentScopeFirstDeclarationsOfName.get(name) === node; - } - return true; - } - - function declaredNameInScope(node: FunctionDeclaration | ClassDeclaration | ModuleDeclaration | EnumDeclaration): __String { - Debug.assertNode(node.name, isIdentifier); - return (node.name as Identifier).escapedText; - } - - /** - * Adds a leading VariableStatement for a enum or module declaration. - */ - function addVarForEnumOrModuleDeclaration(statements: Statement[], node: ModuleDeclaration | EnumDeclaration) { - // Emit a variable statement for the module. We emit top-level enums as a `var` - // declaration to avoid static errors in global scripts scripts due to redeclaration. - // enums in any other scope are emitted as a `let` declaration. - const statement = createVariableStatement( - visitNodes(node.modifiers, modifierVisitor, isModifier), - createVariableDeclarationList([ - createVariableDeclaration( - getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true) - ) - ], currentLexicalScope.kind === SyntaxKind.SourceFile ? NodeFlags.None : NodeFlags.Let) - ); - - setOriginalNode(statement, node); - - recordEmittedDeclarationInScope(node); - if (isFirstEmittedDeclarationInScope(node)) { - // Adjust the source map emit to match the old emitter. - if (node.kind === SyntaxKind.EnumDeclaration) { - setSourceMapRange(statement.declarationList, node); - } - else { - setSourceMapRange(statement, node); - } - - // Trailing comments for module declaration should be emitted after the function closure - // instead of the variable statement: - // - // /** Module comment*/ - // module m1 { - // function foo4Export() { - // } - // } // trailing comment module - // - // Should emit: - // - // /** Module comment*/ - // var m1; - // (function (m1) { - // function foo4Export() { - // } - // })(m1 || (m1 = {})); // trailing comment module - // - setCommentRange(statement, node); - addEmitFlags(statement, EmitFlags.NoTrailingComments | EmitFlags.HasEndOfDeclarationMarker); - statements.push(statement); - return true; - } - else { - // For an EnumDeclaration or ModuleDeclaration that merges with a preceeding - // declaration we do not emit a leading variable declaration. To preserve the - // begin/end semantics of the declararation and to properly handle exports - // we wrap the leading variable declaration in a `MergeDeclarationMarker`. - const mergeMarker = createMergeDeclarationMarker(statement); - setEmitFlags(mergeMarker, EmitFlags.NoComments | EmitFlags.HasEndOfDeclarationMarker); - statements.push(mergeMarker); - return false; - } - } - - /** - * Visits a module declaration node. - * - * This function will be called any time a TypeScript namespace (ModuleDeclaration) is encountered. - * - * @param node The module declaration node. - */ - function visitModuleDeclaration(node: ModuleDeclaration): VisitResult { - if (!shouldEmitModuleDeclaration(node)) { - return createNotEmittedStatement(node); - } - - Debug.assertNode(node.name, isIdentifier, "A TypeScript namespace should have an Identifier name."); - enableSubstitutionForNamespaceExports(); - - const statements: Statement[] = []; - - // We request to be advised when the printer is about to print this node. This allows - // us to set up the correct state for later substitutions. - let emitFlags = EmitFlags.AdviseOnEmitNode; - - // If needed, we should emit a variable declaration for the module. If we emit - // a leading variable declaration, we should not emit leading comments for the - // module body. - const varAdded = addVarForEnumOrModuleDeclaration(statements, node); - if (varAdded) { - // We should still emit the comments if we are emitting a system module. - if (moduleKind !== ModuleKind.System || currentLexicalScope !== currentSourceFile) { - emitFlags |= EmitFlags.NoLeadingComments; - } - } - - // `parameterName` is the declaration name used inside of the namespace. - const parameterName = getNamespaceParameterName(node); - - // `containerName` is the expression used inside of the namespace for exports. - const containerName = getNamespaceContainerName(node); - - // `exportName` is the expression used within this node's container for any exported references. - const exportName = hasModifier(node, ModifierFlags.Export) - ? getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true) - : getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); - - // x || (x = {}) - // exports.x || (exports.x = {}) - let moduleArg = - createLogicalOr( - exportName, - createAssignment( - exportName, - createObjectLiteral() - ) - ); - - if (hasNamespaceQualifiedExportName(node)) { - // `localName` is the expression used within this node's containing scope for any local references. - const localName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); - - // x = (exports.x || (exports.x = {})) - moduleArg = createAssignment(localName, moduleArg); - } - - // (function (x_1) { - // x_1.y = ...; - // })(x || (x = {})); - const moduleStatement = createExpressionStatement( - createCall( - createFunctionExpression( - /*modifiers*/ undefined, - /*asteriskToken*/ undefined, - /*name*/ undefined, - /*typeParameters*/ undefined, - [createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, parameterName)], - /*type*/ undefined, - transformModuleBody(node, containerName) - ), - /*typeArguments*/ undefined, - [moduleArg] - ) - ); - - setOriginalNode(moduleStatement, node); - if (varAdded) { - // If a variable was added, synthetic comments are emitted on it, not on the moduleStatement. - setSyntheticLeadingComments(moduleStatement, undefined); - setSyntheticTrailingComments(moduleStatement, undefined); - } - setTextRange(moduleStatement, node); - addEmitFlags(moduleStatement, emitFlags); - statements.push(moduleStatement); - - // Add a DeclarationMarker for the namespace to preserve trailing comments and mark - // the end of the declaration. - statements.push(createEndOfDeclarationMarker(node)); - return statements; - } - - /** - * Transforms the body of a module declaration. - * - * @param node The module declaration node. - */ - function transformModuleBody(node: ModuleDeclaration, namespaceLocalName: Identifier): Block { - const savedCurrentNamespaceContainerName = currentNamespaceContainerName; - const savedCurrentNamespace = currentNamespace; - const savedCurrentScopeFirstDeclarationsOfName = currentScopeFirstDeclarationsOfName; - currentNamespaceContainerName = namespaceLocalName; - currentNamespace = node; - currentScopeFirstDeclarationsOfName = undefined; - - const statements: Statement[] = []; - startLexicalEnvironment(); - - let statementsLocation: TextRange; - let blockLocation: TextRange | undefined; - const body = node.body!; - if (body.kind === SyntaxKind.ModuleBlock) { - saveStateAndInvoke(body, body => addRange(statements, visitNodes((body).statements, namespaceElementVisitor, isStatement))); - statementsLocation = body.statements; - blockLocation = body; - } - else { - const result = visitModuleDeclaration(body); - if (result) { - if (isArray(result)) { - addRange(statements, result); - } - else { - statements.push(result); - } - } - - const moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node)!.body; - statementsLocation = moveRangePos(moduleBlock.statements, -1); - } - - insertStatementsAfterStandardPrologue(statements, endLexicalEnvironment()); - currentNamespaceContainerName = savedCurrentNamespaceContainerName; - currentNamespace = savedCurrentNamespace; - currentScopeFirstDeclarationsOfName = savedCurrentScopeFirstDeclarationsOfName; - - const block = createBlock( - setTextRange( - createNodeArray(statements), - /*location*/ statementsLocation - ), - /*multiLine*/ true - ); - setTextRange(block, blockLocation); - - // namespace hello.hi.world { - // function foo() {} - // - // // TODO, blah - // } - // - // should be emitted as - // - // var hello; - // (function (hello) { - // var hi; - // (function (hi) { - // var world; - // (function (world) { - // function foo() { } - // // TODO, blah - // })(world = hi.world || (hi.world = {})); - // })(hi = hello.hi || (hello.hi = {})); - // })(hello || (hello = {})); - // We only want to emit comment on the namespace which contains block body itself, not the containing namespaces. - if (body.kind !== SyntaxKind.ModuleBlock) { - setEmitFlags(block, getEmitFlags(block) | EmitFlags.NoComments); - } - return block; - } - - function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration: ModuleDeclaration): ModuleDeclaration | undefined { - if (moduleDeclaration.body!.kind === SyntaxKind.ModuleDeclaration) { - const recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); - return recursiveInnerModule || moduleDeclaration.body; - } - } - - /** - * Visits an import declaration, eliding it if it is not referenced. - * - * @param node The import declaration node. - */ - function visitImportDeclaration(node: ImportDeclaration): VisitResult { - if (!node.importClause) { - // Do not elide a side-effect only import declaration. - // import "foo"; - return node; - } - - // Elide the declaration if the import clause was elided. - const importClause = visitNode(node.importClause, visitImportClause, isImportClause); - return importClause - ? updateImportDeclaration( - node, - /*decorators*/ undefined, - /*modifiers*/ undefined, - importClause, - node.moduleSpecifier) - : undefined; - } - - /** - * Visits an import clause, eliding it if it is not referenced. - * - * @param node The import clause node. - */ - function visitImportClause(node: ImportClause): VisitResult { - // Elide the import clause if we elide both its name and its named bindings. - const name = resolver.isReferencedAliasDeclaration(node) ? node.name : undefined; - const namedBindings = visitNode(node.namedBindings, visitNamedImportBindings, isNamedImportBindings); - return (name || namedBindings) ? updateImportClause(node, name, namedBindings) : undefined; - } - - /** - * Visits named import bindings, eliding it if it is not referenced. - * - * @param node The named import bindings node. - */ - function visitNamedImportBindings(node: NamedImportBindings): VisitResult { - if (node.kind === SyntaxKind.NamespaceImport) { - // Elide a namespace import if it is not referenced. - return resolver.isReferencedAliasDeclaration(node) ? node : undefined; - } - else { - // Elide named imports if all of its import specifiers are elided. - const elements = visitNodes(node.elements, visitImportSpecifier, isImportSpecifier); - return some(elements) ? updateNamedImports(node, elements) : undefined; - } - } - - /** - * Visits an import specifier, eliding it if it is not referenced. - * - * @param node The import specifier node. - */ - function visitImportSpecifier(node: ImportSpecifier): VisitResult { - // Elide an import specifier if it is not referenced. - return resolver.isReferencedAliasDeclaration(node) ? node : undefined; - } - - /** - * Visits an export assignment, eliding it if it does not contain a clause that resolves - * to a value. - * - * @param node The export assignment node. - */ - function visitExportAssignment(node: ExportAssignment): VisitResult { - // Elide the export assignment if it does not reference a value. - return resolver.isValueAliasDeclaration(node) - ? visitEachChild(node, visitor, context) - : undefined; - } - - /** - * Visits an export declaration, eliding it if it does not contain a clause that resolves - * to a value. - * - * @param node The export declaration node. - */ - function visitExportDeclaration(node: ExportDeclaration): VisitResult { - if (!node.exportClause) { - // Elide a star export if the module it references does not export a value. - return compilerOptions.isolatedModules || resolver.moduleExportsSomeValue(node.moduleSpecifier!) ? node : undefined; - } - - if (!resolver.isValueAliasDeclaration(node)) { - // Elide the export declaration if it does not export a value. - return undefined; - } - - // Elide the export declaration if all of its named exports are elided. - const exportClause = visitNode(node.exportClause, visitNamedExports, isNamedExports); - return exportClause - ? updateExportDeclaration( - node, - /*decorators*/ undefined, - /*modifiers*/ undefined, - exportClause, - node.moduleSpecifier) - : undefined; - } - - /** - * Visits named exports, eliding it if it does not contain an export specifier that - * resolves to a value. - * - * @param node The named exports node. - */ - function visitNamedExports(node: NamedExports): VisitResult { - // Elide the named exports if all of its export specifiers were elided. - const elements = visitNodes(node.elements, visitExportSpecifier, isExportSpecifier); - return some(elements) ? updateNamedExports(node, elements) : undefined; - } - - /** - * Visits an export specifier, eliding it if it does not resolve to a value. - * - * @param node The export specifier node. - */ - function visitExportSpecifier(node: ExportSpecifier): VisitResult { - // Elide an export specifier if it does not reference a value. - return resolver.isValueAliasDeclaration(node) ? node : undefined; - } - - /** - * Determines whether to emit an import equals declaration. - * - * @param node The import equals declaration node. - */ - function shouldEmitImportEqualsDeclaration(node: ImportEqualsDeclaration) { - // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when - // - current file is not external module - // - import declaration is top level and target is value imported by entity name - return resolver.isReferencedAliasDeclaration(node) - || (!isExternalModule(currentSourceFile) - && resolver.isTopLevelValueImportEqualsWithEntityName(node)); - } - - /** - * Visits an import equals declaration. - * - * @param node The import equals declaration node. - */ - function visitImportEqualsDeclaration(node: ImportEqualsDeclaration): VisitResult { - if (isExternalModuleImportEqualsDeclaration(node)) { - // Elide external module `import=` if it is not referenced. - return resolver.isReferencedAliasDeclaration(node) - ? visitEachChild(node, visitor, context) - : undefined; - } - - if (!shouldEmitImportEqualsDeclaration(node)) { - return undefined; - } - - const moduleReference = createExpressionFromEntityName(node.moduleReference); - setEmitFlags(moduleReference, EmitFlags.NoComments | EmitFlags.NoNestedComments); - - if (isNamedExternalModuleExport(node) || !isExportOfNamespace(node)) { - // export var ${name} = ${moduleReference}; - // var ${name} = ${moduleReference}; - return setOriginalNode( - setTextRange( - createVariableStatement( - visitNodes(node.modifiers, modifierVisitor, isModifier), - createVariableDeclarationList([ - setOriginalNode( - createVariableDeclaration( - node.name, - /*type*/ undefined, - moduleReference - ), - node - ) - ]) - ), - node - ), - node - ); - } - else { - // exports.${name} = ${moduleReference}; - return setOriginalNode( - createNamespaceExport( - node.name, - moduleReference, - node - ), - node - ); - } - } - - /** - * Gets a value indicating whether the node is exported from a namespace. - * - * @param node The node to test. - */ - function isExportOfNamespace(node: Node) { - return currentNamespace !== undefined && hasModifier(node, ModifierFlags.Export); - } - - /** - * Gets a value indicating whether the node is exported from an external module. - * - * @param node The node to test. - */ - function isExternalModuleExport(node: Node) { - return currentNamespace === undefined && hasModifier(node, ModifierFlags.Export); - } - - /** - * Gets a value indicating whether the node is a named export from an external module. - * - * @param node The node to test. - */ - function isNamedExternalModuleExport(node: Node) { - return isExternalModuleExport(node) - && !hasModifier(node, ModifierFlags.Default); - } - - /** - * Gets a value indicating whether the node is the default export of an external module. - * - * @param node The node to test. - */ - function isDefaultExternalModuleExport(node: Node) { - return isExternalModuleExport(node) - && hasModifier(node, ModifierFlags.Default); - } - - /** - * Creates a statement for the provided expression. This is used in calls to `map`. - */ - function expressionToStatement(expression: Expression) { - return createExpressionStatement(expression); - } - - function addExportMemberAssignment(statements: Statement[], node: ClassDeclaration | FunctionDeclaration) { - const expression = createAssignment( - getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true), - getLocalName(node) - ); - setSourceMapRange(expression, createRange(node.name ? node.name.pos : node.pos, node.end)); - - const statement = createExpressionStatement(expression); - setSourceMapRange(statement, createRange(-1, node.end)); - statements.push(statement); - } - - function createNamespaceExport(exportName: Identifier, exportValue: Expression, location?: TextRange) { - return setTextRange( - createExpressionStatement( - createAssignment( - getNamespaceMemberName(currentNamespaceContainerName, exportName, /*allowComments*/ false, /*allowSourceMaps*/ true), - exportValue - ) - ), - location - ); - } - - function createNamespaceExportExpression(exportName: Identifier, exportValue: Expression, location?: TextRange) { - return setTextRange(createAssignment(getNamespaceMemberNameWithSourceMapsAndWithoutComments(exportName), exportValue), location); - } - - function getNamespaceMemberNameWithSourceMapsAndWithoutComments(name: Identifier) { - return getNamespaceMemberName(currentNamespaceContainerName, name, /*allowComments*/ false, /*allowSourceMaps*/ true); - } - - /** - * Gets the declaration name used inside of a namespace or enum. - */ - function getNamespaceParameterName(node: ModuleDeclaration | EnumDeclaration) { - const name = getGeneratedNameForNode(node); - setSourceMapRange(name, node.name); - return name; - } - - /** - * Gets the expression used to refer to a namespace or enum within the body - * of its declaration. - */ - function getNamespaceContainerName(node: ModuleDeclaration | EnumDeclaration) { - return getGeneratedNameForNode(node); - } - - /** - * Gets a local alias for a class declaration if it is a decorated class with an internal - * reference to the static side of the class. This is necessary to avoid issues with - * double-binding semantics for the class name. - */ - function getClassAliasIfNeeded(node: ClassDeclaration) { - if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithConstructorReference) { - enableSubstitutionForClassAliases(); - const classAlias = createUniqueName(node.name && !isGeneratedIdentifier(node.name) ? idText(node.name) : "default"); - classAliases[getOriginalNodeId(node)] = classAlias; - hoistVariableDeclaration(classAlias); - return classAlias; - } - } - - function getClassPrototype(node: ClassExpression | ClassDeclaration) { - return createPropertyAccess(getDeclarationName(node), "prototype"); - } - - function getClassMemberPrefix(node: ClassExpression | ClassDeclaration, member: ClassElement) { - return hasModifier(member, ModifierFlags.Static) - ? getDeclarationName(node) - : getClassPrototype(node); - } - - function enableSubstitutionForNonQualifiedEnumMembers() { - if ((enabledSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers) === 0) { - enabledSubstitutions |= TypeScriptSubstitutionFlags.NonQualifiedEnumMembers; - context.enableSubstitution(SyntaxKind.Identifier); - } - } - - function enableSubstitutionForClassAliases() { - if ((enabledSubstitutions & TypeScriptSubstitutionFlags.ClassAliases) === 0) { - enabledSubstitutions |= TypeScriptSubstitutionFlags.ClassAliases; - - // We need to enable substitutions for identifiers. This allows us to - // substitute class names inside of a class declaration. - context.enableSubstitution(SyntaxKind.Identifier); - - // Keep track of class aliases. - classAliases = []; - } - } - - function enableSubstitutionForNamespaceExports() { - if ((enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) === 0) { - enabledSubstitutions |= TypeScriptSubstitutionFlags.NamespaceExports; - - // We need to enable substitutions for identifiers and shorthand property assignments. This allows us to - // substitute the names of exported members of a namespace. - context.enableSubstitution(SyntaxKind.Identifier); - context.enableSubstitution(SyntaxKind.ShorthandPropertyAssignment); - - // We need to be notified when entering and exiting namespaces. - context.enableEmitNotification(SyntaxKind.ModuleDeclaration); - } - } - - function isTransformedModuleDeclaration(node: Node): boolean { - return getOriginalNode(node).kind === SyntaxKind.ModuleDeclaration; - } - - function isTransformedEnumDeclaration(node: Node): boolean { - return getOriginalNode(node).kind === SyntaxKind.EnumDeclaration; - } - - /** - * Hook for node emit. - * - * @param hint A hint as to the intended usage of the node. - * @param node The node to emit. - * @param emit A callback used to emit the node in the printer. - */ - function onEmitNode(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void): void { - const savedApplicableSubstitutions = applicableSubstitutions; - const savedCurrentSourceFile = currentSourceFile; - - if (isSourceFile(node)) { - currentSourceFile = node; - } - - if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && isTransformedModuleDeclaration(node)) { - applicableSubstitutions |= TypeScriptSubstitutionFlags.NamespaceExports; - } - - if (enabledSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers && isTransformedEnumDeclaration(node)) { - applicableSubstitutions |= TypeScriptSubstitutionFlags.NonQualifiedEnumMembers; - } - - previousOnEmitNode(hint, node, emitCallback); - - applicableSubstitutions = savedApplicableSubstitutions; - currentSourceFile = savedCurrentSourceFile; - } - - /** - * Hooks node substitutions. - * - * @param hint A hint as to the intended usage of the node. - * @param node The node to substitute. - */ - function onSubstituteNode(hint: EmitHint, node: Node) { - node = previousOnSubstituteNode(hint, node); - if (hint === EmitHint.Expression) { - return substituteExpression(node); - } - else if (isShorthandPropertyAssignment(node)) { - return substituteShorthandPropertyAssignment(node); - } - - return node; - } - - function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike { - if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) { - const name = node.name; - const exportedName = trySubstituteNamespaceExportedName(name); - if (exportedName) { - // A shorthand property with an assignment initializer is probably part of a - // destructuring assignment - if (node.objectAssignmentInitializer) { - const initializer = createAssignment(exportedName, node.objectAssignmentInitializer); - return setTextRange(createPropertyAssignment(name, initializer), node); - } - return setTextRange(createPropertyAssignment(name, exportedName), node); - } - } - return node; - } - - function substituteExpression(node: Expression) { - switch (node.kind) { - case SyntaxKind.Identifier: - return substituteExpressionIdentifier(node); - case SyntaxKind.PropertyAccessExpression: - return substitutePropertyAccessExpression(node); - case SyntaxKind.ElementAccessExpression: - return substituteElementAccessExpression(node); - } - - return node; - } - - function substituteExpressionIdentifier(node: Identifier): Expression { - return trySubstituteClassAlias(node) - || trySubstituteNamespaceExportedName(node) - || node; - } - - function trySubstituteClassAlias(node: Identifier): Expression | undefined { - if (enabledSubstitutions & TypeScriptSubstitutionFlags.ClassAliases) { - if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ConstructorReferenceInClass) { - // Due to the emit for class decorators, any reference to the class from inside of the class body - // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind - // behavior of class names in ES6. - // Also, when emitting statics for class expressions, we must substitute a class alias for - // constructor references in static property initializers. - const declaration = resolver.getReferencedValueDeclaration(node); - if (declaration) { - const classAlias = classAliases[declaration.id!]; // TODO: GH#18217 - if (classAlias) { - const clone = getSynthesizedClone(classAlias); - setSourceMapRange(clone, node); - setCommentRange(clone, node); - return clone; - } - } - } - } - - return undefined; - } - - function trySubstituteNamespaceExportedName(node: Identifier): Expression | undefined { - // If this is explicitly a local name, do not substitute. - if (enabledSubstitutions & applicableSubstitutions && !isGeneratedIdentifier(node) && !isLocalName(node)) { - // If we are nested within a namespace declaration, we may need to qualifiy - // an identifier that is exported from a merged namespace. - const container = resolver.getReferencedExportContainer(node, /*prefixLocals*/ false); - if (container && container.kind !== SyntaxKind.SourceFile) { - const substitute = - (applicableSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && container.kind === SyntaxKind.ModuleDeclaration) || - (applicableSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers && container.kind === SyntaxKind.EnumDeclaration); - if (substitute) { - return setTextRange( - createPropertyAccess(getGeneratedNameForNode(container), node), - /*location*/ node - ); - } - } - } - - return undefined; - } - - function substitutePropertyAccessExpression(node: PropertyAccessExpression) { - return substituteConstantValue(node); - } - - function substituteElementAccessExpression(node: ElementAccessExpression) { - return substituteConstantValue(node); - } - - function substituteConstantValue(node: PropertyAccessExpression | ElementAccessExpression): LeftHandSideExpression { - const constantValue = tryGetConstEnumValue(node); - if (constantValue !== undefined) { - // track the constant value on the node for the printer in needsDotDotForPropertyAccess - setConstantValue(node, constantValue); - - const substitute = createLiteral(constantValue); - if (!compilerOptions.removeComments) { - const propertyName = isPropertyAccessExpression(node) - ? declarationNameToString(node.name) - : getTextOfNode(node.argumentExpression); - - addSyntheticTrailingComment(substitute, SyntaxKind.MultiLineCommentTrivia, ` ${propertyName} `); - } - - return substitute; - } - - return node; - } - - function tryGetConstEnumValue(node: Node): string | number | undefined { - if (compilerOptions.isolatedModules) { - return undefined; - } - - return isPropertyAccessExpression(node) || isElementAccessExpression(node) ? resolver.getConstantValue(node) : undefined; - } - } - - function createDecorateHelper(context: TransformationContext, decoratorExpressions: Expression[], target: Expression, memberName?: Expression, descriptor?: Expression, location?: TextRange) { - const argumentsArray: Expression[] = []; - argumentsArray.push(createArrayLiteral(decoratorExpressions, /*multiLine*/ true)); - argumentsArray.push(target); - if (memberName) { - argumentsArray.push(memberName); - if (descriptor) { - argumentsArray.push(descriptor); - } - } - - context.requestEmitHelper(decorateHelper); - return setTextRange( - createCall( - getUnscopedHelperName("__decorate"), - /*typeArguments*/ undefined, - argumentsArray - ), - location - ); - } - - export const decorateHelper: UnscopedEmitHelper = { - name: "typescript:decorate", - importName: "__decorate", - scoped: false, - priority: 2, - text: ` - var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; - };` - }; - - function createMetadataHelper(context: TransformationContext, metadataKey: string, metadataValue: Expression) { - context.requestEmitHelper(metadataHelper); - return createCall( - getUnscopedHelperName("__metadata"), - /*typeArguments*/ undefined, - [ - createLiteral(metadataKey), - metadataValue - ] - ); - } - - export const metadataHelper: UnscopedEmitHelper = { - name: "typescript:metadata", - importName: "__metadata", - scoped: false, - priority: 3, - text: ` - var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); - };` - }; - - function createParamHelper(context: TransformationContext, expression: Expression, parameterOffset: number, location?: TextRange) { - context.requestEmitHelper(paramHelper); - return setTextRange( - createCall( - getUnscopedHelperName("__param"), - /*typeArguments*/ undefined, - [ - createLiteral(parameterOffset), - expression - ] - ), - location - ); - } - - export const paramHelper: UnscopedEmitHelper = { - name: "typescript:param", - importName: "__param", - scoped: false, - priority: 4, - text: ` - var __param = (this && this.__param) || function (paramIndex, decorator) { - return function (target, key) { decorator(target, key, paramIndex); } - };` - }; -} +/*@internal*/ +namespace ts { + /** + * Indicates whether to emit type metadata in the new format. + */ + const USE_NEW_TYPE_METADATA_FORMAT = false; + + const enum TypeScriptSubstitutionFlags { + /** Enables substitutions for decorated classes. */ + ClassAliases = 1 << 0, + /** Enables substitutions for namespace exports. */ + NamespaceExports = 1 << 1, + /* Enables substitutions for unqualified enum members */ + NonQualifiedEnumMembers = 1 << 3 + } + + const enum ClassFacts { + None = 0, + HasStaticInitializedProperties = 1 << 0, + HasConstructorDecorators = 1 << 1, + HasMemberDecorators = 1 << 2, + IsExportOfNamespace = 1 << 3, + IsNamedExternalExport = 1 << 4, + IsDefaultExternalExport = 1 << 5, + IsDerivedClass = 1 << 6, + UseImmediatelyInvokedFunctionExpression = 1 << 7, + + HasAnyDecorators = HasConstructorDecorators | HasMemberDecorators, + NeedsName = HasStaticInitializedProperties | HasMemberDecorators, + MayNeedImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties, + IsExported = IsExportOfNamespace | IsDefaultExternalExport | IsNamedExternalExport, + } + + export function transformTypeScript(context: TransformationContext) { + const { + startLexicalEnvironment, + resumeLexicalEnvironment, + endLexicalEnvironment, + hoistVariableDeclaration, + } = context; + + const resolver = context.getEmitResolver(); + const compilerOptions = context.getCompilerOptions(); + const strictNullChecks = getStrictOptionValue(compilerOptions, "strictNullChecks"); + const languageVersion = getEmitScriptTarget(compilerOptions); + const moduleKind = getEmitModuleKind(compilerOptions); + + // Save the previous transformation hooks. + const previousOnEmitNode = context.onEmitNode; + const previousOnSubstituteNode = context.onSubstituteNode; + + // Set new transformation hooks. + context.onEmitNode = onEmitNode; + context.onSubstituteNode = onSubstituteNode; + + // Enable substitution for property/element access to emit const enum values. + context.enableSubstitution(SyntaxKind.PropertyAccessExpression); + context.enableSubstitution(SyntaxKind.ElementAccessExpression); + + // These variables contain state that changes as we descend into the tree. + let currentSourceFile: SourceFile; + let currentNamespace: ModuleDeclaration; + let currentNamespaceContainerName: Identifier; + let currentLexicalScope: SourceFile | Block | ModuleBlock | CaseBlock; + let currentNameScope: ClassDeclaration | undefined; + let currentScopeFirstDeclarationsOfName: UnderscoreEscapedMap | undefined; + let currentClassHasParameterProperties: boolean | undefined; + + /** + * Keeps track of whether expression substitution has been enabled for specific edge cases. + * They are persisted between each SourceFile transformation and should not be reset. + */ + let enabledSubstitutions: TypeScriptSubstitutionFlags; + + /** + * A map that keeps track of aliases created for classes with decorators to avoid issues + * with the double-binding behavior of classes. + */ + let classAliases: Identifier[]; + + /** + * Keeps track of whether we are within any containing namespaces when performing + * just-in-time substitution while printing an expression identifier. + */ + let applicableSubstitutions: TypeScriptSubstitutionFlags; + + return transformSourceFileOrBundle; + + function transformSourceFileOrBundle(node: SourceFile | Bundle) { + if (node.kind === SyntaxKind.Bundle) { + return transformBundle(node); + } + return transformSourceFile(node); + } + + function transformBundle(node: Bundle) { + return createBundle(node.sourceFiles.map(transformSourceFile), mapDefined(node.prepends, prepend => { + if (prepend.kind === SyntaxKind.InputFiles) { + return createUnparsedSourceFile(prepend, "js"); + } + return prepend; + })); + } + + /** + * Transform TypeScript-specific syntax in a SourceFile. + * + * @param node A SourceFile node. + */ + function transformSourceFile(node: SourceFile) { + if (node.isDeclarationFile) { + return node; + } + + currentSourceFile = node; + + const visited = saveStateAndInvoke(node, visitSourceFile); + addEmitHelpers(visited, context.readEmitHelpers()); + + currentSourceFile = undefined!; + return visited; + } + + /** + * Visits a node, saving and restoring state variables on the stack. + * + * @param node The node to visit. + */ + function saveStateAndInvoke(node: Node, f: (node: Node) => T): T { + // Save state + const savedCurrentScope = currentLexicalScope; + const savedCurrentNameScope = currentNameScope; + const savedCurrentScopeFirstDeclarationsOfName = currentScopeFirstDeclarationsOfName; + const savedCurrentClassHasParameterProperties = currentClassHasParameterProperties; + + // Handle state changes before visiting a node. + onBeforeVisitNode(node); + + const visited = f(node); + + // Restore state + if (currentLexicalScope !== savedCurrentScope) { + currentScopeFirstDeclarationsOfName = savedCurrentScopeFirstDeclarationsOfName; + } + + currentLexicalScope = savedCurrentScope; + currentNameScope = savedCurrentNameScope; + currentClassHasParameterProperties = savedCurrentClassHasParameterProperties; + return visited; + } + + /** + * Performs actions that should always occur immediately before visiting a node. + * + * @param node The node to visit. + */ + function onBeforeVisitNode(node: Node) { + switch (node.kind) { + case SyntaxKind.SourceFile: + case SyntaxKind.CaseBlock: + case SyntaxKind.ModuleBlock: + case SyntaxKind.Block: + currentLexicalScope = node; + currentNameScope = undefined; + currentScopeFirstDeclarationsOfName = undefined; + break; + + case SyntaxKind.ClassDeclaration: + case SyntaxKind.FunctionDeclaration: + if (hasModifier(node, ModifierFlags.Ambient)) { + break; + } + + // Record these declarations provided that they have a name. + if ((node as ClassDeclaration | FunctionDeclaration).name) { + recordEmittedDeclarationInScope(node as ClassDeclaration | FunctionDeclaration); + } + else { + // These nodes should always have names unless they are default-exports; + // however, class declaration parsing allows for undefined names, so syntactically invalid + // programs may also have an undefined name. + Debug.assert(node.kind === SyntaxKind.ClassDeclaration || hasModifier(node, ModifierFlags.Default)); + } + if (isClassDeclaration(node)) { + // XXX: should probably also cover interfaces and type aliases that can have type variables? + currentNameScope = node; + } + + break; + } + } + + /** + * General-purpose node visitor. + * + * @param node The node to visit. + */ + function visitor(node: Node): VisitResult { + return saveStateAndInvoke(node, visitorWorker); + } + + /** + * Visits and possibly transforms any node. + * + * @param node The node to visit. + */ + function visitorWorker(node: Node): VisitResult { + if (node.transformFlags & TransformFlags.ContainsTypeScript) { + return visitTypeScript(node); + } + return node; + } + + /** + * Specialized visitor that visits the immediate children of a SourceFile. + * + * @param node The node to visit. + */ + function sourceElementVisitor(node: Node): VisitResult { + return saveStateAndInvoke(node, sourceElementVisitorWorker); + } + + /** + * Specialized visitor that visits the immediate children of a SourceFile. + * + * @param node The node to visit. + */ + function sourceElementVisitorWorker(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ExportAssignment: + case SyntaxKind.ExportDeclaration: + return visitEllidableStatement(node); + default: + return visitorWorker(node); + } + } + + function visitEllidableStatement(node: ImportDeclaration | ImportEqualsDeclaration | ExportAssignment | ExportDeclaration): VisitResult { + const parsed = getParseTreeNode(node); + if (parsed !== node) { + // If the node has been transformed by a `before` transformer, perform no ellision on it + // As the type information we would attempt to lookup to perform ellision is potentially unavailable for the synthesized nodes + // We do not reuse `visitorWorker`, as the ellidable statement syntax kinds are technically unrecognized by the switch-case in `visitTypeScript`, + // and will trigger debug failures when debug verbosity is turned up + if (node.transformFlags & TransformFlags.ContainsTypeScript) { + // This node contains TypeScript, so we should visit its children. + return visitEachChild(node, visitor, context); + } + // Otherwise, we can just return the node + return node; + } + switch (node.kind) { + case SyntaxKind.ImportDeclaration: + return visitImportDeclaration(node); + case SyntaxKind.ImportEqualsDeclaration: + return visitImportEqualsDeclaration(node); + case SyntaxKind.ExportAssignment: + return visitExportAssignment(node); + case SyntaxKind.ExportDeclaration: + return visitExportDeclaration(node); + default: + Debug.fail("Unhandled ellided statement"); + } + } + + /** + * Specialized visitor that visits the immediate children of a namespace. + * + * @param node The node to visit. + */ + function namespaceElementVisitor(node: Node): VisitResult { + return saveStateAndInvoke(node, namespaceElementVisitorWorker); + } + + /** + * Specialized visitor that visits the immediate children of a namespace. + * + * @param node The node to visit. + */ + function namespaceElementVisitorWorker(node: Node): VisitResult { + if (node.kind === SyntaxKind.ExportDeclaration || + node.kind === SyntaxKind.ImportDeclaration || + node.kind === SyntaxKind.ImportClause || + (node.kind === SyntaxKind.ImportEqualsDeclaration && + (node).moduleReference.kind === SyntaxKind.ExternalModuleReference)) { + // do not emit ES6 imports and exports since they are illegal inside a namespace + return undefined; + } + else if (node.transformFlags & TransformFlags.ContainsTypeScript || hasModifier(node, ModifierFlags.Export)) { + return visitTypeScript(node); + } + + return node; + } + + /** + * Specialized visitor that visits the immediate children of a class with TypeScript syntax. + * + * @param node The node to visit. + */ + function classElementVisitor(node: Node): VisitResult { + return saveStateAndInvoke(node, classElementVisitorWorker); + } + + /** + * Specialized visitor that visits the immediate children of a class with TypeScript syntax. + * + * @param node The node to visit. + */ + function classElementVisitorWorker(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.Constructor: + return visitConstructor(node as ConstructorDeclaration); + + case SyntaxKind.PropertyDeclaration: + // Property declarations are not TypeScript syntax, but they must be visited + // for the decorator transformation. + return visitPropertyDeclaration(node as PropertyDeclaration); + case SyntaxKind.IndexSignature: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.MethodDeclaration: + // Fallback to the default visit behavior. + return visitorWorker(node); + + case SyntaxKind.SemicolonClassElement: + return node; + + default: + return Debug.failBadSyntaxKind(node); + } + } + + function modifierVisitor(node: Node): VisitResult { + if (modifierToFlag(node.kind) & ModifierFlags.TypeScriptModifier) { + return undefined; + } + else if (currentNamespace && node.kind === SyntaxKind.ExportKeyword) { + return undefined; + } + + return node; + } + + /** + * Branching visitor, visits a TypeScript syntax node. + * + * @param node The node to visit. + */ + function visitTypeScript(node: Node): VisitResult { + if (isStatement(node) && hasModifier(node, ModifierFlags.Ambient)) { + // TypeScript ambient declarations are elided, but some comments may be preserved. + // See the implementation of `getLeadingComments` in comments.ts for more details. + return createNotEmittedStatement(node); + } + + switch (node.kind) { + case SyntaxKind.ExportKeyword: + case SyntaxKind.DefaultKeyword: + // ES6 export and default modifiers are elided when inside a namespace. + return currentNamespace ? undefined : node; + + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + case SyntaxKind.AbstractKeyword: + case SyntaxKind.ConstKeyword: + case SyntaxKind.DeclareKeyword: + case SyntaxKind.ReadonlyKeyword: + // TypeScript accessibility and readonly modifiers are elided + // falls through + case SyntaxKind.ArrayType: + case SyntaxKind.TupleType: + case SyntaxKind.OptionalType: + case SyntaxKind.RestType: + case SyntaxKind.TypeLiteral: + case SyntaxKind.TypePredicate: + case SyntaxKind.TypeParameter: + case SyntaxKind.AnyKeyword: + case SyntaxKind.UnknownKeyword: + case SyntaxKind.BooleanKeyword: + case SyntaxKind.StringKeyword: + case SyntaxKind.NumberKeyword: + case SyntaxKind.NeverKeyword: + case SyntaxKind.VoidKeyword: + case SyntaxKind.SymbolKeyword: + case SyntaxKind.ConstructorType: + case SyntaxKind.FunctionType: + case SyntaxKind.TypeQuery: + case SyntaxKind.TypeReference: + case SyntaxKind.UnionType: + case SyntaxKind.IntersectionType: + case SyntaxKind.ConditionalType: + case SyntaxKind.ParenthesizedType: + case SyntaxKind.ThisType: + case SyntaxKind.TypeOperator: + case SyntaxKind.IndexedAccessType: + case SyntaxKind.MappedType: + case SyntaxKind.LiteralType: + // TypeScript type nodes are elided. + // falls through + + case SyntaxKind.IndexSignature: + // TypeScript index signatures are elided. + // falls through + + case SyntaxKind.Decorator: + // TypeScript decorators are elided. They will be emitted as part of visitClassDeclaration. + // falls through + + case SyntaxKind.TypeAliasDeclaration: + // TypeScript type-only declarations are elided. + return undefined; + + case SyntaxKind.PropertyDeclaration: + // TypeScript property declarations are elided. However their names are still visited, and can potentially be retained if they could have sideeffects + return visitPropertyDeclaration(node as PropertyDeclaration); + + case SyntaxKind.NamespaceExportDeclaration: + // TypeScript namespace export declarations are elided. + return undefined; + + case SyntaxKind.Constructor: + return visitConstructor(node); + + case SyntaxKind.InterfaceDeclaration: + // TypeScript interfaces are elided, but some comments may be preserved. + // See the implementation of `getLeadingComments` in comments.ts for more details. + return createNotEmittedStatement(node); + + case SyntaxKind.ClassDeclaration: + // This may be a class declaration with TypeScript syntax extensions. + // + // TypeScript class syntax extensions include: + // - decorators + // - optional `implements` heritage clause + // - parameter property assignments in the constructor + // - index signatures + // - method overload signatures + return visitClassDeclaration(node); + + case SyntaxKind.ClassExpression: + // This may be a class expression with TypeScript syntax extensions. + // + // TypeScript class syntax extensions include: + // - decorators + // - optional `implements` heritage clause + // - parameter property assignments in the constructor + // - index signatures + // - method overload signatures + return visitClassExpression(node); + + case SyntaxKind.HeritageClause: + // This may be a heritage clause with TypeScript syntax extensions. + // + // TypeScript heritage clause extensions include: + // - `implements` clause + return visitHeritageClause(node); + + case SyntaxKind.ExpressionWithTypeArguments: + // TypeScript supports type arguments on an expression in an `extends` heritage clause. + return visitExpressionWithTypeArguments(node); + + case SyntaxKind.MethodDeclaration: + // TypeScript method declarations may have decorators, modifiers + // or type annotations. + return visitMethodDeclaration(node); + + case SyntaxKind.GetAccessor: + // Get Accessors can have TypeScript modifiers, decorators, and type annotations. + return visitGetAccessor(node); + + case SyntaxKind.SetAccessor: + // Set Accessors can have TypeScript modifiers and type annotations. + return visitSetAccessor(node); + + case SyntaxKind.FunctionDeclaration: + // Typescript function declarations can have modifiers, decorators, and type annotations. + return visitFunctionDeclaration(node); + + case SyntaxKind.FunctionExpression: + // TypeScript function expressions can have modifiers and type annotations. + return visitFunctionExpression(node); + + case SyntaxKind.ArrowFunction: + // TypeScript arrow functions can have modifiers and type annotations. + return visitArrowFunction(node); + + case SyntaxKind.Parameter: + // This may be a parameter declaration with TypeScript syntax extensions. + // + // TypeScript parameter declaration syntax extensions include: + // - decorators + // - accessibility modifiers + // - the question mark (?) token for optional parameters + // - type annotations + // - this parameters + return visitParameter(node); + + case SyntaxKind.ParenthesizedExpression: + // ParenthesizedExpressions are TypeScript if their expression is a + // TypeAssertion or AsExpression + return visitParenthesizedExpression(node); + + case SyntaxKind.TypeAssertionExpression: + case SyntaxKind.AsExpression: + // TypeScript type assertions are removed, but their subtrees are preserved. + return visitAssertionExpression(node); + + case SyntaxKind.CallExpression: + return visitCallExpression(node); + + case SyntaxKind.NewExpression: + return visitNewExpression(node); + + case SyntaxKind.TaggedTemplateExpression: + return visitTaggedTemplateExpression(node); + + case SyntaxKind.NonNullExpression: + // TypeScript non-null expressions are removed, but their subtrees are preserved. + return visitNonNullExpression(node); + + case SyntaxKind.EnumDeclaration: + // TypeScript enum declarations do not exist in ES6 and must be rewritten. + return visitEnumDeclaration(node); + + case SyntaxKind.VariableStatement: + // TypeScript namespace exports for variable statements must be transformed. + return visitVariableStatement(node); + + case SyntaxKind.VariableDeclaration: + return visitVariableDeclaration(node); + + case SyntaxKind.ModuleDeclaration: + // TypeScript namespace declarations must be transformed. + return visitModuleDeclaration(node); + + case SyntaxKind.ImportEqualsDeclaration: + // TypeScript namespace or external module import. + return visitImportEqualsDeclaration(node); + + default: + // node contains some other TypeScript syntax + return visitEachChild(node, visitor, context); + } + } + + function visitSourceFile(node: SourceFile) { + const alwaysStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") && + !(isExternalModule(node) && moduleKind >= ModuleKind.ES2015) && + !isJsonSourceFile(node); + + return updateSourceFileNode( + node, + visitLexicalEnvironment(node.statements, sourceElementVisitor, context, /*start*/ 0, alwaysStrict)); + } + + /** + * Tests whether we should emit a __decorate call for a class declaration. + */ + function shouldEmitDecorateCallForClass(node: ClassDeclaration) { + if (node.decorators && node.decorators.length > 0) { + return true; + } + + const constructor = getFirstConstructorWithBody(node); + if (constructor) { + return forEach(constructor.parameters, shouldEmitDecorateCallForParameter); + } + + return false; + } + + /** + * Tests whether we should emit a __decorate call for a parameter declaration. + */ + function shouldEmitDecorateCallForParameter(parameter: ParameterDeclaration) { + return parameter.decorators !== undefined && parameter.decorators.length > 0; + } + + function getClassFacts(node: ClassDeclaration, staticProperties: readonly PropertyDeclaration[]) { + let facts = ClassFacts.None; + if (some(staticProperties)) facts |= ClassFacts.HasStaticInitializedProperties; + const extendsClauseElement = getEffectiveBaseTypeNode(node); + if (extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword) facts |= ClassFacts.IsDerivedClass; + if (shouldEmitDecorateCallForClass(node)) facts |= ClassFacts.HasConstructorDecorators; + if (childIsDecorated(node)) facts |= ClassFacts.HasMemberDecorators; + if (isExportOfNamespace(node)) facts |= ClassFacts.IsExportOfNamespace; + else if (isDefaultExternalModuleExport(node)) facts |= ClassFacts.IsDefaultExternalExport; + else if (isNamedExternalModuleExport(node)) facts |= ClassFacts.IsNamedExternalExport; + if (languageVersion <= ScriptTarget.ES5 && (facts & ClassFacts.MayNeedImmediatelyInvokedFunctionExpression)) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression; + return facts; + } + + function hasTypeScriptClassSyntax(node: Node) { + return !!(node.transformFlags & TransformFlags.ContainsTypeScriptClassSyntax); + } + + function isClassLikeDeclarationWithTypeScriptSyntax(node: ClassLikeDeclaration) { + return some(node.decorators) + || some(node.typeParameters) + || some(node.heritageClauses, hasTypeScriptClassSyntax) + || some(node.members, hasTypeScriptClassSyntax); + } + + function visitClassDeclaration(node: ClassDeclaration): VisitResult { + if (!isClassLikeDeclarationWithTypeScriptSyntax(node) && !(currentNamespace && hasModifier(node, ModifierFlags.Export))) { + return visitEachChild(node, visitor, context); + } + + const staticProperties = getProperties(node, /*requireInitializer*/ true, /*isStatic*/ true); + const facts = getClassFacts(node, staticProperties); + + if (facts & ClassFacts.UseImmediatelyInvokedFunctionExpression) { + context.startLexicalEnvironment(); + } + + const name = node.name || (facts & ClassFacts.NeedsName ? getGeneratedNameForNode(node) : undefined); + const classStatement = facts & ClassFacts.HasConstructorDecorators + ? createClassDeclarationHeadWithDecorators(node, name) + : createClassDeclarationHeadWithoutDecorators(node, name, facts); + + let statements: Statement[] = [classStatement]; + + + // Write any decorators of the node. + addClassElementDecorationStatements(statements, node, /*isStatic*/ false); + addClassElementDecorationStatements(statements, node, /*isStatic*/ true); + addConstructorDecorationStatement(statements, node); + + if (facts & ClassFacts.UseImmediatelyInvokedFunctionExpression) { + // When we emit a TypeScript class down to ES5, we must wrap it in an IIFE so that the + // 'es2015' transformer can properly nest static initializers and decorators. The result + // looks something like: + // + // var C = function () { + // class C { + // } + // C.static_prop = 1; + // return C; + // }(); + // + const closingBraceLocation = createTokenRange(skipTrivia(currentSourceFile.text, node.members.end), SyntaxKind.CloseBraceToken); + const localName = getInternalName(node); + + // The following partially-emitted expression exists purely to align our sourcemap + // emit with the original emitter. + const outer = createPartiallyEmittedExpression(localName); + outer.end = closingBraceLocation.end; + setEmitFlags(outer, EmitFlags.NoComments); + + const statement = createReturn(outer); + statement.pos = closingBraceLocation.pos; + setEmitFlags(statement, EmitFlags.NoComments | EmitFlags.NoTokenSourceMaps); + statements.push(statement); + + insertStatementsAfterStandardPrologue(statements, context.endLexicalEnvironment()); + + const iife = createImmediatelyInvokedArrowFunction(statements); + setEmitFlags(iife, EmitFlags.TypeScriptClassWrapper); + + const varStatement = createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList([ + createVariableDeclaration( + getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ false), + /*type*/ undefined, + iife + ) + ]) + ); + + setOriginalNode(varStatement, node); + setCommentRange(varStatement, node); + setSourceMapRange(varStatement, moveRangePastDecorators(node)); + startOnNewLine(varStatement); + statements = [varStatement]; + } + + // If the class is exported as part of a TypeScript namespace, emit the namespace export. + // Otherwise, if the class was exported at the top level and was decorated, emit an export + // declaration or export default for the class. + if (facts & ClassFacts.IsExportOfNamespace) { + addExportMemberAssignment(statements, node); + } + else if (facts & ClassFacts.UseImmediatelyInvokedFunctionExpression || facts & ClassFacts.HasConstructorDecorators) { + if (facts & ClassFacts.IsDefaultExternalExport) { + statements.push(createExportDefault(getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true))); + } + else if (facts & ClassFacts.IsNamedExternalExport) { + statements.push(createExternalModuleExport(getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true))); + } + } + + if (statements.length > 1) { + // Add a DeclarationMarker as a marker for the end of the declaration + statements.push(createEndOfDeclarationMarker(node)); + setEmitFlags(classStatement, getEmitFlags(classStatement) | EmitFlags.HasEndOfDeclarationMarker); + } + + return singleOrMany(statements); + } + + /** + * Transforms a non-decorated class declaration and appends the resulting statements. + * + * @param node A ClassDeclaration node. + * @param name The name of the class. + * @param facts Precomputed facts about the class. + */ + function createClassDeclarationHeadWithoutDecorators(node: ClassDeclaration, name: Identifier | undefined, facts: ClassFacts) { + // ${modifiers} class ${name} ${heritageClauses} { + // ${members} + // } + + // we do not emit modifiers on the declaration if we are emitting an IIFE + const modifiers = !(facts & ClassFacts.UseImmediatelyInvokedFunctionExpression) + ? visitNodes(node.modifiers, modifierVisitor, isModifier) + : undefined; + + const classDeclaration = createClassDeclaration( + /*decorators*/ undefined, + modifiers, + name, + /*typeParameters*/ undefined, + visitNodes(node.heritageClauses, visitor, isHeritageClause), + transformClassMembers(node) + ); + + // To better align with the old emitter, we should not emit a trailing source map + // entry if the class has static properties. + let emitFlags = getEmitFlags(node); + if (facts & ClassFacts.HasStaticInitializedProperties) { + emitFlags |= EmitFlags.NoTrailingSourceMap; + } + + aggregateTransformFlags(classDeclaration); + setTextRange(classDeclaration, node); + setOriginalNode(classDeclaration, node); + setEmitFlags(classDeclaration, emitFlags); + return classDeclaration; + } + + /** + * Transforms a decorated class declaration and appends the resulting statements. If + * the class requires an alias to avoid issues with double-binding, the alias is returned. + */ + function createClassDeclarationHeadWithDecorators(node: ClassDeclaration, name: Identifier | undefined) { + // When we emit an ES6 class that has a class decorator, we must tailor the + // emit to certain specific cases. + // + // In the simplest case, we emit the class declaration as a let declaration, and + // evaluate decorators after the close of the class body: + // + // [Example 1] + // --------------------------------------------------------------------- + // TypeScript | Javascript + // --------------------------------------------------------------------- + // @dec | let C = class C { + // class C { | } + // } | C = __decorate([dec], C); + // --------------------------------------------------------------------- + // @dec | let C = class C { + // export class C { | } + // } | C = __decorate([dec], C); + // | export { C }; + // --------------------------------------------------------------------- + // + // If a class declaration contains a reference to itself *inside* of the class body, + // this introduces two bindings to the class: One outside of the class body, and one + // inside of the class body. If we apply decorators as in [Example 1] above, there + // is the possibility that the decorator `dec` will return a new value for the + // constructor, which would result in the binding inside of the class no longer + // pointing to the same reference as the binding outside of the class. + // + // As a result, we must instead rewrite all references to the class *inside* of the + // class body to instead point to a local temporary alias for the class: + // + // [Example 2] + // --------------------------------------------------------------------- + // TypeScript | Javascript + // --------------------------------------------------------------------- + // @dec | let C = C_1 = class C { + // class C { | static x() { return C_1.y; } + // static x() { return C.y; } | } + // static y = 1; | C.y = 1; + // } | C = C_1 = __decorate([dec], C); + // | var C_1; + // --------------------------------------------------------------------- + // @dec | let C = class C { + // export class C { | static x() { return C_1.y; } + // static x() { return C.y; } | } + // static y = 1; | C.y = 1; + // } | C = C_1 = __decorate([dec], C); + // | export { C }; + // | var C_1; + // --------------------------------------------------------------------- + // + // If a class declaration is the default export of a module, we instead emit + // the export after the decorated declaration: + // + // [Example 3] + // --------------------------------------------------------------------- + // TypeScript | Javascript + // --------------------------------------------------------------------- + // @dec | let default_1 = class { + // export default class { | } + // } | default_1 = __decorate([dec], default_1); + // | export default default_1; + // --------------------------------------------------------------------- + // @dec | let C = class C { + // export default class C { | } + // } | C = __decorate([dec], C); + // | export default C; + // --------------------------------------------------------------------- + // + // If the class declaration is the default export and a reference to itself + // inside of the class body, we must emit both an alias for the class *and* + // move the export after the declaration: + // + // [Example 4] + // --------------------------------------------------------------------- + // TypeScript | Javascript + // --------------------------------------------------------------------- + // @dec | let C = class C { + // export default class C { | static x() { return C_1.y; } + // static x() { return C.y; } | } + // static y = 1; | C.y = 1; + // } | C = C_1 = __decorate([dec], C); + // | export default C; + // | var C_1; + // --------------------------------------------------------------------- + // + + const location = moveRangePastDecorators(node); + const classAlias = getClassAliasIfNeeded(node); + const declName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); + + // ... = class ${name} ${heritageClauses} { + // ${members} + // } + const heritageClauses = visitNodes(node.heritageClauses, visitor, isHeritageClause); + const members = transformClassMembers(node); + const classExpression = createClassExpression(/*modifiers*/ undefined, name, /*typeParameters*/ undefined, heritageClauses, members); + aggregateTransformFlags(classExpression); + setOriginalNode(classExpression, node); + setTextRange(classExpression, location); + + // let ${name} = ${classExpression} where name is either declaredName if the class doesn't contain self-reference + // or decoratedClassAlias if the class contain self-reference. + const statement = createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList([ + createVariableDeclaration( + declName, + /*type*/ undefined, + classAlias ? createAssignment(classAlias, classExpression) : classExpression + ) + ], NodeFlags.Let) + ); + setOriginalNode(statement, node); + setTextRange(statement, location); + setCommentRange(statement, node); + return statement; + } + + function visitClassExpression(node: ClassExpression): Expression { + if (!isClassLikeDeclarationWithTypeScriptSyntax(node)) { + return visitEachChild(node, visitor, context); + } + + const classExpression = createClassExpression( + /*modifiers*/ undefined, + node.name, + /*typeParameters*/ undefined, + visitNodes(node.heritageClauses, visitor, isHeritageClause), + transformClassMembers(node) + ); + + aggregateTransformFlags(classExpression); + setOriginalNode(classExpression, node); + setTextRange(classExpression, node); + + return classExpression; + } + + /** + * Transforms the members of a class. + * + * @param node The current class. + */ + function transformClassMembers(node: ClassDeclaration | ClassExpression) { + const members: ClassElement[] = []; + const constructor = getFirstConstructorWithBody(node); + const parametersWithPropertyAssignments = constructor && + filter(constructor.parameters, p => isParameterPropertyDeclaration(p, constructor)); + + if (parametersWithPropertyAssignments) { + for (const parameter of parametersWithPropertyAssignments) { + if (isIdentifier(parameter.name)) { + members.push(aggregateTransformFlags(createProperty( + /*decorators*/ undefined, + /*modifiers*/ undefined, + parameter.name, + /*questionOrExclamationToken*/ undefined, + /*type*/ undefined, + /*initializer*/ undefined))); + } + } + } + + addRange(members, visitNodes(node.members, classElementVisitor, isClassElement)); + return setTextRange(createNodeArray(members), /*location*/ node.members); + } + + + /** + * Gets either the static or instance members of a class that are decorated, or have + * parameters that are decorated. + * + * @param node The class containing the member. + * @param isStatic A value indicating whether to retrieve static or instance members of + * the class. + */ + function getDecoratedClassElements(node: ClassExpression | ClassDeclaration, isStatic: boolean): readonly ClassElement[] { + return filter(node.members, isStatic ? m => isStaticDecoratedClassElement(m, node) : m => isInstanceDecoratedClassElement(m, node)); + } + + /** + * Determines whether a class member is a static member of a class that is decorated, or + * has parameters that are decorated. + * + * @param member The class member. + */ + function isStaticDecoratedClassElement(member: ClassElement, parent: ClassLikeDeclaration) { + return isDecoratedClassElement(member, /*isStatic*/ true, parent); + } + + /** + * Determines whether a class member is an instance member of a class that is decorated, + * or has parameters that are decorated. + * + * @param member The class member. + */ + function isInstanceDecoratedClassElement(member: ClassElement, parent: ClassLikeDeclaration) { + return isDecoratedClassElement(member, /*isStatic*/ false, parent); + } + + /** + * Determines whether a class member is either a static or an instance member of a class + * that is decorated, or has parameters that are decorated. + * + * @param member The class member. + */ + function isDecoratedClassElement(member: ClassElement, isStatic: boolean, parent: ClassLikeDeclaration) { + return nodeOrChildIsDecorated(member, parent) + && isStatic === hasModifier(member, ModifierFlags.Static); + } + + /** + * A structure describing the decorators for a class element. + */ + interface AllDecorators { + decorators: readonly Decorator[] | undefined; + parameters?: readonly (readonly Decorator[] | undefined)[]; + } + + /** + * Gets an array of arrays of decorators for the parameters of a function-like node. + * The offset into the result array should correspond to the offset of the parameter. + * + * @param node The function-like node. + */ + function getDecoratorsOfParameters(node: FunctionLikeDeclaration | undefined) { + let decorators: (readonly Decorator[] | undefined)[] | undefined; + if (node) { + const parameters = node.parameters; + const firstParameterIsThis = parameters.length > 0 && parameterIsThisKeyword(parameters[0]); + const firstParameterOffset = firstParameterIsThis ? 1 : 0; + const numParameters = firstParameterIsThis ? parameters.length - 1 : parameters.length; + for (let i = 0; i < numParameters; i++) { + const parameter = parameters[i + firstParameterOffset]; + if (decorators || parameter.decorators) { + if (!decorators) { + decorators = new Array(numParameters); + } + + decorators[i] = parameter.decorators; + } + } + } + + return decorators; + } + + /** + * Gets an AllDecorators object containing the decorators for the class and the decorators for the + * parameters of the constructor of the class. + * + * @param node The class node. + */ + function getAllDecoratorsOfConstructor(node: ClassExpression | ClassDeclaration): AllDecorators | undefined { + const decorators = node.decorators; + const parameters = getDecoratorsOfParameters(getFirstConstructorWithBody(node)); + if (!decorators && !parameters) { + return undefined; + } + + return { + decorators, + parameters + }; + } + + /** + * Gets an AllDecorators object containing the decorators for the member and its parameters. + * + * @param node The class node that contains the member. + * @param member The class member. + */ + function getAllDecoratorsOfClassElement(node: ClassExpression | ClassDeclaration, member: ClassElement): AllDecorators | undefined { + switch (member.kind) { + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return getAllDecoratorsOfAccessors(node, member); + + case SyntaxKind.MethodDeclaration: + return getAllDecoratorsOfMethod(member); + + case SyntaxKind.PropertyDeclaration: + return getAllDecoratorsOfProperty(member); + + default: + return undefined; + } + } + + /** + * Gets an AllDecorators object containing the decorators for the accessor and its parameters. + * + * @param node The class node that contains the accessor. + * @param accessor The class accessor member. + */ + function getAllDecoratorsOfAccessors(node: ClassExpression | ClassDeclaration, accessor: AccessorDeclaration): AllDecorators | undefined { + if (!accessor.body) { + return undefined; + } + + const { firstAccessor, secondAccessor, setAccessor } = getAllAccessorDeclarations(node.members, accessor); + const firstAccessorWithDecorators = firstAccessor.decorators ? firstAccessor : secondAccessor && secondAccessor.decorators ? secondAccessor : undefined; + if (!firstAccessorWithDecorators || accessor !== firstAccessorWithDecorators) { + return undefined; + } + + const decorators = firstAccessorWithDecorators.decorators; + const parameters = getDecoratorsOfParameters(setAccessor); + if (!decorators && !parameters) { + return undefined; + } + + return { decorators, parameters }; + } + + /** + * Gets an AllDecorators object containing the decorators for the method and its parameters. + * + * @param method The class method member. + */ + function getAllDecoratorsOfMethod(method: MethodDeclaration): AllDecorators | undefined { + if (!method.body) { + return undefined; + } + + const decorators = method.decorators; + const parameters = getDecoratorsOfParameters(method); + if (!decorators && !parameters) { + return undefined; + } + + return { decorators, parameters }; + } + + /** + * Gets an AllDecorators object containing the decorators for the property. + * + * @param property The class property member. + */ + function getAllDecoratorsOfProperty(property: PropertyDeclaration): AllDecorators | undefined { + const decorators = property.decorators; + if (!decorators) { + return undefined; + + } + + return { decorators }; + } + + /** + * Transforms all of the decorators for a declaration into an array of expressions. + * + * @param node The declaration node. + * @param allDecorators An object containing all of the decorators for the declaration. + */ + function transformAllDecoratorsOfDeclaration(node: Declaration, container: ClassLikeDeclaration, allDecorators: AllDecorators | undefined) { + if (!allDecorators) { + return undefined; + } + + const decoratorExpressions: Expression[] = []; + addRange(decoratorExpressions, map(allDecorators.decorators, transformDecorator)); + addRange(decoratorExpressions, flatMap(allDecorators.parameters, transformDecoratorsOfParameter)); + addTypeMetadata(node, container, decoratorExpressions); + return decoratorExpressions; + } + + /** + * Generates statements used to apply decorators to either the static or instance members + * of a class. + * + * @param node The class node. + * @param isStatic A value indicating whether to generate statements for static or + * instance members. + */ + function addClassElementDecorationStatements(statements: Statement[], node: ClassDeclaration, isStatic: boolean) { + addRange(statements, map(generateClassElementDecorationExpressions(node, isStatic), expressionToStatement)); + } + + /** + * Generates expressions used to apply decorators to either the static or instance members + * of a class. + * + * @param node The class node. + * @param isStatic A value indicating whether to generate expressions for static or + * instance members. + */ + function generateClassElementDecorationExpressions(node: ClassExpression | ClassDeclaration, isStatic: boolean) { + const members = getDecoratedClassElements(node, isStatic); + let expressions: Expression[] | undefined; + for (const member of members) { + const expression = generateClassElementDecorationExpression(node, member); + if (expression) { + if (!expressions) { + expressions = [expression]; + } + else { + expressions.push(expression); + } + } + } + return expressions; + } + + /** + * Generates an expression used to evaluate class element decorators at runtime. + * + * @param node The class node that contains the member. + * @param member The class member. + */ + function generateClassElementDecorationExpression(node: ClassExpression | ClassDeclaration, member: ClassElement) { + const allDecorators = getAllDecoratorsOfClassElement(node, member); + const decoratorExpressions = transformAllDecoratorsOfDeclaration(member, node, allDecorators); + if (!decoratorExpressions) { + return undefined; + } + + // Emit the call to __decorate. Given the following: + // + // class C { + // @dec method(@dec2 x) {} + // @dec get accessor() {} + // @dec prop; + // } + // + // The emit for a method is: + // + // __decorate([ + // dec, + // __param(0, dec2), + // __metadata("design:type", Function), + // __metadata("design:paramtypes", [Object]), + // __metadata("design:returntype", void 0) + // ], C.prototype, "method", null); + // + // The emit for an accessor is: + // + // __decorate([ + // dec + // ], C.prototype, "accessor", null); + // + // The emit for a property is: + // + // __decorate([ + // dec + // ], C.prototype, "prop"); + // + + const prefix = getClassMemberPrefix(node, member); + const memberName = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ true); + const descriptor = languageVersion > ScriptTarget.ES3 + ? member.kind === SyntaxKind.PropertyDeclaration + // We emit `void 0` here to indicate to `__decorate` that it can invoke `Object.defineProperty` directly, but that it + // should not invoke `Object.getOwnPropertyDescriptor`. + ? createVoidZero() + + // We emit `null` here to indicate to `__decorate` that it can invoke `Object.getOwnPropertyDescriptor` directly. + // We have this extra argument here so that we can inject an explicit property descriptor at a later date. + : createNull() + : undefined; + + const helper = createDecorateHelper( + context, + decoratorExpressions, + prefix, + memberName, + descriptor, + moveRangePastDecorators(member) + ); + + setEmitFlags(helper, EmitFlags.NoComments); + return helper; + } + + /** + * Generates a __decorate helper call for a class constructor. + * + * @param node The class node. + */ + function addConstructorDecorationStatement(statements: Statement[], node: ClassDeclaration) { + const expression = generateConstructorDecorationExpression(node); + if (expression) { + statements.push(setOriginalNode(createExpressionStatement(expression), node)); + } + } + + /** + * Generates a __decorate helper call for a class constructor. + * + * @param node The class node. + */ + function generateConstructorDecorationExpression(node: ClassExpression | ClassDeclaration) { + const allDecorators = getAllDecoratorsOfConstructor(node); + const decoratorExpressions = transformAllDecoratorsOfDeclaration(node, node, allDecorators); + if (!decoratorExpressions) { + return undefined; + } + + const classAlias = classAliases && classAliases[getOriginalNodeId(node)]; + const localName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); + const decorate = createDecorateHelper(context, decoratorExpressions, localName); + const expression = createAssignment(localName, classAlias ? createAssignment(classAlias, decorate) : decorate); + setEmitFlags(expression, EmitFlags.NoComments); + setSourceMapRange(expression, moveRangePastDecorators(node)); + return expression; + } + + /** + * Transforms a decorator into an expression. + * + * @param decorator The decorator node. + */ + function transformDecorator(decorator: Decorator) { + return visitNode(decorator.expression, visitor, isExpression); + } + + /** + * Transforms the decorators of a parameter. + * + * @param decorators The decorators for the parameter at the provided offset. + * @param parameterOffset The offset of the parameter. + */ + function transformDecoratorsOfParameter(decorators: Decorator[], parameterOffset: number) { + let expressions: Expression[] | undefined; + if (decorators) { + expressions = []; + for (const decorator of decorators) { + const helper = createParamHelper( + context, + transformDecorator(decorator), + parameterOffset, + /*location*/ decorator.expression); + setEmitFlags(helper, EmitFlags.NoComments); + expressions.push(helper); + } + } + + return expressions; + } + + /** + * Adds optional type metadata for a declaration. + * + * @param node The declaration node. + * @param decoratorExpressions The destination array to which to add new decorator expressions. + */ + function addTypeMetadata(node: Declaration, container: ClassLikeDeclaration, decoratorExpressions: Expression[]) { + if (USE_NEW_TYPE_METADATA_FORMAT) { + addNewTypeMetadata(node, container, decoratorExpressions); + } + else { + addOldTypeMetadata(node, container, decoratorExpressions); + } + } + + function addOldTypeMetadata(node: Declaration, container: ClassLikeDeclaration, decoratorExpressions: Expression[]) { + if (compilerOptions.emitDecoratorMetadata) { + if (shouldAddTypeMetadata(node)) { + decoratorExpressions.push(createMetadataHelper(context, "design:type", serializeTypeOfNode(node))); + } + if (shouldAddParamTypesMetadata(node)) { + decoratorExpressions.push(createMetadataHelper(context, "design:paramtypes", serializeParameterTypesOfNode(node, container))); + } + if (shouldAddReturnTypeMetadata(node)) { + decoratorExpressions.push(createMetadataHelper(context, "design:returntype", serializeReturnTypeOfNode(node))); + } + } + } + + function addNewTypeMetadata(node: Declaration, container: ClassLikeDeclaration, decoratorExpressions: Expression[]) { + if (compilerOptions.emitDecoratorMetadata) { + let properties: ObjectLiteralElementLike[] | undefined; + if (shouldAddTypeMetadata(node)) { + (properties || (properties = [])).push(createPropertyAssignment("type", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeTypeOfNode(node)))); + } + if (shouldAddParamTypesMetadata(node)) { + (properties || (properties = [])).push(createPropertyAssignment("paramTypes", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeParameterTypesOfNode(node, container)))); + } + if (shouldAddReturnTypeMetadata(node)) { + (properties || (properties = [])).push(createPropertyAssignment("returnType", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeReturnTypeOfNode(node)))); + } + if (properties) { + decoratorExpressions.push(createMetadataHelper(context, "design:typeinfo", createObjectLiteral(properties, /*multiLine*/ true))); + } + } + } + + /** + * Determines whether to emit the "design:type" metadata based on the node's kind. + * The caller should have already tested whether the node has decorators and whether the + * emitDecoratorMetadata compiler option is set. + * + * @param node The node to test. + */ + function shouldAddTypeMetadata(node: Declaration): boolean { + const kind = node.kind; + return kind === SyntaxKind.MethodDeclaration + || kind === SyntaxKind.GetAccessor + || kind === SyntaxKind.SetAccessor + || kind === SyntaxKind.PropertyDeclaration; + } + + /** + * Determines whether to emit the "design:returntype" metadata based on the node's kind. + * The caller should have already tested whether the node has decorators and whether the + * emitDecoratorMetadata compiler option is set. + * + * @param node The node to test. + */ + function shouldAddReturnTypeMetadata(node: Declaration): boolean { + return node.kind === SyntaxKind.MethodDeclaration; + } + + /** + * Determines whether to emit the "design:paramtypes" metadata based on the node's kind. + * The caller should have already tested whether the node has decorators and whether the + * emitDecoratorMetadata compiler option is set. + * + * @param node The node to test. + */ + function shouldAddParamTypesMetadata(node: Declaration): boolean { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + return getFirstConstructorWithBody(node) !== undefined; + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return true; + } + return false; + } + + type SerializedEntityNameAsExpression = Identifier | BinaryExpression | PropertyAccessExpression; + type SerializedTypeNode = SerializedEntityNameAsExpression | VoidExpression | ConditionalExpression; + + function getAccessorTypeNode(node: AccessorDeclaration) { + const accessors = resolver.getAllAccessorDeclarations(node); + return accessors.setAccessor && getSetAccessorTypeAnnotationNode(accessors.setAccessor) + || accessors.getAccessor && getEffectiveReturnTypeNode(accessors.getAccessor); + } + + /** + * Serializes the type of a node for use with decorator type metadata. + * + * @param node The node that should have its type serialized. + */ + function serializeTypeOfNode(node: Node): SerializedTypeNode { + switch (node.kind) { + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + return serializeTypeNode((node).type); + case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessor: + return serializeTypeNode(getAccessorTypeNode(node as AccessorDeclaration)); + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + case SyntaxKind.MethodDeclaration: + return createIdentifier("Function"); + default: + return createVoidZero(); + } + } + + /** + * Serializes the types of the parameters of a node for use with decorator type metadata. + * + * @param node The node that should have its parameter types serialized. + */ + function serializeParameterTypesOfNode(node: Node, container: ClassLikeDeclaration): ArrayLiteralExpression { + const valueDeclaration = + isClassLike(node) + ? getFirstConstructorWithBody(node) + : isFunctionLike(node) && nodeIsPresent((node as FunctionLikeDeclaration).body) + ? node + : undefined; + + const expressions: SerializedTypeNode[] = []; + if (valueDeclaration) { + const parameters = getParametersOfDecoratedDeclaration(valueDeclaration, container); + const numParameters = parameters.length; + for (let i = 0; i < numParameters; i++) { + const parameter = parameters[i]; + if (i === 0 && isIdentifier(parameter.name) && parameter.name.escapedText === "this") { + continue; + } + if (parameter.dotDotDotToken) { + expressions.push(serializeTypeNode(getRestParameterElementType(parameter.type))); + } + else { + expressions.push(serializeTypeOfNode(parameter)); + } + } + } + + return createArrayLiteral(expressions); + } + + function getParametersOfDecoratedDeclaration(node: SignatureDeclaration, container: ClassLikeDeclaration) { + if (container && node.kind === SyntaxKind.GetAccessor) { + const { setAccessor } = getAllAccessorDeclarations(container.members, node); + if (setAccessor) { + return setAccessor.parameters; + } + } + return node.parameters; + } + + /** + * Serializes the return type of a node for use with decorator type metadata. + * + * @param node The node that should have its return type serialized. + */ + function serializeReturnTypeOfNode(node: Node): SerializedTypeNode { + if (isFunctionLike(node) && node.type) { + return serializeTypeNode(node.type); + } + else if (isAsyncFunction(node)) { + return createIdentifier("Promise"); + } + + return createVoidZero(); + } + + /** + * Serializes a type node for use with decorator type metadata. + * + * Types are serialized in the following fashion: + * - Void types point to "undefined" (e.g. "void 0") + * - Function and Constructor types point to the global "Function" constructor. + * - Interface types with a call or construct signature types point to the global + * "Function" constructor. + * - Array and Tuple types point to the global "Array" constructor. + * - Type predicates and booleans point to the global "Boolean" constructor. + * - String literal types and strings point to the global "String" constructor. + * - Enum and number types point to the global "Number" constructor. + * - Symbol types point to the global "Symbol" constructor. + * - Type references to classes (or class-like variables) point to the constructor for the class. + * - Anything else points to the global "Object" constructor. + * + * @param node The type node to serialize. + */ + function serializeTypeNode(node: TypeNode | undefined): SerializedTypeNode { + if (node === undefined) { + return createIdentifier("Object"); + } + + switch (node.kind) { + case SyntaxKind.VoidKeyword: + case SyntaxKind.UndefinedKeyword: + case SyntaxKind.NullKeyword: + case SyntaxKind.NeverKeyword: + return createVoidZero(); + + case SyntaxKind.ParenthesizedType: + return serializeTypeNode((node).type); + + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + return createIdentifier("Function"); + + case SyntaxKind.ArrayType: + case SyntaxKind.TupleType: + return createIdentifier("Array"); + + case SyntaxKind.TypePredicate: + case SyntaxKind.BooleanKeyword: + return createIdentifier("Boolean"); + + case SyntaxKind.StringKeyword: + return createIdentifier("String"); + + case SyntaxKind.ObjectKeyword: + return createIdentifier("Object"); + + case SyntaxKind.LiteralType: + switch ((node).literal.kind) { + case SyntaxKind.StringLiteral: + return createIdentifier("String"); + + case SyntaxKind.PrefixUnaryExpression: + case SyntaxKind.NumericLiteral: + return createIdentifier("Number"); + + case SyntaxKind.BigIntLiteral: + return getGlobalBigIntNameWithFallback(); + + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: + return createIdentifier("Boolean"); + + default: + return Debug.failBadSyntaxKind((node).literal); + } + + case SyntaxKind.NumberKeyword: + return createIdentifier("Number"); + + case SyntaxKind.BigIntKeyword: + return getGlobalBigIntNameWithFallback(); + + case SyntaxKind.SymbolKeyword: + return languageVersion < ScriptTarget.ES2015 + ? getGlobalSymbolNameWithFallback() + : createIdentifier("Symbol"); + + case SyntaxKind.TypeReference: + return serializeTypeReferenceNode(node); + + case SyntaxKind.IntersectionType: + case SyntaxKind.UnionType: + return serializeTypeList((node).types); + + case SyntaxKind.ConditionalType: + return serializeTypeList([(node).trueType, (node).falseType]); + + case SyntaxKind.TypeOperator: + if ((node).operator === SyntaxKind.ReadonlyKeyword) { + return serializeTypeNode((node).type); + } + break; + + case SyntaxKind.TypeQuery: + case SyntaxKind.IndexedAccessType: + case SyntaxKind.MappedType: + case SyntaxKind.TypeLiteral: + case SyntaxKind.AnyKeyword: + case SyntaxKind.UnknownKeyword: + case SyntaxKind.ThisType: + case SyntaxKind.ImportType: + break; + + + default: + return Debug.failBadSyntaxKind(node); + } + + return createIdentifier("Object"); + } + + function serializeTypeList(types: readonly TypeNode[]): SerializedTypeNode { + // Note when updating logic here also update getEntityNameForDecoratorMetadata + // so that aliases can be marked as referenced + let serializedUnion: SerializedTypeNode | undefined; + for (let typeNode of types) { + while (typeNode.kind === SyntaxKind.ParenthesizedType) { + typeNode = (typeNode as ParenthesizedTypeNode).type; // Skip parens if need be + } + if (typeNode.kind === SyntaxKind.NeverKeyword) { + continue; // Always elide `never` from the union/intersection if possible + } + if (!strictNullChecks && (typeNode.kind === SyntaxKind.NullKeyword || typeNode.kind === SyntaxKind.UndefinedKeyword)) { + continue; // Elide null and undefined from unions for metadata, just like what we did prior to the implementation of strict null checks + } + const serializedIndividual = serializeTypeNode(typeNode); + + if (isIdentifier(serializedIndividual) && serializedIndividual.escapedText === "Object") { + // One of the individual is global object, return immediately + return serializedIndividual; + } + // If there exists union that is not void 0 expression, check if the the common type is identifier. + // anything more complex and we will just default to Object + else if (serializedUnion) { + // Different types + if (!isIdentifier(serializedUnion) || + !isIdentifier(serializedIndividual) || + serializedUnion.escapedText !== serializedIndividual.escapedText) { + return createIdentifier("Object"); + } + } + else { + // Initialize the union type + serializedUnion = serializedIndividual; + } + } + + // If we were able to find common type, use it + return serializedUnion || createVoidZero(); // Fallback is only hit if all union constituients are null/undefined/never + } + + /** + * Serializes a TypeReferenceNode to an appropriate JS constructor value for use with + * decorator type metadata. + * + * @param node The type reference node. + */ + function serializeTypeReferenceNode(node: TypeReferenceNode): SerializedTypeNode { + const kind = resolver.getTypeReferenceSerializationKind(node.typeName, currentNameScope || currentLexicalScope); + switch (kind) { + case TypeReferenceSerializationKind.Unknown: + // From conditional type type reference that cannot be resolved is Similar to any or unknown + if (findAncestor(node, n => n.parent && isConditionalTypeNode(n.parent) && (n.parent.trueType === n || n.parent.falseType === n))) { + return createIdentifier("Object"); + } + + const serialized = serializeEntityNameAsExpressionFallback(node.typeName); + const temp = createTempVariable(hoistVariableDeclaration); + return createConditional( + createTypeCheck(createAssignment(temp, serialized), "function"), + temp, + createIdentifier("Object") + ); + + case TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: + return serializeEntityNameAsExpression(node.typeName); + + case TypeReferenceSerializationKind.VoidNullableOrNeverType: + return createVoidZero(); + + case TypeReferenceSerializationKind.BigIntLikeType: + return getGlobalBigIntNameWithFallback(); + + case TypeReferenceSerializationKind.BooleanType: + return createIdentifier("Boolean"); + + case TypeReferenceSerializationKind.NumberLikeType: + return createIdentifier("Number"); + + case TypeReferenceSerializationKind.StringLikeType: + return createIdentifier("String"); + + case TypeReferenceSerializationKind.ArrayLikeType: + return createIdentifier("Array"); + + case TypeReferenceSerializationKind.ESSymbolType: + return languageVersion < ScriptTarget.ES2015 + ? getGlobalSymbolNameWithFallback() + : createIdentifier("Symbol"); + + case TypeReferenceSerializationKind.TypeWithCallSignature: + return createIdentifier("Function"); + + case TypeReferenceSerializationKind.Promise: + return createIdentifier("Promise"); + + case TypeReferenceSerializationKind.ObjectType: + return createIdentifier("Object"); + default: + return Debug.assertNever(kind); + } + } + + function createCheckedValue(left: Expression, right: Expression) { + return createLogicalAnd( + createStrictInequality(createTypeOf(left), createLiteral("undefined")), + right + ); + } + + /** + * Serializes an entity name which may not exist at runtime, but whose access shouldn't throw + * + * @param node The entity name to serialize. + */ + function serializeEntityNameAsExpressionFallback(node: EntityName): BinaryExpression { + if (node.kind === SyntaxKind.Identifier) { + // A -> typeof A !== undefined && A + const copied = serializeEntityNameAsExpression(node); + return createCheckedValue(copied, copied); + } + if (node.left.kind === SyntaxKind.Identifier) { + // A.B -> typeof A !== undefined && A.B + return createCheckedValue(serializeEntityNameAsExpression(node.left), serializeEntityNameAsExpression(node)); + } + // A.B.C -> typeof A !== undefined && (_a = A.B) !== void 0 && _a.C + const left = serializeEntityNameAsExpressionFallback(node.left); + const temp = createTempVariable(hoistVariableDeclaration); + return createLogicalAnd( + createLogicalAnd( + left.left, + createStrictInequality(createAssignment(temp, left.right), createVoidZero()) + ), + createPropertyAccess(temp, node.right) + ); + } + + /** + * Serializes an entity name as an expression for decorator type metadata. + * + * @param node The entity name to serialize. + */ + function serializeEntityNameAsExpression(node: EntityName): SerializedEntityNameAsExpression { + switch (node.kind) { + case SyntaxKind.Identifier: + // Create a clone of the name with a new parent, and treat it as if it were + // a source tree node for the purposes of the checker. + const name = getMutableClone(node); + name.flags &= ~NodeFlags.Synthesized; + name.original = undefined; + name.parent = getParseTreeNode(currentLexicalScope); // ensure the parent is set to a parse tree node. + + return name; + + case SyntaxKind.QualifiedName: + return serializeQualifiedNameAsExpression(node); + } + } + + /** + * Serializes an qualified name as an expression for decorator type metadata. + * + * @param node The qualified name to serialize. + * @param useFallback A value indicating whether to use logical operators to test for the + * qualified name at runtime. + */ + function serializeQualifiedNameAsExpression(node: QualifiedName): SerializedEntityNameAsExpression { + return createPropertyAccess(serializeEntityNameAsExpression(node.left), node.right); + } + + /** + * Gets an expression that points to the global "Symbol" constructor at runtime if it is + * available. + */ + function getGlobalSymbolNameWithFallback(): ConditionalExpression { + return createConditional( + createTypeCheck(createIdentifier("Symbol"), "function"), + createIdentifier("Symbol"), + createIdentifier("Object") + ); + } + + /** + * Gets an expression that points to the global "BigInt" constructor at runtime if it is + * available. + */ + function getGlobalBigIntNameWithFallback(): SerializedTypeNode { + return languageVersion < ScriptTarget.ESNext + ? createConditional( + createTypeCheck(createIdentifier("BigInt"), "function"), + createIdentifier("BigInt"), + createIdentifier("Object") + ) + : createIdentifier("BigInt"); + } + + /** + * Gets an expression that represents a property name. For a computed property, a + * name is generated for the node. + * + * @param member The member whose name should be converted into an expression. + */ + function getExpressionForPropertyName(member: ClassElement | EnumMember, generateNameForComputedPropertyName: boolean): Expression { + const name = member.name!; + if (isComputedPropertyName(name)) { + return generateNameForComputedPropertyName && !isSimpleInlineableExpression(name.expression) + ? getGeneratedNameForNode(name) + : name.expression; + } + else if (isIdentifier(name)) { + return createLiteral(idText(name)); + } + else { + return getSynthesizedClone(name); + } + } + + /** + * Visits the property name of a class element, for use when emitting property + * initializers. For a computed property on a node with decorators, a temporary + * value is stored for later use. + * + * @param member The member whose name should be visited. + */ + function visitPropertyNameOfClassElement(member: ClassElement): PropertyName { + const name = member.name!; + // Computed property names need to be transformed into a hoisted variable when they are used more than once. + // The names are used more than once when: + // - the property is non-static and its initializer is moved to the constructor (when there are parameter property assignments). + // - the property has a decorator. + if (isComputedPropertyName(name) && ((!hasStaticModifier(member) && currentClassHasParameterProperties) || some(member.decorators))) { + const expression = visitNode(name.expression, visitor, isExpression); + const innerExpression = skipPartiallyEmittedExpressions(expression); + if (!isSimpleInlineableExpression(innerExpression)) { + const generatedName = getGeneratedNameForNode(name); + hoistVariableDeclaration(generatedName); + return updateComputedPropertyName(name, createAssignment(generatedName, expression)); + } + } + return visitNode(name, visitor, isPropertyName); + } + + /** + * Transforms a HeritageClause with TypeScript syntax. + * + * This function will only be called when one of the following conditions are met: + * - The node is a non-`extends` heritage clause that should be elided. + * - The node is an `extends` heritage clause that should be visited, but only allow a single type. + * + * @param node The HeritageClause to transform. + */ + function visitHeritageClause(node: HeritageClause): HeritageClause | undefined { + if (node.token === SyntaxKind.ImplementsKeyword) { + // implements clauses are elided + return undefined; + } + return visitEachChild(node, visitor, context); + } + + /** + * Transforms an ExpressionWithTypeArguments with TypeScript syntax. + * + * This function will only be called when one of the following conditions are met: + * - The node contains type arguments that should be elided. + * + * @param node The ExpressionWithTypeArguments to transform. + */ + function visitExpressionWithTypeArguments(node: ExpressionWithTypeArguments): ExpressionWithTypeArguments { + return updateExpressionWithTypeArguments( + node, + /*typeArguments*/ undefined, + visitNode(node.expression, visitor, isLeftHandSideExpression) + ); + } + + /** + * Determines whether to emit a function-like declaration. We should not emit the + * declaration if it does not have a body. + * + * @param node The declaration node. + */ + function shouldEmitFunctionLikeDeclaration(node: T): node is T & { body: NonNullable } { + return !nodeIsMissing(node.body); + } + + function visitPropertyDeclaration(node: PropertyDeclaration) { + const updated = updateProperty( + node, + /*decorators*/ undefined, + visitNodes(node.modifiers, visitor, isModifier), + visitPropertyNameOfClassElement(node), + /*questionOrExclamationToken*/ undefined, + /*type*/ undefined, + visitNode(node.initializer, visitor) + ); + if (updated !== node) { + // While we emit the source map for the node after skipping decorators and modifiers, + // we need to emit the comments for the original range. + setCommentRange(updated, node); + setSourceMapRange(updated, moveRangePastDecorators(node)); + } + return updated; + } + + function visitConstructor(node: ConstructorDeclaration) { + if (!shouldEmitFunctionLikeDeclaration(node)) { + return undefined; + } + + return updateConstructor( + node, + /*decorators*/ undefined, + /*modifiers*/ undefined, + visitParameterList(node.parameters, visitor, context), + transformConstructorBody(node.body, node) + ); + } + + function transformConstructorBody(body: Block, constructor: ConstructorDeclaration) { + const parametersWithPropertyAssignments = constructor && + filter(constructor.parameters, p => isParameterPropertyDeclaration(p, constructor)); + if (!some(parametersWithPropertyAssignments)) { + return visitFunctionBody(body, visitor, context); + } + + let statements: Statement[] = []; + let indexOfFirstStatement = 0; + + resumeLexicalEnvironment(); + + indexOfFirstStatement = addPrologueDirectivesAndInitialSuperCall(constructor, statements, visitor); + + // Add parameters with property assignments. Transforms this: + // + // constructor (public x, public y) { + // } + // + // Into this: + // + // constructor (x, y) { + // this.x = x; + // this.y = y; + // } + // + addRange(statements, map(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment)); + + // Add the existing statements, skipping the initial super call. + addRange(statements, visitNodes(body.statements, visitor, isStatement, indexOfFirstStatement)); + + // End the lexical environment. + statements = mergeLexicalEnvironment(statements, endLexicalEnvironment()); + const block = createBlock(setTextRange(createNodeArray(statements), body.statements), /*multiLine*/ true); + setTextRange(block, /*location*/ body); + setOriginalNode(block, body); + return block; + } + + /** + * Transforms a parameter into a property assignment statement. + * + * @param node The parameter declaration. + */ + function transformParameterWithPropertyAssignment(node: ParameterPropertyDeclaration) { + const name = node.name; + if (!isIdentifier(name)) { + return undefined; + } + + const propertyName = getMutableClone(name); + setEmitFlags(propertyName, EmitFlags.NoComments | EmitFlags.NoSourceMap); + + const localName = getMutableClone(name); + setEmitFlags(localName, EmitFlags.NoComments); + + return startOnNewLine( + removeAllComments( + setTextRange( + setOriginalNode( + createExpressionStatement( + createAssignment( + setTextRange( + createPropertyAccess( + createThis(), + propertyName + ), + node.name + ), + localName + ) + ), + node + ), + moveRangePos(node, -1) + ) + ) + ); + } + + function visitMethodDeclaration(node: MethodDeclaration) { + if (!shouldEmitFunctionLikeDeclaration(node)) { + return undefined; + } + const updated = updateMethod( + node, + /*decorators*/ undefined, + visitNodes(node.modifiers, modifierVisitor, isModifier), + node.asteriskToken, + visitPropertyNameOfClassElement(node), + /*questionToken*/ undefined, + /*typeParameters*/ undefined, + visitParameterList(node.parameters, visitor, context), + /*type*/ undefined, + visitFunctionBody(node.body, visitor, context) + ); + if (updated !== node) { + // While we emit the source map for the node after skipping decorators and modifiers, + // we need to emit the comments for the original range. + setCommentRange(updated, node); + setSourceMapRange(updated, moveRangePastDecorators(node)); + } + return updated; + } + + /** + * Determines whether to emit an accessor declaration. We should not emit the + * declaration if it does not have a body and is abstract. + * + * @param node The declaration node. + */ + function shouldEmitAccessorDeclaration(node: AccessorDeclaration) { + return !(nodeIsMissing(node.body) && hasModifier(node, ModifierFlags.Abstract)); + } + + function visitGetAccessor(node: GetAccessorDeclaration) { + if (!shouldEmitAccessorDeclaration(node)) { + return undefined; + } + const updated = updateGetAccessor( + node, + /*decorators*/ undefined, + visitNodes(node.modifiers, modifierVisitor, isModifier), + visitPropertyNameOfClassElement(node), + visitParameterList(node.parameters, visitor, context), + /*type*/ undefined, + visitFunctionBody(node.body, visitor, context) || createBlock([]) + ); + if (updated !== node) { + // While we emit the source map for the node after skipping decorators and modifiers, + // we need to emit the comments for the original range. + setCommentRange(updated, node); + setSourceMapRange(updated, moveRangePastDecorators(node)); + } + return updated; + } + + function visitSetAccessor(node: SetAccessorDeclaration) { + if (!shouldEmitAccessorDeclaration(node)) { + return undefined; + } + const updated = updateSetAccessor( + node, + /*decorators*/ undefined, + visitNodes(node.modifiers, modifierVisitor, isModifier), + visitPropertyNameOfClassElement(node), + visitParameterList(node.parameters, visitor, context), + visitFunctionBody(node.body, visitor, context) || createBlock([]) + ); + if (updated !== node) { + // While we emit the source map for the node after skipping decorators and modifiers, + // we need to emit the comments for the original range. + setCommentRange(updated, node); + setSourceMapRange(updated, moveRangePastDecorators(node)); + } + return updated; + } + + function visitFunctionDeclaration(node: FunctionDeclaration): VisitResult { + if (!shouldEmitFunctionLikeDeclaration(node)) { + return createNotEmittedStatement(node); + } + const updated = updateFunctionDeclaration( + node, + /*decorators*/ undefined, + visitNodes(node.modifiers, modifierVisitor, isModifier), + node.asteriskToken, + node.name, + /*typeParameters*/ undefined, + visitParameterList(node.parameters, visitor, context), + /*type*/ undefined, + visitFunctionBody(node.body, visitor, context) || createBlock([]) + ); + if (isExportOfNamespace(node)) { + const statements: Statement[] = [updated]; + addExportMemberAssignment(statements, node); + return statements; + } + return updated; + } + + function visitFunctionExpression(node: FunctionExpression): Expression { + if (!shouldEmitFunctionLikeDeclaration(node)) { + return createOmittedExpression(); + } + const updated = updateFunctionExpression( + node, + visitNodes(node.modifiers, modifierVisitor, isModifier), + node.asteriskToken, + node.name, + /*typeParameters*/ undefined, + visitParameterList(node.parameters, visitor, context), + /*type*/ undefined, + visitFunctionBody(node.body, visitor, context) || createBlock([]) + ); + return updated; + } + + function visitArrowFunction(node: ArrowFunction) { + const updated = updateArrowFunction( + node, + visitNodes(node.modifiers, modifierVisitor, isModifier), + /*typeParameters*/ undefined, + visitParameterList(node.parameters, visitor, context), + /*type*/ undefined, + node.equalsGreaterThanToken, + visitFunctionBody(node.body, visitor, context), + ); + return updated; + } + + function visitParameter(node: ParameterDeclaration) { + if (parameterIsThisKeyword(node)) { + return undefined; + } + + const updated = updateParameter( + node, + /*decorators*/ undefined, + /*modifiers*/ undefined, + node.dotDotDotToken, + visitNode(node.name, visitor, isBindingName), + /*questionToken*/ undefined, + /*type*/ undefined, + visitNode(node.initializer, visitor, isExpression) + ); + if (updated !== node) { + // While we emit the source map for the node after skipping decorators and modifiers, + // we need to emit the comments for the original range. + setCommentRange(updated, node); + setTextRange(updated, moveRangePastModifiers(node)); + setSourceMapRange(updated, moveRangePastModifiers(node)); + setEmitFlags(updated.name, EmitFlags.NoTrailingSourceMap); + } + return updated; + } + + function visitVariableStatement(node: VariableStatement): Statement | undefined { + if (isExportOfNamespace(node)) { + const variables = getInitializedVariables(node.declarationList); + if (variables.length === 0) { + // elide statement if there are no initialized variables. + return undefined; + } + + return setTextRange( + createExpressionStatement( + inlineExpressions( + map(variables, transformInitializedVariable) + ) + ), + node + ); + } + else { + return visitEachChild(node, visitor, context); + } + } + + function transformInitializedVariable(node: VariableDeclaration): Expression { + const name = node.name; + if (isBindingPattern(name)) { + return flattenDestructuringAssignment( + node, + visitor, + context, + FlattenLevel.All, + /*needsValue*/ false, + createNamespaceExportExpression + ); + } + else { + return setTextRange( + createAssignment( + getNamespaceMemberNameWithSourceMapsAndWithoutComments(name), + visitNode(node.initializer, visitor, isExpression) + ), + /*location*/ node + ); + } + } + + function visitVariableDeclaration(node: VariableDeclaration) { + return updateVariableDeclaration( + node, + visitNode(node.name, visitor, isBindingName), + /*type*/ undefined, + visitNode(node.initializer, visitor, isExpression)); + } + + function visitParenthesizedExpression(node: ParenthesizedExpression): Expression { + const innerExpression = skipOuterExpressions(node.expression, ~OuterExpressionKinds.Assertions); + if (isAssertionExpression(innerExpression)) { + // Make sure we consider all nested cast expressions, e.g.: + // (-A).x; + const expression = visitNode(node.expression, visitor, isExpression); + + // We have an expression of the form: (SubExpr). Emitting this as (SubExpr) + // is really not desirable. We would like to emit the subexpression as-is. Omitting + // the parentheses, however, could cause change in the semantics of the generated + // code if the casted expression has a lower precedence than the rest of the + // expression. + // + // To preserve comments, we return a "PartiallyEmittedExpression" here which will + // preserve the position information of the original expression. + // + // Due to the auto-parenthesization rules used by the visitor and factory functions + // we can safely elide the parentheses here, as a new synthetic + // ParenthesizedExpression will be inserted if we remove parentheses too + // aggressively. + // HOWEVER - if there are leading comments on the expression itself, to handle ASI + // correctly for return and throw, we must keep the parenthesis + if (length(getLeadingCommentRangesOfNode(expression, currentSourceFile))) { + return updateParen(node, expression); + } + return createPartiallyEmittedExpression(expression, node); + } + + return visitEachChild(node, visitor, context); + } + + function visitAssertionExpression(node: AssertionExpression): Expression { + const expression = visitNode(node.expression, visitor, isExpression); + return createPartiallyEmittedExpression(expression, node); + } + + function visitNonNullExpression(node: NonNullExpression): Expression { + const expression = visitNode(node.expression, visitor, isLeftHandSideExpression); + return createPartiallyEmittedExpression(expression, node); + } + + function visitCallExpression(node: CallExpression) { + return updateCall( + node, + visitNode(node.expression, visitor, isExpression), + /*typeArguments*/ undefined, + visitNodes(node.arguments, visitor, isExpression)); + } + + function visitNewExpression(node: NewExpression) { + return updateNew( + node, + visitNode(node.expression, visitor, isExpression), + /*typeArguments*/ undefined, + visitNodes(node.arguments, visitor, isExpression)); + } + + function visitTaggedTemplateExpression(node: TaggedTemplateExpression) { + return updateTaggedTemplate( + node, + visitNode(node.tag, visitor, isExpression), + /*typeArguments*/ undefined, + visitNode(node.template, visitor, isExpression)); + } + + /** + * Determines whether to emit an enum declaration. + * + * @param node The enum declaration node. + */ + function shouldEmitEnumDeclaration(node: EnumDeclaration) { + return !isEnumConst(node) + || compilerOptions.preserveConstEnums + || compilerOptions.isolatedModules; + } + + /** + * Visits an enum declaration. + * + * This function will be called any time a TypeScript enum is encountered. + * + * @param node The enum declaration node. + */ + function visitEnumDeclaration(node: EnumDeclaration): VisitResult { + if (!shouldEmitEnumDeclaration(node)) { + return createNotEmittedStatement(node); + } + + const statements: Statement[] = []; + + // We request to be advised when the printer is about to print this node. This allows + // us to set up the correct state for later substitutions. + let emitFlags = EmitFlags.AdviseOnEmitNode; + + // If needed, we should emit a variable declaration for the enum. If we emit + // a leading variable declaration, we should not emit leading comments for the + // enum body. + const varAdded = addVarForEnumOrModuleDeclaration(statements, node); + if (varAdded) { + // We should still emit the comments if we are emitting a system module. + if (moduleKind !== ModuleKind.System || currentLexicalScope !== currentSourceFile) { + emitFlags |= EmitFlags.NoLeadingComments; + } + } + + // `parameterName` is the declaration name used inside of the enum. + const parameterName = getNamespaceParameterName(node); + + // `containerName` is the expression used inside of the enum for assignments. + const containerName = getNamespaceContainerName(node); + + // `exportName` is the expression used within this node's container for any exported references. + const exportName = hasModifier(node, ModifierFlags.Export) + ? getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true) + : getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); + + // x || (x = {}) + // exports.x || (exports.x = {}) + let moduleArg = + createLogicalOr( + exportName, + createAssignment( + exportName, + createObjectLiteral() + ) + ); + + if (hasNamespaceQualifiedExportName(node)) { + // `localName` is the expression used within this node's containing scope for any local references. + const localName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); + + // x = (exports.x || (exports.x = {})) + moduleArg = createAssignment(localName, moduleArg); + } + + // (function (x) { + // x[x["y"] = 0] = "y"; + // ... + // })(x || (x = {})); + const enumStatement = createExpressionStatement( + createCall( + createFunctionExpression( + /*modifiers*/ undefined, + /*asteriskToken*/ undefined, + /*name*/ undefined, + /*typeParameters*/ undefined, + [createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, parameterName)], + /*type*/ undefined, + transformEnumBody(node, containerName) + ), + /*typeArguments*/ undefined, + [moduleArg] + ) + ); + + setOriginalNode(enumStatement, node); + if (varAdded) { + // If a variable was added, synthetic comments are emitted on it, not on the moduleStatement. + setSyntheticLeadingComments(enumStatement, undefined); + setSyntheticTrailingComments(enumStatement, undefined); + } + setTextRange(enumStatement, node); + addEmitFlags(enumStatement, emitFlags); + statements.push(enumStatement); + + // Add a DeclarationMarker for the enum to preserve trailing comments and mark + // the end of the declaration. + statements.push(createEndOfDeclarationMarker(node)); + return statements; + } + + /** + * Transforms the body of an enum declaration. + * + * @param node The enum declaration node. + */ + function transformEnumBody(node: EnumDeclaration, localName: Identifier): Block { + const savedCurrentNamespaceLocalName = currentNamespaceContainerName; + currentNamespaceContainerName = localName; + + const statements: Statement[] = []; + startLexicalEnvironment(); + const members = map(node.members, transformEnumMember); + insertStatementsAfterStandardPrologue(statements, endLexicalEnvironment()); + addRange(statements, members); + + currentNamespaceContainerName = savedCurrentNamespaceLocalName; + return createBlock( + setTextRange(createNodeArray(statements), /*location*/ node.members), + /*multiLine*/ true + ); + } + + /** + * Transforms an enum member into a statement. + * + * @param member The enum member node. + */ + function transformEnumMember(member: EnumMember): Statement { + // enums don't support computed properties + // we pass false as 'generateNameForComputedPropertyName' for a backward compatibility purposes + // old emitter always generate 'expression' part of the name as-is. + const name = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ false); + const valueExpression = transformEnumMemberDeclarationValue(member); + const innerAssignment = createAssignment( + createElementAccess( + currentNamespaceContainerName, + name + ), + valueExpression + ); + const outerAssignment = valueExpression.kind === SyntaxKind.StringLiteral ? + innerAssignment : + createAssignment( + createElementAccess( + currentNamespaceContainerName, + innerAssignment + ), + name + ); + return setTextRange( + createExpressionStatement( + setTextRange( + outerAssignment, + member + ) + ), + member + ); + } + + /** + * Transforms the value of an enum member. + * + * @param member The enum member node. + */ + function transformEnumMemberDeclarationValue(member: EnumMember): Expression { + const value = resolver.getConstantValue(member); + if (value !== undefined) { + return createLiteral(value); + } + else { + enableSubstitutionForNonQualifiedEnumMembers(); + if (member.initializer) { + return visitNode(member.initializer, visitor, isExpression); + } + else { + return createVoidZero(); + } + } + } + + /** + * Determines whether to elide a module declaration. + * + * @param node The module declaration node. + */ + function shouldEmitModuleDeclaration(node: ModuleDeclaration) { + return isInstantiatedModule(node, !!compilerOptions.preserveConstEnums || !!compilerOptions.isolatedModules); + } + + /** + * Determines whether an exported declaration will have a qualified export name (e.g. `f.x` + * or `exports.x`). + */ + function hasNamespaceQualifiedExportName(node: Node) { + return isExportOfNamespace(node) + || (isExternalModuleExport(node) + && moduleKind !== ModuleKind.ES2015 + && moduleKind !== ModuleKind.ESNext + && moduleKind !== ModuleKind.System); + } + + /** + * Records that a declaration was emitted in the current scope, if it was the first + * declaration for the provided symbol. + */ + function recordEmittedDeclarationInScope(node: FunctionDeclaration | ClassDeclaration | ModuleDeclaration | EnumDeclaration) { + if (!currentScopeFirstDeclarationsOfName) { + currentScopeFirstDeclarationsOfName = createUnderscoreEscapedMap(); + } + + const name = declaredNameInScope(node); + if (!currentScopeFirstDeclarationsOfName.has(name)) { + currentScopeFirstDeclarationsOfName.set(name, node); + } + } + + /** + * Determines whether a declaration is the first declaration with + * the same name emitted in the current scope. + */ + function isFirstEmittedDeclarationInScope(node: ModuleDeclaration | EnumDeclaration) { + if (currentScopeFirstDeclarationsOfName) { + const name = declaredNameInScope(node); + return currentScopeFirstDeclarationsOfName.get(name) === node; + } + return true; + } + + function declaredNameInScope(node: FunctionDeclaration | ClassDeclaration | ModuleDeclaration | EnumDeclaration): __String { + Debug.assertNode(node.name, isIdentifier); + return (node.name as Identifier).escapedText; + } + + /** + * Adds a leading VariableStatement for a enum or module declaration. + */ + function addVarForEnumOrModuleDeclaration(statements: Statement[], node: ModuleDeclaration | EnumDeclaration) { + // Emit a variable statement for the module. We emit top-level enums as a `var` + // declaration to avoid static errors in global scripts scripts due to redeclaration. + // enums in any other scope are emitted as a `let` declaration. + const statement = createVariableStatement( + visitNodes(node.modifiers, modifierVisitor, isModifier), + createVariableDeclarationList([ + createVariableDeclaration( + getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true) + ) + ], currentLexicalScope.kind === SyntaxKind.SourceFile ? NodeFlags.None : NodeFlags.Let) + ); + + setOriginalNode(statement, node); + + recordEmittedDeclarationInScope(node); + if (isFirstEmittedDeclarationInScope(node)) { + // Adjust the source map emit to match the old emitter. + if (node.kind === SyntaxKind.EnumDeclaration) { + setSourceMapRange(statement.declarationList, node); + } + else { + setSourceMapRange(statement, node); + } + + // Trailing comments for module declaration should be emitted after the function closure + // instead of the variable statement: + // + // /** Module comment*/ + // module m1 { + // function foo4Export() { + // } + // } // trailing comment module + // + // Should emit: + // + // /** Module comment*/ + // var m1; + // (function (m1) { + // function foo4Export() { + // } + // })(m1 || (m1 = {})); // trailing comment module + // + setCommentRange(statement, node); + addEmitFlags(statement, EmitFlags.NoTrailingComments | EmitFlags.HasEndOfDeclarationMarker); + statements.push(statement); + return true; + } + else { + // For an EnumDeclaration or ModuleDeclaration that merges with a preceeding + // declaration we do not emit a leading variable declaration. To preserve the + // begin/end semantics of the declararation and to properly handle exports + // we wrap the leading variable declaration in a `MergeDeclarationMarker`. + const mergeMarker = createMergeDeclarationMarker(statement); + setEmitFlags(mergeMarker, EmitFlags.NoComments | EmitFlags.HasEndOfDeclarationMarker); + statements.push(mergeMarker); + return false; + } + } + + /** + * Visits a module declaration node. + * + * This function will be called any time a TypeScript namespace (ModuleDeclaration) is encountered. + * + * @param node The module declaration node. + */ + function visitModuleDeclaration(node: ModuleDeclaration): VisitResult { + if (!shouldEmitModuleDeclaration(node)) { + return createNotEmittedStatement(node); + } + + Debug.assertNode(node.name, isIdentifier, "A TypeScript namespace should have an Identifier name."); + enableSubstitutionForNamespaceExports(); + + const statements: Statement[] = []; + + // We request to be advised when the printer is about to print this node. This allows + // us to set up the correct state for later substitutions. + let emitFlags = EmitFlags.AdviseOnEmitNode; + + // If needed, we should emit a variable declaration for the module. If we emit + // a leading variable declaration, we should not emit leading comments for the + // module body. + const varAdded = addVarForEnumOrModuleDeclaration(statements, node); + if (varAdded) { + // We should still emit the comments if we are emitting a system module. + if (moduleKind !== ModuleKind.System || currentLexicalScope !== currentSourceFile) { + emitFlags |= EmitFlags.NoLeadingComments; + } + } + + // `parameterName` is the declaration name used inside of the namespace. + const parameterName = getNamespaceParameterName(node); + + // `containerName` is the expression used inside of the namespace for exports. + const containerName = getNamespaceContainerName(node); + + // `exportName` is the expression used within this node's container for any exported references. + const exportName = hasModifier(node, ModifierFlags.Export) + ? getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true) + : getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); + + // x || (x = {}) + // exports.x || (exports.x = {}) + let moduleArg = + createLogicalOr( + exportName, + createAssignment( + exportName, + createObjectLiteral() + ) + ); + + if (hasNamespaceQualifiedExportName(node)) { + // `localName` is the expression used within this node's containing scope for any local references. + const localName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); + + // x = (exports.x || (exports.x = {})) + moduleArg = createAssignment(localName, moduleArg); + } + + // (function (x_1) { + // x_1.y = ...; + // })(x || (x = {})); + const moduleStatement = createExpressionStatement( + createCall( + createFunctionExpression( + /*modifiers*/ undefined, + /*asteriskToken*/ undefined, + /*name*/ undefined, + /*typeParameters*/ undefined, + [createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, parameterName)], + /*type*/ undefined, + transformModuleBody(node, containerName) + ), + /*typeArguments*/ undefined, + [moduleArg] + ) + ); + + setOriginalNode(moduleStatement, node); + if (varAdded) { + // If a variable was added, synthetic comments are emitted on it, not on the moduleStatement. + setSyntheticLeadingComments(moduleStatement, undefined); + setSyntheticTrailingComments(moduleStatement, undefined); + } + setTextRange(moduleStatement, node); + addEmitFlags(moduleStatement, emitFlags); + statements.push(moduleStatement); + + // Add a DeclarationMarker for the namespace to preserve trailing comments and mark + // the end of the declaration. + statements.push(createEndOfDeclarationMarker(node)); + return statements; + } + + /** + * Transforms the body of a module declaration. + * + * @param node The module declaration node. + */ + function transformModuleBody(node: ModuleDeclaration, namespaceLocalName: Identifier): Block { + const savedCurrentNamespaceContainerName = currentNamespaceContainerName; + const savedCurrentNamespace = currentNamespace; + const savedCurrentScopeFirstDeclarationsOfName = currentScopeFirstDeclarationsOfName; + currentNamespaceContainerName = namespaceLocalName; + currentNamespace = node; + currentScopeFirstDeclarationsOfName = undefined; + + const statements: Statement[] = []; + startLexicalEnvironment(); + + let statementsLocation: TextRange; + let blockLocation: TextRange | undefined; + const body = node.body!; + if (body.kind === SyntaxKind.ModuleBlock) { + saveStateAndInvoke(body, body => addRange(statements, visitNodes((body).statements, namespaceElementVisitor, isStatement))); + statementsLocation = body.statements; + blockLocation = body; + } + else { + const result = visitModuleDeclaration(body); + if (result) { + if (isArray(result)) { + addRange(statements, result); + } + else { + statements.push(result); + } + } + + const moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node)!.body; + statementsLocation = moveRangePos(moduleBlock.statements, -1); + } + + insertStatementsAfterStandardPrologue(statements, endLexicalEnvironment()); + currentNamespaceContainerName = savedCurrentNamespaceContainerName; + currentNamespace = savedCurrentNamespace; + currentScopeFirstDeclarationsOfName = savedCurrentScopeFirstDeclarationsOfName; + + const block = createBlock( + setTextRange( + createNodeArray(statements), + /*location*/ statementsLocation + ), + /*multiLine*/ true + ); + setTextRange(block, blockLocation); + + // namespace hello.hi.world { + // function foo() {} + // + // // TODO, blah + // } + // + // should be emitted as + // + // var hello; + // (function (hello) { + // var hi; + // (function (hi) { + // var world; + // (function (world) { + // function foo() { } + // // TODO, blah + // })(world = hi.world || (hi.world = {})); + // })(hi = hello.hi || (hello.hi = {})); + // })(hello || (hello = {})); + // We only want to emit comment on the namespace which contains block body itself, not the containing namespaces. + if (body.kind !== SyntaxKind.ModuleBlock) { + setEmitFlags(block, getEmitFlags(block) | EmitFlags.NoComments); + } + return block; + } + + function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration: ModuleDeclaration): ModuleDeclaration | undefined { + if (moduleDeclaration.body!.kind === SyntaxKind.ModuleDeclaration) { + const recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); + return recursiveInnerModule || moduleDeclaration.body; + } + } + + /** + * Visits an import declaration, eliding it if it is not referenced. + * + * @param node The import declaration node. + */ + function visitImportDeclaration(node: ImportDeclaration): VisitResult { + if (!node.importClause) { + // Do not elide a side-effect only import declaration. + // import "foo"; + return node; + } + + // Elide the declaration if the import clause was elided. + const importClause = visitNode(node.importClause, visitImportClause, isImportClause); + return importClause + ? updateImportDeclaration( + node, + /*decorators*/ undefined, + /*modifiers*/ undefined, + importClause, + node.moduleSpecifier) + : undefined; + } + + /** + * Visits an import clause, eliding it if it is not referenced. + * + * @param node The import clause node. + */ + function visitImportClause(node: ImportClause): VisitResult { + // Elide the import clause if we elide both its name and its named bindings. + const name = resolver.isReferencedAliasDeclaration(node) ? node.name : undefined; + const namedBindings = visitNode(node.namedBindings, visitNamedImportBindings, isNamedImportBindings); + return (name || namedBindings) ? updateImportClause(node, name, namedBindings) : undefined; + } + + /** + * Visits named import bindings, eliding it if it is not referenced. + * + * @param node The named import bindings node. + */ + function visitNamedImportBindings(node: NamedImportBindings): VisitResult { + if (node.kind === SyntaxKind.NamespaceImport) { + // Elide a namespace import if it is not referenced. + return resolver.isReferencedAliasDeclaration(node) ? node : undefined; + } + else { + // Elide named imports if all of its import specifiers are elided. + const elements = visitNodes(node.elements, visitImportSpecifier, isImportSpecifier); + return some(elements) ? updateNamedImports(node, elements) : undefined; + } + } + + /** + * Visits an import specifier, eliding it if it is not referenced. + * + * @param node The import specifier node. + */ + function visitImportSpecifier(node: ImportSpecifier): VisitResult { + // Elide an import specifier if it is not referenced. + return resolver.isReferencedAliasDeclaration(node) ? node : undefined; + } + + /** + * Visits an export assignment, eliding it if it does not contain a clause that resolves + * to a value. + * + * @param node The export assignment node. + */ + function visitExportAssignment(node: ExportAssignment): VisitResult { + // Elide the export assignment if it does not reference a value. + return resolver.isValueAliasDeclaration(node) + ? visitEachChild(node, visitor, context) + : undefined; + } + + /** + * Visits an export declaration, eliding it if it does not contain a clause that resolves + * to a value. + * + * @param node The export declaration node. + */ + function visitExportDeclaration(node: ExportDeclaration): VisitResult { + if (!node.exportClause) { + // Elide a star export if the module it references does not export a value. + return compilerOptions.isolatedModules || resolver.moduleExportsSomeValue(node.moduleSpecifier!) ? node : undefined; + } + + if (!resolver.isValueAliasDeclaration(node)) { + // Elide the export declaration if it does not export a value. + return undefined; + } + + // Elide the export declaration if all of its named exports are elided. + const exportClause = visitNode(node.exportClause, visitNamedExports, isNamedExports); + return exportClause + ? updateExportDeclaration( + node, + /*decorators*/ undefined, + /*modifiers*/ undefined, + exportClause, + node.moduleSpecifier) + : undefined; + } + + /** + * Visits named exports, eliding it if it does not contain an export specifier that + * resolves to a value. + * + * @param node The named exports node. + */ + function visitNamedExports(node: NamedExports): VisitResult { + // Elide the named exports if all of its export specifiers were elided. + const elements = visitNodes(node.elements, visitExportSpecifier, isExportSpecifier); + return some(elements) ? updateNamedExports(node, elements) : undefined; + } + + /** + * Visits an export specifier, eliding it if it does not resolve to a value. + * + * @param node The export specifier node. + */ + function visitExportSpecifier(node: ExportSpecifier): VisitResult { + // Elide an export specifier if it does not reference a value. + return resolver.isValueAliasDeclaration(node) ? node : undefined; + } + + /** + * Determines whether to emit an import equals declaration. + * + * @param node The import equals declaration node. + */ + function shouldEmitImportEqualsDeclaration(node: ImportEqualsDeclaration) { + // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when + // - current file is not external module + // - import declaration is top level and target is value imported by entity name + return resolver.isReferencedAliasDeclaration(node) + || (!isExternalModule(currentSourceFile) + && resolver.isTopLevelValueImportEqualsWithEntityName(node)); + } + + /** + * Visits an import equals declaration. + * + * @param node The import equals declaration node. + */ + function visitImportEqualsDeclaration(node: ImportEqualsDeclaration): VisitResult { + if (isExternalModuleImportEqualsDeclaration(node)) { + // Elide external module `import=` if it is not referenced. + return resolver.isReferencedAliasDeclaration(node) + ? visitEachChild(node, visitor, context) + : undefined; + } + + if (!shouldEmitImportEqualsDeclaration(node)) { + return undefined; + } + + const moduleReference = createExpressionFromEntityName(node.moduleReference); + setEmitFlags(moduleReference, EmitFlags.NoComments | EmitFlags.NoNestedComments); + + if (isNamedExternalModuleExport(node) || !isExportOfNamespace(node)) { + // export var ${name} = ${moduleReference}; + // var ${name} = ${moduleReference}; + return setOriginalNode( + setTextRange( + createVariableStatement( + visitNodes(node.modifiers, modifierVisitor, isModifier), + createVariableDeclarationList([ + setOriginalNode( + createVariableDeclaration( + node.name, + /*type*/ undefined, + moduleReference + ), + node + ) + ]) + ), + node + ), + node + ); + } + else { + // exports.${name} = ${moduleReference}; + return setOriginalNode( + createNamespaceExport( + node.name, + moduleReference, + node + ), + node + ); + } + } + + /** + * Gets a value indicating whether the node is exported from a namespace. + * + * @param node The node to test. + */ + function isExportOfNamespace(node: Node) { + return currentNamespace !== undefined && hasModifier(node, ModifierFlags.Export); + } + + /** + * Gets a value indicating whether the node is exported from an external module. + * + * @param node The node to test. + */ + function isExternalModuleExport(node: Node) { + return currentNamespace === undefined && hasModifier(node, ModifierFlags.Export); + } + + /** + * Gets a value indicating whether the node is a named export from an external module. + * + * @param node The node to test. + */ + function isNamedExternalModuleExport(node: Node) { + return isExternalModuleExport(node) + && !hasModifier(node, ModifierFlags.Default); + } + + /** + * Gets a value indicating whether the node is the default export of an external module. + * + * @param node The node to test. + */ + function isDefaultExternalModuleExport(node: Node) { + return isExternalModuleExport(node) + && hasModifier(node, ModifierFlags.Default); + } + + /** + * Creates a statement for the provided expression. This is used in calls to `map`. + */ + function expressionToStatement(expression: Expression) { + return createExpressionStatement(expression); + } + + function addExportMemberAssignment(statements: Statement[], node: ClassDeclaration | FunctionDeclaration) { + const expression = createAssignment( + getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true), + getLocalName(node) + ); + setSourceMapRange(expression, createRange(node.name ? node.name.pos : node.pos, node.end)); + + const statement = createExpressionStatement(expression); + setSourceMapRange(statement, createRange(-1, node.end)); + statements.push(statement); + } + + function createNamespaceExport(exportName: Identifier, exportValue: Expression, location?: TextRange) { + return setTextRange( + createExpressionStatement( + createAssignment( + getNamespaceMemberName(currentNamespaceContainerName, exportName, /*allowComments*/ false, /*allowSourceMaps*/ true), + exportValue + ) + ), + location + ); + } + + function createNamespaceExportExpression(exportName: Identifier, exportValue: Expression, location?: TextRange) { + return setTextRange(createAssignment(getNamespaceMemberNameWithSourceMapsAndWithoutComments(exportName), exportValue), location); + } + + function getNamespaceMemberNameWithSourceMapsAndWithoutComments(name: Identifier) { + return getNamespaceMemberName(currentNamespaceContainerName, name, /*allowComments*/ false, /*allowSourceMaps*/ true); + } + + /** + * Gets the declaration name used inside of a namespace or enum. + */ + function getNamespaceParameterName(node: ModuleDeclaration | EnumDeclaration) { + const name = getGeneratedNameForNode(node); + setSourceMapRange(name, node.name); + return name; + } + + /** + * Gets the expression used to refer to a namespace or enum within the body + * of its declaration. + */ + function getNamespaceContainerName(node: ModuleDeclaration | EnumDeclaration) { + return getGeneratedNameForNode(node); + } + + /** + * Gets a local alias for a class declaration if it is a decorated class with an internal + * reference to the static side of the class. This is necessary to avoid issues with + * double-binding semantics for the class name. + */ + function getClassAliasIfNeeded(node: ClassDeclaration) { + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithConstructorReference) { + enableSubstitutionForClassAliases(); + const classAlias = createUniqueName(node.name && !isGeneratedIdentifier(node.name) ? idText(node.name) : "default"); + classAliases[getOriginalNodeId(node)] = classAlias; + hoistVariableDeclaration(classAlias); + return classAlias; + } + } + + function getClassPrototype(node: ClassExpression | ClassDeclaration) { + return createPropertyAccess(getDeclarationName(node), "prototype"); + } + + function getClassMemberPrefix(node: ClassExpression | ClassDeclaration, member: ClassElement) { + return hasModifier(member, ModifierFlags.Static) + ? getDeclarationName(node) + : getClassPrototype(node); + } + + function enableSubstitutionForNonQualifiedEnumMembers() { + if ((enabledSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers) === 0) { + enabledSubstitutions |= TypeScriptSubstitutionFlags.NonQualifiedEnumMembers; + context.enableSubstitution(SyntaxKind.Identifier); + } + } + + function enableSubstitutionForClassAliases() { + if ((enabledSubstitutions & TypeScriptSubstitutionFlags.ClassAliases) === 0) { + enabledSubstitutions |= TypeScriptSubstitutionFlags.ClassAliases; + + // We need to enable substitutions for identifiers. This allows us to + // substitute class names inside of a class declaration. + context.enableSubstitution(SyntaxKind.Identifier); + + // Keep track of class aliases. + classAliases = []; + } + } + + function enableSubstitutionForNamespaceExports() { + if ((enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) === 0) { + enabledSubstitutions |= TypeScriptSubstitutionFlags.NamespaceExports; + + // We need to enable substitutions for identifiers and shorthand property assignments. This allows us to + // substitute the names of exported members of a namespace. + context.enableSubstitution(SyntaxKind.Identifier); + context.enableSubstitution(SyntaxKind.ShorthandPropertyAssignment); + + // We need to be notified when entering and exiting namespaces. + context.enableEmitNotification(SyntaxKind.ModuleDeclaration); + } + } + + function isTransformedModuleDeclaration(node: Node): boolean { + return getOriginalNode(node).kind === SyntaxKind.ModuleDeclaration; + } + + function isTransformedEnumDeclaration(node: Node): boolean { + return getOriginalNode(node).kind === SyntaxKind.EnumDeclaration; + } + + /** + * Hook for node emit. + * + * @param hint A hint as to the intended usage of the node. + * @param node The node to emit. + * @param emit A callback used to emit the node in the printer. + */ + function onEmitNode(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void): void { + const savedApplicableSubstitutions = applicableSubstitutions; + const savedCurrentSourceFile = currentSourceFile; + + if (isSourceFile(node)) { + currentSourceFile = node; + } + + if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && isTransformedModuleDeclaration(node)) { + applicableSubstitutions |= TypeScriptSubstitutionFlags.NamespaceExports; + } + + if (enabledSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers && isTransformedEnumDeclaration(node)) { + applicableSubstitutions |= TypeScriptSubstitutionFlags.NonQualifiedEnumMembers; + } + + previousOnEmitNode(hint, node, emitCallback); + + applicableSubstitutions = savedApplicableSubstitutions; + currentSourceFile = savedCurrentSourceFile; + } + + /** + * Hooks node substitutions. + * + * @param hint A hint as to the intended usage of the node. + * @param node The node to substitute. + */ + function onSubstituteNode(hint: EmitHint, node: Node) { + node = previousOnSubstituteNode(hint, node); + if (hint === EmitHint.Expression) { + return substituteExpression(node); + } + else if (isShorthandPropertyAssignment(node)) { + return substituteShorthandPropertyAssignment(node); + } + + return node; + } + + function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike { + if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) { + const name = node.name; + const exportedName = trySubstituteNamespaceExportedName(name); + if (exportedName) { + // A shorthand property with an assignment initializer is probably part of a + // destructuring assignment + if (node.objectAssignmentInitializer) { + const initializer = createAssignment(exportedName, node.objectAssignmentInitializer); + return setTextRange(createPropertyAssignment(name, initializer), node); + } + return setTextRange(createPropertyAssignment(name, exportedName), node); + } + } + return node; + } + + function substituteExpression(node: Expression) { + switch (node.kind) { + case SyntaxKind.Identifier: + return substituteExpressionIdentifier(node); + case SyntaxKind.PropertyAccessExpression: + return substitutePropertyAccessExpression(node); + case SyntaxKind.ElementAccessExpression: + return substituteElementAccessExpression(node); + } + + return node; + } + + function substituteExpressionIdentifier(node: Identifier): Expression { + return trySubstituteClassAlias(node) + || trySubstituteNamespaceExportedName(node) + || node; + } + + function trySubstituteClassAlias(node: Identifier): Expression | undefined { + if (enabledSubstitutions & TypeScriptSubstitutionFlags.ClassAliases) { + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ConstructorReferenceInClass) { + // Due to the emit for class decorators, any reference to the class from inside of the class body + // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind + // behavior of class names in ES6. + // Also, when emitting statics for class expressions, we must substitute a class alias for + // constructor references in static property initializers. + const declaration = resolver.getReferencedValueDeclaration(node); + if (declaration) { + const classAlias = classAliases[declaration.id!]; // TODO: GH#18217 + if (classAlias) { + const clone = getSynthesizedClone(classAlias); + setSourceMapRange(clone, node); + setCommentRange(clone, node); + return clone; + } + } + } + } + + return undefined; + } + + function trySubstituteNamespaceExportedName(node: Identifier): Expression | undefined { + // If this is explicitly a local name, do not substitute. + if (enabledSubstitutions & applicableSubstitutions && !isGeneratedIdentifier(node) && !isLocalName(node)) { + // If we are nested within a namespace declaration, we may need to qualifiy + // an identifier that is exported from a merged namespace. + const container = resolver.getReferencedExportContainer(node, /*prefixLocals*/ false); + if (container && container.kind !== SyntaxKind.SourceFile) { + const substitute = + (applicableSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && container.kind === SyntaxKind.ModuleDeclaration) || + (applicableSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers && container.kind === SyntaxKind.EnumDeclaration); + if (substitute) { + return setTextRange( + createPropertyAccess(getGeneratedNameForNode(container), node), + /*location*/ node + ); + } + } + } + + return undefined; + } + + function substitutePropertyAccessExpression(node: PropertyAccessExpression) { + return substituteConstantValue(node); + } + + function substituteElementAccessExpression(node: ElementAccessExpression) { + return substituteConstantValue(node); + } + + function substituteConstantValue(node: PropertyAccessExpression | ElementAccessExpression): LeftHandSideExpression { + const constantValue = tryGetConstEnumValue(node); + if (constantValue !== undefined) { + // track the constant value on the node for the printer in needsDotDotForPropertyAccess + setConstantValue(node, constantValue); + + const substitute = createLiteral(constantValue); + if (!compilerOptions.removeComments) { + const propertyName = isPropertyAccessExpression(node) + ? declarationNameToString(node.name) + : getTextOfNode(node.argumentExpression); + + addSyntheticTrailingComment(substitute, SyntaxKind.MultiLineCommentTrivia, ` ${propertyName} `); + } + + return substitute; + } + + return node; + } + + function tryGetConstEnumValue(node: Node): string | number | undefined { + if (compilerOptions.isolatedModules) { + return undefined; + } + + return isPropertyAccessExpression(node) || isElementAccessExpression(node) ? resolver.getConstantValue(node) : undefined; + } + } + + function createDecorateHelper(context: TransformationContext, decoratorExpressions: Expression[], target: Expression, memberName?: Expression, descriptor?: Expression, location?: TextRange) { + const argumentsArray: Expression[] = []; + argumentsArray.push(createArrayLiteral(decoratorExpressions, /*multiLine*/ true)); + argumentsArray.push(target); + if (memberName) { + argumentsArray.push(memberName); + if (descriptor) { + argumentsArray.push(descriptor); + } + } + + context.requestEmitHelper(decorateHelper); + return setTextRange( + createCall( + getUnscopedHelperName("__decorate"), + /*typeArguments*/ undefined, + argumentsArray + ), + location + ); + } + + export const decorateHelper: UnscopedEmitHelper = { + name: "typescript:decorate", + importName: "__decorate", + scoped: false, + priority: 2, + text: ` + var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; + };` + }; + + function createMetadataHelper(context: TransformationContext, metadataKey: string, metadataValue: Expression) { + context.requestEmitHelper(metadataHelper); + return createCall( + getUnscopedHelperName("__metadata"), + /*typeArguments*/ undefined, + [ + createLiteral(metadataKey), + metadataValue + ] + ); + } + + export const metadataHelper: UnscopedEmitHelper = { + name: "typescript:metadata", + importName: "__metadata", + scoped: false, + priority: 3, + text: ` + var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); + };` + }; + + function createParamHelper(context: TransformationContext, expression: Expression, parameterOffset: number, location?: TextRange) { + context.requestEmitHelper(paramHelper); + return setTextRange( + createCall( + getUnscopedHelperName("__param"), + /*typeArguments*/ undefined, + [ + createLiteral(parameterOffset), + expression + ] + ), + location + ); + } + + export const paramHelper: UnscopedEmitHelper = { + name: "typescript:param", + importName: "__param", + scoped: false, + priority: 4, + text: ` + var __param = (this && this.__param) || function (paramIndex, decorator) { + return function (target, key) { decorator(target, key, paramIndex); } + };` + }; +} diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index de4400a24f45d..bede6ca37206b 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -1,337 +1,325 @@ -/* @internal */ -namespace ts { - export function getOriginalNodeId(node: Node) { - node = getOriginalNode(node); - return node ? getNodeId(node) : 0; - } - - export interface ExternalModuleInfo { - externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; // imports of other external modules - externalHelpersImportDeclaration: ImportDeclaration | undefined; // import of external helpers - exportSpecifiers: Map; // export specifiers by name - exportedBindings: Identifier[][]; // exported names of local declarations - exportedNames: Identifier[] | undefined; // all exported names local to module - exportEquals: ExportAssignment | undefined; // an export= declaration if one was present - hasExportStarsToExportValues: boolean; // whether this module contains export* - } - - function containsDefaultReference(node: NamedImportBindings | undefined) { - if (!node) return false; - if (!isNamedImports(node)) return false; - return some(node.elements, isNamedDefaultReference); - } - - function isNamedDefaultReference(e: ImportSpecifier): boolean { - return e.propertyName !== undefined && e.propertyName.escapedText === InternalSymbolName.Default; - } - - export function chainBundle(transformSourceFile: (x: SourceFile) => SourceFile): (x: SourceFile | Bundle) => SourceFile | Bundle { - return transformSourceFileOrBundle; - - function transformSourceFileOrBundle(node: SourceFile | Bundle) { - return node.kind === SyntaxKind.SourceFile ? transformSourceFile(node) : transformBundle(node); - } - - function transformBundle(node: Bundle) { - return createBundle(map(node.sourceFiles, transformSourceFile), node.prepends); - } - } - - export function getImportNeedsImportStarHelper(node: ImportDeclaration): boolean { - if (!!getNamespaceDeclarationNode(node)) { - return true; - } - const bindings = node.importClause && node.importClause.namedBindings; - if (!bindings) { - return false; - } - if (!isNamedImports(bindings)) return false; - let defaultRefCount = 0; - for (const binding of bindings.elements) { - if (isNamedDefaultReference(binding)) { - defaultRefCount++; - } - } - // Import star is required if there's default named refs mixed with non-default refs, or if theres non-default refs and it has a default import - return (defaultRefCount > 0 && defaultRefCount !== bindings.elements.length) || (!!(bindings.elements.length - defaultRefCount) && isDefaultImport(node)); - } - - export function getImportNeedsImportDefaultHelper(node: ImportDeclaration): boolean { - // Import default is needed if there's a default import or a default ref and no other refs (meaning an import star helper wasn't requested) - return !getImportNeedsImportStarHelper(node) && (isDefaultImport(node) || (!!node.importClause && isNamedImports(node.importClause.namedBindings!) && containsDefaultReference(node.importClause.namedBindings))); // TODO: GH#18217 - } - - export function collectExternalModuleInfo(sourceFile: SourceFile, resolver: EmitResolver, compilerOptions: CompilerOptions): ExternalModuleInfo { - const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = []; - const exportSpecifiers = createMultiMap(); - const exportedBindings: Identifier[][] = []; - const uniqueExports = createMap(); - let exportedNames: Identifier[] | undefined; - let hasExportDefault = false; - let exportEquals: ExportAssignment | undefined; - let hasExportStarsToExportValues = false; - let hasImportStar = false; - let hasImportDefault = false; - - for (const node of sourceFile.statements) { - switch (node.kind) { - case SyntaxKind.ImportDeclaration: - // import "mod" - // import x from "mod" - // import * as x from "mod" - // import { x, y } from "mod" - externalImports.push(node); - if (!hasImportStar && getImportNeedsImportStarHelper(node)) { - hasImportStar = true; - } - if (!hasImportDefault && getImportNeedsImportDefaultHelper(node)) { - hasImportDefault = true; - } - break; - - case SyntaxKind.ImportEqualsDeclaration: - if ((node).moduleReference.kind === SyntaxKind.ExternalModuleReference) { - // import x = require("mod") - externalImports.push(node); - } - - break; - - case SyntaxKind.ExportDeclaration: - if ((node).moduleSpecifier) { - if (!(node).exportClause) { - // export * from "mod" - externalImports.push(node); - hasExportStarsToExportValues = true; - } - else { - // export { x, y } from "mod" - externalImports.push(node); - } - } - else { - // export { x, y } - for (const specifier of (node).exportClause!.elements) { - if (!uniqueExports.get(idText(specifier.name))) { - const name = specifier.propertyName || specifier.name; - exportSpecifiers.add(idText(name), specifier); - - const decl = resolver.getReferencedImportDeclaration(name) - || resolver.getReferencedValueDeclaration(name); - - if (decl) { - multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(decl), specifier.name); - } - - uniqueExports.set(idText(specifier.name), true); - exportedNames = append(exportedNames, specifier.name); - } - } - } - break; - - case SyntaxKind.ExportAssignment: - if ((node).isExportEquals && !exportEquals) { - // export = x - exportEquals = node; - } - break; - - case SyntaxKind.VariableStatement: - if (hasModifier(node, ModifierFlags.Export)) { - for (const decl of (node).declarationList.declarations) { - exportedNames = collectExportedVariableInfo(decl, uniqueExports, exportedNames); - } - } - break; - - case SyntaxKind.FunctionDeclaration: - if (hasModifier(node, ModifierFlags.Export)) { - if (hasModifier(node, ModifierFlags.Default)) { - // export default function() { } - if (!hasExportDefault) { - multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), getDeclarationName(node)); - hasExportDefault = true; - } - } - else { - // export function x() { } - const name = (node).name!; - if (!uniqueExports.get(idText(name))) { - multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name); - uniqueExports.set(idText(name), true); - exportedNames = append(exportedNames, name); - } - } - } - break; - - case SyntaxKind.ClassDeclaration: - if (hasModifier(node, ModifierFlags.Export)) { - if (hasModifier(node, ModifierFlags.Default)) { - // export default class { } - if (!hasExportDefault) { - multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), getDeclarationName(node)); - hasExportDefault = true; - } - } - else { - // export class x { } - const name = (node).name; - if (name && !uniqueExports.get(idText(name))) { - multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name); - uniqueExports.set(idText(name), true); - exportedNames = append(exportedNames, name); - } - } - } - break; - } - } - - const externalHelpersImportDeclaration = createExternalHelpersImportDeclarationIfNeeded(sourceFile, compilerOptions, hasExportStarsToExportValues, hasImportStar, hasImportDefault); - if (externalHelpersImportDeclaration) { - externalImports.unshift(externalHelpersImportDeclaration); - } - - return { externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues, exportedBindings, exportedNames, externalHelpersImportDeclaration }; - } - - function collectExportedVariableInfo(decl: VariableDeclaration | BindingElement, uniqueExports: Map, exportedNames: Identifier[] | undefined) { - if (isBindingPattern(decl.name)) { - for (const element of decl.name.elements) { - if (!isOmittedExpression(element)) { - exportedNames = collectExportedVariableInfo(element, uniqueExports, exportedNames); - } - } - } - else if (!isGeneratedIdentifier(decl.name)) { - const text = idText(decl.name); - if (!uniqueExports.get(text)) { - uniqueExports.set(text, true); - exportedNames = append(exportedNames, decl.name); - } - } - return exportedNames; - } - - /** Use a sparse array as a multi-map. */ - function multiMapSparseArrayAdd(map: V[][], key: number, value: V): V[] { - let values = map[key]; - if (values) { - values.push(value); - } - else { - map[key] = values = [value]; - } - return values; - } - - /** - * Used in the module transformer to check if an expression is reasonably without sideeffect, - * and thus better to copy into multiple places rather than to cache in a temporary variable - * - this is mostly subjective beyond the requirement that the expression not be sideeffecting - */ - export function isSimpleCopiableExpression(expression: Expression) { - return isStringLiteralLike(expression) || - expression.kind === SyntaxKind.NumericLiteral || - isKeyword(expression.kind) || - isIdentifier(expression); - } - - /** - * A simple inlinable expression is an expression which can be copied into multiple locations - * without risk of repeating any sideeffects and whose value could not possibly change between - * any such locations - */ - export function isSimpleInlineableExpression(expression: Expression) { - return !isIdentifier(expression) && isSimpleCopiableExpression(expression) || - isWellKnownSymbolSyntactically(expression); - } - - /** - * Adds super call and preceding prologue directives into the list of statements. - * - * @param ctor The constructor node. - * @param result The list of statements. - * @param visitor The visitor to apply to each node added to the result array. - * @returns index of the statement that follows super call - */ - export function addPrologueDirectivesAndInitialSuperCall(ctor: ConstructorDeclaration, result: Statement[], visitor: Visitor): number { - if (ctor.body) { - const statements = ctor.body.statements; - // add prologue directives to the list (if any) - const index = addPrologue(result, statements, /*ensureUseStrict*/ false, visitor); - if (index === statements.length) { - // list contains nothing but prologue directives (or empty) - exit - return index; - } - - const statement = statements[index]; - if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCall((statement).expression)) { - result.push(visitNode(statement, visitor, isStatement)); - return index + 1; - } - - return index; - } - - return 0; - } - - - /** - * @param input Template string input strings - * @param args Names which need to be made file-level unique - */ - export function helperString(input: TemplateStringsArray, ...args: string[]) { - return (uniqueName: EmitHelperUniqueNameCallback) => { - let result = ""; - for (let i = 0; i < args.length; i++) { - result += input[i]; - result += uniqueName(args[i]); - } - result += input[input.length - 1]; - return result; - }; - } - - /** - * Gets all property declarations with initializers on either the static or instance side of a class. - * - * @param node The class node. - * @param isStatic A value indicating whether to get properties from the static or instance side of the class. - */ - export function getInitializedProperties(node: ClassExpression | ClassDeclaration, isStatic: boolean): readonly PropertyDeclaration[] { - return filter(node.members, isStatic ? isStaticInitializedProperty : isInstanceInitializedProperty); - } - - /** - * Gets a value indicating whether a class element is a static property declaration with an initializer. - * - * @param member The class element node. - */ - export function isStaticInitializedProperty(member: ClassElement): member is PropertyDeclaration & { initializer: Expression; } { - return isInitializedProperty(member) && hasStaticModifier(member); - } - - /** - * Gets a value indicating whether a class element is an instance property declaration with an initializer. - * - * @param member The class element node. - */ - export function isInstanceInitializedProperty(member: ClassElement): member is PropertyDeclaration & { initializer: Expression; } { - return isInitializedProperty(member) && !hasStaticModifier(member); - } - - /** - * Gets a value indicating whether a class element is either a static or an instance property declaration with an initializer. - * - * @param member The class element node. - * @param isStatic A value indicating whether the member should be a static or instance member. - */ - export function isInitializedProperty(member: ClassElement): member is PropertyDeclaration & { initializer: Expression; } { - return member.kind === SyntaxKind.PropertyDeclaration - && (member).initializer !== undefined; - } -} \ No newline at end of file +/* @internal */ +namespace ts { + export function getOriginalNodeId(node: Node) { + node = getOriginalNode(node); + return node ? getNodeId(node) : 0; + } + + export interface ExternalModuleInfo { + externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; // imports of other external modules + externalHelpersImportDeclaration: ImportDeclaration | undefined; // import of external helpers + exportSpecifiers: Map; // export specifiers by name + exportedBindings: Identifier[][]; // exported names of local declarations + exportedNames: Identifier[] | undefined; // all exported names local to module + exportEquals: ExportAssignment | undefined; // an export= declaration if one was present + hasExportStarsToExportValues: boolean; // whether this module contains export* + } + + function containsDefaultReference(node: NamedImportBindings | undefined) { + if (!node) return false; + if (!isNamedImports(node)) return false; + return some(node.elements, isNamedDefaultReference); + } + + function isNamedDefaultReference(e: ImportSpecifier): boolean { + return e.propertyName !== undefined && e.propertyName.escapedText === InternalSymbolName.Default; + } + + export function chainBundle(transformSourceFile: (x: SourceFile) => SourceFile): (x: SourceFile | Bundle) => SourceFile | Bundle { + return transformSourceFileOrBundle; + + function transformSourceFileOrBundle(node: SourceFile | Bundle) { + return node.kind === SyntaxKind.SourceFile ? transformSourceFile(node) : transformBundle(node); + } + + function transformBundle(node: Bundle) { + return createBundle(map(node.sourceFiles, transformSourceFile), node.prepends); + } + } + + export function getImportNeedsImportStarHelper(node: ImportDeclaration): boolean { + if (!!getNamespaceDeclarationNode(node)) { + return true; + } + const bindings = node.importClause && node.importClause.namedBindings; + if (!bindings) { + return false; + } + if (!isNamedImports(bindings)) return false; + let defaultRefCount = 0; + for (const binding of bindings.elements) { + if (isNamedDefaultReference(binding)) { + defaultRefCount++; + } + } + // Import star is required if there's default named refs mixed with non-default refs, or if theres non-default refs and it has a default import + return (defaultRefCount > 0 && defaultRefCount !== bindings.elements.length) || (!!(bindings.elements.length - defaultRefCount) && isDefaultImport(node)); + } + + export function getImportNeedsImportDefaultHelper(node: ImportDeclaration): boolean { + // Import default is needed if there's a default import or a default ref and no other refs (meaning an import star helper wasn't requested) + return !getImportNeedsImportStarHelper(node) && (isDefaultImport(node) || (!!node.importClause && isNamedImports(node.importClause.namedBindings!) && containsDefaultReference(node.importClause.namedBindings))); // TODO: GH#18217 + } + + export function collectExternalModuleInfo(sourceFile: SourceFile, resolver: EmitResolver, compilerOptions: CompilerOptions): ExternalModuleInfo { + const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = []; + const exportSpecifiers = createMultiMap(); + const exportedBindings: Identifier[][] = []; + const uniqueExports = createMap(); + let exportedNames: Identifier[] | undefined; + let hasExportDefault = false; + let exportEquals: ExportAssignment | undefined; + let hasExportStarsToExportValues = false; + let hasImportStar = false; + let hasImportDefault = false; + + for (const node of sourceFile.statements) { + switch (node.kind) { + case SyntaxKind.ImportDeclaration: + // import "mod" + // import x from "mod" + // import * as x from "mod" + // import { x, y } from "mod" + externalImports.push(node); + if (!hasImportStar && getImportNeedsImportStarHelper(node)) { + hasImportStar = true; + } + if (!hasImportDefault && getImportNeedsImportDefaultHelper(node)) { + hasImportDefault = true; + } + break; + + case SyntaxKind.ImportEqualsDeclaration: + if ((node).moduleReference.kind === SyntaxKind.ExternalModuleReference) { + // import x = require("mod") + externalImports.push(node); + } + + break; + + case SyntaxKind.ExportDeclaration: + if ((node).moduleSpecifier) { + if (!(node).exportClause) { + // export * from "mod" + externalImports.push(node); + hasExportStarsToExportValues = true; + } + else { + // export { x, y } from "mod" + externalImports.push(node); + } + } + else { + // export { x, y } + for (const specifier of (node).exportClause!.elements) { + if (!uniqueExports.get(idText(specifier.name))) { + const name = specifier.propertyName || specifier.name; + exportSpecifiers.add(idText(name), specifier); + + const decl = resolver.getReferencedImportDeclaration(name) + || resolver.getReferencedValueDeclaration(name); + + if (decl) { + multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(decl), specifier.name); + } + + uniqueExports.set(idText(specifier.name), true); + exportedNames = append(exportedNames, specifier.name); + } + } + } + break; + + case SyntaxKind.ExportAssignment: + if ((node).isExportEquals && !exportEquals) { + // export = x + exportEquals = node; + } + break; + + case SyntaxKind.VariableStatement: + if (hasModifier(node, ModifierFlags.Export)) { + for (const decl of (node).declarationList.declarations) { + exportedNames = collectExportedVariableInfo(decl, uniqueExports, exportedNames); + } + } + break; + + case SyntaxKind.FunctionDeclaration: + if (hasModifier(node, ModifierFlags.Export)) { + if (hasModifier(node, ModifierFlags.Default)) { + // export default function() { } + if (!hasExportDefault) { + multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), getDeclarationName(node)); + hasExportDefault = true; + } + } + else { + // export function x() { } + const name = (node).name!; + if (!uniqueExports.get(idText(name))) { + multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name); + uniqueExports.set(idText(name), true); + exportedNames = append(exportedNames, name); + } + } + } + break; + + case SyntaxKind.ClassDeclaration: + if (hasModifier(node, ModifierFlags.Export)) { + if (hasModifier(node, ModifierFlags.Default)) { + // export default class { } + if (!hasExportDefault) { + multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), getDeclarationName(node)); + hasExportDefault = true; + } + } + else { + // export class x { } + const name = (node).name; + if (name && !uniqueExports.get(idText(name))) { + multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name); + uniqueExports.set(idText(name), true); + exportedNames = append(exportedNames, name); + } + } + } + break; + } + } + + const externalHelpersImportDeclaration = createExternalHelpersImportDeclarationIfNeeded(sourceFile, compilerOptions, hasExportStarsToExportValues, hasImportStar, hasImportDefault); + if (externalHelpersImportDeclaration) { + externalImports.unshift(externalHelpersImportDeclaration); + } + + return { externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues, exportedBindings, exportedNames, externalHelpersImportDeclaration }; + } + + function collectExportedVariableInfo(decl: VariableDeclaration | BindingElement, uniqueExports: Map, exportedNames: Identifier[] | undefined) { + if (isBindingPattern(decl.name)) { + for (const element of decl.name.elements) { + if (!isOmittedExpression(element)) { + exportedNames = collectExportedVariableInfo(element, uniqueExports, exportedNames); + } + } + } + else if (!isGeneratedIdentifier(decl.name)) { + const text = idText(decl.name); + if (!uniqueExports.get(text)) { + uniqueExports.set(text, true); + exportedNames = append(exportedNames, decl.name); + } + } + return exportedNames; + } + + /** Use a sparse array as a multi-map. */ + function multiMapSparseArrayAdd(map: V[][], key: number, value: V): V[] { + let values = map[key]; + if (values) { + values.push(value); + } + else { + map[key] = values = [value]; + } + return values; + } + + /** + * Used in the module transformer to check if an expression is reasonably without sideeffect, + * and thus better to copy into multiple places rather than to cache in a temporary variable + * - this is mostly subjective beyond the requirement that the expression not be sideeffecting + */ + export function isSimpleCopiableExpression(expression: Expression) { + return isStringLiteralLike(expression) || + expression.kind === SyntaxKind.NumericLiteral || + isKeyword(expression.kind) || + isIdentifier(expression); + } + + /** + * A simple inlinable expression is an expression which can be copied into multiple locations + * without risk of repeating any sideeffects and whose value could not possibly change between + * any such locations + */ + export function isSimpleInlineableExpression(expression: Expression) { + return !isIdentifier(expression) && isSimpleCopiableExpression(expression) || + isWellKnownSymbolSyntactically(expression); + } + + /** + * Adds super call and preceding prologue directives into the list of statements. + * + * @param ctor The constructor node. + * @param result The list of statements. + * @param visitor The visitor to apply to each node added to the result array. + * @returns index of the statement that follows super call + */ + export function addPrologueDirectivesAndInitialSuperCall(ctor: ConstructorDeclaration, result: Statement[], visitor: Visitor): number { + if (ctor.body) { + const statements = ctor.body.statements; + // add prologue directives to the list (if any) + const index = addPrologue(result, statements, /*ensureUseStrict*/ false, visitor); + if (index === statements.length) { + // list contains nothing but prologue directives (or empty) - exit + return index; + } + + const statement = statements[index]; + if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCall((statement).expression)) { + result.push(visitNode(statement, visitor, isStatement)); + return index + 1; + } + + return index; + } + + return 0; + } + + + /** + * @param input Template string input strings + * @param args Names which need to be made file-level unique + */ + export function helperString(input: TemplateStringsArray, ...args: string[]) { + return (uniqueName: EmitHelperUniqueNameCallback) => { + let result = ""; + for (let i = 0; i < args.length; i++) { + result += input[i]; + result += uniqueName(args[i]); + } + result += input[input.length - 1]; + return result; + }; + } + + /** + * Gets all the static or all the instance property declarations of a class + * + * @param node The class node. + * @param isStatic A value indicating whether to get properties from the static or instance side of the class. + */ + export function getProperties(node: ClassExpression | ClassDeclaration, requireInitializer: boolean, isStatic: boolean): readonly PropertyDeclaration[] { + return filter(node.members, m => isInitializedOrStaticProperty(m, requireInitializer, isStatic)) as PropertyDeclaration[]; + } + + /** + * Is a class element is either a static or an instance property declaration with an initializer? + * + * @param member The class element node. + * @param isStatic A value indicating whether the member should be a static or instance member. + */ + function isInitializedOrStaticProperty(member: ClassElement, requireInitializer: boolean, isStatic: boolean) { + return isPropertyDeclaration(member) + && !!member.initializer === requireInitializer + && hasStaticModifier(member) === isStatic; + } + + export function isInitializedProperty(member: ClassElement, requireInitializer: boolean): member is PropertyDeclaration { + return isPropertyDeclaration(member) && !!member.initializer === requireInitializer; + } + +} diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1828d056405c6..ba8947c581bdc 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4803,13 +4803,14 @@ namespace ts { /*@internal*/ watch?: boolean; esModuleInterop?: boolean; /* @internal */ showConfig?: boolean; + legacyClassFields?: boolean; [option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined; } export interface TypeAcquisition { /* @deprecated typingOptions.enableAutoDiscovery - * Use typeAcquisition.enable instead. + * Use typeAcquisition.enable instead. */ enableAutoDiscovery?: boolean; enable?: boolean; diff --git a/tests/baselines/reference/accessorsOverrideProperty6.js b/tests/baselines/reference/accessorsOverrideProperty6.js new file mode 100644 index 0000000000000..3cd61062c8626 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty6.js @@ -0,0 +1,39 @@ +//// [accessorsOverrideProperty6.ts] +class A { + p = 'yep' +} +class B extends A { + get p() { return 'oh no' } // error +} +class C { + p = 101 +} +class D extends C { + _secret = 11 + get p() { return this._secret } // error + set p(value) { this._secret = value } // error +} + + +//// [accessorsOverrideProperty6.js] +class A { + constructor() { + this.p = 'yep'; + } +} +class B extends A { + get p() { return 'oh no'; } // error +} +class C { + constructor() { + this.p = 101; + } +} +class D extends C { + constructor() { + super(...arguments); + this._secret = 11; + } + get p() { return this._secret; } // error + set p(value) { this._secret = value; } // error +} diff --git a/tests/baselines/reference/accessorsOverrideProperty6.symbols b/tests/baselines/reference/accessorsOverrideProperty6.symbols new file mode 100644 index 0000000000000..19f93b02630bc --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty6.symbols @@ -0,0 +1,42 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty6.ts === +class A { +>A : Symbol(A, Decl(accessorsOverrideProperty6.ts, 0, 0)) + + p = 'yep' +>p : Symbol(A.p, Decl(accessorsOverrideProperty6.ts, 0, 9)) +} +class B extends A { +>B : Symbol(B, Decl(accessorsOverrideProperty6.ts, 2, 1)) +>A : Symbol(A, Decl(accessorsOverrideProperty6.ts, 0, 0)) + + get p() { return 'oh no' } // error +>p : Symbol(B.p, Decl(accessorsOverrideProperty6.ts, 3, 19)) +} +class C { +>C : Symbol(C, Decl(accessorsOverrideProperty6.ts, 5, 1)) + + p = 101 +>p : Symbol(C.p, Decl(accessorsOverrideProperty6.ts, 6, 9)) +} +class D extends C { +>D : Symbol(D, Decl(accessorsOverrideProperty6.ts, 8, 1)) +>C : Symbol(C, Decl(accessorsOverrideProperty6.ts, 5, 1)) + + _secret = 11 +>_secret : Symbol(D._secret, Decl(accessorsOverrideProperty6.ts, 9, 19)) + + get p() { return this._secret } // error +>p : Symbol(D.p, Decl(accessorsOverrideProperty6.ts, 10, 17), Decl(accessorsOverrideProperty6.ts, 11, 35)) +>this._secret : Symbol(D._secret, Decl(accessorsOverrideProperty6.ts, 9, 19)) +>this : Symbol(D, Decl(accessorsOverrideProperty6.ts, 8, 1)) +>_secret : Symbol(D._secret, Decl(accessorsOverrideProperty6.ts, 9, 19)) + + set p(value) { this._secret = value } // error +>p : Symbol(D.p, Decl(accessorsOverrideProperty6.ts, 10, 17), Decl(accessorsOverrideProperty6.ts, 11, 35)) +>value : Symbol(value, Decl(accessorsOverrideProperty6.ts, 12, 10)) +>this._secret : Symbol(D._secret, Decl(accessorsOverrideProperty6.ts, 9, 19)) +>this : Symbol(D, Decl(accessorsOverrideProperty6.ts, 8, 1)) +>_secret : Symbol(D._secret, Decl(accessorsOverrideProperty6.ts, 9, 19)) +>value : Symbol(value, Decl(accessorsOverrideProperty6.ts, 12, 10)) +} + diff --git a/tests/baselines/reference/accessorsOverrideProperty6.types b/tests/baselines/reference/accessorsOverrideProperty6.types new file mode 100644 index 0000000000000..594dbd372adef --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty6.types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty6.ts === +class A { +>A : A + + p = 'yep' +>p : string +>'yep' : "yep" +} +class B extends A { +>B : B +>A : A + + get p() { return 'oh no' } // error +>p : string +>'oh no' : "oh no" +} +class C { +>C : C + + p = 101 +>p : number +>101 : 101 +} +class D extends C { +>D : D +>C : C + + _secret = 11 +>_secret : number +>11 : 11 + + get p() { return this._secret } // error +>p : number +>this._secret : number +>this : this +>_secret : number + + set p(value) { this._secret = value } // error +>p : number +>value : number +>this._secret = value : number +>this._secret : number +>this : this +>_secret : number +>value : number +} + diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts index 3bf85e9ddd2c1..7db56312022ba 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts @@ -1,10 +1,11 @@ -// @target: esnext -interface I { - p: number -} -interface B extends I { } -class B { } -class C extends B { - get p() { return 1 } - set p(value) { } -} +// @target: esnext +// @legacyClassFields: false +interface I { + p: number +} +interface B extends I { } +class B { } +class C extends B { + get p() { return 1 } + set p(value) { } +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty6.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty6.ts new file mode 100644 index 0000000000000..6c67a968ee913 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty6.ts @@ -0,0 +1,16 @@ +// @target: esnext +// @legacyClassFields: true +class A { + p = 'yep' +} +class B extends A { + get p() { return 'oh no' } // error +} +class C { + p = 101 +} +class D extends C { + _secret = 11 + get p() { return this._secret } // error + set p(value) { this._secret = value } // error +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts index b9dc49c574005..e1c5f49d316af 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts @@ -1,4 +1,4 @@ -// @target: esnext +// @target: es2015 class A { get p() { return 'oh no' } } From 6c35ac26c6004d7a9c67620b33ffb6b807054092 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 20 Sep 2019 08:48:03 -0700 Subject: [PATCH 30/44] Basically right emit --- src/compiler/transformers/classFields.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 716e196f3b87a..70f5218b718d5 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -427,17 +427,27 @@ namespace ts { const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) ? updateComputedPropertyName(property.name, getGeneratedNameForNode(property.name)) : property.name; - const initializer = visitNode(property.initializer, visitor, isExpression); const memberAccess = createMemberAccessForPropertyName(receiver, propertyName, /*location*/ propertyName); - + const initializer = visitNode(property.initializer, visitor, isExpression); return createAssignment(memberAccess, initializer); } else { - return createIdentifier('hi'); - // return createCall(); + // We generate a name here in order to reuse the value cached by the relocated computed name expression (which uses the same generated name) + const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) + ? updateComputedPropertyName(property.name, getGeneratedNameForNode(property.name)) + : property.name; + const initializer = property.initializer ? visitNode(property.initializer, visitor, isExpression) : createVoidZero() + return createObjectDefineForPropertyName(receiver, propertyName, initializer); } } + function createObjectDefineForPropertyName(target: Expression, name: PropertyName, initializer: Expression) { + return createCall( + createPropertyAccess(createIdentifier("Object"), createIdentifier("defineProperty")), + undefined, + [target, isComputedPropertyName(name) ? name.expression : name, createObjectLiteral([createPropertyAssignment("value", initializer)])]); + } + function enableSubstitutionForClassAliases() { if ((enabledSubstitutions & ClassPropertySubstitutionFlags.ClassAliases) === 0) { enabledSubstitutions |= ClassPropertySubstitutionFlags.ClassAliases; From fbeaf0198f4a9c70af5b7bbe6a1dd02b6991a561 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 20 Sep 2019 09:03:39 -0700 Subject: [PATCH 31/44] Fix one last unitialised property declaration --- src/testRunner/unittests/tsserver/helpers.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/testRunner/unittests/tsserver/helpers.ts b/src/testRunner/unittests/tsserver/helpers.ts index 1fb3593590604..796ba67dfa292 100644 --- a/src/testRunner/unittests/tsserver/helpers.ts +++ b/src/testRunner/unittests/tsserver/helpers.ts @@ -292,7 +292,7 @@ namespace ts.projectSystem { export class TestSession extends server.Session { private seq = 0; public events: protocol.Event[] = []; - public host!: TestServerHost; + public testhost: TestServerHost = this.host as TestServerHost; getProjectService() { return this.projectService; @@ -320,7 +320,7 @@ namespace ts.projectSystem { public clearMessages() { clear(this.events); - this.host.clearOutput(); + this.testhost.clearOutput(); } } @@ -721,8 +721,8 @@ namespace ts.projectSystem { const events = session.events; assert.deepEqual(events[index], expectedEvent, `Expected ${JSON.stringify(expectedEvent)} at ${index} in ${JSON.stringify(events)}`); - const outputs = session.host.getOutput(); - assert.equal(outputs[index], server.formatMessage(expectedEvent, nullLogger, Utils.byteLength, session.host.newLine)); + const outputs = session.testhost.getOutput(); + assert.equal(outputs[index], server.formatMessage(expectedEvent, nullLogger, Utils.byteLength, session.testhost.newLine)); if (isMostRecent) { assert.strictEqual(events.length, index + 1, JSON.stringify(events)); From a5b1d8f0fc283e6bbe79d05f45fd96b3f1409f11 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 20 Sep 2019 09:31:14 -0700 Subject: [PATCH 32/44] Haha no I missed another one --- src/testRunner/unittests/tsserver/symLinks.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/testRunner/unittests/tsserver/symLinks.ts b/src/testRunner/unittests/tsserver/symLinks.ts index c264bc2a6df09..54b7cb3fab427 100644 --- a/src/testRunner/unittests/tsserver/symLinks.ts +++ b/src/testRunner/unittests/tsserver/symLinks.ts @@ -159,7 +159,7 @@ new C();` } }); - const host = session.host; + const host = session.testhost; host.checkTimeoutQueueLengthAndRun(1); checkErrorMessage(session, "syntaxDiag", { file: recognizersDateTimeSrcFile.path, diagnostics: [] }); @@ -219,7 +219,7 @@ new C();` const projectService = session.getProjectService(); const project = projectService.configuredProjects.get(recognizerDateTimeTsconfigPath)!; checkProjectActualFiles(project, filesInProjectWithResolvedModule); - verifyWatchedFilesAndDirectories(session.host, filesInProjectWithResolvedModule, watchedDirectoriesWithResolvedModule, nonRecursiveWatchedDirectories); + verifyWatchedFilesAndDirectories(session.testhost, filesInProjectWithResolvedModule, watchedDirectoriesWithResolvedModule, nonRecursiveWatchedDirectories); verifyErrors(session, []); } @@ -227,7 +227,7 @@ new C();` const projectService = session.getProjectService(); const project = projectService.configuredProjects.get(recognizerDateTimeTsconfigPath)!; checkProjectActualFiles(project, filesInProjectWithUnresolvedModule); - verifyWatchedFilesAndDirectories(session.host, filesInProjectWithUnresolvedModule, watchedDirectoriesWithUnresolvedModule, nonRecursiveWatchedDirectories); + verifyWatchedFilesAndDirectories(session.testhost, filesInProjectWithUnresolvedModule, watchedDirectoriesWithUnresolvedModule, nonRecursiveWatchedDirectories); const startOffset = recognizersDateTimeSrcFile.content.indexOf('"') + 1; verifyErrors(session, [ createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + moduleNameInFile.length }, Diagnostics.Cannot_find_module_0, [moduleName]) From 32a73b39a232bd16b6fe55361a9918487cd6d406 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 20 Sep 2019 09:33:04 -0700 Subject: [PATCH 33/44] Fix whitespace back to CRLF --- src/compiler/transformers/classFields.ts | 1072 ++-- src/compiler/transformers/ts.ts | 6716 +++++++++++----------- src/compiler/transformers/utilities.ts | 650 +-- 3 files changed, 4219 insertions(+), 4219 deletions(-) diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 70f5218b718d5..e2b372fd950eb 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -1,536 +1,536 @@ -/*@internal*/ -namespace ts { - const enum ClassPropertySubstitutionFlags { - /** - * Enables substitutions for class expressions with static fields - * which have initializers that reference the class name. - */ - ClassAliases = 1 << 0, - } - /** - * Transforms ECMAScript Class Syntax. - * TypeScript parameter property syntax is transformed in the TypeScript transformer. - * For now, this transforms public field declarations using TypeScript class semantics - * (where the declarations get elided and initializers are transformed as assignments in the constructor). - * Eventually, this transform will change to the ECMAScript semantics (with Object.defineProperty). - */ - export function transformClassFields(context: TransformationContext) { - const { - hoistVariableDeclaration, - endLexicalEnvironment, - resumeLexicalEnvironment - } = context; - const resolver = context.getEmitResolver(); - - const previousOnSubstituteNode = context.onSubstituteNode; - context.onSubstituteNode = onSubstituteNode; - - let enabledSubstitutions: ClassPropertySubstitutionFlags; - - let classAliases: Identifier[]; - - /** - * Tracks what computed name expressions originating from elided names must be inlined - * at the next execution site, in document order - */ - let pendingExpressions: Expression[] | undefined; - - /** - * Tracks what computed name expression statements and static property initializers must be - * emitted at the next execution site, in document order (for decorated classes). - */ - let pendingStatements: Statement[] | undefined; - - return chainBundle(transformSourceFile); - - function transformSourceFile(node: SourceFile) { - const options = context.getCompilerOptions(); - if (node.isDeclarationFile - // TODO: ES3 target will still need to emit set semantics probably - // TODO: Need to test computed proeprties too - // [x] = 1 => Object.defineProperty(this, x, ...) - // -vs- - // [x] = 1 -> this[x] = 1 - // TODO: Unininitialised properties need to be emitted too. - || !options.legacyClassFields && options.target === ScriptTarget.ESNext) { - return node; - } - const visited = visitEachChild(node, visitor, context); - addEmitHelpers(visited, context.readEmitHelpers()); - return visited; - } - - function visitor(node: Node): VisitResult { - if (!(node.transformFlags & TransformFlags.ContainsClassFields)) return node; - - switch (node.kind) { - case SyntaxKind.ClassExpression: - return visitClassExpression(node as ClassExpression); - case SyntaxKind.ClassDeclaration: - return visitClassDeclaration(node as ClassDeclaration); - case SyntaxKind.VariableStatement: - return visitVariableStatement(node as VariableStatement); - } - return visitEachChild(node, visitor, context); - } - - /** - * Visits the members of a class that has fields. - * - * @param node The node to visit. - */ - function classElementVisitor(node: Node): VisitResult { - switch (node.kind) { - case SyntaxKind.Constructor: - // Constructors for classes using class fields are transformed in - // `visitClassDeclaration` or `visitClassExpression`. - return undefined; - - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.MethodDeclaration: - // Visit the name of the member (if it's a computed property name). - return visitEachChild(node, classElementVisitor, context); - - case SyntaxKind.PropertyDeclaration: - return visitPropertyDeclaration(node as PropertyDeclaration); - - case SyntaxKind.ComputedPropertyName: - return visitComputedPropertyName(node as ComputedPropertyName); - - case SyntaxKind.SemicolonClassElement: - return node; - - default: - return visitor(node); - } - } - - function visitVariableStatement(node: VariableStatement) { - const savedPendingStatements = pendingStatements; - pendingStatements = []; - - const visitedNode = visitEachChild(node, visitor, context); - const statement = some(pendingStatements) ? - [visitedNode, ...pendingStatements] : - visitedNode; - - pendingStatements = savedPendingStatements; - return statement; - } - - function visitComputedPropertyName(name: ComputedPropertyName) { - let node = visitEachChild(name, visitor, context); - if (some(pendingExpressions)) { - const expressions = pendingExpressions; - expressions.push(name.expression); - pendingExpressions = []; - node = updateComputedPropertyName( - node, - inlineExpressions(expressions) - ); - } - return node; - } - - function visitPropertyDeclaration(node: PropertyDeclaration) { - Debug.assert(!some(node.decorators)); - // Create a temporary variable to store a computed property name (if necessary). - // If it's not inlineable, then we emit an expression after the class which assigns - // the property name to the temporary variable. - const expr = getPropertyNameExpressionIfNeeded(node.name, !!node.initializer); - if (expr && !isSimpleInlineableExpression(expr)) { - (pendingExpressions || (pendingExpressions = [])).push(expr); - } - return undefined; - } - - function visitClassDeclaration(node: ClassDeclaration) { - if (!forEach(node.members, isPropertyDeclaration)) { - return visitEachChild(node, visitor, context); - } - - const savedPendingExpressions = pendingExpressions; - pendingExpressions = undefined!; - - const extendsClauseElement = getEffectiveBaseTypeNode(node); - const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword); - - const statements: Statement[] = [ - updateClassDeclaration( - node, - /*decorators*/ undefined, - node.modifiers, - node.name, - /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, visitor, isHeritageClause), - transformClassMembers(node, isDerivedClass) - ) - ]; - - // Write any pending expressions from elided or moved computed property names - if (some(pendingExpressions)) { - statements.push(createExpressionStatement(inlineExpressions(pendingExpressions))); - } - - pendingExpressions = savedPendingExpressions; - - // Emit static property assignment. Because classDeclaration is lexically evaluated, - // it is safe to emit static property assignment after classDeclaration - // From ES6 specification: - // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using - // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. - const staticProperties = getProperties(node, /*requireInitializer*/ true, /*isStatic*/ true); - if (some(staticProperties)) { - addPropertyStatements(statements, staticProperties, getInternalName(node)); - } - - return statements; - } - - function visitClassExpression(node: ClassExpression): Expression { - if (!forEach(node.members, isPropertyDeclaration)) { - return visitEachChild(node, visitor, context); - } - const savedPendingExpressions = pendingExpressions; - pendingExpressions = undefined; - - // If this class expression is a transformation of a decorated class declaration, - // then we want to output the pendingExpressions as statements, not as inlined - // expressions with the class statement. - // - // In this case, we use pendingStatements to produce the same output as the - // class declaration transformation. The VariableStatement visitor will insert - // these statements after the class expression variable statement. - const isDecoratedClassDeclaration = isClassDeclaration(getOriginalNode(node)); - - const staticProperties = getProperties(node, /*requireInitializer*/ true, /*isStatic*/ true); - const extendsClauseElement = getEffectiveBaseTypeNode(node); - const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword); - - const classExpression = updateClassExpression( - node, - node.modifiers, - node.name, - /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, visitor, isHeritageClause), - transformClassMembers(node, isDerivedClass) - ); - - if (some(staticProperties) || some(pendingExpressions)) { - if (isDecoratedClassDeclaration) { - Debug.assertDefined(pendingStatements, "Decorated classes transformed by TypeScript are expected to be within a variable declaration."); - - // Write any pending expressions from elided or moved computed property names - if (pendingStatements && pendingExpressions && some(pendingExpressions)) { - pendingStatements.push(createExpressionStatement(inlineExpressions(pendingExpressions))); - } - pendingExpressions = savedPendingExpressions; - - if (pendingStatements && some(staticProperties)) { - addPropertyStatements(pendingStatements, staticProperties, getInternalName(node)); - } - return classExpression; - } - else { - const expressions: Expression[] = []; - const isClassWithConstructorReference = resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithConstructorReference; - const temp = createTempVariable(hoistVariableDeclaration, !!isClassWithConstructorReference); - if (isClassWithConstructorReference) { - // record an alias as the class name is not in scope for statics. - enableSubstitutionForClassAliases(); - const alias = getSynthesizedClone(temp); - alias.autoGenerateFlags &= ~GeneratedIdentifierFlags.ReservedInNestedScopes; - classAliases[getOriginalNodeId(node)] = alias; - } - - // To preserve the behavior of the old emitter, we explicitly indent - // the body of a class with static initializers. - setEmitFlags(classExpression, EmitFlags.Indented | getEmitFlags(classExpression)); - expressions.push(startOnNewLine(createAssignment(temp, classExpression))); - // Add any pending expressions leftover from elided or relocated computed property names - addRange(expressions, map(pendingExpressions, startOnNewLine)); - addRange(expressions, generateInitializedPropertyExpressions(staticProperties, temp)); - expressions.push(startOnNewLine(temp)); - - pendingExpressions = savedPendingExpressions; - return inlineExpressions(expressions); - } - } - - pendingExpressions = savedPendingExpressions; - return classExpression; - } - - function transformClassMembers(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { - const members: ClassElement[] = []; - const constructor = transformConstructor(node, isDerivedClass); - if (constructor) { - members.push(constructor); - } - addRange(members, visitNodes(node.members, classElementVisitor, isClassElement)); - return setTextRange(createNodeArray(members), /*location*/ node.members); - } - - function transformConstructor(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { - const constructor = visitNode(getFirstConstructorWithBody(node), visitor, isConstructorDeclaration); - const containsProperty = forEach(node.members, m => isInitializedProperty(m, !!context.getCompilerOptions().legacyClassFields)); - if (!containsProperty) { - return constructor; - } - const parameters = visitParameterList(constructor ? constructor.parameters : undefined, visitor, context); - const body = transformConstructorBody(node, constructor, isDerivedClass); - if (!body) { - return undefined; - } - return startOnNewLine( - setOriginalNode( - setTextRange( - createConstructor( - /*decorators*/ undefined, - /*modifiers*/ undefined, - parameters, - body - ), - constructor || node - ), - constructor - ) - ); - } - - function transformConstructorBody(node: ClassDeclaration | ClassExpression, constructor: ConstructorDeclaration | undefined, isDerivedClass: boolean) { - const properties = getProperties(node, /*requireInitializer*/ !!context.getCompilerOptions().legacyClassFields, /*isStatic*/ false); - - // Only generate synthetic constructor when there are property initializers to move. - if (!constructor && !some(properties)) { - return visitFunctionBody(/*node*/ undefined, visitor, context); - } - - resumeLexicalEnvironment(); - - let indexOfFirstStatement = 0; - let statements: Statement[] = []; - - if (!constructor && isDerivedClass) { - // Add a synthetic `super` call: - // - // super(...arguments); - // - statements.push( - createExpressionStatement( - createCall( - createSuper(), - /*typeArguments*/ undefined, - [createSpread(createIdentifier("arguments"))] - ) - ) - ); - } - - if (constructor) { - indexOfFirstStatement = addPrologueDirectivesAndInitialSuperCall(constructor, statements, visitor); - } - - // Add the property initializers. Transforms this: - // - // public x = 1; - // - // Into this: - // - // constructor() { - // this.x = 1; - // } - // - if (constructor && constructor.body) { - // TODO: Need to think about parameter property declarations - let parameterPropertyDeclarationCount = 0; - for (let i = indexOfFirstStatement; i < constructor.body.statements.length; i++) { - if (isParameterPropertyDeclaration(getOriginalNode(constructor.body.statements[i]), constructor)) { - parameterPropertyDeclarationCount++; - } - else { - break; - } - } - if (parameterPropertyDeclarationCount > 0) { - addRange(statements, visitNodes(constructor.body.statements, visitor, isStatement, indexOfFirstStatement, parameterPropertyDeclarationCount)); - indexOfFirstStatement += parameterPropertyDeclarationCount; - } - } - addPropertyStatements(statements, properties, createThis()); - - // Add existing statements, skipping the initial super call. - if (constructor) { - addRange(statements, visitNodes(constructor.body!.statements, visitor, isStatement, indexOfFirstStatement)); - } - - statements = mergeLexicalEnvironment(statements, endLexicalEnvironment()); - - return setTextRange( - createBlock( - setTextRange( - createNodeArray(statements), - /*location*/ constructor ? constructor.body!.statements : node.members - ), - /*multiLine*/ true - ), - /*location*/ constructor ? constructor.body : undefined - ); - } - - /** - * Generates assignment statements for property initializers. - * - * @param properties An array of property declarations to transform. - * @param receiver The receiver on which each property should be assigned. - */ - function addPropertyStatements(statements: Statement[], properties: readonly PropertyDeclaration[], receiver: LeftHandSideExpression) { - for (const property of properties) { - const statement = createExpressionStatement(transformInitializedProperty(property, receiver)); - setSourceMapRange(statement, moveRangePastModifiers(property)); - setCommentRange(statement, property); - setOriginalNode(statement, property); - statements.push(statement); - } - } - - /** - * Generates assignment expressions for property initializers. - * - * @param properties An array of property declarations to transform. - * @param receiver The receiver on which each property should be assigned. - */ - function generateInitializedPropertyExpressions(properties: readonly PropertyDeclaration[], receiver: LeftHandSideExpression) { - const expressions: Expression[] = []; - for (const property of properties) { - const expression = transformInitializedProperty(property, receiver); - startOnNewLine(expression); - setSourceMapRange(expression, moveRangePastModifiers(property)); - setCommentRange(expression, property); - setOriginalNode(expression, property); - expressions.push(expression); - } - - return expressions; - } - - /** - * Transforms a property initializer into an assignment statement. - * - * @param property The property declaration. - * @param receiver The object receiving the property assignment. - */ - function transformInitializedProperty(property: PropertyDeclaration, receiver: LeftHandSideExpression) { - if (context.getCompilerOptions().legacyClassFields) { - // We generate a name here in order to reuse the value cached by the relocated computed name expression (which uses the same generated name) - const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) - ? updateComputedPropertyName(property.name, getGeneratedNameForNode(property.name)) - : property.name; - const memberAccess = createMemberAccessForPropertyName(receiver, propertyName, /*location*/ propertyName); - const initializer = visitNode(property.initializer, visitor, isExpression); - return createAssignment(memberAccess, initializer); - } - else { - // We generate a name here in order to reuse the value cached by the relocated computed name expression (which uses the same generated name) - const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) - ? updateComputedPropertyName(property.name, getGeneratedNameForNode(property.name)) - : property.name; - const initializer = property.initializer ? visitNode(property.initializer, visitor, isExpression) : createVoidZero() - return createObjectDefineForPropertyName(receiver, propertyName, initializer); - } - } - - function createObjectDefineForPropertyName(target: Expression, name: PropertyName, initializer: Expression) { - return createCall( - createPropertyAccess(createIdentifier("Object"), createIdentifier("defineProperty")), - undefined, - [target, isComputedPropertyName(name) ? name.expression : name, createObjectLiteral([createPropertyAssignment("value", initializer)])]); - } - - function enableSubstitutionForClassAliases() { - if ((enabledSubstitutions & ClassPropertySubstitutionFlags.ClassAliases) === 0) { - enabledSubstitutions |= ClassPropertySubstitutionFlags.ClassAliases; - - // We need to enable substitutions for identifiers. This allows us to - // substitute class names inside of a class declaration. - context.enableSubstitution(SyntaxKind.Identifier); - - // Keep track of class aliases. - classAliases = []; - } - } - - /** - * Hooks node substitutions. - * - * @param hint The context for the emitter. - * @param node The node to substitute. - */ - function onSubstituteNode(hint: EmitHint, node: Node) { - node = previousOnSubstituteNode(hint, node); - if (hint === EmitHint.Expression) { - return substituteExpression(node as Expression); - } - return node; - } - - function substituteExpression(node: Expression) { - switch (node.kind) { - case SyntaxKind.Identifier: - return substituteExpressionIdentifier(node as Identifier); - } - return node; - } - - function substituteExpressionIdentifier(node: Identifier): Expression { - return trySubstituteClassAlias(node) || node; - } - - function trySubstituteClassAlias(node: Identifier): Expression | undefined { - if (enabledSubstitutions & ClassPropertySubstitutionFlags.ClassAliases) { - if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ConstructorReferenceInClass) { - // Due to the emit for class decorators, any reference to the class from inside of the class body - // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind - // behavior of class names in ES6. - // Also, when emitting statics for class expressions, we must substitute a class alias for - // constructor references in static property initializers. - const declaration = resolver.getReferencedValueDeclaration(node); - if (declaration) { - const classAlias = classAliases[declaration.id!]; // TODO: GH#18217 - if (classAlias) { - const clone = getSynthesizedClone(classAlias); - setSourceMapRange(clone, node); - setCommentRange(clone, node); - return clone; - } - } - } - } - - return undefined; - } - - - /** - * If the name is a computed property, this function transforms it, then either returns an expression which caches the - * value of the result or the expression itself if the value is either unused or safe to inline into multiple locations - * @param shouldHoist Does the expression need to be reused? (ie, for an initializer or a decorator) - */ - function getPropertyNameExpressionIfNeeded(name: PropertyName, shouldHoist: boolean): Expression | undefined { - if (isComputedPropertyName(name)) { - const expression = visitNode(name.expression, visitor, isExpression); - const innerExpression = skipPartiallyEmittedExpressions(expression); - const inlinable = isSimpleInlineableExpression(innerExpression); - const alreadyTransformed = isAssignmentExpression(innerExpression) && isGeneratedIdentifier(innerExpression.left); - if (!alreadyTransformed && !inlinable && shouldHoist) { - const generatedName = getGeneratedNameForNode(name); - hoistVariableDeclaration(generatedName); - return createAssignment(generatedName, expression); - } - return (inlinable || isIdentifier(innerExpression)) ? undefined : expression; - } - } - } - -} +/*@internal*/ +namespace ts { + const enum ClassPropertySubstitutionFlags { + /** + * Enables substitutions for class expressions with static fields + * which have initializers that reference the class name. + */ + ClassAliases = 1 << 0, + } + /** + * Transforms ECMAScript Class Syntax. + * TypeScript parameter property syntax is transformed in the TypeScript transformer. + * For now, this transforms public field declarations using TypeScript class semantics + * (where the declarations get elided and initializers are transformed as assignments in the constructor). + * Eventually, this transform will change to the ECMAScript semantics (with Object.defineProperty). + */ + export function transformClassFields(context: TransformationContext) { + const { + hoistVariableDeclaration, + endLexicalEnvironment, + resumeLexicalEnvironment + } = context; + const resolver = context.getEmitResolver(); + + const previousOnSubstituteNode = context.onSubstituteNode; + context.onSubstituteNode = onSubstituteNode; + + let enabledSubstitutions: ClassPropertySubstitutionFlags; + + let classAliases: Identifier[]; + + /** + * Tracks what computed name expressions originating from elided names must be inlined + * at the next execution site, in document order + */ + let pendingExpressions: Expression[] | undefined; + + /** + * Tracks what computed name expression statements and static property initializers must be + * emitted at the next execution site, in document order (for decorated classes). + */ + let pendingStatements: Statement[] | undefined; + + return chainBundle(transformSourceFile); + + function transformSourceFile(node: SourceFile) { + const options = context.getCompilerOptions(); + if (node.isDeclarationFile + // TODO: ES3 target will still need to emit set semantics probably + // TODO: Need to test computed proeprties too + // [x] = 1 => Object.defineProperty(this, x, ...) + // -vs- + // [x] = 1 -> this[x] = 1 + // TODO: Unininitialised properties need to be emitted too. + || !options.legacyClassFields && options.target === ScriptTarget.ESNext) { + return node; + } + const visited = visitEachChild(node, visitor, context); + addEmitHelpers(visited, context.readEmitHelpers()); + return visited; + } + + function visitor(node: Node): VisitResult { + if (!(node.transformFlags & TransformFlags.ContainsClassFields)) return node; + + switch (node.kind) { + case SyntaxKind.ClassExpression: + return visitClassExpression(node as ClassExpression); + case SyntaxKind.ClassDeclaration: + return visitClassDeclaration(node as ClassDeclaration); + case SyntaxKind.VariableStatement: + return visitVariableStatement(node as VariableStatement); + } + return visitEachChild(node, visitor, context); + } + + /** + * Visits the members of a class that has fields. + * + * @param node The node to visit. + */ + function classElementVisitor(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.Constructor: + // Constructors for classes using class fields are transformed in + // `visitClassDeclaration` or `visitClassExpression`. + return undefined; + + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.MethodDeclaration: + // Visit the name of the member (if it's a computed property name). + return visitEachChild(node, classElementVisitor, context); + + case SyntaxKind.PropertyDeclaration: + return visitPropertyDeclaration(node as PropertyDeclaration); + + case SyntaxKind.ComputedPropertyName: + return visitComputedPropertyName(node as ComputedPropertyName); + + case SyntaxKind.SemicolonClassElement: + return node; + + default: + return visitor(node); + } + } + + function visitVariableStatement(node: VariableStatement) { + const savedPendingStatements = pendingStatements; + pendingStatements = []; + + const visitedNode = visitEachChild(node, visitor, context); + const statement = some(pendingStatements) ? + [visitedNode, ...pendingStatements] : + visitedNode; + + pendingStatements = savedPendingStatements; + return statement; + } + + function visitComputedPropertyName(name: ComputedPropertyName) { + let node = visitEachChild(name, visitor, context); + if (some(pendingExpressions)) { + const expressions = pendingExpressions; + expressions.push(name.expression); + pendingExpressions = []; + node = updateComputedPropertyName( + node, + inlineExpressions(expressions) + ); + } + return node; + } + + function visitPropertyDeclaration(node: PropertyDeclaration) { + Debug.assert(!some(node.decorators)); + // Create a temporary variable to store a computed property name (if necessary). + // If it's not inlineable, then we emit an expression after the class which assigns + // the property name to the temporary variable. + const expr = getPropertyNameExpressionIfNeeded(node.name, !!node.initializer); + if (expr && !isSimpleInlineableExpression(expr)) { + (pendingExpressions || (pendingExpressions = [])).push(expr); + } + return undefined; + } + + function visitClassDeclaration(node: ClassDeclaration) { + if (!forEach(node.members, isPropertyDeclaration)) { + return visitEachChild(node, visitor, context); + } + + const savedPendingExpressions = pendingExpressions; + pendingExpressions = undefined!; + + const extendsClauseElement = getEffectiveBaseTypeNode(node); + const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword); + + const statements: Statement[] = [ + updateClassDeclaration( + node, + /*decorators*/ undefined, + node.modifiers, + node.name, + /*typeParameters*/ undefined, + visitNodes(node.heritageClauses, visitor, isHeritageClause), + transformClassMembers(node, isDerivedClass) + ) + ]; + + // Write any pending expressions from elided or moved computed property names + if (some(pendingExpressions)) { + statements.push(createExpressionStatement(inlineExpressions(pendingExpressions))); + } + + pendingExpressions = savedPendingExpressions; + + // Emit static property assignment. Because classDeclaration is lexically evaluated, + // it is safe to emit static property assignment after classDeclaration + // From ES6 specification: + // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using + // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. + const staticProperties = getProperties(node, /*requireInitializer*/ true, /*isStatic*/ true); + if (some(staticProperties)) { + addPropertyStatements(statements, staticProperties, getInternalName(node)); + } + + return statements; + } + + function visitClassExpression(node: ClassExpression): Expression { + if (!forEach(node.members, isPropertyDeclaration)) { + return visitEachChild(node, visitor, context); + } + const savedPendingExpressions = pendingExpressions; + pendingExpressions = undefined; + + // If this class expression is a transformation of a decorated class declaration, + // then we want to output the pendingExpressions as statements, not as inlined + // expressions with the class statement. + // + // In this case, we use pendingStatements to produce the same output as the + // class declaration transformation. The VariableStatement visitor will insert + // these statements after the class expression variable statement. + const isDecoratedClassDeclaration = isClassDeclaration(getOriginalNode(node)); + + const staticProperties = getProperties(node, /*requireInitializer*/ true, /*isStatic*/ true); + const extendsClauseElement = getEffectiveBaseTypeNode(node); + const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword); + + const classExpression = updateClassExpression( + node, + node.modifiers, + node.name, + /*typeParameters*/ undefined, + visitNodes(node.heritageClauses, visitor, isHeritageClause), + transformClassMembers(node, isDerivedClass) + ); + + if (some(staticProperties) || some(pendingExpressions)) { + if (isDecoratedClassDeclaration) { + Debug.assertDefined(pendingStatements, "Decorated classes transformed by TypeScript are expected to be within a variable declaration."); + + // Write any pending expressions from elided or moved computed property names + if (pendingStatements && pendingExpressions && some(pendingExpressions)) { + pendingStatements.push(createExpressionStatement(inlineExpressions(pendingExpressions))); + } + pendingExpressions = savedPendingExpressions; + + if (pendingStatements && some(staticProperties)) { + addPropertyStatements(pendingStatements, staticProperties, getInternalName(node)); + } + return classExpression; + } + else { + const expressions: Expression[] = []; + const isClassWithConstructorReference = resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithConstructorReference; + const temp = createTempVariable(hoistVariableDeclaration, !!isClassWithConstructorReference); + if (isClassWithConstructorReference) { + // record an alias as the class name is not in scope for statics. + enableSubstitutionForClassAliases(); + const alias = getSynthesizedClone(temp); + alias.autoGenerateFlags &= ~GeneratedIdentifierFlags.ReservedInNestedScopes; + classAliases[getOriginalNodeId(node)] = alias; + } + + // To preserve the behavior of the old emitter, we explicitly indent + // the body of a class with static initializers. + setEmitFlags(classExpression, EmitFlags.Indented | getEmitFlags(classExpression)); + expressions.push(startOnNewLine(createAssignment(temp, classExpression))); + // Add any pending expressions leftover from elided or relocated computed property names + addRange(expressions, map(pendingExpressions, startOnNewLine)); + addRange(expressions, generateInitializedPropertyExpressions(staticProperties, temp)); + expressions.push(startOnNewLine(temp)); + + pendingExpressions = savedPendingExpressions; + return inlineExpressions(expressions); + } + } + + pendingExpressions = savedPendingExpressions; + return classExpression; + } + + function transformClassMembers(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { + const members: ClassElement[] = []; + const constructor = transformConstructor(node, isDerivedClass); + if (constructor) { + members.push(constructor); + } + addRange(members, visitNodes(node.members, classElementVisitor, isClassElement)); + return setTextRange(createNodeArray(members), /*location*/ node.members); + } + + function transformConstructor(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { + const constructor = visitNode(getFirstConstructorWithBody(node), visitor, isConstructorDeclaration); + const containsProperty = forEach(node.members, m => isInitializedProperty(m, !!context.getCompilerOptions().legacyClassFields)); + if (!containsProperty) { + return constructor; + } + const parameters = visitParameterList(constructor ? constructor.parameters : undefined, visitor, context); + const body = transformConstructorBody(node, constructor, isDerivedClass); + if (!body) { + return undefined; + } + return startOnNewLine( + setOriginalNode( + setTextRange( + createConstructor( + /*decorators*/ undefined, + /*modifiers*/ undefined, + parameters, + body + ), + constructor || node + ), + constructor + ) + ); + } + + function transformConstructorBody(node: ClassDeclaration | ClassExpression, constructor: ConstructorDeclaration | undefined, isDerivedClass: boolean) { + const properties = getProperties(node, /*requireInitializer*/ !!context.getCompilerOptions().legacyClassFields, /*isStatic*/ false); + + // Only generate synthetic constructor when there are property initializers to move. + if (!constructor && !some(properties)) { + return visitFunctionBody(/*node*/ undefined, visitor, context); + } + + resumeLexicalEnvironment(); + + let indexOfFirstStatement = 0; + let statements: Statement[] = []; + + if (!constructor && isDerivedClass) { + // Add a synthetic `super` call: + // + // super(...arguments); + // + statements.push( + createExpressionStatement( + createCall( + createSuper(), + /*typeArguments*/ undefined, + [createSpread(createIdentifier("arguments"))] + ) + ) + ); + } + + if (constructor) { + indexOfFirstStatement = addPrologueDirectivesAndInitialSuperCall(constructor, statements, visitor); + } + + // Add the property initializers. Transforms this: + // + // public x = 1; + // + // Into this: + // + // constructor() { + // this.x = 1; + // } + // + if (constructor && constructor.body) { + // TODO: Need to think about parameter property declarations + let parameterPropertyDeclarationCount = 0; + for (let i = indexOfFirstStatement; i < constructor.body.statements.length; i++) { + if (isParameterPropertyDeclaration(getOriginalNode(constructor.body.statements[i]), constructor)) { + parameterPropertyDeclarationCount++; + } + else { + break; + } + } + if (parameterPropertyDeclarationCount > 0) { + addRange(statements, visitNodes(constructor.body.statements, visitor, isStatement, indexOfFirstStatement, parameterPropertyDeclarationCount)); + indexOfFirstStatement += parameterPropertyDeclarationCount; + } + } + addPropertyStatements(statements, properties, createThis()); + + // Add existing statements, skipping the initial super call. + if (constructor) { + addRange(statements, visitNodes(constructor.body!.statements, visitor, isStatement, indexOfFirstStatement)); + } + + statements = mergeLexicalEnvironment(statements, endLexicalEnvironment()); + + return setTextRange( + createBlock( + setTextRange( + createNodeArray(statements), + /*location*/ constructor ? constructor.body!.statements : node.members + ), + /*multiLine*/ true + ), + /*location*/ constructor ? constructor.body : undefined + ); + } + + /** + * Generates assignment statements for property initializers. + * + * @param properties An array of property declarations to transform. + * @param receiver The receiver on which each property should be assigned. + */ + function addPropertyStatements(statements: Statement[], properties: readonly PropertyDeclaration[], receiver: LeftHandSideExpression) { + for (const property of properties) { + const statement = createExpressionStatement(transformInitializedProperty(property, receiver)); + setSourceMapRange(statement, moveRangePastModifiers(property)); + setCommentRange(statement, property); + setOriginalNode(statement, property); + statements.push(statement); + } + } + + /** + * Generates assignment expressions for property initializers. + * + * @param properties An array of property declarations to transform. + * @param receiver The receiver on which each property should be assigned. + */ + function generateInitializedPropertyExpressions(properties: readonly PropertyDeclaration[], receiver: LeftHandSideExpression) { + const expressions: Expression[] = []; + for (const property of properties) { + const expression = transformInitializedProperty(property, receiver); + startOnNewLine(expression); + setSourceMapRange(expression, moveRangePastModifiers(property)); + setCommentRange(expression, property); + setOriginalNode(expression, property); + expressions.push(expression); + } + + return expressions; + } + + /** + * Transforms a property initializer into an assignment statement. + * + * @param property The property declaration. + * @param receiver The object receiving the property assignment. + */ + function transformInitializedProperty(property: PropertyDeclaration, receiver: LeftHandSideExpression) { + if (context.getCompilerOptions().legacyClassFields) { + // We generate a name here in order to reuse the value cached by the relocated computed name expression (which uses the same generated name) + const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) + ? updateComputedPropertyName(property.name, getGeneratedNameForNode(property.name)) + : property.name; + const memberAccess = createMemberAccessForPropertyName(receiver, propertyName, /*location*/ propertyName); + const initializer = visitNode(property.initializer, visitor, isExpression); + return createAssignment(memberAccess, initializer); + } + else { + // We generate a name here in order to reuse the value cached by the relocated computed name expression (which uses the same generated name) + const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) + ? updateComputedPropertyName(property.name, getGeneratedNameForNode(property.name)) + : property.name; + const initializer = property.initializer ? visitNode(property.initializer, visitor, isExpression) : createVoidZero() + return createObjectDefineForPropertyName(receiver, propertyName, initializer); + } + } + + function createObjectDefineForPropertyName(target: Expression, name: PropertyName, initializer: Expression) { + return createCall( + createPropertyAccess(createIdentifier("Object"), createIdentifier("defineProperty")), + undefined, + [target, isComputedPropertyName(name) ? name.expression : name, createObjectLiteral([createPropertyAssignment("value", initializer)])]); + } + + function enableSubstitutionForClassAliases() { + if ((enabledSubstitutions & ClassPropertySubstitutionFlags.ClassAliases) === 0) { + enabledSubstitutions |= ClassPropertySubstitutionFlags.ClassAliases; + + // We need to enable substitutions for identifiers. This allows us to + // substitute class names inside of a class declaration. + context.enableSubstitution(SyntaxKind.Identifier); + + // Keep track of class aliases. + classAliases = []; + } + } + + /** + * Hooks node substitutions. + * + * @param hint The context for the emitter. + * @param node The node to substitute. + */ + function onSubstituteNode(hint: EmitHint, node: Node) { + node = previousOnSubstituteNode(hint, node); + if (hint === EmitHint.Expression) { + return substituteExpression(node as Expression); + } + return node; + } + + function substituteExpression(node: Expression) { + switch (node.kind) { + case SyntaxKind.Identifier: + return substituteExpressionIdentifier(node as Identifier); + } + return node; + } + + function substituteExpressionIdentifier(node: Identifier): Expression { + return trySubstituteClassAlias(node) || node; + } + + function trySubstituteClassAlias(node: Identifier): Expression | undefined { + if (enabledSubstitutions & ClassPropertySubstitutionFlags.ClassAliases) { + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ConstructorReferenceInClass) { + // Due to the emit for class decorators, any reference to the class from inside of the class body + // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind + // behavior of class names in ES6. + // Also, when emitting statics for class expressions, we must substitute a class alias for + // constructor references in static property initializers. + const declaration = resolver.getReferencedValueDeclaration(node); + if (declaration) { + const classAlias = classAliases[declaration.id!]; // TODO: GH#18217 + if (classAlias) { + const clone = getSynthesizedClone(classAlias); + setSourceMapRange(clone, node); + setCommentRange(clone, node); + return clone; + } + } + } + } + + return undefined; + } + + + /** + * If the name is a computed property, this function transforms it, then either returns an expression which caches the + * value of the result or the expression itself if the value is either unused or safe to inline into multiple locations + * @param shouldHoist Does the expression need to be reused? (ie, for an initializer or a decorator) + */ + function getPropertyNameExpressionIfNeeded(name: PropertyName, shouldHoist: boolean): Expression | undefined { + if (isComputedPropertyName(name)) { + const expression = visitNode(name.expression, visitor, isExpression); + const innerExpression = skipPartiallyEmittedExpressions(expression); + const inlinable = isSimpleInlineableExpression(innerExpression); + const alreadyTransformed = isAssignmentExpression(innerExpression) && isGeneratedIdentifier(innerExpression.left); + if (!alreadyTransformed && !inlinable && shouldHoist) { + const generatedName = getGeneratedNameForNode(name); + hoistVariableDeclaration(generatedName); + return createAssignment(generatedName, expression); + } + return (inlinable || isIdentifier(innerExpression)) ? undefined : expression; + } + } + } + +} diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 16f436c95a406..ddb545f0eb575 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -1,3358 +1,3358 @@ -/*@internal*/ -namespace ts { - /** - * Indicates whether to emit type metadata in the new format. - */ - const USE_NEW_TYPE_METADATA_FORMAT = false; - - const enum TypeScriptSubstitutionFlags { - /** Enables substitutions for decorated classes. */ - ClassAliases = 1 << 0, - /** Enables substitutions for namespace exports. */ - NamespaceExports = 1 << 1, - /* Enables substitutions for unqualified enum members */ - NonQualifiedEnumMembers = 1 << 3 - } - - const enum ClassFacts { - None = 0, - HasStaticInitializedProperties = 1 << 0, - HasConstructorDecorators = 1 << 1, - HasMemberDecorators = 1 << 2, - IsExportOfNamespace = 1 << 3, - IsNamedExternalExport = 1 << 4, - IsDefaultExternalExport = 1 << 5, - IsDerivedClass = 1 << 6, - UseImmediatelyInvokedFunctionExpression = 1 << 7, - - HasAnyDecorators = HasConstructorDecorators | HasMemberDecorators, - NeedsName = HasStaticInitializedProperties | HasMemberDecorators, - MayNeedImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties, - IsExported = IsExportOfNamespace | IsDefaultExternalExport | IsNamedExternalExport, - } - - export function transformTypeScript(context: TransformationContext) { - const { - startLexicalEnvironment, - resumeLexicalEnvironment, - endLexicalEnvironment, - hoistVariableDeclaration, - } = context; - - const resolver = context.getEmitResolver(); - const compilerOptions = context.getCompilerOptions(); - const strictNullChecks = getStrictOptionValue(compilerOptions, "strictNullChecks"); - const languageVersion = getEmitScriptTarget(compilerOptions); - const moduleKind = getEmitModuleKind(compilerOptions); - - // Save the previous transformation hooks. - const previousOnEmitNode = context.onEmitNode; - const previousOnSubstituteNode = context.onSubstituteNode; - - // Set new transformation hooks. - context.onEmitNode = onEmitNode; - context.onSubstituteNode = onSubstituteNode; - - // Enable substitution for property/element access to emit const enum values. - context.enableSubstitution(SyntaxKind.PropertyAccessExpression); - context.enableSubstitution(SyntaxKind.ElementAccessExpression); - - // These variables contain state that changes as we descend into the tree. - let currentSourceFile: SourceFile; - let currentNamespace: ModuleDeclaration; - let currentNamespaceContainerName: Identifier; - let currentLexicalScope: SourceFile | Block | ModuleBlock | CaseBlock; - let currentNameScope: ClassDeclaration | undefined; - let currentScopeFirstDeclarationsOfName: UnderscoreEscapedMap | undefined; - let currentClassHasParameterProperties: boolean | undefined; - - /** - * Keeps track of whether expression substitution has been enabled for specific edge cases. - * They are persisted between each SourceFile transformation and should not be reset. - */ - let enabledSubstitutions: TypeScriptSubstitutionFlags; - - /** - * A map that keeps track of aliases created for classes with decorators to avoid issues - * with the double-binding behavior of classes. - */ - let classAliases: Identifier[]; - - /** - * Keeps track of whether we are within any containing namespaces when performing - * just-in-time substitution while printing an expression identifier. - */ - let applicableSubstitutions: TypeScriptSubstitutionFlags; - - return transformSourceFileOrBundle; - - function transformSourceFileOrBundle(node: SourceFile | Bundle) { - if (node.kind === SyntaxKind.Bundle) { - return transformBundle(node); - } - return transformSourceFile(node); - } - - function transformBundle(node: Bundle) { - return createBundle(node.sourceFiles.map(transformSourceFile), mapDefined(node.prepends, prepend => { - if (prepend.kind === SyntaxKind.InputFiles) { - return createUnparsedSourceFile(prepend, "js"); - } - return prepend; - })); - } - - /** - * Transform TypeScript-specific syntax in a SourceFile. - * - * @param node A SourceFile node. - */ - function transformSourceFile(node: SourceFile) { - if (node.isDeclarationFile) { - return node; - } - - currentSourceFile = node; - - const visited = saveStateAndInvoke(node, visitSourceFile); - addEmitHelpers(visited, context.readEmitHelpers()); - - currentSourceFile = undefined!; - return visited; - } - - /** - * Visits a node, saving and restoring state variables on the stack. - * - * @param node The node to visit. - */ - function saveStateAndInvoke(node: Node, f: (node: Node) => T): T { - // Save state - const savedCurrentScope = currentLexicalScope; - const savedCurrentNameScope = currentNameScope; - const savedCurrentScopeFirstDeclarationsOfName = currentScopeFirstDeclarationsOfName; - const savedCurrentClassHasParameterProperties = currentClassHasParameterProperties; - - // Handle state changes before visiting a node. - onBeforeVisitNode(node); - - const visited = f(node); - - // Restore state - if (currentLexicalScope !== savedCurrentScope) { - currentScopeFirstDeclarationsOfName = savedCurrentScopeFirstDeclarationsOfName; - } - - currentLexicalScope = savedCurrentScope; - currentNameScope = savedCurrentNameScope; - currentClassHasParameterProperties = savedCurrentClassHasParameterProperties; - return visited; - } - - /** - * Performs actions that should always occur immediately before visiting a node. - * - * @param node The node to visit. - */ - function onBeforeVisitNode(node: Node) { - switch (node.kind) { - case SyntaxKind.SourceFile: - case SyntaxKind.CaseBlock: - case SyntaxKind.ModuleBlock: - case SyntaxKind.Block: - currentLexicalScope = node; - currentNameScope = undefined; - currentScopeFirstDeclarationsOfName = undefined; - break; - - case SyntaxKind.ClassDeclaration: - case SyntaxKind.FunctionDeclaration: - if (hasModifier(node, ModifierFlags.Ambient)) { - break; - } - - // Record these declarations provided that they have a name. - if ((node as ClassDeclaration | FunctionDeclaration).name) { - recordEmittedDeclarationInScope(node as ClassDeclaration | FunctionDeclaration); - } - else { - // These nodes should always have names unless they are default-exports; - // however, class declaration parsing allows for undefined names, so syntactically invalid - // programs may also have an undefined name. - Debug.assert(node.kind === SyntaxKind.ClassDeclaration || hasModifier(node, ModifierFlags.Default)); - } - if (isClassDeclaration(node)) { - // XXX: should probably also cover interfaces and type aliases that can have type variables? - currentNameScope = node; - } - - break; - } - } - - /** - * General-purpose node visitor. - * - * @param node The node to visit. - */ - function visitor(node: Node): VisitResult { - return saveStateAndInvoke(node, visitorWorker); - } - - /** - * Visits and possibly transforms any node. - * - * @param node The node to visit. - */ - function visitorWorker(node: Node): VisitResult { - if (node.transformFlags & TransformFlags.ContainsTypeScript) { - return visitTypeScript(node); - } - return node; - } - - /** - * Specialized visitor that visits the immediate children of a SourceFile. - * - * @param node The node to visit. - */ - function sourceElementVisitor(node: Node): VisitResult { - return saveStateAndInvoke(node, sourceElementVisitorWorker); - } - - /** - * Specialized visitor that visits the immediate children of a SourceFile. - * - * @param node The node to visit. - */ - function sourceElementVisitorWorker(node: Node): VisitResult { - switch (node.kind) { - case SyntaxKind.ImportDeclaration: - case SyntaxKind.ImportEqualsDeclaration: - case SyntaxKind.ExportAssignment: - case SyntaxKind.ExportDeclaration: - return visitEllidableStatement(node); - default: - return visitorWorker(node); - } - } - - function visitEllidableStatement(node: ImportDeclaration | ImportEqualsDeclaration | ExportAssignment | ExportDeclaration): VisitResult { - const parsed = getParseTreeNode(node); - if (parsed !== node) { - // If the node has been transformed by a `before` transformer, perform no ellision on it - // As the type information we would attempt to lookup to perform ellision is potentially unavailable for the synthesized nodes - // We do not reuse `visitorWorker`, as the ellidable statement syntax kinds are technically unrecognized by the switch-case in `visitTypeScript`, - // and will trigger debug failures when debug verbosity is turned up - if (node.transformFlags & TransformFlags.ContainsTypeScript) { - // This node contains TypeScript, so we should visit its children. - return visitEachChild(node, visitor, context); - } - // Otherwise, we can just return the node - return node; - } - switch (node.kind) { - case SyntaxKind.ImportDeclaration: - return visitImportDeclaration(node); - case SyntaxKind.ImportEqualsDeclaration: - return visitImportEqualsDeclaration(node); - case SyntaxKind.ExportAssignment: - return visitExportAssignment(node); - case SyntaxKind.ExportDeclaration: - return visitExportDeclaration(node); - default: - Debug.fail("Unhandled ellided statement"); - } - } - - /** - * Specialized visitor that visits the immediate children of a namespace. - * - * @param node The node to visit. - */ - function namespaceElementVisitor(node: Node): VisitResult { - return saveStateAndInvoke(node, namespaceElementVisitorWorker); - } - - /** - * Specialized visitor that visits the immediate children of a namespace. - * - * @param node The node to visit. - */ - function namespaceElementVisitorWorker(node: Node): VisitResult { - if (node.kind === SyntaxKind.ExportDeclaration || - node.kind === SyntaxKind.ImportDeclaration || - node.kind === SyntaxKind.ImportClause || - (node.kind === SyntaxKind.ImportEqualsDeclaration && - (node).moduleReference.kind === SyntaxKind.ExternalModuleReference)) { - // do not emit ES6 imports and exports since they are illegal inside a namespace - return undefined; - } - else if (node.transformFlags & TransformFlags.ContainsTypeScript || hasModifier(node, ModifierFlags.Export)) { - return visitTypeScript(node); - } - - return node; - } - - /** - * Specialized visitor that visits the immediate children of a class with TypeScript syntax. - * - * @param node The node to visit. - */ - function classElementVisitor(node: Node): VisitResult { - return saveStateAndInvoke(node, classElementVisitorWorker); - } - - /** - * Specialized visitor that visits the immediate children of a class with TypeScript syntax. - * - * @param node The node to visit. - */ - function classElementVisitorWorker(node: Node): VisitResult { - switch (node.kind) { - case SyntaxKind.Constructor: - return visitConstructor(node as ConstructorDeclaration); - - case SyntaxKind.PropertyDeclaration: - // Property declarations are not TypeScript syntax, but they must be visited - // for the decorator transformation. - return visitPropertyDeclaration(node as PropertyDeclaration); - case SyntaxKind.IndexSignature: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.MethodDeclaration: - // Fallback to the default visit behavior. - return visitorWorker(node); - - case SyntaxKind.SemicolonClassElement: - return node; - - default: - return Debug.failBadSyntaxKind(node); - } - } - - function modifierVisitor(node: Node): VisitResult { - if (modifierToFlag(node.kind) & ModifierFlags.TypeScriptModifier) { - return undefined; - } - else if (currentNamespace && node.kind === SyntaxKind.ExportKeyword) { - return undefined; - } - - return node; - } - - /** - * Branching visitor, visits a TypeScript syntax node. - * - * @param node The node to visit. - */ - function visitTypeScript(node: Node): VisitResult { - if (isStatement(node) && hasModifier(node, ModifierFlags.Ambient)) { - // TypeScript ambient declarations are elided, but some comments may be preserved. - // See the implementation of `getLeadingComments` in comments.ts for more details. - return createNotEmittedStatement(node); - } - - switch (node.kind) { - case SyntaxKind.ExportKeyword: - case SyntaxKind.DefaultKeyword: - // ES6 export and default modifiers are elided when inside a namespace. - return currentNamespace ? undefined : node; - - case SyntaxKind.PublicKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.ProtectedKeyword: - case SyntaxKind.AbstractKeyword: - case SyntaxKind.ConstKeyword: - case SyntaxKind.DeclareKeyword: - case SyntaxKind.ReadonlyKeyword: - // TypeScript accessibility and readonly modifiers are elided - // falls through - case SyntaxKind.ArrayType: - case SyntaxKind.TupleType: - case SyntaxKind.OptionalType: - case SyntaxKind.RestType: - case SyntaxKind.TypeLiteral: - case SyntaxKind.TypePredicate: - case SyntaxKind.TypeParameter: - case SyntaxKind.AnyKeyword: - case SyntaxKind.UnknownKeyword: - case SyntaxKind.BooleanKeyword: - case SyntaxKind.StringKeyword: - case SyntaxKind.NumberKeyword: - case SyntaxKind.NeverKeyword: - case SyntaxKind.VoidKeyword: - case SyntaxKind.SymbolKeyword: - case SyntaxKind.ConstructorType: - case SyntaxKind.FunctionType: - case SyntaxKind.TypeQuery: - case SyntaxKind.TypeReference: - case SyntaxKind.UnionType: - case SyntaxKind.IntersectionType: - case SyntaxKind.ConditionalType: - case SyntaxKind.ParenthesizedType: - case SyntaxKind.ThisType: - case SyntaxKind.TypeOperator: - case SyntaxKind.IndexedAccessType: - case SyntaxKind.MappedType: - case SyntaxKind.LiteralType: - // TypeScript type nodes are elided. - // falls through - - case SyntaxKind.IndexSignature: - // TypeScript index signatures are elided. - // falls through - - case SyntaxKind.Decorator: - // TypeScript decorators are elided. They will be emitted as part of visitClassDeclaration. - // falls through - - case SyntaxKind.TypeAliasDeclaration: - // TypeScript type-only declarations are elided. - return undefined; - - case SyntaxKind.PropertyDeclaration: - // TypeScript property declarations are elided. However their names are still visited, and can potentially be retained if they could have sideeffects - return visitPropertyDeclaration(node as PropertyDeclaration); - - case SyntaxKind.NamespaceExportDeclaration: - // TypeScript namespace export declarations are elided. - return undefined; - - case SyntaxKind.Constructor: - return visitConstructor(node); - - case SyntaxKind.InterfaceDeclaration: - // TypeScript interfaces are elided, but some comments may be preserved. - // See the implementation of `getLeadingComments` in comments.ts for more details. - return createNotEmittedStatement(node); - - case SyntaxKind.ClassDeclaration: - // This may be a class declaration with TypeScript syntax extensions. - // - // TypeScript class syntax extensions include: - // - decorators - // - optional `implements` heritage clause - // - parameter property assignments in the constructor - // - index signatures - // - method overload signatures - return visitClassDeclaration(node); - - case SyntaxKind.ClassExpression: - // This may be a class expression with TypeScript syntax extensions. - // - // TypeScript class syntax extensions include: - // - decorators - // - optional `implements` heritage clause - // - parameter property assignments in the constructor - // - index signatures - // - method overload signatures - return visitClassExpression(node); - - case SyntaxKind.HeritageClause: - // This may be a heritage clause with TypeScript syntax extensions. - // - // TypeScript heritage clause extensions include: - // - `implements` clause - return visitHeritageClause(node); - - case SyntaxKind.ExpressionWithTypeArguments: - // TypeScript supports type arguments on an expression in an `extends` heritage clause. - return visitExpressionWithTypeArguments(node); - - case SyntaxKind.MethodDeclaration: - // TypeScript method declarations may have decorators, modifiers - // or type annotations. - return visitMethodDeclaration(node); - - case SyntaxKind.GetAccessor: - // Get Accessors can have TypeScript modifiers, decorators, and type annotations. - return visitGetAccessor(node); - - case SyntaxKind.SetAccessor: - // Set Accessors can have TypeScript modifiers and type annotations. - return visitSetAccessor(node); - - case SyntaxKind.FunctionDeclaration: - // Typescript function declarations can have modifiers, decorators, and type annotations. - return visitFunctionDeclaration(node); - - case SyntaxKind.FunctionExpression: - // TypeScript function expressions can have modifiers and type annotations. - return visitFunctionExpression(node); - - case SyntaxKind.ArrowFunction: - // TypeScript arrow functions can have modifiers and type annotations. - return visitArrowFunction(node); - - case SyntaxKind.Parameter: - // This may be a parameter declaration with TypeScript syntax extensions. - // - // TypeScript parameter declaration syntax extensions include: - // - decorators - // - accessibility modifiers - // - the question mark (?) token for optional parameters - // - type annotations - // - this parameters - return visitParameter(node); - - case SyntaxKind.ParenthesizedExpression: - // ParenthesizedExpressions are TypeScript if their expression is a - // TypeAssertion or AsExpression - return visitParenthesizedExpression(node); - - case SyntaxKind.TypeAssertionExpression: - case SyntaxKind.AsExpression: - // TypeScript type assertions are removed, but their subtrees are preserved. - return visitAssertionExpression(node); - - case SyntaxKind.CallExpression: - return visitCallExpression(node); - - case SyntaxKind.NewExpression: - return visitNewExpression(node); - - case SyntaxKind.TaggedTemplateExpression: - return visitTaggedTemplateExpression(node); - - case SyntaxKind.NonNullExpression: - // TypeScript non-null expressions are removed, but their subtrees are preserved. - return visitNonNullExpression(node); - - case SyntaxKind.EnumDeclaration: - // TypeScript enum declarations do not exist in ES6 and must be rewritten. - return visitEnumDeclaration(node); - - case SyntaxKind.VariableStatement: - // TypeScript namespace exports for variable statements must be transformed. - return visitVariableStatement(node); - - case SyntaxKind.VariableDeclaration: - return visitVariableDeclaration(node); - - case SyntaxKind.ModuleDeclaration: - // TypeScript namespace declarations must be transformed. - return visitModuleDeclaration(node); - - case SyntaxKind.ImportEqualsDeclaration: - // TypeScript namespace or external module import. - return visitImportEqualsDeclaration(node); - - default: - // node contains some other TypeScript syntax - return visitEachChild(node, visitor, context); - } - } - - function visitSourceFile(node: SourceFile) { - const alwaysStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") && - !(isExternalModule(node) && moduleKind >= ModuleKind.ES2015) && - !isJsonSourceFile(node); - - return updateSourceFileNode( - node, - visitLexicalEnvironment(node.statements, sourceElementVisitor, context, /*start*/ 0, alwaysStrict)); - } - - /** - * Tests whether we should emit a __decorate call for a class declaration. - */ - function shouldEmitDecorateCallForClass(node: ClassDeclaration) { - if (node.decorators && node.decorators.length > 0) { - return true; - } - - const constructor = getFirstConstructorWithBody(node); - if (constructor) { - return forEach(constructor.parameters, shouldEmitDecorateCallForParameter); - } - - return false; - } - - /** - * Tests whether we should emit a __decorate call for a parameter declaration. - */ - function shouldEmitDecorateCallForParameter(parameter: ParameterDeclaration) { - return parameter.decorators !== undefined && parameter.decorators.length > 0; - } - - function getClassFacts(node: ClassDeclaration, staticProperties: readonly PropertyDeclaration[]) { - let facts = ClassFacts.None; - if (some(staticProperties)) facts |= ClassFacts.HasStaticInitializedProperties; - const extendsClauseElement = getEffectiveBaseTypeNode(node); - if (extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword) facts |= ClassFacts.IsDerivedClass; - if (shouldEmitDecorateCallForClass(node)) facts |= ClassFacts.HasConstructorDecorators; - if (childIsDecorated(node)) facts |= ClassFacts.HasMemberDecorators; - if (isExportOfNamespace(node)) facts |= ClassFacts.IsExportOfNamespace; - else if (isDefaultExternalModuleExport(node)) facts |= ClassFacts.IsDefaultExternalExport; - else if (isNamedExternalModuleExport(node)) facts |= ClassFacts.IsNamedExternalExport; - if (languageVersion <= ScriptTarget.ES5 && (facts & ClassFacts.MayNeedImmediatelyInvokedFunctionExpression)) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression; - return facts; - } - - function hasTypeScriptClassSyntax(node: Node) { - return !!(node.transformFlags & TransformFlags.ContainsTypeScriptClassSyntax); - } - - function isClassLikeDeclarationWithTypeScriptSyntax(node: ClassLikeDeclaration) { - return some(node.decorators) - || some(node.typeParameters) - || some(node.heritageClauses, hasTypeScriptClassSyntax) - || some(node.members, hasTypeScriptClassSyntax); - } - - function visitClassDeclaration(node: ClassDeclaration): VisitResult { - if (!isClassLikeDeclarationWithTypeScriptSyntax(node) && !(currentNamespace && hasModifier(node, ModifierFlags.Export))) { - return visitEachChild(node, visitor, context); - } - - const staticProperties = getProperties(node, /*requireInitializer*/ true, /*isStatic*/ true); - const facts = getClassFacts(node, staticProperties); - - if (facts & ClassFacts.UseImmediatelyInvokedFunctionExpression) { - context.startLexicalEnvironment(); - } - - const name = node.name || (facts & ClassFacts.NeedsName ? getGeneratedNameForNode(node) : undefined); - const classStatement = facts & ClassFacts.HasConstructorDecorators - ? createClassDeclarationHeadWithDecorators(node, name) - : createClassDeclarationHeadWithoutDecorators(node, name, facts); - - let statements: Statement[] = [classStatement]; - - - // Write any decorators of the node. - addClassElementDecorationStatements(statements, node, /*isStatic*/ false); - addClassElementDecorationStatements(statements, node, /*isStatic*/ true); - addConstructorDecorationStatement(statements, node); - - if (facts & ClassFacts.UseImmediatelyInvokedFunctionExpression) { - // When we emit a TypeScript class down to ES5, we must wrap it in an IIFE so that the - // 'es2015' transformer can properly nest static initializers and decorators. The result - // looks something like: - // - // var C = function () { - // class C { - // } - // C.static_prop = 1; - // return C; - // }(); - // - const closingBraceLocation = createTokenRange(skipTrivia(currentSourceFile.text, node.members.end), SyntaxKind.CloseBraceToken); - const localName = getInternalName(node); - - // The following partially-emitted expression exists purely to align our sourcemap - // emit with the original emitter. - const outer = createPartiallyEmittedExpression(localName); - outer.end = closingBraceLocation.end; - setEmitFlags(outer, EmitFlags.NoComments); - - const statement = createReturn(outer); - statement.pos = closingBraceLocation.pos; - setEmitFlags(statement, EmitFlags.NoComments | EmitFlags.NoTokenSourceMaps); - statements.push(statement); - - insertStatementsAfterStandardPrologue(statements, context.endLexicalEnvironment()); - - const iife = createImmediatelyInvokedArrowFunction(statements); - setEmitFlags(iife, EmitFlags.TypeScriptClassWrapper); - - const varStatement = createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList([ - createVariableDeclaration( - getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ false), - /*type*/ undefined, - iife - ) - ]) - ); - - setOriginalNode(varStatement, node); - setCommentRange(varStatement, node); - setSourceMapRange(varStatement, moveRangePastDecorators(node)); - startOnNewLine(varStatement); - statements = [varStatement]; - } - - // If the class is exported as part of a TypeScript namespace, emit the namespace export. - // Otherwise, if the class was exported at the top level and was decorated, emit an export - // declaration or export default for the class. - if (facts & ClassFacts.IsExportOfNamespace) { - addExportMemberAssignment(statements, node); - } - else if (facts & ClassFacts.UseImmediatelyInvokedFunctionExpression || facts & ClassFacts.HasConstructorDecorators) { - if (facts & ClassFacts.IsDefaultExternalExport) { - statements.push(createExportDefault(getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true))); - } - else if (facts & ClassFacts.IsNamedExternalExport) { - statements.push(createExternalModuleExport(getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true))); - } - } - - if (statements.length > 1) { - // Add a DeclarationMarker as a marker for the end of the declaration - statements.push(createEndOfDeclarationMarker(node)); - setEmitFlags(classStatement, getEmitFlags(classStatement) | EmitFlags.HasEndOfDeclarationMarker); - } - - return singleOrMany(statements); - } - - /** - * Transforms a non-decorated class declaration and appends the resulting statements. - * - * @param node A ClassDeclaration node. - * @param name The name of the class. - * @param facts Precomputed facts about the class. - */ - function createClassDeclarationHeadWithoutDecorators(node: ClassDeclaration, name: Identifier | undefined, facts: ClassFacts) { - // ${modifiers} class ${name} ${heritageClauses} { - // ${members} - // } - - // we do not emit modifiers on the declaration if we are emitting an IIFE - const modifiers = !(facts & ClassFacts.UseImmediatelyInvokedFunctionExpression) - ? visitNodes(node.modifiers, modifierVisitor, isModifier) - : undefined; - - const classDeclaration = createClassDeclaration( - /*decorators*/ undefined, - modifiers, - name, - /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, visitor, isHeritageClause), - transformClassMembers(node) - ); - - // To better align with the old emitter, we should not emit a trailing source map - // entry if the class has static properties. - let emitFlags = getEmitFlags(node); - if (facts & ClassFacts.HasStaticInitializedProperties) { - emitFlags |= EmitFlags.NoTrailingSourceMap; - } - - aggregateTransformFlags(classDeclaration); - setTextRange(classDeclaration, node); - setOriginalNode(classDeclaration, node); - setEmitFlags(classDeclaration, emitFlags); - return classDeclaration; - } - - /** - * Transforms a decorated class declaration and appends the resulting statements. If - * the class requires an alias to avoid issues with double-binding, the alias is returned. - */ - function createClassDeclarationHeadWithDecorators(node: ClassDeclaration, name: Identifier | undefined) { - // When we emit an ES6 class that has a class decorator, we must tailor the - // emit to certain specific cases. - // - // In the simplest case, we emit the class declaration as a let declaration, and - // evaluate decorators after the close of the class body: - // - // [Example 1] - // --------------------------------------------------------------------- - // TypeScript | Javascript - // --------------------------------------------------------------------- - // @dec | let C = class C { - // class C { | } - // } | C = __decorate([dec], C); - // --------------------------------------------------------------------- - // @dec | let C = class C { - // export class C { | } - // } | C = __decorate([dec], C); - // | export { C }; - // --------------------------------------------------------------------- - // - // If a class declaration contains a reference to itself *inside* of the class body, - // this introduces two bindings to the class: One outside of the class body, and one - // inside of the class body. If we apply decorators as in [Example 1] above, there - // is the possibility that the decorator `dec` will return a new value for the - // constructor, which would result in the binding inside of the class no longer - // pointing to the same reference as the binding outside of the class. - // - // As a result, we must instead rewrite all references to the class *inside* of the - // class body to instead point to a local temporary alias for the class: - // - // [Example 2] - // --------------------------------------------------------------------- - // TypeScript | Javascript - // --------------------------------------------------------------------- - // @dec | let C = C_1 = class C { - // class C { | static x() { return C_1.y; } - // static x() { return C.y; } | } - // static y = 1; | C.y = 1; - // } | C = C_1 = __decorate([dec], C); - // | var C_1; - // --------------------------------------------------------------------- - // @dec | let C = class C { - // export class C { | static x() { return C_1.y; } - // static x() { return C.y; } | } - // static y = 1; | C.y = 1; - // } | C = C_1 = __decorate([dec], C); - // | export { C }; - // | var C_1; - // --------------------------------------------------------------------- - // - // If a class declaration is the default export of a module, we instead emit - // the export after the decorated declaration: - // - // [Example 3] - // --------------------------------------------------------------------- - // TypeScript | Javascript - // --------------------------------------------------------------------- - // @dec | let default_1 = class { - // export default class { | } - // } | default_1 = __decorate([dec], default_1); - // | export default default_1; - // --------------------------------------------------------------------- - // @dec | let C = class C { - // export default class C { | } - // } | C = __decorate([dec], C); - // | export default C; - // --------------------------------------------------------------------- - // - // If the class declaration is the default export and a reference to itself - // inside of the class body, we must emit both an alias for the class *and* - // move the export after the declaration: - // - // [Example 4] - // --------------------------------------------------------------------- - // TypeScript | Javascript - // --------------------------------------------------------------------- - // @dec | let C = class C { - // export default class C { | static x() { return C_1.y; } - // static x() { return C.y; } | } - // static y = 1; | C.y = 1; - // } | C = C_1 = __decorate([dec], C); - // | export default C; - // | var C_1; - // --------------------------------------------------------------------- - // - - const location = moveRangePastDecorators(node); - const classAlias = getClassAliasIfNeeded(node); - const declName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); - - // ... = class ${name} ${heritageClauses} { - // ${members} - // } - const heritageClauses = visitNodes(node.heritageClauses, visitor, isHeritageClause); - const members = transformClassMembers(node); - const classExpression = createClassExpression(/*modifiers*/ undefined, name, /*typeParameters*/ undefined, heritageClauses, members); - aggregateTransformFlags(classExpression); - setOriginalNode(classExpression, node); - setTextRange(classExpression, location); - - // let ${name} = ${classExpression} where name is either declaredName if the class doesn't contain self-reference - // or decoratedClassAlias if the class contain self-reference. - const statement = createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList([ - createVariableDeclaration( - declName, - /*type*/ undefined, - classAlias ? createAssignment(classAlias, classExpression) : classExpression - ) - ], NodeFlags.Let) - ); - setOriginalNode(statement, node); - setTextRange(statement, location); - setCommentRange(statement, node); - return statement; - } - - function visitClassExpression(node: ClassExpression): Expression { - if (!isClassLikeDeclarationWithTypeScriptSyntax(node)) { - return visitEachChild(node, visitor, context); - } - - const classExpression = createClassExpression( - /*modifiers*/ undefined, - node.name, - /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, visitor, isHeritageClause), - transformClassMembers(node) - ); - - aggregateTransformFlags(classExpression); - setOriginalNode(classExpression, node); - setTextRange(classExpression, node); - - return classExpression; - } - - /** - * Transforms the members of a class. - * - * @param node The current class. - */ - function transformClassMembers(node: ClassDeclaration | ClassExpression) { - const members: ClassElement[] = []; - const constructor = getFirstConstructorWithBody(node); - const parametersWithPropertyAssignments = constructor && - filter(constructor.parameters, p => isParameterPropertyDeclaration(p, constructor)); - - if (parametersWithPropertyAssignments) { - for (const parameter of parametersWithPropertyAssignments) { - if (isIdentifier(parameter.name)) { - members.push(aggregateTransformFlags(createProperty( - /*decorators*/ undefined, - /*modifiers*/ undefined, - parameter.name, - /*questionOrExclamationToken*/ undefined, - /*type*/ undefined, - /*initializer*/ undefined))); - } - } - } - - addRange(members, visitNodes(node.members, classElementVisitor, isClassElement)); - return setTextRange(createNodeArray(members), /*location*/ node.members); - } - - - /** - * Gets either the static or instance members of a class that are decorated, or have - * parameters that are decorated. - * - * @param node The class containing the member. - * @param isStatic A value indicating whether to retrieve static or instance members of - * the class. - */ - function getDecoratedClassElements(node: ClassExpression | ClassDeclaration, isStatic: boolean): readonly ClassElement[] { - return filter(node.members, isStatic ? m => isStaticDecoratedClassElement(m, node) : m => isInstanceDecoratedClassElement(m, node)); - } - - /** - * Determines whether a class member is a static member of a class that is decorated, or - * has parameters that are decorated. - * - * @param member The class member. - */ - function isStaticDecoratedClassElement(member: ClassElement, parent: ClassLikeDeclaration) { - return isDecoratedClassElement(member, /*isStatic*/ true, parent); - } - - /** - * Determines whether a class member is an instance member of a class that is decorated, - * or has parameters that are decorated. - * - * @param member The class member. - */ - function isInstanceDecoratedClassElement(member: ClassElement, parent: ClassLikeDeclaration) { - return isDecoratedClassElement(member, /*isStatic*/ false, parent); - } - - /** - * Determines whether a class member is either a static or an instance member of a class - * that is decorated, or has parameters that are decorated. - * - * @param member The class member. - */ - function isDecoratedClassElement(member: ClassElement, isStatic: boolean, parent: ClassLikeDeclaration) { - return nodeOrChildIsDecorated(member, parent) - && isStatic === hasModifier(member, ModifierFlags.Static); - } - - /** - * A structure describing the decorators for a class element. - */ - interface AllDecorators { - decorators: readonly Decorator[] | undefined; - parameters?: readonly (readonly Decorator[] | undefined)[]; - } - - /** - * Gets an array of arrays of decorators for the parameters of a function-like node. - * The offset into the result array should correspond to the offset of the parameter. - * - * @param node The function-like node. - */ - function getDecoratorsOfParameters(node: FunctionLikeDeclaration | undefined) { - let decorators: (readonly Decorator[] | undefined)[] | undefined; - if (node) { - const parameters = node.parameters; - const firstParameterIsThis = parameters.length > 0 && parameterIsThisKeyword(parameters[0]); - const firstParameterOffset = firstParameterIsThis ? 1 : 0; - const numParameters = firstParameterIsThis ? parameters.length - 1 : parameters.length; - for (let i = 0; i < numParameters; i++) { - const parameter = parameters[i + firstParameterOffset]; - if (decorators || parameter.decorators) { - if (!decorators) { - decorators = new Array(numParameters); - } - - decorators[i] = parameter.decorators; - } - } - } - - return decorators; - } - - /** - * Gets an AllDecorators object containing the decorators for the class and the decorators for the - * parameters of the constructor of the class. - * - * @param node The class node. - */ - function getAllDecoratorsOfConstructor(node: ClassExpression | ClassDeclaration): AllDecorators | undefined { - const decorators = node.decorators; - const parameters = getDecoratorsOfParameters(getFirstConstructorWithBody(node)); - if (!decorators && !parameters) { - return undefined; - } - - return { - decorators, - parameters - }; - } - - /** - * Gets an AllDecorators object containing the decorators for the member and its parameters. - * - * @param node The class node that contains the member. - * @param member The class member. - */ - function getAllDecoratorsOfClassElement(node: ClassExpression | ClassDeclaration, member: ClassElement): AllDecorators | undefined { - switch (member.kind) { - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return getAllDecoratorsOfAccessors(node, member); - - case SyntaxKind.MethodDeclaration: - return getAllDecoratorsOfMethod(member); - - case SyntaxKind.PropertyDeclaration: - return getAllDecoratorsOfProperty(member); - - default: - return undefined; - } - } - - /** - * Gets an AllDecorators object containing the decorators for the accessor and its parameters. - * - * @param node The class node that contains the accessor. - * @param accessor The class accessor member. - */ - function getAllDecoratorsOfAccessors(node: ClassExpression | ClassDeclaration, accessor: AccessorDeclaration): AllDecorators | undefined { - if (!accessor.body) { - return undefined; - } - - const { firstAccessor, secondAccessor, setAccessor } = getAllAccessorDeclarations(node.members, accessor); - const firstAccessorWithDecorators = firstAccessor.decorators ? firstAccessor : secondAccessor && secondAccessor.decorators ? secondAccessor : undefined; - if (!firstAccessorWithDecorators || accessor !== firstAccessorWithDecorators) { - return undefined; - } - - const decorators = firstAccessorWithDecorators.decorators; - const parameters = getDecoratorsOfParameters(setAccessor); - if (!decorators && !parameters) { - return undefined; - } - - return { decorators, parameters }; - } - - /** - * Gets an AllDecorators object containing the decorators for the method and its parameters. - * - * @param method The class method member. - */ - function getAllDecoratorsOfMethod(method: MethodDeclaration): AllDecorators | undefined { - if (!method.body) { - return undefined; - } - - const decorators = method.decorators; - const parameters = getDecoratorsOfParameters(method); - if (!decorators && !parameters) { - return undefined; - } - - return { decorators, parameters }; - } - - /** - * Gets an AllDecorators object containing the decorators for the property. - * - * @param property The class property member. - */ - function getAllDecoratorsOfProperty(property: PropertyDeclaration): AllDecorators | undefined { - const decorators = property.decorators; - if (!decorators) { - return undefined; - - } - - return { decorators }; - } - - /** - * Transforms all of the decorators for a declaration into an array of expressions. - * - * @param node The declaration node. - * @param allDecorators An object containing all of the decorators for the declaration. - */ - function transformAllDecoratorsOfDeclaration(node: Declaration, container: ClassLikeDeclaration, allDecorators: AllDecorators | undefined) { - if (!allDecorators) { - return undefined; - } - - const decoratorExpressions: Expression[] = []; - addRange(decoratorExpressions, map(allDecorators.decorators, transformDecorator)); - addRange(decoratorExpressions, flatMap(allDecorators.parameters, transformDecoratorsOfParameter)); - addTypeMetadata(node, container, decoratorExpressions); - return decoratorExpressions; - } - - /** - * Generates statements used to apply decorators to either the static or instance members - * of a class. - * - * @param node The class node. - * @param isStatic A value indicating whether to generate statements for static or - * instance members. - */ - function addClassElementDecorationStatements(statements: Statement[], node: ClassDeclaration, isStatic: boolean) { - addRange(statements, map(generateClassElementDecorationExpressions(node, isStatic), expressionToStatement)); - } - - /** - * Generates expressions used to apply decorators to either the static or instance members - * of a class. - * - * @param node The class node. - * @param isStatic A value indicating whether to generate expressions for static or - * instance members. - */ - function generateClassElementDecorationExpressions(node: ClassExpression | ClassDeclaration, isStatic: boolean) { - const members = getDecoratedClassElements(node, isStatic); - let expressions: Expression[] | undefined; - for (const member of members) { - const expression = generateClassElementDecorationExpression(node, member); - if (expression) { - if (!expressions) { - expressions = [expression]; - } - else { - expressions.push(expression); - } - } - } - return expressions; - } - - /** - * Generates an expression used to evaluate class element decorators at runtime. - * - * @param node The class node that contains the member. - * @param member The class member. - */ - function generateClassElementDecorationExpression(node: ClassExpression | ClassDeclaration, member: ClassElement) { - const allDecorators = getAllDecoratorsOfClassElement(node, member); - const decoratorExpressions = transformAllDecoratorsOfDeclaration(member, node, allDecorators); - if (!decoratorExpressions) { - return undefined; - } - - // Emit the call to __decorate. Given the following: - // - // class C { - // @dec method(@dec2 x) {} - // @dec get accessor() {} - // @dec prop; - // } - // - // The emit for a method is: - // - // __decorate([ - // dec, - // __param(0, dec2), - // __metadata("design:type", Function), - // __metadata("design:paramtypes", [Object]), - // __metadata("design:returntype", void 0) - // ], C.prototype, "method", null); - // - // The emit for an accessor is: - // - // __decorate([ - // dec - // ], C.prototype, "accessor", null); - // - // The emit for a property is: - // - // __decorate([ - // dec - // ], C.prototype, "prop"); - // - - const prefix = getClassMemberPrefix(node, member); - const memberName = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ true); - const descriptor = languageVersion > ScriptTarget.ES3 - ? member.kind === SyntaxKind.PropertyDeclaration - // We emit `void 0` here to indicate to `__decorate` that it can invoke `Object.defineProperty` directly, but that it - // should not invoke `Object.getOwnPropertyDescriptor`. - ? createVoidZero() - - // We emit `null` here to indicate to `__decorate` that it can invoke `Object.getOwnPropertyDescriptor` directly. - // We have this extra argument here so that we can inject an explicit property descriptor at a later date. - : createNull() - : undefined; - - const helper = createDecorateHelper( - context, - decoratorExpressions, - prefix, - memberName, - descriptor, - moveRangePastDecorators(member) - ); - - setEmitFlags(helper, EmitFlags.NoComments); - return helper; - } - - /** - * Generates a __decorate helper call for a class constructor. - * - * @param node The class node. - */ - function addConstructorDecorationStatement(statements: Statement[], node: ClassDeclaration) { - const expression = generateConstructorDecorationExpression(node); - if (expression) { - statements.push(setOriginalNode(createExpressionStatement(expression), node)); - } - } - - /** - * Generates a __decorate helper call for a class constructor. - * - * @param node The class node. - */ - function generateConstructorDecorationExpression(node: ClassExpression | ClassDeclaration) { - const allDecorators = getAllDecoratorsOfConstructor(node); - const decoratorExpressions = transformAllDecoratorsOfDeclaration(node, node, allDecorators); - if (!decoratorExpressions) { - return undefined; - } - - const classAlias = classAliases && classAliases[getOriginalNodeId(node)]; - const localName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); - const decorate = createDecorateHelper(context, decoratorExpressions, localName); - const expression = createAssignment(localName, classAlias ? createAssignment(classAlias, decorate) : decorate); - setEmitFlags(expression, EmitFlags.NoComments); - setSourceMapRange(expression, moveRangePastDecorators(node)); - return expression; - } - - /** - * Transforms a decorator into an expression. - * - * @param decorator The decorator node. - */ - function transformDecorator(decorator: Decorator) { - return visitNode(decorator.expression, visitor, isExpression); - } - - /** - * Transforms the decorators of a parameter. - * - * @param decorators The decorators for the parameter at the provided offset. - * @param parameterOffset The offset of the parameter. - */ - function transformDecoratorsOfParameter(decorators: Decorator[], parameterOffset: number) { - let expressions: Expression[] | undefined; - if (decorators) { - expressions = []; - for (const decorator of decorators) { - const helper = createParamHelper( - context, - transformDecorator(decorator), - parameterOffset, - /*location*/ decorator.expression); - setEmitFlags(helper, EmitFlags.NoComments); - expressions.push(helper); - } - } - - return expressions; - } - - /** - * Adds optional type metadata for a declaration. - * - * @param node The declaration node. - * @param decoratorExpressions The destination array to which to add new decorator expressions. - */ - function addTypeMetadata(node: Declaration, container: ClassLikeDeclaration, decoratorExpressions: Expression[]) { - if (USE_NEW_TYPE_METADATA_FORMAT) { - addNewTypeMetadata(node, container, decoratorExpressions); - } - else { - addOldTypeMetadata(node, container, decoratorExpressions); - } - } - - function addOldTypeMetadata(node: Declaration, container: ClassLikeDeclaration, decoratorExpressions: Expression[]) { - if (compilerOptions.emitDecoratorMetadata) { - if (shouldAddTypeMetadata(node)) { - decoratorExpressions.push(createMetadataHelper(context, "design:type", serializeTypeOfNode(node))); - } - if (shouldAddParamTypesMetadata(node)) { - decoratorExpressions.push(createMetadataHelper(context, "design:paramtypes", serializeParameterTypesOfNode(node, container))); - } - if (shouldAddReturnTypeMetadata(node)) { - decoratorExpressions.push(createMetadataHelper(context, "design:returntype", serializeReturnTypeOfNode(node))); - } - } - } - - function addNewTypeMetadata(node: Declaration, container: ClassLikeDeclaration, decoratorExpressions: Expression[]) { - if (compilerOptions.emitDecoratorMetadata) { - let properties: ObjectLiteralElementLike[] | undefined; - if (shouldAddTypeMetadata(node)) { - (properties || (properties = [])).push(createPropertyAssignment("type", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeTypeOfNode(node)))); - } - if (shouldAddParamTypesMetadata(node)) { - (properties || (properties = [])).push(createPropertyAssignment("paramTypes", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeParameterTypesOfNode(node, container)))); - } - if (shouldAddReturnTypeMetadata(node)) { - (properties || (properties = [])).push(createPropertyAssignment("returnType", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeReturnTypeOfNode(node)))); - } - if (properties) { - decoratorExpressions.push(createMetadataHelper(context, "design:typeinfo", createObjectLiteral(properties, /*multiLine*/ true))); - } - } - } - - /** - * Determines whether to emit the "design:type" metadata based on the node's kind. - * The caller should have already tested whether the node has decorators and whether the - * emitDecoratorMetadata compiler option is set. - * - * @param node The node to test. - */ - function shouldAddTypeMetadata(node: Declaration): boolean { - const kind = node.kind; - return kind === SyntaxKind.MethodDeclaration - || kind === SyntaxKind.GetAccessor - || kind === SyntaxKind.SetAccessor - || kind === SyntaxKind.PropertyDeclaration; - } - - /** - * Determines whether to emit the "design:returntype" metadata based on the node's kind. - * The caller should have already tested whether the node has decorators and whether the - * emitDecoratorMetadata compiler option is set. - * - * @param node The node to test. - */ - function shouldAddReturnTypeMetadata(node: Declaration): boolean { - return node.kind === SyntaxKind.MethodDeclaration; - } - - /** - * Determines whether to emit the "design:paramtypes" metadata based on the node's kind. - * The caller should have already tested whether the node has decorators and whether the - * emitDecoratorMetadata compiler option is set. - * - * @param node The node to test. - */ - function shouldAddParamTypesMetadata(node: Declaration): boolean { - switch (node.kind) { - case SyntaxKind.ClassDeclaration: - case SyntaxKind.ClassExpression: - return getFirstConstructorWithBody(node) !== undefined; - case SyntaxKind.MethodDeclaration: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return true; - } - return false; - } - - type SerializedEntityNameAsExpression = Identifier | BinaryExpression | PropertyAccessExpression; - type SerializedTypeNode = SerializedEntityNameAsExpression | VoidExpression | ConditionalExpression; - - function getAccessorTypeNode(node: AccessorDeclaration) { - const accessors = resolver.getAllAccessorDeclarations(node); - return accessors.setAccessor && getSetAccessorTypeAnnotationNode(accessors.setAccessor) - || accessors.getAccessor && getEffectiveReturnTypeNode(accessors.getAccessor); - } - - /** - * Serializes the type of a node for use with decorator type metadata. - * - * @param node The node that should have its type serialized. - */ - function serializeTypeOfNode(node: Node): SerializedTypeNode { - switch (node.kind) { - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.Parameter: - return serializeTypeNode((node).type); - case SyntaxKind.SetAccessor: - case SyntaxKind.GetAccessor: - return serializeTypeNode(getAccessorTypeNode(node as AccessorDeclaration)); - case SyntaxKind.ClassDeclaration: - case SyntaxKind.ClassExpression: - case SyntaxKind.MethodDeclaration: - return createIdentifier("Function"); - default: - return createVoidZero(); - } - } - - /** - * Serializes the types of the parameters of a node for use with decorator type metadata. - * - * @param node The node that should have its parameter types serialized. - */ - function serializeParameterTypesOfNode(node: Node, container: ClassLikeDeclaration): ArrayLiteralExpression { - const valueDeclaration = - isClassLike(node) - ? getFirstConstructorWithBody(node) - : isFunctionLike(node) && nodeIsPresent((node as FunctionLikeDeclaration).body) - ? node - : undefined; - - const expressions: SerializedTypeNode[] = []; - if (valueDeclaration) { - const parameters = getParametersOfDecoratedDeclaration(valueDeclaration, container); - const numParameters = parameters.length; - for (let i = 0; i < numParameters; i++) { - const parameter = parameters[i]; - if (i === 0 && isIdentifier(parameter.name) && parameter.name.escapedText === "this") { - continue; - } - if (parameter.dotDotDotToken) { - expressions.push(serializeTypeNode(getRestParameterElementType(parameter.type))); - } - else { - expressions.push(serializeTypeOfNode(parameter)); - } - } - } - - return createArrayLiteral(expressions); - } - - function getParametersOfDecoratedDeclaration(node: SignatureDeclaration, container: ClassLikeDeclaration) { - if (container && node.kind === SyntaxKind.GetAccessor) { - const { setAccessor } = getAllAccessorDeclarations(container.members, node); - if (setAccessor) { - return setAccessor.parameters; - } - } - return node.parameters; - } - - /** - * Serializes the return type of a node for use with decorator type metadata. - * - * @param node The node that should have its return type serialized. - */ - function serializeReturnTypeOfNode(node: Node): SerializedTypeNode { - if (isFunctionLike(node) && node.type) { - return serializeTypeNode(node.type); - } - else if (isAsyncFunction(node)) { - return createIdentifier("Promise"); - } - - return createVoidZero(); - } - - /** - * Serializes a type node for use with decorator type metadata. - * - * Types are serialized in the following fashion: - * - Void types point to "undefined" (e.g. "void 0") - * - Function and Constructor types point to the global "Function" constructor. - * - Interface types with a call or construct signature types point to the global - * "Function" constructor. - * - Array and Tuple types point to the global "Array" constructor. - * - Type predicates and booleans point to the global "Boolean" constructor. - * - String literal types and strings point to the global "String" constructor. - * - Enum and number types point to the global "Number" constructor. - * - Symbol types point to the global "Symbol" constructor. - * - Type references to classes (or class-like variables) point to the constructor for the class. - * - Anything else points to the global "Object" constructor. - * - * @param node The type node to serialize. - */ - function serializeTypeNode(node: TypeNode | undefined): SerializedTypeNode { - if (node === undefined) { - return createIdentifier("Object"); - } - - switch (node.kind) { - case SyntaxKind.VoidKeyword: - case SyntaxKind.UndefinedKeyword: - case SyntaxKind.NullKeyword: - case SyntaxKind.NeverKeyword: - return createVoidZero(); - - case SyntaxKind.ParenthesizedType: - return serializeTypeNode((node).type); - - case SyntaxKind.FunctionType: - case SyntaxKind.ConstructorType: - return createIdentifier("Function"); - - case SyntaxKind.ArrayType: - case SyntaxKind.TupleType: - return createIdentifier("Array"); - - case SyntaxKind.TypePredicate: - case SyntaxKind.BooleanKeyword: - return createIdentifier("Boolean"); - - case SyntaxKind.StringKeyword: - return createIdentifier("String"); - - case SyntaxKind.ObjectKeyword: - return createIdentifier("Object"); - - case SyntaxKind.LiteralType: - switch ((node).literal.kind) { - case SyntaxKind.StringLiteral: - return createIdentifier("String"); - - case SyntaxKind.PrefixUnaryExpression: - case SyntaxKind.NumericLiteral: - return createIdentifier("Number"); - - case SyntaxKind.BigIntLiteral: - return getGlobalBigIntNameWithFallback(); - - case SyntaxKind.TrueKeyword: - case SyntaxKind.FalseKeyword: - return createIdentifier("Boolean"); - - default: - return Debug.failBadSyntaxKind((node).literal); - } - - case SyntaxKind.NumberKeyword: - return createIdentifier("Number"); - - case SyntaxKind.BigIntKeyword: - return getGlobalBigIntNameWithFallback(); - - case SyntaxKind.SymbolKeyword: - return languageVersion < ScriptTarget.ES2015 - ? getGlobalSymbolNameWithFallback() - : createIdentifier("Symbol"); - - case SyntaxKind.TypeReference: - return serializeTypeReferenceNode(node); - - case SyntaxKind.IntersectionType: - case SyntaxKind.UnionType: - return serializeTypeList((node).types); - - case SyntaxKind.ConditionalType: - return serializeTypeList([(node).trueType, (node).falseType]); - - case SyntaxKind.TypeOperator: - if ((node).operator === SyntaxKind.ReadonlyKeyword) { - return serializeTypeNode((node).type); - } - break; - - case SyntaxKind.TypeQuery: - case SyntaxKind.IndexedAccessType: - case SyntaxKind.MappedType: - case SyntaxKind.TypeLiteral: - case SyntaxKind.AnyKeyword: - case SyntaxKind.UnknownKeyword: - case SyntaxKind.ThisType: - case SyntaxKind.ImportType: - break; - - - default: - return Debug.failBadSyntaxKind(node); - } - - return createIdentifier("Object"); - } - - function serializeTypeList(types: readonly TypeNode[]): SerializedTypeNode { - // Note when updating logic here also update getEntityNameForDecoratorMetadata - // so that aliases can be marked as referenced - let serializedUnion: SerializedTypeNode | undefined; - for (let typeNode of types) { - while (typeNode.kind === SyntaxKind.ParenthesizedType) { - typeNode = (typeNode as ParenthesizedTypeNode).type; // Skip parens if need be - } - if (typeNode.kind === SyntaxKind.NeverKeyword) { - continue; // Always elide `never` from the union/intersection if possible - } - if (!strictNullChecks && (typeNode.kind === SyntaxKind.NullKeyword || typeNode.kind === SyntaxKind.UndefinedKeyword)) { - continue; // Elide null and undefined from unions for metadata, just like what we did prior to the implementation of strict null checks - } - const serializedIndividual = serializeTypeNode(typeNode); - - if (isIdentifier(serializedIndividual) && serializedIndividual.escapedText === "Object") { - // One of the individual is global object, return immediately - return serializedIndividual; - } - // If there exists union that is not void 0 expression, check if the the common type is identifier. - // anything more complex and we will just default to Object - else if (serializedUnion) { - // Different types - if (!isIdentifier(serializedUnion) || - !isIdentifier(serializedIndividual) || - serializedUnion.escapedText !== serializedIndividual.escapedText) { - return createIdentifier("Object"); - } - } - else { - // Initialize the union type - serializedUnion = serializedIndividual; - } - } - - // If we were able to find common type, use it - return serializedUnion || createVoidZero(); // Fallback is only hit if all union constituients are null/undefined/never - } - - /** - * Serializes a TypeReferenceNode to an appropriate JS constructor value for use with - * decorator type metadata. - * - * @param node The type reference node. - */ - function serializeTypeReferenceNode(node: TypeReferenceNode): SerializedTypeNode { - const kind = resolver.getTypeReferenceSerializationKind(node.typeName, currentNameScope || currentLexicalScope); - switch (kind) { - case TypeReferenceSerializationKind.Unknown: - // From conditional type type reference that cannot be resolved is Similar to any or unknown - if (findAncestor(node, n => n.parent && isConditionalTypeNode(n.parent) && (n.parent.trueType === n || n.parent.falseType === n))) { - return createIdentifier("Object"); - } - - const serialized = serializeEntityNameAsExpressionFallback(node.typeName); - const temp = createTempVariable(hoistVariableDeclaration); - return createConditional( - createTypeCheck(createAssignment(temp, serialized), "function"), - temp, - createIdentifier("Object") - ); - - case TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: - return serializeEntityNameAsExpression(node.typeName); - - case TypeReferenceSerializationKind.VoidNullableOrNeverType: - return createVoidZero(); - - case TypeReferenceSerializationKind.BigIntLikeType: - return getGlobalBigIntNameWithFallback(); - - case TypeReferenceSerializationKind.BooleanType: - return createIdentifier("Boolean"); - - case TypeReferenceSerializationKind.NumberLikeType: - return createIdentifier("Number"); - - case TypeReferenceSerializationKind.StringLikeType: - return createIdentifier("String"); - - case TypeReferenceSerializationKind.ArrayLikeType: - return createIdentifier("Array"); - - case TypeReferenceSerializationKind.ESSymbolType: - return languageVersion < ScriptTarget.ES2015 - ? getGlobalSymbolNameWithFallback() - : createIdentifier("Symbol"); - - case TypeReferenceSerializationKind.TypeWithCallSignature: - return createIdentifier("Function"); - - case TypeReferenceSerializationKind.Promise: - return createIdentifier("Promise"); - - case TypeReferenceSerializationKind.ObjectType: - return createIdentifier("Object"); - default: - return Debug.assertNever(kind); - } - } - - function createCheckedValue(left: Expression, right: Expression) { - return createLogicalAnd( - createStrictInequality(createTypeOf(left), createLiteral("undefined")), - right - ); - } - - /** - * Serializes an entity name which may not exist at runtime, but whose access shouldn't throw - * - * @param node The entity name to serialize. - */ - function serializeEntityNameAsExpressionFallback(node: EntityName): BinaryExpression { - if (node.kind === SyntaxKind.Identifier) { - // A -> typeof A !== undefined && A - const copied = serializeEntityNameAsExpression(node); - return createCheckedValue(copied, copied); - } - if (node.left.kind === SyntaxKind.Identifier) { - // A.B -> typeof A !== undefined && A.B - return createCheckedValue(serializeEntityNameAsExpression(node.left), serializeEntityNameAsExpression(node)); - } - // A.B.C -> typeof A !== undefined && (_a = A.B) !== void 0 && _a.C - const left = serializeEntityNameAsExpressionFallback(node.left); - const temp = createTempVariable(hoistVariableDeclaration); - return createLogicalAnd( - createLogicalAnd( - left.left, - createStrictInequality(createAssignment(temp, left.right), createVoidZero()) - ), - createPropertyAccess(temp, node.right) - ); - } - - /** - * Serializes an entity name as an expression for decorator type metadata. - * - * @param node The entity name to serialize. - */ - function serializeEntityNameAsExpression(node: EntityName): SerializedEntityNameAsExpression { - switch (node.kind) { - case SyntaxKind.Identifier: - // Create a clone of the name with a new parent, and treat it as if it were - // a source tree node for the purposes of the checker. - const name = getMutableClone(node); - name.flags &= ~NodeFlags.Synthesized; - name.original = undefined; - name.parent = getParseTreeNode(currentLexicalScope); // ensure the parent is set to a parse tree node. - - return name; - - case SyntaxKind.QualifiedName: - return serializeQualifiedNameAsExpression(node); - } - } - - /** - * Serializes an qualified name as an expression for decorator type metadata. - * - * @param node The qualified name to serialize. - * @param useFallback A value indicating whether to use logical operators to test for the - * qualified name at runtime. - */ - function serializeQualifiedNameAsExpression(node: QualifiedName): SerializedEntityNameAsExpression { - return createPropertyAccess(serializeEntityNameAsExpression(node.left), node.right); - } - - /** - * Gets an expression that points to the global "Symbol" constructor at runtime if it is - * available. - */ - function getGlobalSymbolNameWithFallback(): ConditionalExpression { - return createConditional( - createTypeCheck(createIdentifier("Symbol"), "function"), - createIdentifier("Symbol"), - createIdentifier("Object") - ); - } - - /** - * Gets an expression that points to the global "BigInt" constructor at runtime if it is - * available. - */ - function getGlobalBigIntNameWithFallback(): SerializedTypeNode { - return languageVersion < ScriptTarget.ESNext - ? createConditional( - createTypeCheck(createIdentifier("BigInt"), "function"), - createIdentifier("BigInt"), - createIdentifier("Object") - ) - : createIdentifier("BigInt"); - } - - /** - * Gets an expression that represents a property name. For a computed property, a - * name is generated for the node. - * - * @param member The member whose name should be converted into an expression. - */ - function getExpressionForPropertyName(member: ClassElement | EnumMember, generateNameForComputedPropertyName: boolean): Expression { - const name = member.name!; - if (isComputedPropertyName(name)) { - return generateNameForComputedPropertyName && !isSimpleInlineableExpression(name.expression) - ? getGeneratedNameForNode(name) - : name.expression; - } - else if (isIdentifier(name)) { - return createLiteral(idText(name)); - } - else { - return getSynthesizedClone(name); - } - } - - /** - * Visits the property name of a class element, for use when emitting property - * initializers. For a computed property on a node with decorators, a temporary - * value is stored for later use. - * - * @param member The member whose name should be visited. - */ - function visitPropertyNameOfClassElement(member: ClassElement): PropertyName { - const name = member.name!; - // Computed property names need to be transformed into a hoisted variable when they are used more than once. - // The names are used more than once when: - // - the property is non-static and its initializer is moved to the constructor (when there are parameter property assignments). - // - the property has a decorator. - if (isComputedPropertyName(name) && ((!hasStaticModifier(member) && currentClassHasParameterProperties) || some(member.decorators))) { - const expression = visitNode(name.expression, visitor, isExpression); - const innerExpression = skipPartiallyEmittedExpressions(expression); - if (!isSimpleInlineableExpression(innerExpression)) { - const generatedName = getGeneratedNameForNode(name); - hoistVariableDeclaration(generatedName); - return updateComputedPropertyName(name, createAssignment(generatedName, expression)); - } - } - return visitNode(name, visitor, isPropertyName); - } - - /** - * Transforms a HeritageClause with TypeScript syntax. - * - * This function will only be called when one of the following conditions are met: - * - The node is a non-`extends` heritage clause that should be elided. - * - The node is an `extends` heritage clause that should be visited, but only allow a single type. - * - * @param node The HeritageClause to transform. - */ - function visitHeritageClause(node: HeritageClause): HeritageClause | undefined { - if (node.token === SyntaxKind.ImplementsKeyword) { - // implements clauses are elided - return undefined; - } - return visitEachChild(node, visitor, context); - } - - /** - * Transforms an ExpressionWithTypeArguments with TypeScript syntax. - * - * This function will only be called when one of the following conditions are met: - * - The node contains type arguments that should be elided. - * - * @param node The ExpressionWithTypeArguments to transform. - */ - function visitExpressionWithTypeArguments(node: ExpressionWithTypeArguments): ExpressionWithTypeArguments { - return updateExpressionWithTypeArguments( - node, - /*typeArguments*/ undefined, - visitNode(node.expression, visitor, isLeftHandSideExpression) - ); - } - - /** - * Determines whether to emit a function-like declaration. We should not emit the - * declaration if it does not have a body. - * - * @param node The declaration node. - */ - function shouldEmitFunctionLikeDeclaration(node: T): node is T & { body: NonNullable } { - return !nodeIsMissing(node.body); - } - - function visitPropertyDeclaration(node: PropertyDeclaration) { - const updated = updateProperty( - node, - /*decorators*/ undefined, - visitNodes(node.modifiers, visitor, isModifier), - visitPropertyNameOfClassElement(node), - /*questionOrExclamationToken*/ undefined, - /*type*/ undefined, - visitNode(node.initializer, visitor) - ); - if (updated !== node) { - // While we emit the source map for the node after skipping decorators and modifiers, - // we need to emit the comments for the original range. - setCommentRange(updated, node); - setSourceMapRange(updated, moveRangePastDecorators(node)); - } - return updated; - } - - function visitConstructor(node: ConstructorDeclaration) { - if (!shouldEmitFunctionLikeDeclaration(node)) { - return undefined; - } - - return updateConstructor( - node, - /*decorators*/ undefined, - /*modifiers*/ undefined, - visitParameterList(node.parameters, visitor, context), - transformConstructorBody(node.body, node) - ); - } - - function transformConstructorBody(body: Block, constructor: ConstructorDeclaration) { - const parametersWithPropertyAssignments = constructor && - filter(constructor.parameters, p => isParameterPropertyDeclaration(p, constructor)); - if (!some(parametersWithPropertyAssignments)) { - return visitFunctionBody(body, visitor, context); - } - - let statements: Statement[] = []; - let indexOfFirstStatement = 0; - - resumeLexicalEnvironment(); - - indexOfFirstStatement = addPrologueDirectivesAndInitialSuperCall(constructor, statements, visitor); - - // Add parameters with property assignments. Transforms this: - // - // constructor (public x, public y) { - // } - // - // Into this: - // - // constructor (x, y) { - // this.x = x; - // this.y = y; - // } - // - addRange(statements, map(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment)); - - // Add the existing statements, skipping the initial super call. - addRange(statements, visitNodes(body.statements, visitor, isStatement, indexOfFirstStatement)); - - // End the lexical environment. - statements = mergeLexicalEnvironment(statements, endLexicalEnvironment()); - const block = createBlock(setTextRange(createNodeArray(statements), body.statements), /*multiLine*/ true); - setTextRange(block, /*location*/ body); - setOriginalNode(block, body); - return block; - } - - /** - * Transforms a parameter into a property assignment statement. - * - * @param node The parameter declaration. - */ - function transformParameterWithPropertyAssignment(node: ParameterPropertyDeclaration) { - const name = node.name; - if (!isIdentifier(name)) { - return undefined; - } - - const propertyName = getMutableClone(name); - setEmitFlags(propertyName, EmitFlags.NoComments | EmitFlags.NoSourceMap); - - const localName = getMutableClone(name); - setEmitFlags(localName, EmitFlags.NoComments); - - return startOnNewLine( - removeAllComments( - setTextRange( - setOriginalNode( - createExpressionStatement( - createAssignment( - setTextRange( - createPropertyAccess( - createThis(), - propertyName - ), - node.name - ), - localName - ) - ), - node - ), - moveRangePos(node, -1) - ) - ) - ); - } - - function visitMethodDeclaration(node: MethodDeclaration) { - if (!shouldEmitFunctionLikeDeclaration(node)) { - return undefined; - } - const updated = updateMethod( - node, - /*decorators*/ undefined, - visitNodes(node.modifiers, modifierVisitor, isModifier), - node.asteriskToken, - visitPropertyNameOfClassElement(node), - /*questionToken*/ undefined, - /*typeParameters*/ undefined, - visitParameterList(node.parameters, visitor, context), - /*type*/ undefined, - visitFunctionBody(node.body, visitor, context) - ); - if (updated !== node) { - // While we emit the source map for the node after skipping decorators and modifiers, - // we need to emit the comments for the original range. - setCommentRange(updated, node); - setSourceMapRange(updated, moveRangePastDecorators(node)); - } - return updated; - } - - /** - * Determines whether to emit an accessor declaration. We should not emit the - * declaration if it does not have a body and is abstract. - * - * @param node The declaration node. - */ - function shouldEmitAccessorDeclaration(node: AccessorDeclaration) { - return !(nodeIsMissing(node.body) && hasModifier(node, ModifierFlags.Abstract)); - } - - function visitGetAccessor(node: GetAccessorDeclaration) { - if (!shouldEmitAccessorDeclaration(node)) { - return undefined; - } - const updated = updateGetAccessor( - node, - /*decorators*/ undefined, - visitNodes(node.modifiers, modifierVisitor, isModifier), - visitPropertyNameOfClassElement(node), - visitParameterList(node.parameters, visitor, context), - /*type*/ undefined, - visitFunctionBody(node.body, visitor, context) || createBlock([]) - ); - if (updated !== node) { - // While we emit the source map for the node after skipping decorators and modifiers, - // we need to emit the comments for the original range. - setCommentRange(updated, node); - setSourceMapRange(updated, moveRangePastDecorators(node)); - } - return updated; - } - - function visitSetAccessor(node: SetAccessorDeclaration) { - if (!shouldEmitAccessorDeclaration(node)) { - return undefined; - } - const updated = updateSetAccessor( - node, - /*decorators*/ undefined, - visitNodes(node.modifiers, modifierVisitor, isModifier), - visitPropertyNameOfClassElement(node), - visitParameterList(node.parameters, visitor, context), - visitFunctionBody(node.body, visitor, context) || createBlock([]) - ); - if (updated !== node) { - // While we emit the source map for the node after skipping decorators and modifiers, - // we need to emit the comments for the original range. - setCommentRange(updated, node); - setSourceMapRange(updated, moveRangePastDecorators(node)); - } - return updated; - } - - function visitFunctionDeclaration(node: FunctionDeclaration): VisitResult { - if (!shouldEmitFunctionLikeDeclaration(node)) { - return createNotEmittedStatement(node); - } - const updated = updateFunctionDeclaration( - node, - /*decorators*/ undefined, - visitNodes(node.modifiers, modifierVisitor, isModifier), - node.asteriskToken, - node.name, - /*typeParameters*/ undefined, - visitParameterList(node.parameters, visitor, context), - /*type*/ undefined, - visitFunctionBody(node.body, visitor, context) || createBlock([]) - ); - if (isExportOfNamespace(node)) { - const statements: Statement[] = [updated]; - addExportMemberAssignment(statements, node); - return statements; - } - return updated; - } - - function visitFunctionExpression(node: FunctionExpression): Expression { - if (!shouldEmitFunctionLikeDeclaration(node)) { - return createOmittedExpression(); - } - const updated = updateFunctionExpression( - node, - visitNodes(node.modifiers, modifierVisitor, isModifier), - node.asteriskToken, - node.name, - /*typeParameters*/ undefined, - visitParameterList(node.parameters, visitor, context), - /*type*/ undefined, - visitFunctionBody(node.body, visitor, context) || createBlock([]) - ); - return updated; - } - - function visitArrowFunction(node: ArrowFunction) { - const updated = updateArrowFunction( - node, - visitNodes(node.modifiers, modifierVisitor, isModifier), - /*typeParameters*/ undefined, - visitParameterList(node.parameters, visitor, context), - /*type*/ undefined, - node.equalsGreaterThanToken, - visitFunctionBody(node.body, visitor, context), - ); - return updated; - } - - function visitParameter(node: ParameterDeclaration) { - if (parameterIsThisKeyword(node)) { - return undefined; - } - - const updated = updateParameter( - node, - /*decorators*/ undefined, - /*modifiers*/ undefined, - node.dotDotDotToken, - visitNode(node.name, visitor, isBindingName), - /*questionToken*/ undefined, - /*type*/ undefined, - visitNode(node.initializer, visitor, isExpression) - ); - if (updated !== node) { - // While we emit the source map for the node after skipping decorators and modifiers, - // we need to emit the comments for the original range. - setCommentRange(updated, node); - setTextRange(updated, moveRangePastModifiers(node)); - setSourceMapRange(updated, moveRangePastModifiers(node)); - setEmitFlags(updated.name, EmitFlags.NoTrailingSourceMap); - } - return updated; - } - - function visitVariableStatement(node: VariableStatement): Statement | undefined { - if (isExportOfNamespace(node)) { - const variables = getInitializedVariables(node.declarationList); - if (variables.length === 0) { - // elide statement if there are no initialized variables. - return undefined; - } - - return setTextRange( - createExpressionStatement( - inlineExpressions( - map(variables, transformInitializedVariable) - ) - ), - node - ); - } - else { - return visitEachChild(node, visitor, context); - } - } - - function transformInitializedVariable(node: VariableDeclaration): Expression { - const name = node.name; - if (isBindingPattern(name)) { - return flattenDestructuringAssignment( - node, - visitor, - context, - FlattenLevel.All, - /*needsValue*/ false, - createNamespaceExportExpression - ); - } - else { - return setTextRange( - createAssignment( - getNamespaceMemberNameWithSourceMapsAndWithoutComments(name), - visitNode(node.initializer, visitor, isExpression) - ), - /*location*/ node - ); - } - } - - function visitVariableDeclaration(node: VariableDeclaration) { - return updateVariableDeclaration( - node, - visitNode(node.name, visitor, isBindingName), - /*type*/ undefined, - visitNode(node.initializer, visitor, isExpression)); - } - - function visitParenthesizedExpression(node: ParenthesizedExpression): Expression { - const innerExpression = skipOuterExpressions(node.expression, ~OuterExpressionKinds.Assertions); - if (isAssertionExpression(innerExpression)) { - // Make sure we consider all nested cast expressions, e.g.: - // (-A).x; - const expression = visitNode(node.expression, visitor, isExpression); - - // We have an expression of the form: (SubExpr). Emitting this as (SubExpr) - // is really not desirable. We would like to emit the subexpression as-is. Omitting - // the parentheses, however, could cause change in the semantics of the generated - // code if the casted expression has a lower precedence than the rest of the - // expression. - // - // To preserve comments, we return a "PartiallyEmittedExpression" here which will - // preserve the position information of the original expression. - // - // Due to the auto-parenthesization rules used by the visitor and factory functions - // we can safely elide the parentheses here, as a new synthetic - // ParenthesizedExpression will be inserted if we remove parentheses too - // aggressively. - // HOWEVER - if there are leading comments on the expression itself, to handle ASI - // correctly for return and throw, we must keep the parenthesis - if (length(getLeadingCommentRangesOfNode(expression, currentSourceFile))) { - return updateParen(node, expression); - } - return createPartiallyEmittedExpression(expression, node); - } - - return visitEachChild(node, visitor, context); - } - - function visitAssertionExpression(node: AssertionExpression): Expression { - const expression = visitNode(node.expression, visitor, isExpression); - return createPartiallyEmittedExpression(expression, node); - } - - function visitNonNullExpression(node: NonNullExpression): Expression { - const expression = visitNode(node.expression, visitor, isLeftHandSideExpression); - return createPartiallyEmittedExpression(expression, node); - } - - function visitCallExpression(node: CallExpression) { - return updateCall( - node, - visitNode(node.expression, visitor, isExpression), - /*typeArguments*/ undefined, - visitNodes(node.arguments, visitor, isExpression)); - } - - function visitNewExpression(node: NewExpression) { - return updateNew( - node, - visitNode(node.expression, visitor, isExpression), - /*typeArguments*/ undefined, - visitNodes(node.arguments, visitor, isExpression)); - } - - function visitTaggedTemplateExpression(node: TaggedTemplateExpression) { - return updateTaggedTemplate( - node, - visitNode(node.tag, visitor, isExpression), - /*typeArguments*/ undefined, - visitNode(node.template, visitor, isExpression)); - } - - /** - * Determines whether to emit an enum declaration. - * - * @param node The enum declaration node. - */ - function shouldEmitEnumDeclaration(node: EnumDeclaration) { - return !isEnumConst(node) - || compilerOptions.preserveConstEnums - || compilerOptions.isolatedModules; - } - - /** - * Visits an enum declaration. - * - * This function will be called any time a TypeScript enum is encountered. - * - * @param node The enum declaration node. - */ - function visitEnumDeclaration(node: EnumDeclaration): VisitResult { - if (!shouldEmitEnumDeclaration(node)) { - return createNotEmittedStatement(node); - } - - const statements: Statement[] = []; - - // We request to be advised when the printer is about to print this node. This allows - // us to set up the correct state for later substitutions. - let emitFlags = EmitFlags.AdviseOnEmitNode; - - // If needed, we should emit a variable declaration for the enum. If we emit - // a leading variable declaration, we should not emit leading comments for the - // enum body. - const varAdded = addVarForEnumOrModuleDeclaration(statements, node); - if (varAdded) { - // We should still emit the comments if we are emitting a system module. - if (moduleKind !== ModuleKind.System || currentLexicalScope !== currentSourceFile) { - emitFlags |= EmitFlags.NoLeadingComments; - } - } - - // `parameterName` is the declaration name used inside of the enum. - const parameterName = getNamespaceParameterName(node); - - // `containerName` is the expression used inside of the enum for assignments. - const containerName = getNamespaceContainerName(node); - - // `exportName` is the expression used within this node's container for any exported references. - const exportName = hasModifier(node, ModifierFlags.Export) - ? getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true) - : getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); - - // x || (x = {}) - // exports.x || (exports.x = {}) - let moduleArg = - createLogicalOr( - exportName, - createAssignment( - exportName, - createObjectLiteral() - ) - ); - - if (hasNamespaceQualifiedExportName(node)) { - // `localName` is the expression used within this node's containing scope for any local references. - const localName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); - - // x = (exports.x || (exports.x = {})) - moduleArg = createAssignment(localName, moduleArg); - } - - // (function (x) { - // x[x["y"] = 0] = "y"; - // ... - // })(x || (x = {})); - const enumStatement = createExpressionStatement( - createCall( - createFunctionExpression( - /*modifiers*/ undefined, - /*asteriskToken*/ undefined, - /*name*/ undefined, - /*typeParameters*/ undefined, - [createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, parameterName)], - /*type*/ undefined, - transformEnumBody(node, containerName) - ), - /*typeArguments*/ undefined, - [moduleArg] - ) - ); - - setOriginalNode(enumStatement, node); - if (varAdded) { - // If a variable was added, synthetic comments are emitted on it, not on the moduleStatement. - setSyntheticLeadingComments(enumStatement, undefined); - setSyntheticTrailingComments(enumStatement, undefined); - } - setTextRange(enumStatement, node); - addEmitFlags(enumStatement, emitFlags); - statements.push(enumStatement); - - // Add a DeclarationMarker for the enum to preserve trailing comments and mark - // the end of the declaration. - statements.push(createEndOfDeclarationMarker(node)); - return statements; - } - - /** - * Transforms the body of an enum declaration. - * - * @param node The enum declaration node. - */ - function transformEnumBody(node: EnumDeclaration, localName: Identifier): Block { - const savedCurrentNamespaceLocalName = currentNamespaceContainerName; - currentNamespaceContainerName = localName; - - const statements: Statement[] = []; - startLexicalEnvironment(); - const members = map(node.members, transformEnumMember); - insertStatementsAfterStandardPrologue(statements, endLexicalEnvironment()); - addRange(statements, members); - - currentNamespaceContainerName = savedCurrentNamespaceLocalName; - return createBlock( - setTextRange(createNodeArray(statements), /*location*/ node.members), - /*multiLine*/ true - ); - } - - /** - * Transforms an enum member into a statement. - * - * @param member The enum member node. - */ - function transformEnumMember(member: EnumMember): Statement { - // enums don't support computed properties - // we pass false as 'generateNameForComputedPropertyName' for a backward compatibility purposes - // old emitter always generate 'expression' part of the name as-is. - const name = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ false); - const valueExpression = transformEnumMemberDeclarationValue(member); - const innerAssignment = createAssignment( - createElementAccess( - currentNamespaceContainerName, - name - ), - valueExpression - ); - const outerAssignment = valueExpression.kind === SyntaxKind.StringLiteral ? - innerAssignment : - createAssignment( - createElementAccess( - currentNamespaceContainerName, - innerAssignment - ), - name - ); - return setTextRange( - createExpressionStatement( - setTextRange( - outerAssignment, - member - ) - ), - member - ); - } - - /** - * Transforms the value of an enum member. - * - * @param member The enum member node. - */ - function transformEnumMemberDeclarationValue(member: EnumMember): Expression { - const value = resolver.getConstantValue(member); - if (value !== undefined) { - return createLiteral(value); - } - else { - enableSubstitutionForNonQualifiedEnumMembers(); - if (member.initializer) { - return visitNode(member.initializer, visitor, isExpression); - } - else { - return createVoidZero(); - } - } - } - - /** - * Determines whether to elide a module declaration. - * - * @param node The module declaration node. - */ - function shouldEmitModuleDeclaration(node: ModuleDeclaration) { - return isInstantiatedModule(node, !!compilerOptions.preserveConstEnums || !!compilerOptions.isolatedModules); - } - - /** - * Determines whether an exported declaration will have a qualified export name (e.g. `f.x` - * or `exports.x`). - */ - function hasNamespaceQualifiedExportName(node: Node) { - return isExportOfNamespace(node) - || (isExternalModuleExport(node) - && moduleKind !== ModuleKind.ES2015 - && moduleKind !== ModuleKind.ESNext - && moduleKind !== ModuleKind.System); - } - - /** - * Records that a declaration was emitted in the current scope, if it was the first - * declaration for the provided symbol. - */ - function recordEmittedDeclarationInScope(node: FunctionDeclaration | ClassDeclaration | ModuleDeclaration | EnumDeclaration) { - if (!currentScopeFirstDeclarationsOfName) { - currentScopeFirstDeclarationsOfName = createUnderscoreEscapedMap(); - } - - const name = declaredNameInScope(node); - if (!currentScopeFirstDeclarationsOfName.has(name)) { - currentScopeFirstDeclarationsOfName.set(name, node); - } - } - - /** - * Determines whether a declaration is the first declaration with - * the same name emitted in the current scope. - */ - function isFirstEmittedDeclarationInScope(node: ModuleDeclaration | EnumDeclaration) { - if (currentScopeFirstDeclarationsOfName) { - const name = declaredNameInScope(node); - return currentScopeFirstDeclarationsOfName.get(name) === node; - } - return true; - } - - function declaredNameInScope(node: FunctionDeclaration | ClassDeclaration | ModuleDeclaration | EnumDeclaration): __String { - Debug.assertNode(node.name, isIdentifier); - return (node.name as Identifier).escapedText; - } - - /** - * Adds a leading VariableStatement for a enum or module declaration. - */ - function addVarForEnumOrModuleDeclaration(statements: Statement[], node: ModuleDeclaration | EnumDeclaration) { - // Emit a variable statement for the module. We emit top-level enums as a `var` - // declaration to avoid static errors in global scripts scripts due to redeclaration. - // enums in any other scope are emitted as a `let` declaration. - const statement = createVariableStatement( - visitNodes(node.modifiers, modifierVisitor, isModifier), - createVariableDeclarationList([ - createVariableDeclaration( - getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true) - ) - ], currentLexicalScope.kind === SyntaxKind.SourceFile ? NodeFlags.None : NodeFlags.Let) - ); - - setOriginalNode(statement, node); - - recordEmittedDeclarationInScope(node); - if (isFirstEmittedDeclarationInScope(node)) { - // Adjust the source map emit to match the old emitter. - if (node.kind === SyntaxKind.EnumDeclaration) { - setSourceMapRange(statement.declarationList, node); - } - else { - setSourceMapRange(statement, node); - } - - // Trailing comments for module declaration should be emitted after the function closure - // instead of the variable statement: - // - // /** Module comment*/ - // module m1 { - // function foo4Export() { - // } - // } // trailing comment module - // - // Should emit: - // - // /** Module comment*/ - // var m1; - // (function (m1) { - // function foo4Export() { - // } - // })(m1 || (m1 = {})); // trailing comment module - // - setCommentRange(statement, node); - addEmitFlags(statement, EmitFlags.NoTrailingComments | EmitFlags.HasEndOfDeclarationMarker); - statements.push(statement); - return true; - } - else { - // For an EnumDeclaration or ModuleDeclaration that merges with a preceeding - // declaration we do not emit a leading variable declaration. To preserve the - // begin/end semantics of the declararation and to properly handle exports - // we wrap the leading variable declaration in a `MergeDeclarationMarker`. - const mergeMarker = createMergeDeclarationMarker(statement); - setEmitFlags(mergeMarker, EmitFlags.NoComments | EmitFlags.HasEndOfDeclarationMarker); - statements.push(mergeMarker); - return false; - } - } - - /** - * Visits a module declaration node. - * - * This function will be called any time a TypeScript namespace (ModuleDeclaration) is encountered. - * - * @param node The module declaration node. - */ - function visitModuleDeclaration(node: ModuleDeclaration): VisitResult { - if (!shouldEmitModuleDeclaration(node)) { - return createNotEmittedStatement(node); - } - - Debug.assertNode(node.name, isIdentifier, "A TypeScript namespace should have an Identifier name."); - enableSubstitutionForNamespaceExports(); - - const statements: Statement[] = []; - - // We request to be advised when the printer is about to print this node. This allows - // us to set up the correct state for later substitutions. - let emitFlags = EmitFlags.AdviseOnEmitNode; - - // If needed, we should emit a variable declaration for the module. If we emit - // a leading variable declaration, we should not emit leading comments for the - // module body. - const varAdded = addVarForEnumOrModuleDeclaration(statements, node); - if (varAdded) { - // We should still emit the comments if we are emitting a system module. - if (moduleKind !== ModuleKind.System || currentLexicalScope !== currentSourceFile) { - emitFlags |= EmitFlags.NoLeadingComments; - } - } - - // `parameterName` is the declaration name used inside of the namespace. - const parameterName = getNamespaceParameterName(node); - - // `containerName` is the expression used inside of the namespace for exports. - const containerName = getNamespaceContainerName(node); - - // `exportName` is the expression used within this node's container for any exported references. - const exportName = hasModifier(node, ModifierFlags.Export) - ? getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true) - : getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); - - // x || (x = {}) - // exports.x || (exports.x = {}) - let moduleArg = - createLogicalOr( - exportName, - createAssignment( - exportName, - createObjectLiteral() - ) - ); - - if (hasNamespaceQualifiedExportName(node)) { - // `localName` is the expression used within this node's containing scope for any local references. - const localName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); - - // x = (exports.x || (exports.x = {})) - moduleArg = createAssignment(localName, moduleArg); - } - - // (function (x_1) { - // x_1.y = ...; - // })(x || (x = {})); - const moduleStatement = createExpressionStatement( - createCall( - createFunctionExpression( - /*modifiers*/ undefined, - /*asteriskToken*/ undefined, - /*name*/ undefined, - /*typeParameters*/ undefined, - [createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, parameterName)], - /*type*/ undefined, - transformModuleBody(node, containerName) - ), - /*typeArguments*/ undefined, - [moduleArg] - ) - ); - - setOriginalNode(moduleStatement, node); - if (varAdded) { - // If a variable was added, synthetic comments are emitted on it, not on the moduleStatement. - setSyntheticLeadingComments(moduleStatement, undefined); - setSyntheticTrailingComments(moduleStatement, undefined); - } - setTextRange(moduleStatement, node); - addEmitFlags(moduleStatement, emitFlags); - statements.push(moduleStatement); - - // Add a DeclarationMarker for the namespace to preserve trailing comments and mark - // the end of the declaration. - statements.push(createEndOfDeclarationMarker(node)); - return statements; - } - - /** - * Transforms the body of a module declaration. - * - * @param node The module declaration node. - */ - function transformModuleBody(node: ModuleDeclaration, namespaceLocalName: Identifier): Block { - const savedCurrentNamespaceContainerName = currentNamespaceContainerName; - const savedCurrentNamespace = currentNamespace; - const savedCurrentScopeFirstDeclarationsOfName = currentScopeFirstDeclarationsOfName; - currentNamespaceContainerName = namespaceLocalName; - currentNamespace = node; - currentScopeFirstDeclarationsOfName = undefined; - - const statements: Statement[] = []; - startLexicalEnvironment(); - - let statementsLocation: TextRange; - let blockLocation: TextRange | undefined; - const body = node.body!; - if (body.kind === SyntaxKind.ModuleBlock) { - saveStateAndInvoke(body, body => addRange(statements, visitNodes((body).statements, namespaceElementVisitor, isStatement))); - statementsLocation = body.statements; - blockLocation = body; - } - else { - const result = visitModuleDeclaration(body); - if (result) { - if (isArray(result)) { - addRange(statements, result); - } - else { - statements.push(result); - } - } - - const moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node)!.body; - statementsLocation = moveRangePos(moduleBlock.statements, -1); - } - - insertStatementsAfterStandardPrologue(statements, endLexicalEnvironment()); - currentNamespaceContainerName = savedCurrentNamespaceContainerName; - currentNamespace = savedCurrentNamespace; - currentScopeFirstDeclarationsOfName = savedCurrentScopeFirstDeclarationsOfName; - - const block = createBlock( - setTextRange( - createNodeArray(statements), - /*location*/ statementsLocation - ), - /*multiLine*/ true - ); - setTextRange(block, blockLocation); - - // namespace hello.hi.world { - // function foo() {} - // - // // TODO, blah - // } - // - // should be emitted as - // - // var hello; - // (function (hello) { - // var hi; - // (function (hi) { - // var world; - // (function (world) { - // function foo() { } - // // TODO, blah - // })(world = hi.world || (hi.world = {})); - // })(hi = hello.hi || (hello.hi = {})); - // })(hello || (hello = {})); - // We only want to emit comment on the namespace which contains block body itself, not the containing namespaces. - if (body.kind !== SyntaxKind.ModuleBlock) { - setEmitFlags(block, getEmitFlags(block) | EmitFlags.NoComments); - } - return block; - } - - function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration: ModuleDeclaration): ModuleDeclaration | undefined { - if (moduleDeclaration.body!.kind === SyntaxKind.ModuleDeclaration) { - const recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); - return recursiveInnerModule || moduleDeclaration.body; - } - } - - /** - * Visits an import declaration, eliding it if it is not referenced. - * - * @param node The import declaration node. - */ - function visitImportDeclaration(node: ImportDeclaration): VisitResult { - if (!node.importClause) { - // Do not elide a side-effect only import declaration. - // import "foo"; - return node; - } - - // Elide the declaration if the import clause was elided. - const importClause = visitNode(node.importClause, visitImportClause, isImportClause); - return importClause - ? updateImportDeclaration( - node, - /*decorators*/ undefined, - /*modifiers*/ undefined, - importClause, - node.moduleSpecifier) - : undefined; - } - - /** - * Visits an import clause, eliding it if it is not referenced. - * - * @param node The import clause node. - */ - function visitImportClause(node: ImportClause): VisitResult { - // Elide the import clause if we elide both its name and its named bindings. - const name = resolver.isReferencedAliasDeclaration(node) ? node.name : undefined; - const namedBindings = visitNode(node.namedBindings, visitNamedImportBindings, isNamedImportBindings); - return (name || namedBindings) ? updateImportClause(node, name, namedBindings) : undefined; - } - - /** - * Visits named import bindings, eliding it if it is not referenced. - * - * @param node The named import bindings node. - */ - function visitNamedImportBindings(node: NamedImportBindings): VisitResult { - if (node.kind === SyntaxKind.NamespaceImport) { - // Elide a namespace import if it is not referenced. - return resolver.isReferencedAliasDeclaration(node) ? node : undefined; - } - else { - // Elide named imports if all of its import specifiers are elided. - const elements = visitNodes(node.elements, visitImportSpecifier, isImportSpecifier); - return some(elements) ? updateNamedImports(node, elements) : undefined; - } - } - - /** - * Visits an import specifier, eliding it if it is not referenced. - * - * @param node The import specifier node. - */ - function visitImportSpecifier(node: ImportSpecifier): VisitResult { - // Elide an import specifier if it is not referenced. - return resolver.isReferencedAliasDeclaration(node) ? node : undefined; - } - - /** - * Visits an export assignment, eliding it if it does not contain a clause that resolves - * to a value. - * - * @param node The export assignment node. - */ - function visitExportAssignment(node: ExportAssignment): VisitResult { - // Elide the export assignment if it does not reference a value. - return resolver.isValueAliasDeclaration(node) - ? visitEachChild(node, visitor, context) - : undefined; - } - - /** - * Visits an export declaration, eliding it if it does not contain a clause that resolves - * to a value. - * - * @param node The export declaration node. - */ - function visitExportDeclaration(node: ExportDeclaration): VisitResult { - if (!node.exportClause) { - // Elide a star export if the module it references does not export a value. - return compilerOptions.isolatedModules || resolver.moduleExportsSomeValue(node.moduleSpecifier!) ? node : undefined; - } - - if (!resolver.isValueAliasDeclaration(node)) { - // Elide the export declaration if it does not export a value. - return undefined; - } - - // Elide the export declaration if all of its named exports are elided. - const exportClause = visitNode(node.exportClause, visitNamedExports, isNamedExports); - return exportClause - ? updateExportDeclaration( - node, - /*decorators*/ undefined, - /*modifiers*/ undefined, - exportClause, - node.moduleSpecifier) - : undefined; - } - - /** - * Visits named exports, eliding it if it does not contain an export specifier that - * resolves to a value. - * - * @param node The named exports node. - */ - function visitNamedExports(node: NamedExports): VisitResult { - // Elide the named exports if all of its export specifiers were elided. - const elements = visitNodes(node.elements, visitExportSpecifier, isExportSpecifier); - return some(elements) ? updateNamedExports(node, elements) : undefined; - } - - /** - * Visits an export specifier, eliding it if it does not resolve to a value. - * - * @param node The export specifier node. - */ - function visitExportSpecifier(node: ExportSpecifier): VisitResult { - // Elide an export specifier if it does not reference a value. - return resolver.isValueAliasDeclaration(node) ? node : undefined; - } - - /** - * Determines whether to emit an import equals declaration. - * - * @param node The import equals declaration node. - */ - function shouldEmitImportEqualsDeclaration(node: ImportEqualsDeclaration) { - // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when - // - current file is not external module - // - import declaration is top level and target is value imported by entity name - return resolver.isReferencedAliasDeclaration(node) - || (!isExternalModule(currentSourceFile) - && resolver.isTopLevelValueImportEqualsWithEntityName(node)); - } - - /** - * Visits an import equals declaration. - * - * @param node The import equals declaration node. - */ - function visitImportEqualsDeclaration(node: ImportEqualsDeclaration): VisitResult { - if (isExternalModuleImportEqualsDeclaration(node)) { - // Elide external module `import=` if it is not referenced. - return resolver.isReferencedAliasDeclaration(node) - ? visitEachChild(node, visitor, context) - : undefined; - } - - if (!shouldEmitImportEqualsDeclaration(node)) { - return undefined; - } - - const moduleReference = createExpressionFromEntityName(node.moduleReference); - setEmitFlags(moduleReference, EmitFlags.NoComments | EmitFlags.NoNestedComments); - - if (isNamedExternalModuleExport(node) || !isExportOfNamespace(node)) { - // export var ${name} = ${moduleReference}; - // var ${name} = ${moduleReference}; - return setOriginalNode( - setTextRange( - createVariableStatement( - visitNodes(node.modifiers, modifierVisitor, isModifier), - createVariableDeclarationList([ - setOriginalNode( - createVariableDeclaration( - node.name, - /*type*/ undefined, - moduleReference - ), - node - ) - ]) - ), - node - ), - node - ); - } - else { - // exports.${name} = ${moduleReference}; - return setOriginalNode( - createNamespaceExport( - node.name, - moduleReference, - node - ), - node - ); - } - } - - /** - * Gets a value indicating whether the node is exported from a namespace. - * - * @param node The node to test. - */ - function isExportOfNamespace(node: Node) { - return currentNamespace !== undefined && hasModifier(node, ModifierFlags.Export); - } - - /** - * Gets a value indicating whether the node is exported from an external module. - * - * @param node The node to test. - */ - function isExternalModuleExport(node: Node) { - return currentNamespace === undefined && hasModifier(node, ModifierFlags.Export); - } - - /** - * Gets a value indicating whether the node is a named export from an external module. - * - * @param node The node to test. - */ - function isNamedExternalModuleExport(node: Node) { - return isExternalModuleExport(node) - && !hasModifier(node, ModifierFlags.Default); - } - - /** - * Gets a value indicating whether the node is the default export of an external module. - * - * @param node The node to test. - */ - function isDefaultExternalModuleExport(node: Node) { - return isExternalModuleExport(node) - && hasModifier(node, ModifierFlags.Default); - } - - /** - * Creates a statement for the provided expression. This is used in calls to `map`. - */ - function expressionToStatement(expression: Expression) { - return createExpressionStatement(expression); - } - - function addExportMemberAssignment(statements: Statement[], node: ClassDeclaration | FunctionDeclaration) { - const expression = createAssignment( - getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true), - getLocalName(node) - ); - setSourceMapRange(expression, createRange(node.name ? node.name.pos : node.pos, node.end)); - - const statement = createExpressionStatement(expression); - setSourceMapRange(statement, createRange(-1, node.end)); - statements.push(statement); - } - - function createNamespaceExport(exportName: Identifier, exportValue: Expression, location?: TextRange) { - return setTextRange( - createExpressionStatement( - createAssignment( - getNamespaceMemberName(currentNamespaceContainerName, exportName, /*allowComments*/ false, /*allowSourceMaps*/ true), - exportValue - ) - ), - location - ); - } - - function createNamespaceExportExpression(exportName: Identifier, exportValue: Expression, location?: TextRange) { - return setTextRange(createAssignment(getNamespaceMemberNameWithSourceMapsAndWithoutComments(exportName), exportValue), location); - } - - function getNamespaceMemberNameWithSourceMapsAndWithoutComments(name: Identifier) { - return getNamespaceMemberName(currentNamespaceContainerName, name, /*allowComments*/ false, /*allowSourceMaps*/ true); - } - - /** - * Gets the declaration name used inside of a namespace or enum. - */ - function getNamespaceParameterName(node: ModuleDeclaration | EnumDeclaration) { - const name = getGeneratedNameForNode(node); - setSourceMapRange(name, node.name); - return name; - } - - /** - * Gets the expression used to refer to a namespace or enum within the body - * of its declaration. - */ - function getNamespaceContainerName(node: ModuleDeclaration | EnumDeclaration) { - return getGeneratedNameForNode(node); - } - - /** - * Gets a local alias for a class declaration if it is a decorated class with an internal - * reference to the static side of the class. This is necessary to avoid issues with - * double-binding semantics for the class name. - */ - function getClassAliasIfNeeded(node: ClassDeclaration) { - if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithConstructorReference) { - enableSubstitutionForClassAliases(); - const classAlias = createUniqueName(node.name && !isGeneratedIdentifier(node.name) ? idText(node.name) : "default"); - classAliases[getOriginalNodeId(node)] = classAlias; - hoistVariableDeclaration(classAlias); - return classAlias; - } - } - - function getClassPrototype(node: ClassExpression | ClassDeclaration) { - return createPropertyAccess(getDeclarationName(node), "prototype"); - } - - function getClassMemberPrefix(node: ClassExpression | ClassDeclaration, member: ClassElement) { - return hasModifier(member, ModifierFlags.Static) - ? getDeclarationName(node) - : getClassPrototype(node); - } - - function enableSubstitutionForNonQualifiedEnumMembers() { - if ((enabledSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers) === 0) { - enabledSubstitutions |= TypeScriptSubstitutionFlags.NonQualifiedEnumMembers; - context.enableSubstitution(SyntaxKind.Identifier); - } - } - - function enableSubstitutionForClassAliases() { - if ((enabledSubstitutions & TypeScriptSubstitutionFlags.ClassAliases) === 0) { - enabledSubstitutions |= TypeScriptSubstitutionFlags.ClassAliases; - - // We need to enable substitutions for identifiers. This allows us to - // substitute class names inside of a class declaration. - context.enableSubstitution(SyntaxKind.Identifier); - - // Keep track of class aliases. - classAliases = []; - } - } - - function enableSubstitutionForNamespaceExports() { - if ((enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) === 0) { - enabledSubstitutions |= TypeScriptSubstitutionFlags.NamespaceExports; - - // We need to enable substitutions for identifiers and shorthand property assignments. This allows us to - // substitute the names of exported members of a namespace. - context.enableSubstitution(SyntaxKind.Identifier); - context.enableSubstitution(SyntaxKind.ShorthandPropertyAssignment); - - // We need to be notified when entering and exiting namespaces. - context.enableEmitNotification(SyntaxKind.ModuleDeclaration); - } - } - - function isTransformedModuleDeclaration(node: Node): boolean { - return getOriginalNode(node).kind === SyntaxKind.ModuleDeclaration; - } - - function isTransformedEnumDeclaration(node: Node): boolean { - return getOriginalNode(node).kind === SyntaxKind.EnumDeclaration; - } - - /** - * Hook for node emit. - * - * @param hint A hint as to the intended usage of the node. - * @param node The node to emit. - * @param emit A callback used to emit the node in the printer. - */ - function onEmitNode(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void): void { - const savedApplicableSubstitutions = applicableSubstitutions; - const savedCurrentSourceFile = currentSourceFile; - - if (isSourceFile(node)) { - currentSourceFile = node; - } - - if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && isTransformedModuleDeclaration(node)) { - applicableSubstitutions |= TypeScriptSubstitutionFlags.NamespaceExports; - } - - if (enabledSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers && isTransformedEnumDeclaration(node)) { - applicableSubstitutions |= TypeScriptSubstitutionFlags.NonQualifiedEnumMembers; - } - - previousOnEmitNode(hint, node, emitCallback); - - applicableSubstitutions = savedApplicableSubstitutions; - currentSourceFile = savedCurrentSourceFile; - } - - /** - * Hooks node substitutions. - * - * @param hint A hint as to the intended usage of the node. - * @param node The node to substitute. - */ - function onSubstituteNode(hint: EmitHint, node: Node) { - node = previousOnSubstituteNode(hint, node); - if (hint === EmitHint.Expression) { - return substituteExpression(node); - } - else if (isShorthandPropertyAssignment(node)) { - return substituteShorthandPropertyAssignment(node); - } - - return node; - } - - function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike { - if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) { - const name = node.name; - const exportedName = trySubstituteNamespaceExportedName(name); - if (exportedName) { - // A shorthand property with an assignment initializer is probably part of a - // destructuring assignment - if (node.objectAssignmentInitializer) { - const initializer = createAssignment(exportedName, node.objectAssignmentInitializer); - return setTextRange(createPropertyAssignment(name, initializer), node); - } - return setTextRange(createPropertyAssignment(name, exportedName), node); - } - } - return node; - } - - function substituteExpression(node: Expression) { - switch (node.kind) { - case SyntaxKind.Identifier: - return substituteExpressionIdentifier(node); - case SyntaxKind.PropertyAccessExpression: - return substitutePropertyAccessExpression(node); - case SyntaxKind.ElementAccessExpression: - return substituteElementAccessExpression(node); - } - - return node; - } - - function substituteExpressionIdentifier(node: Identifier): Expression { - return trySubstituteClassAlias(node) - || trySubstituteNamespaceExportedName(node) - || node; - } - - function trySubstituteClassAlias(node: Identifier): Expression | undefined { - if (enabledSubstitutions & TypeScriptSubstitutionFlags.ClassAliases) { - if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ConstructorReferenceInClass) { - // Due to the emit for class decorators, any reference to the class from inside of the class body - // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind - // behavior of class names in ES6. - // Also, when emitting statics for class expressions, we must substitute a class alias for - // constructor references in static property initializers. - const declaration = resolver.getReferencedValueDeclaration(node); - if (declaration) { - const classAlias = classAliases[declaration.id!]; // TODO: GH#18217 - if (classAlias) { - const clone = getSynthesizedClone(classAlias); - setSourceMapRange(clone, node); - setCommentRange(clone, node); - return clone; - } - } - } - } - - return undefined; - } - - function trySubstituteNamespaceExportedName(node: Identifier): Expression | undefined { - // If this is explicitly a local name, do not substitute. - if (enabledSubstitutions & applicableSubstitutions && !isGeneratedIdentifier(node) && !isLocalName(node)) { - // If we are nested within a namespace declaration, we may need to qualifiy - // an identifier that is exported from a merged namespace. - const container = resolver.getReferencedExportContainer(node, /*prefixLocals*/ false); - if (container && container.kind !== SyntaxKind.SourceFile) { - const substitute = - (applicableSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && container.kind === SyntaxKind.ModuleDeclaration) || - (applicableSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers && container.kind === SyntaxKind.EnumDeclaration); - if (substitute) { - return setTextRange( - createPropertyAccess(getGeneratedNameForNode(container), node), - /*location*/ node - ); - } - } - } - - return undefined; - } - - function substitutePropertyAccessExpression(node: PropertyAccessExpression) { - return substituteConstantValue(node); - } - - function substituteElementAccessExpression(node: ElementAccessExpression) { - return substituteConstantValue(node); - } - - function substituteConstantValue(node: PropertyAccessExpression | ElementAccessExpression): LeftHandSideExpression { - const constantValue = tryGetConstEnumValue(node); - if (constantValue !== undefined) { - // track the constant value on the node for the printer in needsDotDotForPropertyAccess - setConstantValue(node, constantValue); - - const substitute = createLiteral(constantValue); - if (!compilerOptions.removeComments) { - const propertyName = isPropertyAccessExpression(node) - ? declarationNameToString(node.name) - : getTextOfNode(node.argumentExpression); - - addSyntheticTrailingComment(substitute, SyntaxKind.MultiLineCommentTrivia, ` ${propertyName} `); - } - - return substitute; - } - - return node; - } - - function tryGetConstEnumValue(node: Node): string | number | undefined { - if (compilerOptions.isolatedModules) { - return undefined; - } - - return isPropertyAccessExpression(node) || isElementAccessExpression(node) ? resolver.getConstantValue(node) : undefined; - } - } - - function createDecorateHelper(context: TransformationContext, decoratorExpressions: Expression[], target: Expression, memberName?: Expression, descriptor?: Expression, location?: TextRange) { - const argumentsArray: Expression[] = []; - argumentsArray.push(createArrayLiteral(decoratorExpressions, /*multiLine*/ true)); - argumentsArray.push(target); - if (memberName) { - argumentsArray.push(memberName); - if (descriptor) { - argumentsArray.push(descriptor); - } - } - - context.requestEmitHelper(decorateHelper); - return setTextRange( - createCall( - getUnscopedHelperName("__decorate"), - /*typeArguments*/ undefined, - argumentsArray - ), - location - ); - } - - export const decorateHelper: UnscopedEmitHelper = { - name: "typescript:decorate", - importName: "__decorate", - scoped: false, - priority: 2, - text: ` - var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; - };` - }; - - function createMetadataHelper(context: TransformationContext, metadataKey: string, metadataValue: Expression) { - context.requestEmitHelper(metadataHelper); - return createCall( - getUnscopedHelperName("__metadata"), - /*typeArguments*/ undefined, - [ - createLiteral(metadataKey), - metadataValue - ] - ); - } - - export const metadataHelper: UnscopedEmitHelper = { - name: "typescript:metadata", - importName: "__metadata", - scoped: false, - priority: 3, - text: ` - var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); - };` - }; - - function createParamHelper(context: TransformationContext, expression: Expression, parameterOffset: number, location?: TextRange) { - context.requestEmitHelper(paramHelper); - return setTextRange( - createCall( - getUnscopedHelperName("__param"), - /*typeArguments*/ undefined, - [ - createLiteral(parameterOffset), - expression - ] - ), - location - ); - } - - export const paramHelper: UnscopedEmitHelper = { - name: "typescript:param", - importName: "__param", - scoped: false, - priority: 4, - text: ` - var __param = (this && this.__param) || function (paramIndex, decorator) { - return function (target, key) { decorator(target, key, paramIndex); } - };` - }; -} +/*@internal*/ +namespace ts { + /** + * Indicates whether to emit type metadata in the new format. + */ + const USE_NEW_TYPE_METADATA_FORMAT = false; + + const enum TypeScriptSubstitutionFlags { + /** Enables substitutions for decorated classes. */ + ClassAliases = 1 << 0, + /** Enables substitutions for namespace exports. */ + NamespaceExports = 1 << 1, + /* Enables substitutions for unqualified enum members */ + NonQualifiedEnumMembers = 1 << 3 + } + + const enum ClassFacts { + None = 0, + HasStaticInitializedProperties = 1 << 0, + HasConstructorDecorators = 1 << 1, + HasMemberDecorators = 1 << 2, + IsExportOfNamespace = 1 << 3, + IsNamedExternalExport = 1 << 4, + IsDefaultExternalExport = 1 << 5, + IsDerivedClass = 1 << 6, + UseImmediatelyInvokedFunctionExpression = 1 << 7, + + HasAnyDecorators = HasConstructorDecorators | HasMemberDecorators, + NeedsName = HasStaticInitializedProperties | HasMemberDecorators, + MayNeedImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties, + IsExported = IsExportOfNamespace | IsDefaultExternalExport | IsNamedExternalExport, + } + + export function transformTypeScript(context: TransformationContext) { + const { + startLexicalEnvironment, + resumeLexicalEnvironment, + endLexicalEnvironment, + hoistVariableDeclaration, + } = context; + + const resolver = context.getEmitResolver(); + const compilerOptions = context.getCompilerOptions(); + const strictNullChecks = getStrictOptionValue(compilerOptions, "strictNullChecks"); + const languageVersion = getEmitScriptTarget(compilerOptions); + const moduleKind = getEmitModuleKind(compilerOptions); + + // Save the previous transformation hooks. + const previousOnEmitNode = context.onEmitNode; + const previousOnSubstituteNode = context.onSubstituteNode; + + // Set new transformation hooks. + context.onEmitNode = onEmitNode; + context.onSubstituteNode = onSubstituteNode; + + // Enable substitution for property/element access to emit const enum values. + context.enableSubstitution(SyntaxKind.PropertyAccessExpression); + context.enableSubstitution(SyntaxKind.ElementAccessExpression); + + // These variables contain state that changes as we descend into the tree. + let currentSourceFile: SourceFile; + let currentNamespace: ModuleDeclaration; + let currentNamespaceContainerName: Identifier; + let currentLexicalScope: SourceFile | Block | ModuleBlock | CaseBlock; + let currentNameScope: ClassDeclaration | undefined; + let currentScopeFirstDeclarationsOfName: UnderscoreEscapedMap | undefined; + let currentClassHasParameterProperties: boolean | undefined; + + /** + * Keeps track of whether expression substitution has been enabled for specific edge cases. + * They are persisted between each SourceFile transformation and should not be reset. + */ + let enabledSubstitutions: TypeScriptSubstitutionFlags; + + /** + * A map that keeps track of aliases created for classes with decorators to avoid issues + * with the double-binding behavior of classes. + */ + let classAliases: Identifier[]; + + /** + * Keeps track of whether we are within any containing namespaces when performing + * just-in-time substitution while printing an expression identifier. + */ + let applicableSubstitutions: TypeScriptSubstitutionFlags; + + return transformSourceFileOrBundle; + + function transformSourceFileOrBundle(node: SourceFile | Bundle) { + if (node.kind === SyntaxKind.Bundle) { + return transformBundle(node); + } + return transformSourceFile(node); + } + + function transformBundle(node: Bundle) { + return createBundle(node.sourceFiles.map(transformSourceFile), mapDefined(node.prepends, prepend => { + if (prepend.kind === SyntaxKind.InputFiles) { + return createUnparsedSourceFile(prepend, "js"); + } + return prepend; + })); + } + + /** + * Transform TypeScript-specific syntax in a SourceFile. + * + * @param node A SourceFile node. + */ + function transformSourceFile(node: SourceFile) { + if (node.isDeclarationFile) { + return node; + } + + currentSourceFile = node; + + const visited = saveStateAndInvoke(node, visitSourceFile); + addEmitHelpers(visited, context.readEmitHelpers()); + + currentSourceFile = undefined!; + return visited; + } + + /** + * Visits a node, saving and restoring state variables on the stack. + * + * @param node The node to visit. + */ + function saveStateAndInvoke(node: Node, f: (node: Node) => T): T { + // Save state + const savedCurrentScope = currentLexicalScope; + const savedCurrentNameScope = currentNameScope; + const savedCurrentScopeFirstDeclarationsOfName = currentScopeFirstDeclarationsOfName; + const savedCurrentClassHasParameterProperties = currentClassHasParameterProperties; + + // Handle state changes before visiting a node. + onBeforeVisitNode(node); + + const visited = f(node); + + // Restore state + if (currentLexicalScope !== savedCurrentScope) { + currentScopeFirstDeclarationsOfName = savedCurrentScopeFirstDeclarationsOfName; + } + + currentLexicalScope = savedCurrentScope; + currentNameScope = savedCurrentNameScope; + currentClassHasParameterProperties = savedCurrentClassHasParameterProperties; + return visited; + } + + /** + * Performs actions that should always occur immediately before visiting a node. + * + * @param node The node to visit. + */ + function onBeforeVisitNode(node: Node) { + switch (node.kind) { + case SyntaxKind.SourceFile: + case SyntaxKind.CaseBlock: + case SyntaxKind.ModuleBlock: + case SyntaxKind.Block: + currentLexicalScope = node; + currentNameScope = undefined; + currentScopeFirstDeclarationsOfName = undefined; + break; + + case SyntaxKind.ClassDeclaration: + case SyntaxKind.FunctionDeclaration: + if (hasModifier(node, ModifierFlags.Ambient)) { + break; + } + + // Record these declarations provided that they have a name. + if ((node as ClassDeclaration | FunctionDeclaration).name) { + recordEmittedDeclarationInScope(node as ClassDeclaration | FunctionDeclaration); + } + else { + // These nodes should always have names unless they are default-exports; + // however, class declaration parsing allows for undefined names, so syntactically invalid + // programs may also have an undefined name. + Debug.assert(node.kind === SyntaxKind.ClassDeclaration || hasModifier(node, ModifierFlags.Default)); + } + if (isClassDeclaration(node)) { + // XXX: should probably also cover interfaces and type aliases that can have type variables? + currentNameScope = node; + } + + break; + } + } + + /** + * General-purpose node visitor. + * + * @param node The node to visit. + */ + function visitor(node: Node): VisitResult { + return saveStateAndInvoke(node, visitorWorker); + } + + /** + * Visits and possibly transforms any node. + * + * @param node The node to visit. + */ + function visitorWorker(node: Node): VisitResult { + if (node.transformFlags & TransformFlags.ContainsTypeScript) { + return visitTypeScript(node); + } + return node; + } + + /** + * Specialized visitor that visits the immediate children of a SourceFile. + * + * @param node The node to visit. + */ + function sourceElementVisitor(node: Node): VisitResult { + return saveStateAndInvoke(node, sourceElementVisitorWorker); + } + + /** + * Specialized visitor that visits the immediate children of a SourceFile. + * + * @param node The node to visit. + */ + function sourceElementVisitorWorker(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ExportAssignment: + case SyntaxKind.ExportDeclaration: + return visitEllidableStatement(node); + default: + return visitorWorker(node); + } + } + + function visitEllidableStatement(node: ImportDeclaration | ImportEqualsDeclaration | ExportAssignment | ExportDeclaration): VisitResult { + const parsed = getParseTreeNode(node); + if (parsed !== node) { + // If the node has been transformed by a `before` transformer, perform no ellision on it + // As the type information we would attempt to lookup to perform ellision is potentially unavailable for the synthesized nodes + // We do not reuse `visitorWorker`, as the ellidable statement syntax kinds are technically unrecognized by the switch-case in `visitTypeScript`, + // and will trigger debug failures when debug verbosity is turned up + if (node.transformFlags & TransformFlags.ContainsTypeScript) { + // This node contains TypeScript, so we should visit its children. + return visitEachChild(node, visitor, context); + } + // Otherwise, we can just return the node + return node; + } + switch (node.kind) { + case SyntaxKind.ImportDeclaration: + return visitImportDeclaration(node); + case SyntaxKind.ImportEqualsDeclaration: + return visitImportEqualsDeclaration(node); + case SyntaxKind.ExportAssignment: + return visitExportAssignment(node); + case SyntaxKind.ExportDeclaration: + return visitExportDeclaration(node); + default: + Debug.fail("Unhandled ellided statement"); + } + } + + /** + * Specialized visitor that visits the immediate children of a namespace. + * + * @param node The node to visit. + */ + function namespaceElementVisitor(node: Node): VisitResult { + return saveStateAndInvoke(node, namespaceElementVisitorWorker); + } + + /** + * Specialized visitor that visits the immediate children of a namespace. + * + * @param node The node to visit. + */ + function namespaceElementVisitorWorker(node: Node): VisitResult { + if (node.kind === SyntaxKind.ExportDeclaration || + node.kind === SyntaxKind.ImportDeclaration || + node.kind === SyntaxKind.ImportClause || + (node.kind === SyntaxKind.ImportEqualsDeclaration && + (node).moduleReference.kind === SyntaxKind.ExternalModuleReference)) { + // do not emit ES6 imports and exports since they are illegal inside a namespace + return undefined; + } + else if (node.transformFlags & TransformFlags.ContainsTypeScript || hasModifier(node, ModifierFlags.Export)) { + return visitTypeScript(node); + } + + return node; + } + + /** + * Specialized visitor that visits the immediate children of a class with TypeScript syntax. + * + * @param node The node to visit. + */ + function classElementVisitor(node: Node): VisitResult { + return saveStateAndInvoke(node, classElementVisitorWorker); + } + + /** + * Specialized visitor that visits the immediate children of a class with TypeScript syntax. + * + * @param node The node to visit. + */ + function classElementVisitorWorker(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.Constructor: + return visitConstructor(node as ConstructorDeclaration); + + case SyntaxKind.PropertyDeclaration: + // Property declarations are not TypeScript syntax, but they must be visited + // for the decorator transformation. + return visitPropertyDeclaration(node as PropertyDeclaration); + case SyntaxKind.IndexSignature: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.MethodDeclaration: + // Fallback to the default visit behavior. + return visitorWorker(node); + + case SyntaxKind.SemicolonClassElement: + return node; + + default: + return Debug.failBadSyntaxKind(node); + } + } + + function modifierVisitor(node: Node): VisitResult { + if (modifierToFlag(node.kind) & ModifierFlags.TypeScriptModifier) { + return undefined; + } + else if (currentNamespace && node.kind === SyntaxKind.ExportKeyword) { + return undefined; + } + + return node; + } + + /** + * Branching visitor, visits a TypeScript syntax node. + * + * @param node The node to visit. + */ + function visitTypeScript(node: Node): VisitResult { + if (isStatement(node) && hasModifier(node, ModifierFlags.Ambient)) { + // TypeScript ambient declarations are elided, but some comments may be preserved. + // See the implementation of `getLeadingComments` in comments.ts for more details. + return createNotEmittedStatement(node); + } + + switch (node.kind) { + case SyntaxKind.ExportKeyword: + case SyntaxKind.DefaultKeyword: + // ES6 export and default modifiers are elided when inside a namespace. + return currentNamespace ? undefined : node; + + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + case SyntaxKind.AbstractKeyword: + case SyntaxKind.ConstKeyword: + case SyntaxKind.DeclareKeyword: + case SyntaxKind.ReadonlyKeyword: + // TypeScript accessibility and readonly modifiers are elided + // falls through + case SyntaxKind.ArrayType: + case SyntaxKind.TupleType: + case SyntaxKind.OptionalType: + case SyntaxKind.RestType: + case SyntaxKind.TypeLiteral: + case SyntaxKind.TypePredicate: + case SyntaxKind.TypeParameter: + case SyntaxKind.AnyKeyword: + case SyntaxKind.UnknownKeyword: + case SyntaxKind.BooleanKeyword: + case SyntaxKind.StringKeyword: + case SyntaxKind.NumberKeyword: + case SyntaxKind.NeverKeyword: + case SyntaxKind.VoidKeyword: + case SyntaxKind.SymbolKeyword: + case SyntaxKind.ConstructorType: + case SyntaxKind.FunctionType: + case SyntaxKind.TypeQuery: + case SyntaxKind.TypeReference: + case SyntaxKind.UnionType: + case SyntaxKind.IntersectionType: + case SyntaxKind.ConditionalType: + case SyntaxKind.ParenthesizedType: + case SyntaxKind.ThisType: + case SyntaxKind.TypeOperator: + case SyntaxKind.IndexedAccessType: + case SyntaxKind.MappedType: + case SyntaxKind.LiteralType: + // TypeScript type nodes are elided. + // falls through + + case SyntaxKind.IndexSignature: + // TypeScript index signatures are elided. + // falls through + + case SyntaxKind.Decorator: + // TypeScript decorators are elided. They will be emitted as part of visitClassDeclaration. + // falls through + + case SyntaxKind.TypeAliasDeclaration: + // TypeScript type-only declarations are elided. + return undefined; + + case SyntaxKind.PropertyDeclaration: + // TypeScript property declarations are elided. However their names are still visited, and can potentially be retained if they could have sideeffects + return visitPropertyDeclaration(node as PropertyDeclaration); + + case SyntaxKind.NamespaceExportDeclaration: + // TypeScript namespace export declarations are elided. + return undefined; + + case SyntaxKind.Constructor: + return visitConstructor(node); + + case SyntaxKind.InterfaceDeclaration: + // TypeScript interfaces are elided, but some comments may be preserved. + // See the implementation of `getLeadingComments` in comments.ts for more details. + return createNotEmittedStatement(node); + + case SyntaxKind.ClassDeclaration: + // This may be a class declaration with TypeScript syntax extensions. + // + // TypeScript class syntax extensions include: + // - decorators + // - optional `implements` heritage clause + // - parameter property assignments in the constructor + // - index signatures + // - method overload signatures + return visitClassDeclaration(node); + + case SyntaxKind.ClassExpression: + // This may be a class expression with TypeScript syntax extensions. + // + // TypeScript class syntax extensions include: + // - decorators + // - optional `implements` heritage clause + // - parameter property assignments in the constructor + // - index signatures + // - method overload signatures + return visitClassExpression(node); + + case SyntaxKind.HeritageClause: + // This may be a heritage clause with TypeScript syntax extensions. + // + // TypeScript heritage clause extensions include: + // - `implements` clause + return visitHeritageClause(node); + + case SyntaxKind.ExpressionWithTypeArguments: + // TypeScript supports type arguments on an expression in an `extends` heritage clause. + return visitExpressionWithTypeArguments(node); + + case SyntaxKind.MethodDeclaration: + // TypeScript method declarations may have decorators, modifiers + // or type annotations. + return visitMethodDeclaration(node); + + case SyntaxKind.GetAccessor: + // Get Accessors can have TypeScript modifiers, decorators, and type annotations. + return visitGetAccessor(node); + + case SyntaxKind.SetAccessor: + // Set Accessors can have TypeScript modifiers and type annotations. + return visitSetAccessor(node); + + case SyntaxKind.FunctionDeclaration: + // Typescript function declarations can have modifiers, decorators, and type annotations. + return visitFunctionDeclaration(node); + + case SyntaxKind.FunctionExpression: + // TypeScript function expressions can have modifiers and type annotations. + return visitFunctionExpression(node); + + case SyntaxKind.ArrowFunction: + // TypeScript arrow functions can have modifiers and type annotations. + return visitArrowFunction(node); + + case SyntaxKind.Parameter: + // This may be a parameter declaration with TypeScript syntax extensions. + // + // TypeScript parameter declaration syntax extensions include: + // - decorators + // - accessibility modifiers + // - the question mark (?) token for optional parameters + // - type annotations + // - this parameters + return visitParameter(node); + + case SyntaxKind.ParenthesizedExpression: + // ParenthesizedExpressions are TypeScript if their expression is a + // TypeAssertion or AsExpression + return visitParenthesizedExpression(node); + + case SyntaxKind.TypeAssertionExpression: + case SyntaxKind.AsExpression: + // TypeScript type assertions are removed, but their subtrees are preserved. + return visitAssertionExpression(node); + + case SyntaxKind.CallExpression: + return visitCallExpression(node); + + case SyntaxKind.NewExpression: + return visitNewExpression(node); + + case SyntaxKind.TaggedTemplateExpression: + return visitTaggedTemplateExpression(node); + + case SyntaxKind.NonNullExpression: + // TypeScript non-null expressions are removed, but their subtrees are preserved. + return visitNonNullExpression(node); + + case SyntaxKind.EnumDeclaration: + // TypeScript enum declarations do not exist in ES6 and must be rewritten. + return visitEnumDeclaration(node); + + case SyntaxKind.VariableStatement: + // TypeScript namespace exports for variable statements must be transformed. + return visitVariableStatement(node); + + case SyntaxKind.VariableDeclaration: + return visitVariableDeclaration(node); + + case SyntaxKind.ModuleDeclaration: + // TypeScript namespace declarations must be transformed. + return visitModuleDeclaration(node); + + case SyntaxKind.ImportEqualsDeclaration: + // TypeScript namespace or external module import. + return visitImportEqualsDeclaration(node); + + default: + // node contains some other TypeScript syntax + return visitEachChild(node, visitor, context); + } + } + + function visitSourceFile(node: SourceFile) { + const alwaysStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") && + !(isExternalModule(node) && moduleKind >= ModuleKind.ES2015) && + !isJsonSourceFile(node); + + return updateSourceFileNode( + node, + visitLexicalEnvironment(node.statements, sourceElementVisitor, context, /*start*/ 0, alwaysStrict)); + } + + /** + * Tests whether we should emit a __decorate call for a class declaration. + */ + function shouldEmitDecorateCallForClass(node: ClassDeclaration) { + if (node.decorators && node.decorators.length > 0) { + return true; + } + + const constructor = getFirstConstructorWithBody(node); + if (constructor) { + return forEach(constructor.parameters, shouldEmitDecorateCallForParameter); + } + + return false; + } + + /** + * Tests whether we should emit a __decorate call for a parameter declaration. + */ + function shouldEmitDecorateCallForParameter(parameter: ParameterDeclaration) { + return parameter.decorators !== undefined && parameter.decorators.length > 0; + } + + function getClassFacts(node: ClassDeclaration, staticProperties: readonly PropertyDeclaration[]) { + let facts = ClassFacts.None; + if (some(staticProperties)) facts |= ClassFacts.HasStaticInitializedProperties; + const extendsClauseElement = getEffectiveBaseTypeNode(node); + if (extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword) facts |= ClassFacts.IsDerivedClass; + if (shouldEmitDecorateCallForClass(node)) facts |= ClassFacts.HasConstructorDecorators; + if (childIsDecorated(node)) facts |= ClassFacts.HasMemberDecorators; + if (isExportOfNamespace(node)) facts |= ClassFacts.IsExportOfNamespace; + else if (isDefaultExternalModuleExport(node)) facts |= ClassFacts.IsDefaultExternalExport; + else if (isNamedExternalModuleExport(node)) facts |= ClassFacts.IsNamedExternalExport; + if (languageVersion <= ScriptTarget.ES5 && (facts & ClassFacts.MayNeedImmediatelyInvokedFunctionExpression)) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression; + return facts; + } + + function hasTypeScriptClassSyntax(node: Node) { + return !!(node.transformFlags & TransformFlags.ContainsTypeScriptClassSyntax); + } + + function isClassLikeDeclarationWithTypeScriptSyntax(node: ClassLikeDeclaration) { + return some(node.decorators) + || some(node.typeParameters) + || some(node.heritageClauses, hasTypeScriptClassSyntax) + || some(node.members, hasTypeScriptClassSyntax); + } + + function visitClassDeclaration(node: ClassDeclaration): VisitResult { + if (!isClassLikeDeclarationWithTypeScriptSyntax(node) && !(currentNamespace && hasModifier(node, ModifierFlags.Export))) { + return visitEachChild(node, visitor, context); + } + + const staticProperties = getProperties(node, /*requireInitializer*/ true, /*isStatic*/ true); + const facts = getClassFacts(node, staticProperties); + + if (facts & ClassFacts.UseImmediatelyInvokedFunctionExpression) { + context.startLexicalEnvironment(); + } + + const name = node.name || (facts & ClassFacts.NeedsName ? getGeneratedNameForNode(node) : undefined); + const classStatement = facts & ClassFacts.HasConstructorDecorators + ? createClassDeclarationHeadWithDecorators(node, name) + : createClassDeclarationHeadWithoutDecorators(node, name, facts); + + let statements: Statement[] = [classStatement]; + + + // Write any decorators of the node. + addClassElementDecorationStatements(statements, node, /*isStatic*/ false); + addClassElementDecorationStatements(statements, node, /*isStatic*/ true); + addConstructorDecorationStatement(statements, node); + + if (facts & ClassFacts.UseImmediatelyInvokedFunctionExpression) { + // When we emit a TypeScript class down to ES5, we must wrap it in an IIFE so that the + // 'es2015' transformer can properly nest static initializers and decorators. The result + // looks something like: + // + // var C = function () { + // class C { + // } + // C.static_prop = 1; + // return C; + // }(); + // + const closingBraceLocation = createTokenRange(skipTrivia(currentSourceFile.text, node.members.end), SyntaxKind.CloseBraceToken); + const localName = getInternalName(node); + + // The following partially-emitted expression exists purely to align our sourcemap + // emit with the original emitter. + const outer = createPartiallyEmittedExpression(localName); + outer.end = closingBraceLocation.end; + setEmitFlags(outer, EmitFlags.NoComments); + + const statement = createReturn(outer); + statement.pos = closingBraceLocation.pos; + setEmitFlags(statement, EmitFlags.NoComments | EmitFlags.NoTokenSourceMaps); + statements.push(statement); + + insertStatementsAfterStandardPrologue(statements, context.endLexicalEnvironment()); + + const iife = createImmediatelyInvokedArrowFunction(statements); + setEmitFlags(iife, EmitFlags.TypeScriptClassWrapper); + + const varStatement = createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList([ + createVariableDeclaration( + getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ false), + /*type*/ undefined, + iife + ) + ]) + ); + + setOriginalNode(varStatement, node); + setCommentRange(varStatement, node); + setSourceMapRange(varStatement, moveRangePastDecorators(node)); + startOnNewLine(varStatement); + statements = [varStatement]; + } + + // If the class is exported as part of a TypeScript namespace, emit the namespace export. + // Otherwise, if the class was exported at the top level and was decorated, emit an export + // declaration or export default for the class. + if (facts & ClassFacts.IsExportOfNamespace) { + addExportMemberAssignment(statements, node); + } + else if (facts & ClassFacts.UseImmediatelyInvokedFunctionExpression || facts & ClassFacts.HasConstructorDecorators) { + if (facts & ClassFacts.IsDefaultExternalExport) { + statements.push(createExportDefault(getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true))); + } + else if (facts & ClassFacts.IsNamedExternalExport) { + statements.push(createExternalModuleExport(getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true))); + } + } + + if (statements.length > 1) { + // Add a DeclarationMarker as a marker for the end of the declaration + statements.push(createEndOfDeclarationMarker(node)); + setEmitFlags(classStatement, getEmitFlags(classStatement) | EmitFlags.HasEndOfDeclarationMarker); + } + + return singleOrMany(statements); + } + + /** + * Transforms a non-decorated class declaration and appends the resulting statements. + * + * @param node A ClassDeclaration node. + * @param name The name of the class. + * @param facts Precomputed facts about the class. + */ + function createClassDeclarationHeadWithoutDecorators(node: ClassDeclaration, name: Identifier | undefined, facts: ClassFacts) { + // ${modifiers} class ${name} ${heritageClauses} { + // ${members} + // } + + // we do not emit modifiers on the declaration if we are emitting an IIFE + const modifiers = !(facts & ClassFacts.UseImmediatelyInvokedFunctionExpression) + ? visitNodes(node.modifiers, modifierVisitor, isModifier) + : undefined; + + const classDeclaration = createClassDeclaration( + /*decorators*/ undefined, + modifiers, + name, + /*typeParameters*/ undefined, + visitNodes(node.heritageClauses, visitor, isHeritageClause), + transformClassMembers(node) + ); + + // To better align with the old emitter, we should not emit a trailing source map + // entry if the class has static properties. + let emitFlags = getEmitFlags(node); + if (facts & ClassFacts.HasStaticInitializedProperties) { + emitFlags |= EmitFlags.NoTrailingSourceMap; + } + + aggregateTransformFlags(classDeclaration); + setTextRange(classDeclaration, node); + setOriginalNode(classDeclaration, node); + setEmitFlags(classDeclaration, emitFlags); + return classDeclaration; + } + + /** + * Transforms a decorated class declaration and appends the resulting statements. If + * the class requires an alias to avoid issues with double-binding, the alias is returned. + */ + function createClassDeclarationHeadWithDecorators(node: ClassDeclaration, name: Identifier | undefined) { + // When we emit an ES6 class that has a class decorator, we must tailor the + // emit to certain specific cases. + // + // In the simplest case, we emit the class declaration as a let declaration, and + // evaluate decorators after the close of the class body: + // + // [Example 1] + // --------------------------------------------------------------------- + // TypeScript | Javascript + // --------------------------------------------------------------------- + // @dec | let C = class C { + // class C { | } + // } | C = __decorate([dec], C); + // --------------------------------------------------------------------- + // @dec | let C = class C { + // export class C { | } + // } | C = __decorate([dec], C); + // | export { C }; + // --------------------------------------------------------------------- + // + // If a class declaration contains a reference to itself *inside* of the class body, + // this introduces two bindings to the class: One outside of the class body, and one + // inside of the class body. If we apply decorators as in [Example 1] above, there + // is the possibility that the decorator `dec` will return a new value for the + // constructor, which would result in the binding inside of the class no longer + // pointing to the same reference as the binding outside of the class. + // + // As a result, we must instead rewrite all references to the class *inside* of the + // class body to instead point to a local temporary alias for the class: + // + // [Example 2] + // --------------------------------------------------------------------- + // TypeScript | Javascript + // --------------------------------------------------------------------- + // @dec | let C = C_1 = class C { + // class C { | static x() { return C_1.y; } + // static x() { return C.y; } | } + // static y = 1; | C.y = 1; + // } | C = C_1 = __decorate([dec], C); + // | var C_1; + // --------------------------------------------------------------------- + // @dec | let C = class C { + // export class C { | static x() { return C_1.y; } + // static x() { return C.y; } | } + // static y = 1; | C.y = 1; + // } | C = C_1 = __decorate([dec], C); + // | export { C }; + // | var C_1; + // --------------------------------------------------------------------- + // + // If a class declaration is the default export of a module, we instead emit + // the export after the decorated declaration: + // + // [Example 3] + // --------------------------------------------------------------------- + // TypeScript | Javascript + // --------------------------------------------------------------------- + // @dec | let default_1 = class { + // export default class { | } + // } | default_1 = __decorate([dec], default_1); + // | export default default_1; + // --------------------------------------------------------------------- + // @dec | let C = class C { + // export default class C { | } + // } | C = __decorate([dec], C); + // | export default C; + // --------------------------------------------------------------------- + // + // If the class declaration is the default export and a reference to itself + // inside of the class body, we must emit both an alias for the class *and* + // move the export after the declaration: + // + // [Example 4] + // --------------------------------------------------------------------- + // TypeScript | Javascript + // --------------------------------------------------------------------- + // @dec | let C = class C { + // export default class C { | static x() { return C_1.y; } + // static x() { return C.y; } | } + // static y = 1; | C.y = 1; + // } | C = C_1 = __decorate([dec], C); + // | export default C; + // | var C_1; + // --------------------------------------------------------------------- + // + + const location = moveRangePastDecorators(node); + const classAlias = getClassAliasIfNeeded(node); + const declName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); + + // ... = class ${name} ${heritageClauses} { + // ${members} + // } + const heritageClauses = visitNodes(node.heritageClauses, visitor, isHeritageClause); + const members = transformClassMembers(node); + const classExpression = createClassExpression(/*modifiers*/ undefined, name, /*typeParameters*/ undefined, heritageClauses, members); + aggregateTransformFlags(classExpression); + setOriginalNode(classExpression, node); + setTextRange(classExpression, location); + + // let ${name} = ${classExpression} where name is either declaredName if the class doesn't contain self-reference + // or decoratedClassAlias if the class contain self-reference. + const statement = createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList([ + createVariableDeclaration( + declName, + /*type*/ undefined, + classAlias ? createAssignment(classAlias, classExpression) : classExpression + ) + ], NodeFlags.Let) + ); + setOriginalNode(statement, node); + setTextRange(statement, location); + setCommentRange(statement, node); + return statement; + } + + function visitClassExpression(node: ClassExpression): Expression { + if (!isClassLikeDeclarationWithTypeScriptSyntax(node)) { + return visitEachChild(node, visitor, context); + } + + const classExpression = createClassExpression( + /*modifiers*/ undefined, + node.name, + /*typeParameters*/ undefined, + visitNodes(node.heritageClauses, visitor, isHeritageClause), + transformClassMembers(node) + ); + + aggregateTransformFlags(classExpression); + setOriginalNode(classExpression, node); + setTextRange(classExpression, node); + + return classExpression; + } + + /** + * Transforms the members of a class. + * + * @param node The current class. + */ + function transformClassMembers(node: ClassDeclaration | ClassExpression) { + const members: ClassElement[] = []; + const constructor = getFirstConstructorWithBody(node); + const parametersWithPropertyAssignments = constructor && + filter(constructor.parameters, p => isParameterPropertyDeclaration(p, constructor)); + + if (parametersWithPropertyAssignments) { + for (const parameter of parametersWithPropertyAssignments) { + if (isIdentifier(parameter.name)) { + members.push(aggregateTransformFlags(createProperty( + /*decorators*/ undefined, + /*modifiers*/ undefined, + parameter.name, + /*questionOrExclamationToken*/ undefined, + /*type*/ undefined, + /*initializer*/ undefined))); + } + } + } + + addRange(members, visitNodes(node.members, classElementVisitor, isClassElement)); + return setTextRange(createNodeArray(members), /*location*/ node.members); + } + + + /** + * Gets either the static or instance members of a class that are decorated, or have + * parameters that are decorated. + * + * @param node The class containing the member. + * @param isStatic A value indicating whether to retrieve static or instance members of + * the class. + */ + function getDecoratedClassElements(node: ClassExpression | ClassDeclaration, isStatic: boolean): readonly ClassElement[] { + return filter(node.members, isStatic ? m => isStaticDecoratedClassElement(m, node) : m => isInstanceDecoratedClassElement(m, node)); + } + + /** + * Determines whether a class member is a static member of a class that is decorated, or + * has parameters that are decorated. + * + * @param member The class member. + */ + function isStaticDecoratedClassElement(member: ClassElement, parent: ClassLikeDeclaration) { + return isDecoratedClassElement(member, /*isStatic*/ true, parent); + } + + /** + * Determines whether a class member is an instance member of a class that is decorated, + * or has parameters that are decorated. + * + * @param member The class member. + */ + function isInstanceDecoratedClassElement(member: ClassElement, parent: ClassLikeDeclaration) { + return isDecoratedClassElement(member, /*isStatic*/ false, parent); + } + + /** + * Determines whether a class member is either a static or an instance member of a class + * that is decorated, or has parameters that are decorated. + * + * @param member The class member. + */ + function isDecoratedClassElement(member: ClassElement, isStatic: boolean, parent: ClassLikeDeclaration) { + return nodeOrChildIsDecorated(member, parent) + && isStatic === hasModifier(member, ModifierFlags.Static); + } + + /** + * A structure describing the decorators for a class element. + */ + interface AllDecorators { + decorators: readonly Decorator[] | undefined; + parameters?: readonly (readonly Decorator[] | undefined)[]; + } + + /** + * Gets an array of arrays of decorators for the parameters of a function-like node. + * The offset into the result array should correspond to the offset of the parameter. + * + * @param node The function-like node. + */ + function getDecoratorsOfParameters(node: FunctionLikeDeclaration | undefined) { + let decorators: (readonly Decorator[] | undefined)[] | undefined; + if (node) { + const parameters = node.parameters; + const firstParameterIsThis = parameters.length > 0 && parameterIsThisKeyword(parameters[0]); + const firstParameterOffset = firstParameterIsThis ? 1 : 0; + const numParameters = firstParameterIsThis ? parameters.length - 1 : parameters.length; + for (let i = 0; i < numParameters; i++) { + const parameter = parameters[i + firstParameterOffset]; + if (decorators || parameter.decorators) { + if (!decorators) { + decorators = new Array(numParameters); + } + + decorators[i] = parameter.decorators; + } + } + } + + return decorators; + } + + /** + * Gets an AllDecorators object containing the decorators for the class and the decorators for the + * parameters of the constructor of the class. + * + * @param node The class node. + */ + function getAllDecoratorsOfConstructor(node: ClassExpression | ClassDeclaration): AllDecorators | undefined { + const decorators = node.decorators; + const parameters = getDecoratorsOfParameters(getFirstConstructorWithBody(node)); + if (!decorators && !parameters) { + return undefined; + } + + return { + decorators, + parameters + }; + } + + /** + * Gets an AllDecorators object containing the decorators for the member and its parameters. + * + * @param node The class node that contains the member. + * @param member The class member. + */ + function getAllDecoratorsOfClassElement(node: ClassExpression | ClassDeclaration, member: ClassElement): AllDecorators | undefined { + switch (member.kind) { + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return getAllDecoratorsOfAccessors(node, member); + + case SyntaxKind.MethodDeclaration: + return getAllDecoratorsOfMethod(member); + + case SyntaxKind.PropertyDeclaration: + return getAllDecoratorsOfProperty(member); + + default: + return undefined; + } + } + + /** + * Gets an AllDecorators object containing the decorators for the accessor and its parameters. + * + * @param node The class node that contains the accessor. + * @param accessor The class accessor member. + */ + function getAllDecoratorsOfAccessors(node: ClassExpression | ClassDeclaration, accessor: AccessorDeclaration): AllDecorators | undefined { + if (!accessor.body) { + return undefined; + } + + const { firstAccessor, secondAccessor, setAccessor } = getAllAccessorDeclarations(node.members, accessor); + const firstAccessorWithDecorators = firstAccessor.decorators ? firstAccessor : secondAccessor && secondAccessor.decorators ? secondAccessor : undefined; + if (!firstAccessorWithDecorators || accessor !== firstAccessorWithDecorators) { + return undefined; + } + + const decorators = firstAccessorWithDecorators.decorators; + const parameters = getDecoratorsOfParameters(setAccessor); + if (!decorators && !parameters) { + return undefined; + } + + return { decorators, parameters }; + } + + /** + * Gets an AllDecorators object containing the decorators for the method and its parameters. + * + * @param method The class method member. + */ + function getAllDecoratorsOfMethod(method: MethodDeclaration): AllDecorators | undefined { + if (!method.body) { + return undefined; + } + + const decorators = method.decorators; + const parameters = getDecoratorsOfParameters(method); + if (!decorators && !parameters) { + return undefined; + } + + return { decorators, parameters }; + } + + /** + * Gets an AllDecorators object containing the decorators for the property. + * + * @param property The class property member. + */ + function getAllDecoratorsOfProperty(property: PropertyDeclaration): AllDecorators | undefined { + const decorators = property.decorators; + if (!decorators) { + return undefined; + + } + + return { decorators }; + } + + /** + * Transforms all of the decorators for a declaration into an array of expressions. + * + * @param node The declaration node. + * @param allDecorators An object containing all of the decorators for the declaration. + */ + function transformAllDecoratorsOfDeclaration(node: Declaration, container: ClassLikeDeclaration, allDecorators: AllDecorators | undefined) { + if (!allDecorators) { + return undefined; + } + + const decoratorExpressions: Expression[] = []; + addRange(decoratorExpressions, map(allDecorators.decorators, transformDecorator)); + addRange(decoratorExpressions, flatMap(allDecorators.parameters, transformDecoratorsOfParameter)); + addTypeMetadata(node, container, decoratorExpressions); + return decoratorExpressions; + } + + /** + * Generates statements used to apply decorators to either the static or instance members + * of a class. + * + * @param node The class node. + * @param isStatic A value indicating whether to generate statements for static or + * instance members. + */ + function addClassElementDecorationStatements(statements: Statement[], node: ClassDeclaration, isStatic: boolean) { + addRange(statements, map(generateClassElementDecorationExpressions(node, isStatic), expressionToStatement)); + } + + /** + * Generates expressions used to apply decorators to either the static or instance members + * of a class. + * + * @param node The class node. + * @param isStatic A value indicating whether to generate expressions for static or + * instance members. + */ + function generateClassElementDecorationExpressions(node: ClassExpression | ClassDeclaration, isStatic: boolean) { + const members = getDecoratedClassElements(node, isStatic); + let expressions: Expression[] | undefined; + for (const member of members) { + const expression = generateClassElementDecorationExpression(node, member); + if (expression) { + if (!expressions) { + expressions = [expression]; + } + else { + expressions.push(expression); + } + } + } + return expressions; + } + + /** + * Generates an expression used to evaluate class element decorators at runtime. + * + * @param node The class node that contains the member. + * @param member The class member. + */ + function generateClassElementDecorationExpression(node: ClassExpression | ClassDeclaration, member: ClassElement) { + const allDecorators = getAllDecoratorsOfClassElement(node, member); + const decoratorExpressions = transformAllDecoratorsOfDeclaration(member, node, allDecorators); + if (!decoratorExpressions) { + return undefined; + } + + // Emit the call to __decorate. Given the following: + // + // class C { + // @dec method(@dec2 x) {} + // @dec get accessor() {} + // @dec prop; + // } + // + // The emit for a method is: + // + // __decorate([ + // dec, + // __param(0, dec2), + // __metadata("design:type", Function), + // __metadata("design:paramtypes", [Object]), + // __metadata("design:returntype", void 0) + // ], C.prototype, "method", null); + // + // The emit for an accessor is: + // + // __decorate([ + // dec + // ], C.prototype, "accessor", null); + // + // The emit for a property is: + // + // __decorate([ + // dec + // ], C.prototype, "prop"); + // + + const prefix = getClassMemberPrefix(node, member); + const memberName = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ true); + const descriptor = languageVersion > ScriptTarget.ES3 + ? member.kind === SyntaxKind.PropertyDeclaration + // We emit `void 0` here to indicate to `__decorate` that it can invoke `Object.defineProperty` directly, but that it + // should not invoke `Object.getOwnPropertyDescriptor`. + ? createVoidZero() + + // We emit `null` here to indicate to `__decorate` that it can invoke `Object.getOwnPropertyDescriptor` directly. + // We have this extra argument here so that we can inject an explicit property descriptor at a later date. + : createNull() + : undefined; + + const helper = createDecorateHelper( + context, + decoratorExpressions, + prefix, + memberName, + descriptor, + moveRangePastDecorators(member) + ); + + setEmitFlags(helper, EmitFlags.NoComments); + return helper; + } + + /** + * Generates a __decorate helper call for a class constructor. + * + * @param node The class node. + */ + function addConstructorDecorationStatement(statements: Statement[], node: ClassDeclaration) { + const expression = generateConstructorDecorationExpression(node); + if (expression) { + statements.push(setOriginalNode(createExpressionStatement(expression), node)); + } + } + + /** + * Generates a __decorate helper call for a class constructor. + * + * @param node The class node. + */ + function generateConstructorDecorationExpression(node: ClassExpression | ClassDeclaration) { + const allDecorators = getAllDecoratorsOfConstructor(node); + const decoratorExpressions = transformAllDecoratorsOfDeclaration(node, node, allDecorators); + if (!decoratorExpressions) { + return undefined; + } + + const classAlias = classAliases && classAliases[getOriginalNodeId(node)]; + const localName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); + const decorate = createDecorateHelper(context, decoratorExpressions, localName); + const expression = createAssignment(localName, classAlias ? createAssignment(classAlias, decorate) : decorate); + setEmitFlags(expression, EmitFlags.NoComments); + setSourceMapRange(expression, moveRangePastDecorators(node)); + return expression; + } + + /** + * Transforms a decorator into an expression. + * + * @param decorator The decorator node. + */ + function transformDecorator(decorator: Decorator) { + return visitNode(decorator.expression, visitor, isExpression); + } + + /** + * Transforms the decorators of a parameter. + * + * @param decorators The decorators for the parameter at the provided offset. + * @param parameterOffset The offset of the parameter. + */ + function transformDecoratorsOfParameter(decorators: Decorator[], parameterOffset: number) { + let expressions: Expression[] | undefined; + if (decorators) { + expressions = []; + for (const decorator of decorators) { + const helper = createParamHelper( + context, + transformDecorator(decorator), + parameterOffset, + /*location*/ decorator.expression); + setEmitFlags(helper, EmitFlags.NoComments); + expressions.push(helper); + } + } + + return expressions; + } + + /** + * Adds optional type metadata for a declaration. + * + * @param node The declaration node. + * @param decoratorExpressions The destination array to which to add new decorator expressions. + */ + function addTypeMetadata(node: Declaration, container: ClassLikeDeclaration, decoratorExpressions: Expression[]) { + if (USE_NEW_TYPE_METADATA_FORMAT) { + addNewTypeMetadata(node, container, decoratorExpressions); + } + else { + addOldTypeMetadata(node, container, decoratorExpressions); + } + } + + function addOldTypeMetadata(node: Declaration, container: ClassLikeDeclaration, decoratorExpressions: Expression[]) { + if (compilerOptions.emitDecoratorMetadata) { + if (shouldAddTypeMetadata(node)) { + decoratorExpressions.push(createMetadataHelper(context, "design:type", serializeTypeOfNode(node))); + } + if (shouldAddParamTypesMetadata(node)) { + decoratorExpressions.push(createMetadataHelper(context, "design:paramtypes", serializeParameterTypesOfNode(node, container))); + } + if (shouldAddReturnTypeMetadata(node)) { + decoratorExpressions.push(createMetadataHelper(context, "design:returntype", serializeReturnTypeOfNode(node))); + } + } + } + + function addNewTypeMetadata(node: Declaration, container: ClassLikeDeclaration, decoratorExpressions: Expression[]) { + if (compilerOptions.emitDecoratorMetadata) { + let properties: ObjectLiteralElementLike[] | undefined; + if (shouldAddTypeMetadata(node)) { + (properties || (properties = [])).push(createPropertyAssignment("type", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeTypeOfNode(node)))); + } + if (shouldAddParamTypesMetadata(node)) { + (properties || (properties = [])).push(createPropertyAssignment("paramTypes", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeParameterTypesOfNode(node, container)))); + } + if (shouldAddReturnTypeMetadata(node)) { + (properties || (properties = [])).push(createPropertyAssignment("returnType", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeReturnTypeOfNode(node)))); + } + if (properties) { + decoratorExpressions.push(createMetadataHelper(context, "design:typeinfo", createObjectLiteral(properties, /*multiLine*/ true))); + } + } + } + + /** + * Determines whether to emit the "design:type" metadata based on the node's kind. + * The caller should have already tested whether the node has decorators and whether the + * emitDecoratorMetadata compiler option is set. + * + * @param node The node to test. + */ + function shouldAddTypeMetadata(node: Declaration): boolean { + const kind = node.kind; + return kind === SyntaxKind.MethodDeclaration + || kind === SyntaxKind.GetAccessor + || kind === SyntaxKind.SetAccessor + || kind === SyntaxKind.PropertyDeclaration; + } + + /** + * Determines whether to emit the "design:returntype" metadata based on the node's kind. + * The caller should have already tested whether the node has decorators and whether the + * emitDecoratorMetadata compiler option is set. + * + * @param node The node to test. + */ + function shouldAddReturnTypeMetadata(node: Declaration): boolean { + return node.kind === SyntaxKind.MethodDeclaration; + } + + /** + * Determines whether to emit the "design:paramtypes" metadata based on the node's kind. + * The caller should have already tested whether the node has decorators and whether the + * emitDecoratorMetadata compiler option is set. + * + * @param node The node to test. + */ + function shouldAddParamTypesMetadata(node: Declaration): boolean { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + return getFirstConstructorWithBody(node) !== undefined; + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return true; + } + return false; + } + + type SerializedEntityNameAsExpression = Identifier | BinaryExpression | PropertyAccessExpression; + type SerializedTypeNode = SerializedEntityNameAsExpression | VoidExpression | ConditionalExpression; + + function getAccessorTypeNode(node: AccessorDeclaration) { + const accessors = resolver.getAllAccessorDeclarations(node); + return accessors.setAccessor && getSetAccessorTypeAnnotationNode(accessors.setAccessor) + || accessors.getAccessor && getEffectiveReturnTypeNode(accessors.getAccessor); + } + + /** + * Serializes the type of a node for use with decorator type metadata. + * + * @param node The node that should have its type serialized. + */ + function serializeTypeOfNode(node: Node): SerializedTypeNode { + switch (node.kind) { + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + return serializeTypeNode((node).type); + case SyntaxKind.SetAccessor: + case SyntaxKind.GetAccessor: + return serializeTypeNode(getAccessorTypeNode(node as AccessorDeclaration)); + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + case SyntaxKind.MethodDeclaration: + return createIdentifier("Function"); + default: + return createVoidZero(); + } + } + + /** + * Serializes the types of the parameters of a node for use with decorator type metadata. + * + * @param node The node that should have its parameter types serialized. + */ + function serializeParameterTypesOfNode(node: Node, container: ClassLikeDeclaration): ArrayLiteralExpression { + const valueDeclaration = + isClassLike(node) + ? getFirstConstructorWithBody(node) + : isFunctionLike(node) && nodeIsPresent((node as FunctionLikeDeclaration).body) + ? node + : undefined; + + const expressions: SerializedTypeNode[] = []; + if (valueDeclaration) { + const parameters = getParametersOfDecoratedDeclaration(valueDeclaration, container); + const numParameters = parameters.length; + for (let i = 0; i < numParameters; i++) { + const parameter = parameters[i]; + if (i === 0 && isIdentifier(parameter.name) && parameter.name.escapedText === "this") { + continue; + } + if (parameter.dotDotDotToken) { + expressions.push(serializeTypeNode(getRestParameterElementType(parameter.type))); + } + else { + expressions.push(serializeTypeOfNode(parameter)); + } + } + } + + return createArrayLiteral(expressions); + } + + function getParametersOfDecoratedDeclaration(node: SignatureDeclaration, container: ClassLikeDeclaration) { + if (container && node.kind === SyntaxKind.GetAccessor) { + const { setAccessor } = getAllAccessorDeclarations(container.members, node); + if (setAccessor) { + return setAccessor.parameters; + } + } + return node.parameters; + } + + /** + * Serializes the return type of a node for use with decorator type metadata. + * + * @param node The node that should have its return type serialized. + */ + function serializeReturnTypeOfNode(node: Node): SerializedTypeNode { + if (isFunctionLike(node) && node.type) { + return serializeTypeNode(node.type); + } + else if (isAsyncFunction(node)) { + return createIdentifier("Promise"); + } + + return createVoidZero(); + } + + /** + * Serializes a type node for use with decorator type metadata. + * + * Types are serialized in the following fashion: + * - Void types point to "undefined" (e.g. "void 0") + * - Function and Constructor types point to the global "Function" constructor. + * - Interface types with a call or construct signature types point to the global + * "Function" constructor. + * - Array and Tuple types point to the global "Array" constructor. + * - Type predicates and booleans point to the global "Boolean" constructor. + * - String literal types and strings point to the global "String" constructor. + * - Enum and number types point to the global "Number" constructor. + * - Symbol types point to the global "Symbol" constructor. + * - Type references to classes (or class-like variables) point to the constructor for the class. + * - Anything else points to the global "Object" constructor. + * + * @param node The type node to serialize. + */ + function serializeTypeNode(node: TypeNode | undefined): SerializedTypeNode { + if (node === undefined) { + return createIdentifier("Object"); + } + + switch (node.kind) { + case SyntaxKind.VoidKeyword: + case SyntaxKind.UndefinedKeyword: + case SyntaxKind.NullKeyword: + case SyntaxKind.NeverKeyword: + return createVoidZero(); + + case SyntaxKind.ParenthesizedType: + return serializeTypeNode((node).type); + + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + return createIdentifier("Function"); + + case SyntaxKind.ArrayType: + case SyntaxKind.TupleType: + return createIdentifier("Array"); + + case SyntaxKind.TypePredicate: + case SyntaxKind.BooleanKeyword: + return createIdentifier("Boolean"); + + case SyntaxKind.StringKeyword: + return createIdentifier("String"); + + case SyntaxKind.ObjectKeyword: + return createIdentifier("Object"); + + case SyntaxKind.LiteralType: + switch ((node).literal.kind) { + case SyntaxKind.StringLiteral: + return createIdentifier("String"); + + case SyntaxKind.PrefixUnaryExpression: + case SyntaxKind.NumericLiteral: + return createIdentifier("Number"); + + case SyntaxKind.BigIntLiteral: + return getGlobalBigIntNameWithFallback(); + + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: + return createIdentifier("Boolean"); + + default: + return Debug.failBadSyntaxKind((node).literal); + } + + case SyntaxKind.NumberKeyword: + return createIdentifier("Number"); + + case SyntaxKind.BigIntKeyword: + return getGlobalBigIntNameWithFallback(); + + case SyntaxKind.SymbolKeyword: + return languageVersion < ScriptTarget.ES2015 + ? getGlobalSymbolNameWithFallback() + : createIdentifier("Symbol"); + + case SyntaxKind.TypeReference: + return serializeTypeReferenceNode(node); + + case SyntaxKind.IntersectionType: + case SyntaxKind.UnionType: + return serializeTypeList((node).types); + + case SyntaxKind.ConditionalType: + return serializeTypeList([(node).trueType, (node).falseType]); + + case SyntaxKind.TypeOperator: + if ((node).operator === SyntaxKind.ReadonlyKeyword) { + return serializeTypeNode((node).type); + } + break; + + case SyntaxKind.TypeQuery: + case SyntaxKind.IndexedAccessType: + case SyntaxKind.MappedType: + case SyntaxKind.TypeLiteral: + case SyntaxKind.AnyKeyword: + case SyntaxKind.UnknownKeyword: + case SyntaxKind.ThisType: + case SyntaxKind.ImportType: + break; + + + default: + return Debug.failBadSyntaxKind(node); + } + + return createIdentifier("Object"); + } + + function serializeTypeList(types: readonly TypeNode[]): SerializedTypeNode { + // Note when updating logic here also update getEntityNameForDecoratorMetadata + // so that aliases can be marked as referenced + let serializedUnion: SerializedTypeNode | undefined; + for (let typeNode of types) { + while (typeNode.kind === SyntaxKind.ParenthesizedType) { + typeNode = (typeNode as ParenthesizedTypeNode).type; // Skip parens if need be + } + if (typeNode.kind === SyntaxKind.NeverKeyword) { + continue; // Always elide `never` from the union/intersection if possible + } + if (!strictNullChecks && (typeNode.kind === SyntaxKind.NullKeyword || typeNode.kind === SyntaxKind.UndefinedKeyword)) { + continue; // Elide null and undefined from unions for metadata, just like what we did prior to the implementation of strict null checks + } + const serializedIndividual = serializeTypeNode(typeNode); + + if (isIdentifier(serializedIndividual) && serializedIndividual.escapedText === "Object") { + // One of the individual is global object, return immediately + return serializedIndividual; + } + // If there exists union that is not void 0 expression, check if the the common type is identifier. + // anything more complex and we will just default to Object + else if (serializedUnion) { + // Different types + if (!isIdentifier(serializedUnion) || + !isIdentifier(serializedIndividual) || + serializedUnion.escapedText !== serializedIndividual.escapedText) { + return createIdentifier("Object"); + } + } + else { + // Initialize the union type + serializedUnion = serializedIndividual; + } + } + + // If we were able to find common type, use it + return serializedUnion || createVoidZero(); // Fallback is only hit if all union constituients are null/undefined/never + } + + /** + * Serializes a TypeReferenceNode to an appropriate JS constructor value for use with + * decorator type metadata. + * + * @param node The type reference node. + */ + function serializeTypeReferenceNode(node: TypeReferenceNode): SerializedTypeNode { + const kind = resolver.getTypeReferenceSerializationKind(node.typeName, currentNameScope || currentLexicalScope); + switch (kind) { + case TypeReferenceSerializationKind.Unknown: + // From conditional type type reference that cannot be resolved is Similar to any or unknown + if (findAncestor(node, n => n.parent && isConditionalTypeNode(n.parent) && (n.parent.trueType === n || n.parent.falseType === n))) { + return createIdentifier("Object"); + } + + const serialized = serializeEntityNameAsExpressionFallback(node.typeName); + const temp = createTempVariable(hoistVariableDeclaration); + return createConditional( + createTypeCheck(createAssignment(temp, serialized), "function"), + temp, + createIdentifier("Object") + ); + + case TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: + return serializeEntityNameAsExpression(node.typeName); + + case TypeReferenceSerializationKind.VoidNullableOrNeverType: + return createVoidZero(); + + case TypeReferenceSerializationKind.BigIntLikeType: + return getGlobalBigIntNameWithFallback(); + + case TypeReferenceSerializationKind.BooleanType: + return createIdentifier("Boolean"); + + case TypeReferenceSerializationKind.NumberLikeType: + return createIdentifier("Number"); + + case TypeReferenceSerializationKind.StringLikeType: + return createIdentifier("String"); + + case TypeReferenceSerializationKind.ArrayLikeType: + return createIdentifier("Array"); + + case TypeReferenceSerializationKind.ESSymbolType: + return languageVersion < ScriptTarget.ES2015 + ? getGlobalSymbolNameWithFallback() + : createIdentifier("Symbol"); + + case TypeReferenceSerializationKind.TypeWithCallSignature: + return createIdentifier("Function"); + + case TypeReferenceSerializationKind.Promise: + return createIdentifier("Promise"); + + case TypeReferenceSerializationKind.ObjectType: + return createIdentifier("Object"); + default: + return Debug.assertNever(kind); + } + } + + function createCheckedValue(left: Expression, right: Expression) { + return createLogicalAnd( + createStrictInequality(createTypeOf(left), createLiteral("undefined")), + right + ); + } + + /** + * Serializes an entity name which may not exist at runtime, but whose access shouldn't throw + * + * @param node The entity name to serialize. + */ + function serializeEntityNameAsExpressionFallback(node: EntityName): BinaryExpression { + if (node.kind === SyntaxKind.Identifier) { + // A -> typeof A !== undefined && A + const copied = serializeEntityNameAsExpression(node); + return createCheckedValue(copied, copied); + } + if (node.left.kind === SyntaxKind.Identifier) { + // A.B -> typeof A !== undefined && A.B + return createCheckedValue(serializeEntityNameAsExpression(node.left), serializeEntityNameAsExpression(node)); + } + // A.B.C -> typeof A !== undefined && (_a = A.B) !== void 0 && _a.C + const left = serializeEntityNameAsExpressionFallback(node.left); + const temp = createTempVariable(hoistVariableDeclaration); + return createLogicalAnd( + createLogicalAnd( + left.left, + createStrictInequality(createAssignment(temp, left.right), createVoidZero()) + ), + createPropertyAccess(temp, node.right) + ); + } + + /** + * Serializes an entity name as an expression for decorator type metadata. + * + * @param node The entity name to serialize. + */ + function serializeEntityNameAsExpression(node: EntityName): SerializedEntityNameAsExpression { + switch (node.kind) { + case SyntaxKind.Identifier: + // Create a clone of the name with a new parent, and treat it as if it were + // a source tree node for the purposes of the checker. + const name = getMutableClone(node); + name.flags &= ~NodeFlags.Synthesized; + name.original = undefined; + name.parent = getParseTreeNode(currentLexicalScope); // ensure the parent is set to a parse tree node. + + return name; + + case SyntaxKind.QualifiedName: + return serializeQualifiedNameAsExpression(node); + } + } + + /** + * Serializes an qualified name as an expression for decorator type metadata. + * + * @param node The qualified name to serialize. + * @param useFallback A value indicating whether to use logical operators to test for the + * qualified name at runtime. + */ + function serializeQualifiedNameAsExpression(node: QualifiedName): SerializedEntityNameAsExpression { + return createPropertyAccess(serializeEntityNameAsExpression(node.left), node.right); + } + + /** + * Gets an expression that points to the global "Symbol" constructor at runtime if it is + * available. + */ + function getGlobalSymbolNameWithFallback(): ConditionalExpression { + return createConditional( + createTypeCheck(createIdentifier("Symbol"), "function"), + createIdentifier("Symbol"), + createIdentifier("Object") + ); + } + + /** + * Gets an expression that points to the global "BigInt" constructor at runtime if it is + * available. + */ + function getGlobalBigIntNameWithFallback(): SerializedTypeNode { + return languageVersion < ScriptTarget.ESNext + ? createConditional( + createTypeCheck(createIdentifier("BigInt"), "function"), + createIdentifier("BigInt"), + createIdentifier("Object") + ) + : createIdentifier("BigInt"); + } + + /** + * Gets an expression that represents a property name. For a computed property, a + * name is generated for the node. + * + * @param member The member whose name should be converted into an expression. + */ + function getExpressionForPropertyName(member: ClassElement | EnumMember, generateNameForComputedPropertyName: boolean): Expression { + const name = member.name!; + if (isComputedPropertyName(name)) { + return generateNameForComputedPropertyName && !isSimpleInlineableExpression(name.expression) + ? getGeneratedNameForNode(name) + : name.expression; + } + else if (isIdentifier(name)) { + return createLiteral(idText(name)); + } + else { + return getSynthesizedClone(name); + } + } + + /** + * Visits the property name of a class element, for use when emitting property + * initializers. For a computed property on a node with decorators, a temporary + * value is stored for later use. + * + * @param member The member whose name should be visited. + */ + function visitPropertyNameOfClassElement(member: ClassElement): PropertyName { + const name = member.name!; + // Computed property names need to be transformed into a hoisted variable when they are used more than once. + // The names are used more than once when: + // - the property is non-static and its initializer is moved to the constructor (when there are parameter property assignments). + // - the property has a decorator. + if (isComputedPropertyName(name) && ((!hasStaticModifier(member) && currentClassHasParameterProperties) || some(member.decorators))) { + const expression = visitNode(name.expression, visitor, isExpression); + const innerExpression = skipPartiallyEmittedExpressions(expression); + if (!isSimpleInlineableExpression(innerExpression)) { + const generatedName = getGeneratedNameForNode(name); + hoistVariableDeclaration(generatedName); + return updateComputedPropertyName(name, createAssignment(generatedName, expression)); + } + } + return visitNode(name, visitor, isPropertyName); + } + + /** + * Transforms a HeritageClause with TypeScript syntax. + * + * This function will only be called when one of the following conditions are met: + * - The node is a non-`extends` heritage clause that should be elided. + * - The node is an `extends` heritage clause that should be visited, but only allow a single type. + * + * @param node The HeritageClause to transform. + */ + function visitHeritageClause(node: HeritageClause): HeritageClause | undefined { + if (node.token === SyntaxKind.ImplementsKeyword) { + // implements clauses are elided + return undefined; + } + return visitEachChild(node, visitor, context); + } + + /** + * Transforms an ExpressionWithTypeArguments with TypeScript syntax. + * + * This function will only be called when one of the following conditions are met: + * - The node contains type arguments that should be elided. + * + * @param node The ExpressionWithTypeArguments to transform. + */ + function visitExpressionWithTypeArguments(node: ExpressionWithTypeArguments): ExpressionWithTypeArguments { + return updateExpressionWithTypeArguments( + node, + /*typeArguments*/ undefined, + visitNode(node.expression, visitor, isLeftHandSideExpression) + ); + } + + /** + * Determines whether to emit a function-like declaration. We should not emit the + * declaration if it does not have a body. + * + * @param node The declaration node. + */ + function shouldEmitFunctionLikeDeclaration(node: T): node is T & { body: NonNullable } { + return !nodeIsMissing(node.body); + } + + function visitPropertyDeclaration(node: PropertyDeclaration) { + const updated = updateProperty( + node, + /*decorators*/ undefined, + visitNodes(node.modifiers, visitor, isModifier), + visitPropertyNameOfClassElement(node), + /*questionOrExclamationToken*/ undefined, + /*type*/ undefined, + visitNode(node.initializer, visitor) + ); + if (updated !== node) { + // While we emit the source map for the node after skipping decorators and modifiers, + // we need to emit the comments for the original range. + setCommentRange(updated, node); + setSourceMapRange(updated, moveRangePastDecorators(node)); + } + return updated; + } + + function visitConstructor(node: ConstructorDeclaration) { + if (!shouldEmitFunctionLikeDeclaration(node)) { + return undefined; + } + + return updateConstructor( + node, + /*decorators*/ undefined, + /*modifiers*/ undefined, + visitParameterList(node.parameters, visitor, context), + transformConstructorBody(node.body, node) + ); + } + + function transformConstructorBody(body: Block, constructor: ConstructorDeclaration) { + const parametersWithPropertyAssignments = constructor && + filter(constructor.parameters, p => isParameterPropertyDeclaration(p, constructor)); + if (!some(parametersWithPropertyAssignments)) { + return visitFunctionBody(body, visitor, context); + } + + let statements: Statement[] = []; + let indexOfFirstStatement = 0; + + resumeLexicalEnvironment(); + + indexOfFirstStatement = addPrologueDirectivesAndInitialSuperCall(constructor, statements, visitor); + + // Add parameters with property assignments. Transforms this: + // + // constructor (public x, public y) { + // } + // + // Into this: + // + // constructor (x, y) { + // this.x = x; + // this.y = y; + // } + // + addRange(statements, map(parametersWithPropertyAssignments, transformParameterWithPropertyAssignment)); + + // Add the existing statements, skipping the initial super call. + addRange(statements, visitNodes(body.statements, visitor, isStatement, indexOfFirstStatement)); + + // End the lexical environment. + statements = mergeLexicalEnvironment(statements, endLexicalEnvironment()); + const block = createBlock(setTextRange(createNodeArray(statements), body.statements), /*multiLine*/ true); + setTextRange(block, /*location*/ body); + setOriginalNode(block, body); + return block; + } + + /** + * Transforms a parameter into a property assignment statement. + * + * @param node The parameter declaration. + */ + function transformParameterWithPropertyAssignment(node: ParameterPropertyDeclaration) { + const name = node.name; + if (!isIdentifier(name)) { + return undefined; + } + + const propertyName = getMutableClone(name); + setEmitFlags(propertyName, EmitFlags.NoComments | EmitFlags.NoSourceMap); + + const localName = getMutableClone(name); + setEmitFlags(localName, EmitFlags.NoComments); + + return startOnNewLine( + removeAllComments( + setTextRange( + setOriginalNode( + createExpressionStatement( + createAssignment( + setTextRange( + createPropertyAccess( + createThis(), + propertyName + ), + node.name + ), + localName + ) + ), + node + ), + moveRangePos(node, -1) + ) + ) + ); + } + + function visitMethodDeclaration(node: MethodDeclaration) { + if (!shouldEmitFunctionLikeDeclaration(node)) { + return undefined; + } + const updated = updateMethod( + node, + /*decorators*/ undefined, + visitNodes(node.modifiers, modifierVisitor, isModifier), + node.asteriskToken, + visitPropertyNameOfClassElement(node), + /*questionToken*/ undefined, + /*typeParameters*/ undefined, + visitParameterList(node.parameters, visitor, context), + /*type*/ undefined, + visitFunctionBody(node.body, visitor, context) + ); + if (updated !== node) { + // While we emit the source map for the node after skipping decorators and modifiers, + // we need to emit the comments for the original range. + setCommentRange(updated, node); + setSourceMapRange(updated, moveRangePastDecorators(node)); + } + return updated; + } + + /** + * Determines whether to emit an accessor declaration. We should not emit the + * declaration if it does not have a body and is abstract. + * + * @param node The declaration node. + */ + function shouldEmitAccessorDeclaration(node: AccessorDeclaration) { + return !(nodeIsMissing(node.body) && hasModifier(node, ModifierFlags.Abstract)); + } + + function visitGetAccessor(node: GetAccessorDeclaration) { + if (!shouldEmitAccessorDeclaration(node)) { + return undefined; + } + const updated = updateGetAccessor( + node, + /*decorators*/ undefined, + visitNodes(node.modifiers, modifierVisitor, isModifier), + visitPropertyNameOfClassElement(node), + visitParameterList(node.parameters, visitor, context), + /*type*/ undefined, + visitFunctionBody(node.body, visitor, context) || createBlock([]) + ); + if (updated !== node) { + // While we emit the source map for the node after skipping decorators and modifiers, + // we need to emit the comments for the original range. + setCommentRange(updated, node); + setSourceMapRange(updated, moveRangePastDecorators(node)); + } + return updated; + } + + function visitSetAccessor(node: SetAccessorDeclaration) { + if (!shouldEmitAccessorDeclaration(node)) { + return undefined; + } + const updated = updateSetAccessor( + node, + /*decorators*/ undefined, + visitNodes(node.modifiers, modifierVisitor, isModifier), + visitPropertyNameOfClassElement(node), + visitParameterList(node.parameters, visitor, context), + visitFunctionBody(node.body, visitor, context) || createBlock([]) + ); + if (updated !== node) { + // While we emit the source map for the node after skipping decorators and modifiers, + // we need to emit the comments for the original range. + setCommentRange(updated, node); + setSourceMapRange(updated, moveRangePastDecorators(node)); + } + return updated; + } + + function visitFunctionDeclaration(node: FunctionDeclaration): VisitResult { + if (!shouldEmitFunctionLikeDeclaration(node)) { + return createNotEmittedStatement(node); + } + const updated = updateFunctionDeclaration( + node, + /*decorators*/ undefined, + visitNodes(node.modifiers, modifierVisitor, isModifier), + node.asteriskToken, + node.name, + /*typeParameters*/ undefined, + visitParameterList(node.parameters, visitor, context), + /*type*/ undefined, + visitFunctionBody(node.body, visitor, context) || createBlock([]) + ); + if (isExportOfNamespace(node)) { + const statements: Statement[] = [updated]; + addExportMemberAssignment(statements, node); + return statements; + } + return updated; + } + + function visitFunctionExpression(node: FunctionExpression): Expression { + if (!shouldEmitFunctionLikeDeclaration(node)) { + return createOmittedExpression(); + } + const updated = updateFunctionExpression( + node, + visitNodes(node.modifiers, modifierVisitor, isModifier), + node.asteriskToken, + node.name, + /*typeParameters*/ undefined, + visitParameterList(node.parameters, visitor, context), + /*type*/ undefined, + visitFunctionBody(node.body, visitor, context) || createBlock([]) + ); + return updated; + } + + function visitArrowFunction(node: ArrowFunction) { + const updated = updateArrowFunction( + node, + visitNodes(node.modifiers, modifierVisitor, isModifier), + /*typeParameters*/ undefined, + visitParameterList(node.parameters, visitor, context), + /*type*/ undefined, + node.equalsGreaterThanToken, + visitFunctionBody(node.body, visitor, context), + ); + return updated; + } + + function visitParameter(node: ParameterDeclaration) { + if (parameterIsThisKeyword(node)) { + return undefined; + } + + const updated = updateParameter( + node, + /*decorators*/ undefined, + /*modifiers*/ undefined, + node.dotDotDotToken, + visitNode(node.name, visitor, isBindingName), + /*questionToken*/ undefined, + /*type*/ undefined, + visitNode(node.initializer, visitor, isExpression) + ); + if (updated !== node) { + // While we emit the source map for the node after skipping decorators and modifiers, + // we need to emit the comments for the original range. + setCommentRange(updated, node); + setTextRange(updated, moveRangePastModifiers(node)); + setSourceMapRange(updated, moveRangePastModifiers(node)); + setEmitFlags(updated.name, EmitFlags.NoTrailingSourceMap); + } + return updated; + } + + function visitVariableStatement(node: VariableStatement): Statement | undefined { + if (isExportOfNamespace(node)) { + const variables = getInitializedVariables(node.declarationList); + if (variables.length === 0) { + // elide statement if there are no initialized variables. + return undefined; + } + + return setTextRange( + createExpressionStatement( + inlineExpressions( + map(variables, transformInitializedVariable) + ) + ), + node + ); + } + else { + return visitEachChild(node, visitor, context); + } + } + + function transformInitializedVariable(node: VariableDeclaration): Expression { + const name = node.name; + if (isBindingPattern(name)) { + return flattenDestructuringAssignment( + node, + visitor, + context, + FlattenLevel.All, + /*needsValue*/ false, + createNamespaceExportExpression + ); + } + else { + return setTextRange( + createAssignment( + getNamespaceMemberNameWithSourceMapsAndWithoutComments(name), + visitNode(node.initializer, visitor, isExpression) + ), + /*location*/ node + ); + } + } + + function visitVariableDeclaration(node: VariableDeclaration) { + return updateVariableDeclaration( + node, + visitNode(node.name, visitor, isBindingName), + /*type*/ undefined, + visitNode(node.initializer, visitor, isExpression)); + } + + function visitParenthesizedExpression(node: ParenthesizedExpression): Expression { + const innerExpression = skipOuterExpressions(node.expression, ~OuterExpressionKinds.Assertions); + if (isAssertionExpression(innerExpression)) { + // Make sure we consider all nested cast expressions, e.g.: + // (-A).x; + const expression = visitNode(node.expression, visitor, isExpression); + + // We have an expression of the form: (SubExpr). Emitting this as (SubExpr) + // is really not desirable. We would like to emit the subexpression as-is. Omitting + // the parentheses, however, could cause change in the semantics of the generated + // code if the casted expression has a lower precedence than the rest of the + // expression. + // + // To preserve comments, we return a "PartiallyEmittedExpression" here which will + // preserve the position information of the original expression. + // + // Due to the auto-parenthesization rules used by the visitor and factory functions + // we can safely elide the parentheses here, as a new synthetic + // ParenthesizedExpression will be inserted if we remove parentheses too + // aggressively. + // HOWEVER - if there are leading comments on the expression itself, to handle ASI + // correctly for return and throw, we must keep the parenthesis + if (length(getLeadingCommentRangesOfNode(expression, currentSourceFile))) { + return updateParen(node, expression); + } + return createPartiallyEmittedExpression(expression, node); + } + + return visitEachChild(node, visitor, context); + } + + function visitAssertionExpression(node: AssertionExpression): Expression { + const expression = visitNode(node.expression, visitor, isExpression); + return createPartiallyEmittedExpression(expression, node); + } + + function visitNonNullExpression(node: NonNullExpression): Expression { + const expression = visitNode(node.expression, visitor, isLeftHandSideExpression); + return createPartiallyEmittedExpression(expression, node); + } + + function visitCallExpression(node: CallExpression) { + return updateCall( + node, + visitNode(node.expression, visitor, isExpression), + /*typeArguments*/ undefined, + visitNodes(node.arguments, visitor, isExpression)); + } + + function visitNewExpression(node: NewExpression) { + return updateNew( + node, + visitNode(node.expression, visitor, isExpression), + /*typeArguments*/ undefined, + visitNodes(node.arguments, visitor, isExpression)); + } + + function visitTaggedTemplateExpression(node: TaggedTemplateExpression) { + return updateTaggedTemplate( + node, + visitNode(node.tag, visitor, isExpression), + /*typeArguments*/ undefined, + visitNode(node.template, visitor, isExpression)); + } + + /** + * Determines whether to emit an enum declaration. + * + * @param node The enum declaration node. + */ + function shouldEmitEnumDeclaration(node: EnumDeclaration) { + return !isEnumConst(node) + || compilerOptions.preserveConstEnums + || compilerOptions.isolatedModules; + } + + /** + * Visits an enum declaration. + * + * This function will be called any time a TypeScript enum is encountered. + * + * @param node The enum declaration node. + */ + function visitEnumDeclaration(node: EnumDeclaration): VisitResult { + if (!shouldEmitEnumDeclaration(node)) { + return createNotEmittedStatement(node); + } + + const statements: Statement[] = []; + + // We request to be advised when the printer is about to print this node. This allows + // us to set up the correct state for later substitutions. + let emitFlags = EmitFlags.AdviseOnEmitNode; + + // If needed, we should emit a variable declaration for the enum. If we emit + // a leading variable declaration, we should not emit leading comments for the + // enum body. + const varAdded = addVarForEnumOrModuleDeclaration(statements, node); + if (varAdded) { + // We should still emit the comments if we are emitting a system module. + if (moduleKind !== ModuleKind.System || currentLexicalScope !== currentSourceFile) { + emitFlags |= EmitFlags.NoLeadingComments; + } + } + + // `parameterName` is the declaration name used inside of the enum. + const parameterName = getNamespaceParameterName(node); + + // `containerName` is the expression used inside of the enum for assignments. + const containerName = getNamespaceContainerName(node); + + // `exportName` is the expression used within this node's container for any exported references. + const exportName = hasModifier(node, ModifierFlags.Export) + ? getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true) + : getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); + + // x || (x = {}) + // exports.x || (exports.x = {}) + let moduleArg = + createLogicalOr( + exportName, + createAssignment( + exportName, + createObjectLiteral() + ) + ); + + if (hasNamespaceQualifiedExportName(node)) { + // `localName` is the expression used within this node's containing scope for any local references. + const localName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); + + // x = (exports.x || (exports.x = {})) + moduleArg = createAssignment(localName, moduleArg); + } + + // (function (x) { + // x[x["y"] = 0] = "y"; + // ... + // })(x || (x = {})); + const enumStatement = createExpressionStatement( + createCall( + createFunctionExpression( + /*modifiers*/ undefined, + /*asteriskToken*/ undefined, + /*name*/ undefined, + /*typeParameters*/ undefined, + [createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, parameterName)], + /*type*/ undefined, + transformEnumBody(node, containerName) + ), + /*typeArguments*/ undefined, + [moduleArg] + ) + ); + + setOriginalNode(enumStatement, node); + if (varAdded) { + // If a variable was added, synthetic comments are emitted on it, not on the moduleStatement. + setSyntheticLeadingComments(enumStatement, undefined); + setSyntheticTrailingComments(enumStatement, undefined); + } + setTextRange(enumStatement, node); + addEmitFlags(enumStatement, emitFlags); + statements.push(enumStatement); + + // Add a DeclarationMarker for the enum to preserve trailing comments and mark + // the end of the declaration. + statements.push(createEndOfDeclarationMarker(node)); + return statements; + } + + /** + * Transforms the body of an enum declaration. + * + * @param node The enum declaration node. + */ + function transformEnumBody(node: EnumDeclaration, localName: Identifier): Block { + const savedCurrentNamespaceLocalName = currentNamespaceContainerName; + currentNamespaceContainerName = localName; + + const statements: Statement[] = []; + startLexicalEnvironment(); + const members = map(node.members, transformEnumMember); + insertStatementsAfterStandardPrologue(statements, endLexicalEnvironment()); + addRange(statements, members); + + currentNamespaceContainerName = savedCurrentNamespaceLocalName; + return createBlock( + setTextRange(createNodeArray(statements), /*location*/ node.members), + /*multiLine*/ true + ); + } + + /** + * Transforms an enum member into a statement. + * + * @param member The enum member node. + */ + function transformEnumMember(member: EnumMember): Statement { + // enums don't support computed properties + // we pass false as 'generateNameForComputedPropertyName' for a backward compatibility purposes + // old emitter always generate 'expression' part of the name as-is. + const name = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ false); + const valueExpression = transformEnumMemberDeclarationValue(member); + const innerAssignment = createAssignment( + createElementAccess( + currentNamespaceContainerName, + name + ), + valueExpression + ); + const outerAssignment = valueExpression.kind === SyntaxKind.StringLiteral ? + innerAssignment : + createAssignment( + createElementAccess( + currentNamespaceContainerName, + innerAssignment + ), + name + ); + return setTextRange( + createExpressionStatement( + setTextRange( + outerAssignment, + member + ) + ), + member + ); + } + + /** + * Transforms the value of an enum member. + * + * @param member The enum member node. + */ + function transformEnumMemberDeclarationValue(member: EnumMember): Expression { + const value = resolver.getConstantValue(member); + if (value !== undefined) { + return createLiteral(value); + } + else { + enableSubstitutionForNonQualifiedEnumMembers(); + if (member.initializer) { + return visitNode(member.initializer, visitor, isExpression); + } + else { + return createVoidZero(); + } + } + } + + /** + * Determines whether to elide a module declaration. + * + * @param node The module declaration node. + */ + function shouldEmitModuleDeclaration(node: ModuleDeclaration) { + return isInstantiatedModule(node, !!compilerOptions.preserveConstEnums || !!compilerOptions.isolatedModules); + } + + /** + * Determines whether an exported declaration will have a qualified export name (e.g. `f.x` + * or `exports.x`). + */ + function hasNamespaceQualifiedExportName(node: Node) { + return isExportOfNamespace(node) + || (isExternalModuleExport(node) + && moduleKind !== ModuleKind.ES2015 + && moduleKind !== ModuleKind.ESNext + && moduleKind !== ModuleKind.System); + } + + /** + * Records that a declaration was emitted in the current scope, if it was the first + * declaration for the provided symbol. + */ + function recordEmittedDeclarationInScope(node: FunctionDeclaration | ClassDeclaration | ModuleDeclaration | EnumDeclaration) { + if (!currentScopeFirstDeclarationsOfName) { + currentScopeFirstDeclarationsOfName = createUnderscoreEscapedMap(); + } + + const name = declaredNameInScope(node); + if (!currentScopeFirstDeclarationsOfName.has(name)) { + currentScopeFirstDeclarationsOfName.set(name, node); + } + } + + /** + * Determines whether a declaration is the first declaration with + * the same name emitted in the current scope. + */ + function isFirstEmittedDeclarationInScope(node: ModuleDeclaration | EnumDeclaration) { + if (currentScopeFirstDeclarationsOfName) { + const name = declaredNameInScope(node); + return currentScopeFirstDeclarationsOfName.get(name) === node; + } + return true; + } + + function declaredNameInScope(node: FunctionDeclaration | ClassDeclaration | ModuleDeclaration | EnumDeclaration): __String { + Debug.assertNode(node.name, isIdentifier); + return (node.name as Identifier).escapedText; + } + + /** + * Adds a leading VariableStatement for a enum or module declaration. + */ + function addVarForEnumOrModuleDeclaration(statements: Statement[], node: ModuleDeclaration | EnumDeclaration) { + // Emit a variable statement for the module. We emit top-level enums as a `var` + // declaration to avoid static errors in global scripts scripts due to redeclaration. + // enums in any other scope are emitted as a `let` declaration. + const statement = createVariableStatement( + visitNodes(node.modifiers, modifierVisitor, isModifier), + createVariableDeclarationList([ + createVariableDeclaration( + getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true) + ) + ], currentLexicalScope.kind === SyntaxKind.SourceFile ? NodeFlags.None : NodeFlags.Let) + ); + + setOriginalNode(statement, node); + + recordEmittedDeclarationInScope(node); + if (isFirstEmittedDeclarationInScope(node)) { + // Adjust the source map emit to match the old emitter. + if (node.kind === SyntaxKind.EnumDeclaration) { + setSourceMapRange(statement.declarationList, node); + } + else { + setSourceMapRange(statement, node); + } + + // Trailing comments for module declaration should be emitted after the function closure + // instead of the variable statement: + // + // /** Module comment*/ + // module m1 { + // function foo4Export() { + // } + // } // trailing comment module + // + // Should emit: + // + // /** Module comment*/ + // var m1; + // (function (m1) { + // function foo4Export() { + // } + // })(m1 || (m1 = {})); // trailing comment module + // + setCommentRange(statement, node); + addEmitFlags(statement, EmitFlags.NoTrailingComments | EmitFlags.HasEndOfDeclarationMarker); + statements.push(statement); + return true; + } + else { + // For an EnumDeclaration or ModuleDeclaration that merges with a preceeding + // declaration we do not emit a leading variable declaration. To preserve the + // begin/end semantics of the declararation and to properly handle exports + // we wrap the leading variable declaration in a `MergeDeclarationMarker`. + const mergeMarker = createMergeDeclarationMarker(statement); + setEmitFlags(mergeMarker, EmitFlags.NoComments | EmitFlags.HasEndOfDeclarationMarker); + statements.push(mergeMarker); + return false; + } + } + + /** + * Visits a module declaration node. + * + * This function will be called any time a TypeScript namespace (ModuleDeclaration) is encountered. + * + * @param node The module declaration node. + */ + function visitModuleDeclaration(node: ModuleDeclaration): VisitResult { + if (!shouldEmitModuleDeclaration(node)) { + return createNotEmittedStatement(node); + } + + Debug.assertNode(node.name, isIdentifier, "A TypeScript namespace should have an Identifier name."); + enableSubstitutionForNamespaceExports(); + + const statements: Statement[] = []; + + // We request to be advised when the printer is about to print this node. This allows + // us to set up the correct state for later substitutions. + let emitFlags = EmitFlags.AdviseOnEmitNode; + + // If needed, we should emit a variable declaration for the module. If we emit + // a leading variable declaration, we should not emit leading comments for the + // module body. + const varAdded = addVarForEnumOrModuleDeclaration(statements, node); + if (varAdded) { + // We should still emit the comments if we are emitting a system module. + if (moduleKind !== ModuleKind.System || currentLexicalScope !== currentSourceFile) { + emitFlags |= EmitFlags.NoLeadingComments; + } + } + + // `parameterName` is the declaration name used inside of the namespace. + const parameterName = getNamespaceParameterName(node); + + // `containerName` is the expression used inside of the namespace for exports. + const containerName = getNamespaceContainerName(node); + + // `exportName` is the expression used within this node's container for any exported references. + const exportName = hasModifier(node, ModifierFlags.Export) + ? getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true) + : getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); + + // x || (x = {}) + // exports.x || (exports.x = {}) + let moduleArg = + createLogicalOr( + exportName, + createAssignment( + exportName, + createObjectLiteral() + ) + ); + + if (hasNamespaceQualifiedExportName(node)) { + // `localName` is the expression used within this node's containing scope for any local references. + const localName = getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true); + + // x = (exports.x || (exports.x = {})) + moduleArg = createAssignment(localName, moduleArg); + } + + // (function (x_1) { + // x_1.y = ...; + // })(x || (x = {})); + const moduleStatement = createExpressionStatement( + createCall( + createFunctionExpression( + /*modifiers*/ undefined, + /*asteriskToken*/ undefined, + /*name*/ undefined, + /*typeParameters*/ undefined, + [createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, parameterName)], + /*type*/ undefined, + transformModuleBody(node, containerName) + ), + /*typeArguments*/ undefined, + [moduleArg] + ) + ); + + setOriginalNode(moduleStatement, node); + if (varAdded) { + // If a variable was added, synthetic comments are emitted on it, not on the moduleStatement. + setSyntheticLeadingComments(moduleStatement, undefined); + setSyntheticTrailingComments(moduleStatement, undefined); + } + setTextRange(moduleStatement, node); + addEmitFlags(moduleStatement, emitFlags); + statements.push(moduleStatement); + + // Add a DeclarationMarker for the namespace to preserve trailing comments and mark + // the end of the declaration. + statements.push(createEndOfDeclarationMarker(node)); + return statements; + } + + /** + * Transforms the body of a module declaration. + * + * @param node The module declaration node. + */ + function transformModuleBody(node: ModuleDeclaration, namespaceLocalName: Identifier): Block { + const savedCurrentNamespaceContainerName = currentNamespaceContainerName; + const savedCurrentNamespace = currentNamespace; + const savedCurrentScopeFirstDeclarationsOfName = currentScopeFirstDeclarationsOfName; + currentNamespaceContainerName = namespaceLocalName; + currentNamespace = node; + currentScopeFirstDeclarationsOfName = undefined; + + const statements: Statement[] = []; + startLexicalEnvironment(); + + let statementsLocation: TextRange; + let blockLocation: TextRange | undefined; + const body = node.body!; + if (body.kind === SyntaxKind.ModuleBlock) { + saveStateAndInvoke(body, body => addRange(statements, visitNodes((body).statements, namespaceElementVisitor, isStatement))); + statementsLocation = body.statements; + blockLocation = body; + } + else { + const result = visitModuleDeclaration(body); + if (result) { + if (isArray(result)) { + addRange(statements, result); + } + else { + statements.push(result); + } + } + + const moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node)!.body; + statementsLocation = moveRangePos(moduleBlock.statements, -1); + } + + insertStatementsAfterStandardPrologue(statements, endLexicalEnvironment()); + currentNamespaceContainerName = savedCurrentNamespaceContainerName; + currentNamespace = savedCurrentNamespace; + currentScopeFirstDeclarationsOfName = savedCurrentScopeFirstDeclarationsOfName; + + const block = createBlock( + setTextRange( + createNodeArray(statements), + /*location*/ statementsLocation + ), + /*multiLine*/ true + ); + setTextRange(block, blockLocation); + + // namespace hello.hi.world { + // function foo() {} + // + // // TODO, blah + // } + // + // should be emitted as + // + // var hello; + // (function (hello) { + // var hi; + // (function (hi) { + // var world; + // (function (world) { + // function foo() { } + // // TODO, blah + // })(world = hi.world || (hi.world = {})); + // })(hi = hello.hi || (hello.hi = {})); + // })(hello || (hello = {})); + // We only want to emit comment on the namespace which contains block body itself, not the containing namespaces. + if (body.kind !== SyntaxKind.ModuleBlock) { + setEmitFlags(block, getEmitFlags(block) | EmitFlags.NoComments); + } + return block; + } + + function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration: ModuleDeclaration): ModuleDeclaration | undefined { + if (moduleDeclaration.body!.kind === SyntaxKind.ModuleDeclaration) { + const recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); + return recursiveInnerModule || moduleDeclaration.body; + } + } + + /** + * Visits an import declaration, eliding it if it is not referenced. + * + * @param node The import declaration node. + */ + function visitImportDeclaration(node: ImportDeclaration): VisitResult { + if (!node.importClause) { + // Do not elide a side-effect only import declaration. + // import "foo"; + return node; + } + + // Elide the declaration if the import clause was elided. + const importClause = visitNode(node.importClause, visitImportClause, isImportClause); + return importClause + ? updateImportDeclaration( + node, + /*decorators*/ undefined, + /*modifiers*/ undefined, + importClause, + node.moduleSpecifier) + : undefined; + } + + /** + * Visits an import clause, eliding it if it is not referenced. + * + * @param node The import clause node. + */ + function visitImportClause(node: ImportClause): VisitResult { + // Elide the import clause if we elide both its name and its named bindings. + const name = resolver.isReferencedAliasDeclaration(node) ? node.name : undefined; + const namedBindings = visitNode(node.namedBindings, visitNamedImportBindings, isNamedImportBindings); + return (name || namedBindings) ? updateImportClause(node, name, namedBindings) : undefined; + } + + /** + * Visits named import bindings, eliding it if it is not referenced. + * + * @param node The named import bindings node. + */ + function visitNamedImportBindings(node: NamedImportBindings): VisitResult { + if (node.kind === SyntaxKind.NamespaceImport) { + // Elide a namespace import if it is not referenced. + return resolver.isReferencedAliasDeclaration(node) ? node : undefined; + } + else { + // Elide named imports if all of its import specifiers are elided. + const elements = visitNodes(node.elements, visitImportSpecifier, isImportSpecifier); + return some(elements) ? updateNamedImports(node, elements) : undefined; + } + } + + /** + * Visits an import specifier, eliding it if it is not referenced. + * + * @param node The import specifier node. + */ + function visitImportSpecifier(node: ImportSpecifier): VisitResult { + // Elide an import specifier if it is not referenced. + return resolver.isReferencedAliasDeclaration(node) ? node : undefined; + } + + /** + * Visits an export assignment, eliding it if it does not contain a clause that resolves + * to a value. + * + * @param node The export assignment node. + */ + function visitExportAssignment(node: ExportAssignment): VisitResult { + // Elide the export assignment if it does not reference a value. + return resolver.isValueAliasDeclaration(node) + ? visitEachChild(node, visitor, context) + : undefined; + } + + /** + * Visits an export declaration, eliding it if it does not contain a clause that resolves + * to a value. + * + * @param node The export declaration node. + */ + function visitExportDeclaration(node: ExportDeclaration): VisitResult { + if (!node.exportClause) { + // Elide a star export if the module it references does not export a value. + return compilerOptions.isolatedModules || resolver.moduleExportsSomeValue(node.moduleSpecifier!) ? node : undefined; + } + + if (!resolver.isValueAliasDeclaration(node)) { + // Elide the export declaration if it does not export a value. + return undefined; + } + + // Elide the export declaration if all of its named exports are elided. + const exportClause = visitNode(node.exportClause, visitNamedExports, isNamedExports); + return exportClause + ? updateExportDeclaration( + node, + /*decorators*/ undefined, + /*modifiers*/ undefined, + exportClause, + node.moduleSpecifier) + : undefined; + } + + /** + * Visits named exports, eliding it if it does not contain an export specifier that + * resolves to a value. + * + * @param node The named exports node. + */ + function visitNamedExports(node: NamedExports): VisitResult { + // Elide the named exports if all of its export specifiers were elided. + const elements = visitNodes(node.elements, visitExportSpecifier, isExportSpecifier); + return some(elements) ? updateNamedExports(node, elements) : undefined; + } + + /** + * Visits an export specifier, eliding it if it does not resolve to a value. + * + * @param node The export specifier node. + */ + function visitExportSpecifier(node: ExportSpecifier): VisitResult { + // Elide an export specifier if it does not reference a value. + return resolver.isValueAliasDeclaration(node) ? node : undefined; + } + + /** + * Determines whether to emit an import equals declaration. + * + * @param node The import equals declaration node. + */ + function shouldEmitImportEqualsDeclaration(node: ImportEqualsDeclaration) { + // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when + // - current file is not external module + // - import declaration is top level and target is value imported by entity name + return resolver.isReferencedAliasDeclaration(node) + || (!isExternalModule(currentSourceFile) + && resolver.isTopLevelValueImportEqualsWithEntityName(node)); + } + + /** + * Visits an import equals declaration. + * + * @param node The import equals declaration node. + */ + function visitImportEqualsDeclaration(node: ImportEqualsDeclaration): VisitResult { + if (isExternalModuleImportEqualsDeclaration(node)) { + // Elide external module `import=` if it is not referenced. + return resolver.isReferencedAliasDeclaration(node) + ? visitEachChild(node, visitor, context) + : undefined; + } + + if (!shouldEmitImportEqualsDeclaration(node)) { + return undefined; + } + + const moduleReference = createExpressionFromEntityName(node.moduleReference); + setEmitFlags(moduleReference, EmitFlags.NoComments | EmitFlags.NoNestedComments); + + if (isNamedExternalModuleExport(node) || !isExportOfNamespace(node)) { + // export var ${name} = ${moduleReference}; + // var ${name} = ${moduleReference}; + return setOriginalNode( + setTextRange( + createVariableStatement( + visitNodes(node.modifiers, modifierVisitor, isModifier), + createVariableDeclarationList([ + setOriginalNode( + createVariableDeclaration( + node.name, + /*type*/ undefined, + moduleReference + ), + node + ) + ]) + ), + node + ), + node + ); + } + else { + // exports.${name} = ${moduleReference}; + return setOriginalNode( + createNamespaceExport( + node.name, + moduleReference, + node + ), + node + ); + } + } + + /** + * Gets a value indicating whether the node is exported from a namespace. + * + * @param node The node to test. + */ + function isExportOfNamespace(node: Node) { + return currentNamespace !== undefined && hasModifier(node, ModifierFlags.Export); + } + + /** + * Gets a value indicating whether the node is exported from an external module. + * + * @param node The node to test. + */ + function isExternalModuleExport(node: Node) { + return currentNamespace === undefined && hasModifier(node, ModifierFlags.Export); + } + + /** + * Gets a value indicating whether the node is a named export from an external module. + * + * @param node The node to test. + */ + function isNamedExternalModuleExport(node: Node) { + return isExternalModuleExport(node) + && !hasModifier(node, ModifierFlags.Default); + } + + /** + * Gets a value indicating whether the node is the default export of an external module. + * + * @param node The node to test. + */ + function isDefaultExternalModuleExport(node: Node) { + return isExternalModuleExport(node) + && hasModifier(node, ModifierFlags.Default); + } + + /** + * Creates a statement for the provided expression. This is used in calls to `map`. + */ + function expressionToStatement(expression: Expression) { + return createExpressionStatement(expression); + } + + function addExportMemberAssignment(statements: Statement[], node: ClassDeclaration | FunctionDeclaration) { + const expression = createAssignment( + getExternalModuleOrNamespaceExportName(currentNamespaceContainerName, node, /*allowComments*/ false, /*allowSourceMaps*/ true), + getLocalName(node) + ); + setSourceMapRange(expression, createRange(node.name ? node.name.pos : node.pos, node.end)); + + const statement = createExpressionStatement(expression); + setSourceMapRange(statement, createRange(-1, node.end)); + statements.push(statement); + } + + function createNamespaceExport(exportName: Identifier, exportValue: Expression, location?: TextRange) { + return setTextRange( + createExpressionStatement( + createAssignment( + getNamespaceMemberName(currentNamespaceContainerName, exportName, /*allowComments*/ false, /*allowSourceMaps*/ true), + exportValue + ) + ), + location + ); + } + + function createNamespaceExportExpression(exportName: Identifier, exportValue: Expression, location?: TextRange) { + return setTextRange(createAssignment(getNamespaceMemberNameWithSourceMapsAndWithoutComments(exportName), exportValue), location); + } + + function getNamespaceMemberNameWithSourceMapsAndWithoutComments(name: Identifier) { + return getNamespaceMemberName(currentNamespaceContainerName, name, /*allowComments*/ false, /*allowSourceMaps*/ true); + } + + /** + * Gets the declaration name used inside of a namespace or enum. + */ + function getNamespaceParameterName(node: ModuleDeclaration | EnumDeclaration) { + const name = getGeneratedNameForNode(node); + setSourceMapRange(name, node.name); + return name; + } + + /** + * Gets the expression used to refer to a namespace or enum within the body + * of its declaration. + */ + function getNamespaceContainerName(node: ModuleDeclaration | EnumDeclaration) { + return getGeneratedNameForNode(node); + } + + /** + * Gets a local alias for a class declaration if it is a decorated class with an internal + * reference to the static side of the class. This is necessary to avoid issues with + * double-binding semantics for the class name. + */ + function getClassAliasIfNeeded(node: ClassDeclaration) { + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithConstructorReference) { + enableSubstitutionForClassAliases(); + const classAlias = createUniqueName(node.name && !isGeneratedIdentifier(node.name) ? idText(node.name) : "default"); + classAliases[getOriginalNodeId(node)] = classAlias; + hoistVariableDeclaration(classAlias); + return classAlias; + } + } + + function getClassPrototype(node: ClassExpression | ClassDeclaration) { + return createPropertyAccess(getDeclarationName(node), "prototype"); + } + + function getClassMemberPrefix(node: ClassExpression | ClassDeclaration, member: ClassElement) { + return hasModifier(member, ModifierFlags.Static) + ? getDeclarationName(node) + : getClassPrototype(node); + } + + function enableSubstitutionForNonQualifiedEnumMembers() { + if ((enabledSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers) === 0) { + enabledSubstitutions |= TypeScriptSubstitutionFlags.NonQualifiedEnumMembers; + context.enableSubstitution(SyntaxKind.Identifier); + } + } + + function enableSubstitutionForClassAliases() { + if ((enabledSubstitutions & TypeScriptSubstitutionFlags.ClassAliases) === 0) { + enabledSubstitutions |= TypeScriptSubstitutionFlags.ClassAliases; + + // We need to enable substitutions for identifiers. This allows us to + // substitute class names inside of a class declaration. + context.enableSubstitution(SyntaxKind.Identifier); + + // Keep track of class aliases. + classAliases = []; + } + } + + function enableSubstitutionForNamespaceExports() { + if ((enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) === 0) { + enabledSubstitutions |= TypeScriptSubstitutionFlags.NamespaceExports; + + // We need to enable substitutions for identifiers and shorthand property assignments. This allows us to + // substitute the names of exported members of a namespace. + context.enableSubstitution(SyntaxKind.Identifier); + context.enableSubstitution(SyntaxKind.ShorthandPropertyAssignment); + + // We need to be notified when entering and exiting namespaces. + context.enableEmitNotification(SyntaxKind.ModuleDeclaration); + } + } + + function isTransformedModuleDeclaration(node: Node): boolean { + return getOriginalNode(node).kind === SyntaxKind.ModuleDeclaration; + } + + function isTransformedEnumDeclaration(node: Node): boolean { + return getOriginalNode(node).kind === SyntaxKind.EnumDeclaration; + } + + /** + * Hook for node emit. + * + * @param hint A hint as to the intended usage of the node. + * @param node The node to emit. + * @param emit A callback used to emit the node in the printer. + */ + function onEmitNode(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void): void { + const savedApplicableSubstitutions = applicableSubstitutions; + const savedCurrentSourceFile = currentSourceFile; + + if (isSourceFile(node)) { + currentSourceFile = node; + } + + if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && isTransformedModuleDeclaration(node)) { + applicableSubstitutions |= TypeScriptSubstitutionFlags.NamespaceExports; + } + + if (enabledSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers && isTransformedEnumDeclaration(node)) { + applicableSubstitutions |= TypeScriptSubstitutionFlags.NonQualifiedEnumMembers; + } + + previousOnEmitNode(hint, node, emitCallback); + + applicableSubstitutions = savedApplicableSubstitutions; + currentSourceFile = savedCurrentSourceFile; + } + + /** + * Hooks node substitutions. + * + * @param hint A hint as to the intended usage of the node. + * @param node The node to substitute. + */ + function onSubstituteNode(hint: EmitHint, node: Node) { + node = previousOnSubstituteNode(hint, node); + if (hint === EmitHint.Expression) { + return substituteExpression(node); + } + else if (isShorthandPropertyAssignment(node)) { + return substituteShorthandPropertyAssignment(node); + } + + return node; + } + + function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike { + if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) { + const name = node.name; + const exportedName = trySubstituteNamespaceExportedName(name); + if (exportedName) { + // A shorthand property with an assignment initializer is probably part of a + // destructuring assignment + if (node.objectAssignmentInitializer) { + const initializer = createAssignment(exportedName, node.objectAssignmentInitializer); + return setTextRange(createPropertyAssignment(name, initializer), node); + } + return setTextRange(createPropertyAssignment(name, exportedName), node); + } + } + return node; + } + + function substituteExpression(node: Expression) { + switch (node.kind) { + case SyntaxKind.Identifier: + return substituteExpressionIdentifier(node); + case SyntaxKind.PropertyAccessExpression: + return substitutePropertyAccessExpression(node); + case SyntaxKind.ElementAccessExpression: + return substituteElementAccessExpression(node); + } + + return node; + } + + function substituteExpressionIdentifier(node: Identifier): Expression { + return trySubstituteClassAlias(node) + || trySubstituteNamespaceExportedName(node) + || node; + } + + function trySubstituteClassAlias(node: Identifier): Expression | undefined { + if (enabledSubstitutions & TypeScriptSubstitutionFlags.ClassAliases) { + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ConstructorReferenceInClass) { + // Due to the emit for class decorators, any reference to the class from inside of the class body + // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind + // behavior of class names in ES6. + // Also, when emitting statics for class expressions, we must substitute a class alias for + // constructor references in static property initializers. + const declaration = resolver.getReferencedValueDeclaration(node); + if (declaration) { + const classAlias = classAliases[declaration.id!]; // TODO: GH#18217 + if (classAlias) { + const clone = getSynthesizedClone(classAlias); + setSourceMapRange(clone, node); + setCommentRange(clone, node); + return clone; + } + } + } + } + + return undefined; + } + + function trySubstituteNamespaceExportedName(node: Identifier): Expression | undefined { + // If this is explicitly a local name, do not substitute. + if (enabledSubstitutions & applicableSubstitutions && !isGeneratedIdentifier(node) && !isLocalName(node)) { + // If we are nested within a namespace declaration, we may need to qualifiy + // an identifier that is exported from a merged namespace. + const container = resolver.getReferencedExportContainer(node, /*prefixLocals*/ false); + if (container && container.kind !== SyntaxKind.SourceFile) { + const substitute = + (applicableSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && container.kind === SyntaxKind.ModuleDeclaration) || + (applicableSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers && container.kind === SyntaxKind.EnumDeclaration); + if (substitute) { + return setTextRange( + createPropertyAccess(getGeneratedNameForNode(container), node), + /*location*/ node + ); + } + } + } + + return undefined; + } + + function substitutePropertyAccessExpression(node: PropertyAccessExpression) { + return substituteConstantValue(node); + } + + function substituteElementAccessExpression(node: ElementAccessExpression) { + return substituteConstantValue(node); + } + + function substituteConstantValue(node: PropertyAccessExpression | ElementAccessExpression): LeftHandSideExpression { + const constantValue = tryGetConstEnumValue(node); + if (constantValue !== undefined) { + // track the constant value on the node for the printer in needsDotDotForPropertyAccess + setConstantValue(node, constantValue); + + const substitute = createLiteral(constantValue); + if (!compilerOptions.removeComments) { + const propertyName = isPropertyAccessExpression(node) + ? declarationNameToString(node.name) + : getTextOfNode(node.argumentExpression); + + addSyntheticTrailingComment(substitute, SyntaxKind.MultiLineCommentTrivia, ` ${propertyName} `); + } + + return substitute; + } + + return node; + } + + function tryGetConstEnumValue(node: Node): string | number | undefined { + if (compilerOptions.isolatedModules) { + return undefined; + } + + return isPropertyAccessExpression(node) || isElementAccessExpression(node) ? resolver.getConstantValue(node) : undefined; + } + } + + function createDecorateHelper(context: TransformationContext, decoratorExpressions: Expression[], target: Expression, memberName?: Expression, descriptor?: Expression, location?: TextRange) { + const argumentsArray: Expression[] = []; + argumentsArray.push(createArrayLiteral(decoratorExpressions, /*multiLine*/ true)); + argumentsArray.push(target); + if (memberName) { + argumentsArray.push(memberName); + if (descriptor) { + argumentsArray.push(descriptor); + } + } + + context.requestEmitHelper(decorateHelper); + return setTextRange( + createCall( + getUnscopedHelperName("__decorate"), + /*typeArguments*/ undefined, + argumentsArray + ), + location + ); + } + + export const decorateHelper: UnscopedEmitHelper = { + name: "typescript:decorate", + importName: "__decorate", + scoped: false, + priority: 2, + text: ` + var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; + };` + }; + + function createMetadataHelper(context: TransformationContext, metadataKey: string, metadataValue: Expression) { + context.requestEmitHelper(metadataHelper); + return createCall( + getUnscopedHelperName("__metadata"), + /*typeArguments*/ undefined, + [ + createLiteral(metadataKey), + metadataValue + ] + ); + } + + export const metadataHelper: UnscopedEmitHelper = { + name: "typescript:metadata", + importName: "__metadata", + scoped: false, + priority: 3, + text: ` + var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); + };` + }; + + function createParamHelper(context: TransformationContext, expression: Expression, parameterOffset: number, location?: TextRange) { + context.requestEmitHelper(paramHelper); + return setTextRange( + createCall( + getUnscopedHelperName("__param"), + /*typeArguments*/ undefined, + [ + createLiteral(parameterOffset), + expression + ] + ), + location + ); + } + + export const paramHelper: UnscopedEmitHelper = { + name: "typescript:param", + importName: "__param", + scoped: false, + priority: 4, + text: ` + var __param = (this && this.__param) || function (paramIndex, decorator) { + return function (target, key) { decorator(target, key, paramIndex); } + };` + }; +} diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index bede6ca37206b..bcb72bce74e6b 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -1,325 +1,325 @@ -/* @internal */ -namespace ts { - export function getOriginalNodeId(node: Node) { - node = getOriginalNode(node); - return node ? getNodeId(node) : 0; - } - - export interface ExternalModuleInfo { - externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; // imports of other external modules - externalHelpersImportDeclaration: ImportDeclaration | undefined; // import of external helpers - exportSpecifiers: Map; // export specifiers by name - exportedBindings: Identifier[][]; // exported names of local declarations - exportedNames: Identifier[] | undefined; // all exported names local to module - exportEquals: ExportAssignment | undefined; // an export= declaration if one was present - hasExportStarsToExportValues: boolean; // whether this module contains export* - } - - function containsDefaultReference(node: NamedImportBindings | undefined) { - if (!node) return false; - if (!isNamedImports(node)) return false; - return some(node.elements, isNamedDefaultReference); - } - - function isNamedDefaultReference(e: ImportSpecifier): boolean { - return e.propertyName !== undefined && e.propertyName.escapedText === InternalSymbolName.Default; - } - - export function chainBundle(transformSourceFile: (x: SourceFile) => SourceFile): (x: SourceFile | Bundle) => SourceFile | Bundle { - return transformSourceFileOrBundle; - - function transformSourceFileOrBundle(node: SourceFile | Bundle) { - return node.kind === SyntaxKind.SourceFile ? transformSourceFile(node) : transformBundle(node); - } - - function transformBundle(node: Bundle) { - return createBundle(map(node.sourceFiles, transformSourceFile), node.prepends); - } - } - - export function getImportNeedsImportStarHelper(node: ImportDeclaration): boolean { - if (!!getNamespaceDeclarationNode(node)) { - return true; - } - const bindings = node.importClause && node.importClause.namedBindings; - if (!bindings) { - return false; - } - if (!isNamedImports(bindings)) return false; - let defaultRefCount = 0; - for (const binding of bindings.elements) { - if (isNamedDefaultReference(binding)) { - defaultRefCount++; - } - } - // Import star is required if there's default named refs mixed with non-default refs, or if theres non-default refs and it has a default import - return (defaultRefCount > 0 && defaultRefCount !== bindings.elements.length) || (!!(bindings.elements.length - defaultRefCount) && isDefaultImport(node)); - } - - export function getImportNeedsImportDefaultHelper(node: ImportDeclaration): boolean { - // Import default is needed if there's a default import or a default ref and no other refs (meaning an import star helper wasn't requested) - return !getImportNeedsImportStarHelper(node) && (isDefaultImport(node) || (!!node.importClause && isNamedImports(node.importClause.namedBindings!) && containsDefaultReference(node.importClause.namedBindings))); // TODO: GH#18217 - } - - export function collectExternalModuleInfo(sourceFile: SourceFile, resolver: EmitResolver, compilerOptions: CompilerOptions): ExternalModuleInfo { - const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = []; - const exportSpecifiers = createMultiMap(); - const exportedBindings: Identifier[][] = []; - const uniqueExports = createMap(); - let exportedNames: Identifier[] | undefined; - let hasExportDefault = false; - let exportEquals: ExportAssignment | undefined; - let hasExportStarsToExportValues = false; - let hasImportStar = false; - let hasImportDefault = false; - - for (const node of sourceFile.statements) { - switch (node.kind) { - case SyntaxKind.ImportDeclaration: - // import "mod" - // import x from "mod" - // import * as x from "mod" - // import { x, y } from "mod" - externalImports.push(node); - if (!hasImportStar && getImportNeedsImportStarHelper(node)) { - hasImportStar = true; - } - if (!hasImportDefault && getImportNeedsImportDefaultHelper(node)) { - hasImportDefault = true; - } - break; - - case SyntaxKind.ImportEqualsDeclaration: - if ((node).moduleReference.kind === SyntaxKind.ExternalModuleReference) { - // import x = require("mod") - externalImports.push(node); - } - - break; - - case SyntaxKind.ExportDeclaration: - if ((node).moduleSpecifier) { - if (!(node).exportClause) { - // export * from "mod" - externalImports.push(node); - hasExportStarsToExportValues = true; - } - else { - // export { x, y } from "mod" - externalImports.push(node); - } - } - else { - // export { x, y } - for (const specifier of (node).exportClause!.elements) { - if (!uniqueExports.get(idText(specifier.name))) { - const name = specifier.propertyName || specifier.name; - exportSpecifiers.add(idText(name), specifier); - - const decl = resolver.getReferencedImportDeclaration(name) - || resolver.getReferencedValueDeclaration(name); - - if (decl) { - multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(decl), specifier.name); - } - - uniqueExports.set(idText(specifier.name), true); - exportedNames = append(exportedNames, specifier.name); - } - } - } - break; - - case SyntaxKind.ExportAssignment: - if ((node).isExportEquals && !exportEquals) { - // export = x - exportEquals = node; - } - break; - - case SyntaxKind.VariableStatement: - if (hasModifier(node, ModifierFlags.Export)) { - for (const decl of (node).declarationList.declarations) { - exportedNames = collectExportedVariableInfo(decl, uniqueExports, exportedNames); - } - } - break; - - case SyntaxKind.FunctionDeclaration: - if (hasModifier(node, ModifierFlags.Export)) { - if (hasModifier(node, ModifierFlags.Default)) { - // export default function() { } - if (!hasExportDefault) { - multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), getDeclarationName(node)); - hasExportDefault = true; - } - } - else { - // export function x() { } - const name = (node).name!; - if (!uniqueExports.get(idText(name))) { - multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name); - uniqueExports.set(idText(name), true); - exportedNames = append(exportedNames, name); - } - } - } - break; - - case SyntaxKind.ClassDeclaration: - if (hasModifier(node, ModifierFlags.Export)) { - if (hasModifier(node, ModifierFlags.Default)) { - // export default class { } - if (!hasExportDefault) { - multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), getDeclarationName(node)); - hasExportDefault = true; - } - } - else { - // export class x { } - const name = (node).name; - if (name && !uniqueExports.get(idText(name))) { - multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name); - uniqueExports.set(idText(name), true); - exportedNames = append(exportedNames, name); - } - } - } - break; - } - } - - const externalHelpersImportDeclaration = createExternalHelpersImportDeclarationIfNeeded(sourceFile, compilerOptions, hasExportStarsToExportValues, hasImportStar, hasImportDefault); - if (externalHelpersImportDeclaration) { - externalImports.unshift(externalHelpersImportDeclaration); - } - - return { externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues, exportedBindings, exportedNames, externalHelpersImportDeclaration }; - } - - function collectExportedVariableInfo(decl: VariableDeclaration | BindingElement, uniqueExports: Map, exportedNames: Identifier[] | undefined) { - if (isBindingPattern(decl.name)) { - for (const element of decl.name.elements) { - if (!isOmittedExpression(element)) { - exportedNames = collectExportedVariableInfo(element, uniqueExports, exportedNames); - } - } - } - else if (!isGeneratedIdentifier(decl.name)) { - const text = idText(decl.name); - if (!uniqueExports.get(text)) { - uniqueExports.set(text, true); - exportedNames = append(exportedNames, decl.name); - } - } - return exportedNames; - } - - /** Use a sparse array as a multi-map. */ - function multiMapSparseArrayAdd(map: V[][], key: number, value: V): V[] { - let values = map[key]; - if (values) { - values.push(value); - } - else { - map[key] = values = [value]; - } - return values; - } - - /** - * Used in the module transformer to check if an expression is reasonably without sideeffect, - * and thus better to copy into multiple places rather than to cache in a temporary variable - * - this is mostly subjective beyond the requirement that the expression not be sideeffecting - */ - export function isSimpleCopiableExpression(expression: Expression) { - return isStringLiteralLike(expression) || - expression.kind === SyntaxKind.NumericLiteral || - isKeyword(expression.kind) || - isIdentifier(expression); - } - - /** - * A simple inlinable expression is an expression which can be copied into multiple locations - * without risk of repeating any sideeffects and whose value could not possibly change between - * any such locations - */ - export function isSimpleInlineableExpression(expression: Expression) { - return !isIdentifier(expression) && isSimpleCopiableExpression(expression) || - isWellKnownSymbolSyntactically(expression); - } - - /** - * Adds super call and preceding prologue directives into the list of statements. - * - * @param ctor The constructor node. - * @param result The list of statements. - * @param visitor The visitor to apply to each node added to the result array. - * @returns index of the statement that follows super call - */ - export function addPrologueDirectivesAndInitialSuperCall(ctor: ConstructorDeclaration, result: Statement[], visitor: Visitor): number { - if (ctor.body) { - const statements = ctor.body.statements; - // add prologue directives to the list (if any) - const index = addPrologue(result, statements, /*ensureUseStrict*/ false, visitor); - if (index === statements.length) { - // list contains nothing but prologue directives (or empty) - exit - return index; - } - - const statement = statements[index]; - if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCall((statement).expression)) { - result.push(visitNode(statement, visitor, isStatement)); - return index + 1; - } - - return index; - } - - return 0; - } - - - /** - * @param input Template string input strings - * @param args Names which need to be made file-level unique - */ - export function helperString(input: TemplateStringsArray, ...args: string[]) { - return (uniqueName: EmitHelperUniqueNameCallback) => { - let result = ""; - for (let i = 0; i < args.length; i++) { - result += input[i]; - result += uniqueName(args[i]); - } - result += input[input.length - 1]; - return result; - }; - } - - /** - * Gets all the static or all the instance property declarations of a class - * - * @param node The class node. - * @param isStatic A value indicating whether to get properties from the static or instance side of the class. - */ - export function getProperties(node: ClassExpression | ClassDeclaration, requireInitializer: boolean, isStatic: boolean): readonly PropertyDeclaration[] { - return filter(node.members, m => isInitializedOrStaticProperty(m, requireInitializer, isStatic)) as PropertyDeclaration[]; - } - - /** - * Is a class element is either a static or an instance property declaration with an initializer? - * - * @param member The class element node. - * @param isStatic A value indicating whether the member should be a static or instance member. - */ - function isInitializedOrStaticProperty(member: ClassElement, requireInitializer: boolean, isStatic: boolean) { - return isPropertyDeclaration(member) - && !!member.initializer === requireInitializer - && hasStaticModifier(member) === isStatic; - } - - export function isInitializedProperty(member: ClassElement, requireInitializer: boolean): member is PropertyDeclaration { - return isPropertyDeclaration(member) && !!member.initializer === requireInitializer; - } - -} +/* @internal */ +namespace ts { + export function getOriginalNodeId(node: Node) { + node = getOriginalNode(node); + return node ? getNodeId(node) : 0; + } + + export interface ExternalModuleInfo { + externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; // imports of other external modules + externalHelpersImportDeclaration: ImportDeclaration | undefined; // import of external helpers + exportSpecifiers: Map; // export specifiers by name + exportedBindings: Identifier[][]; // exported names of local declarations + exportedNames: Identifier[] | undefined; // all exported names local to module + exportEquals: ExportAssignment | undefined; // an export= declaration if one was present + hasExportStarsToExportValues: boolean; // whether this module contains export* + } + + function containsDefaultReference(node: NamedImportBindings | undefined) { + if (!node) return false; + if (!isNamedImports(node)) return false; + return some(node.elements, isNamedDefaultReference); + } + + function isNamedDefaultReference(e: ImportSpecifier): boolean { + return e.propertyName !== undefined && e.propertyName.escapedText === InternalSymbolName.Default; + } + + export function chainBundle(transformSourceFile: (x: SourceFile) => SourceFile): (x: SourceFile | Bundle) => SourceFile | Bundle { + return transformSourceFileOrBundle; + + function transformSourceFileOrBundle(node: SourceFile | Bundle) { + return node.kind === SyntaxKind.SourceFile ? transformSourceFile(node) : transformBundle(node); + } + + function transformBundle(node: Bundle) { + return createBundle(map(node.sourceFiles, transformSourceFile), node.prepends); + } + } + + export function getImportNeedsImportStarHelper(node: ImportDeclaration): boolean { + if (!!getNamespaceDeclarationNode(node)) { + return true; + } + const bindings = node.importClause && node.importClause.namedBindings; + if (!bindings) { + return false; + } + if (!isNamedImports(bindings)) return false; + let defaultRefCount = 0; + for (const binding of bindings.elements) { + if (isNamedDefaultReference(binding)) { + defaultRefCount++; + } + } + // Import star is required if there's default named refs mixed with non-default refs, or if theres non-default refs and it has a default import + return (defaultRefCount > 0 && defaultRefCount !== bindings.elements.length) || (!!(bindings.elements.length - defaultRefCount) && isDefaultImport(node)); + } + + export function getImportNeedsImportDefaultHelper(node: ImportDeclaration): boolean { + // Import default is needed if there's a default import or a default ref and no other refs (meaning an import star helper wasn't requested) + return !getImportNeedsImportStarHelper(node) && (isDefaultImport(node) || (!!node.importClause && isNamedImports(node.importClause.namedBindings!) && containsDefaultReference(node.importClause.namedBindings))); // TODO: GH#18217 + } + + export function collectExternalModuleInfo(sourceFile: SourceFile, resolver: EmitResolver, compilerOptions: CompilerOptions): ExternalModuleInfo { + const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = []; + const exportSpecifiers = createMultiMap(); + const exportedBindings: Identifier[][] = []; + const uniqueExports = createMap(); + let exportedNames: Identifier[] | undefined; + let hasExportDefault = false; + let exportEquals: ExportAssignment | undefined; + let hasExportStarsToExportValues = false; + let hasImportStar = false; + let hasImportDefault = false; + + for (const node of sourceFile.statements) { + switch (node.kind) { + case SyntaxKind.ImportDeclaration: + // import "mod" + // import x from "mod" + // import * as x from "mod" + // import { x, y } from "mod" + externalImports.push(node); + if (!hasImportStar && getImportNeedsImportStarHelper(node)) { + hasImportStar = true; + } + if (!hasImportDefault && getImportNeedsImportDefaultHelper(node)) { + hasImportDefault = true; + } + break; + + case SyntaxKind.ImportEqualsDeclaration: + if ((node).moduleReference.kind === SyntaxKind.ExternalModuleReference) { + // import x = require("mod") + externalImports.push(node); + } + + break; + + case SyntaxKind.ExportDeclaration: + if ((node).moduleSpecifier) { + if (!(node).exportClause) { + // export * from "mod" + externalImports.push(node); + hasExportStarsToExportValues = true; + } + else { + // export { x, y } from "mod" + externalImports.push(node); + } + } + else { + // export { x, y } + for (const specifier of (node).exportClause!.elements) { + if (!uniqueExports.get(idText(specifier.name))) { + const name = specifier.propertyName || specifier.name; + exportSpecifiers.add(idText(name), specifier); + + const decl = resolver.getReferencedImportDeclaration(name) + || resolver.getReferencedValueDeclaration(name); + + if (decl) { + multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(decl), specifier.name); + } + + uniqueExports.set(idText(specifier.name), true); + exportedNames = append(exportedNames, specifier.name); + } + } + } + break; + + case SyntaxKind.ExportAssignment: + if ((node).isExportEquals && !exportEquals) { + // export = x + exportEquals = node; + } + break; + + case SyntaxKind.VariableStatement: + if (hasModifier(node, ModifierFlags.Export)) { + for (const decl of (node).declarationList.declarations) { + exportedNames = collectExportedVariableInfo(decl, uniqueExports, exportedNames); + } + } + break; + + case SyntaxKind.FunctionDeclaration: + if (hasModifier(node, ModifierFlags.Export)) { + if (hasModifier(node, ModifierFlags.Default)) { + // export default function() { } + if (!hasExportDefault) { + multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), getDeclarationName(node)); + hasExportDefault = true; + } + } + else { + // export function x() { } + const name = (node).name!; + if (!uniqueExports.get(idText(name))) { + multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name); + uniqueExports.set(idText(name), true); + exportedNames = append(exportedNames, name); + } + } + } + break; + + case SyntaxKind.ClassDeclaration: + if (hasModifier(node, ModifierFlags.Export)) { + if (hasModifier(node, ModifierFlags.Default)) { + // export default class { } + if (!hasExportDefault) { + multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), getDeclarationName(node)); + hasExportDefault = true; + } + } + else { + // export class x { } + const name = (node).name; + if (name && !uniqueExports.get(idText(name))) { + multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name); + uniqueExports.set(idText(name), true); + exportedNames = append(exportedNames, name); + } + } + } + break; + } + } + + const externalHelpersImportDeclaration = createExternalHelpersImportDeclarationIfNeeded(sourceFile, compilerOptions, hasExportStarsToExportValues, hasImportStar, hasImportDefault); + if (externalHelpersImportDeclaration) { + externalImports.unshift(externalHelpersImportDeclaration); + } + + return { externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues, exportedBindings, exportedNames, externalHelpersImportDeclaration }; + } + + function collectExportedVariableInfo(decl: VariableDeclaration | BindingElement, uniqueExports: Map, exportedNames: Identifier[] | undefined) { + if (isBindingPattern(decl.name)) { + for (const element of decl.name.elements) { + if (!isOmittedExpression(element)) { + exportedNames = collectExportedVariableInfo(element, uniqueExports, exportedNames); + } + } + } + else if (!isGeneratedIdentifier(decl.name)) { + const text = idText(decl.name); + if (!uniqueExports.get(text)) { + uniqueExports.set(text, true); + exportedNames = append(exportedNames, decl.name); + } + } + return exportedNames; + } + + /** Use a sparse array as a multi-map. */ + function multiMapSparseArrayAdd(map: V[][], key: number, value: V): V[] { + let values = map[key]; + if (values) { + values.push(value); + } + else { + map[key] = values = [value]; + } + return values; + } + + /** + * Used in the module transformer to check if an expression is reasonably without sideeffect, + * and thus better to copy into multiple places rather than to cache in a temporary variable + * - this is mostly subjective beyond the requirement that the expression not be sideeffecting + */ + export function isSimpleCopiableExpression(expression: Expression) { + return isStringLiteralLike(expression) || + expression.kind === SyntaxKind.NumericLiteral || + isKeyword(expression.kind) || + isIdentifier(expression); + } + + /** + * A simple inlinable expression is an expression which can be copied into multiple locations + * without risk of repeating any sideeffects and whose value could not possibly change between + * any such locations + */ + export function isSimpleInlineableExpression(expression: Expression) { + return !isIdentifier(expression) && isSimpleCopiableExpression(expression) || + isWellKnownSymbolSyntactically(expression); + } + + /** + * Adds super call and preceding prologue directives into the list of statements. + * + * @param ctor The constructor node. + * @param result The list of statements. + * @param visitor The visitor to apply to each node added to the result array. + * @returns index of the statement that follows super call + */ + export function addPrologueDirectivesAndInitialSuperCall(ctor: ConstructorDeclaration, result: Statement[], visitor: Visitor): number { + if (ctor.body) { + const statements = ctor.body.statements; + // add prologue directives to the list (if any) + const index = addPrologue(result, statements, /*ensureUseStrict*/ false, visitor); + if (index === statements.length) { + // list contains nothing but prologue directives (or empty) - exit + return index; + } + + const statement = statements[index]; + if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCall((statement).expression)) { + result.push(visitNode(statement, visitor, isStatement)); + return index + 1; + } + + return index; + } + + return 0; + } + + + /** + * @param input Template string input strings + * @param args Names which need to be made file-level unique + */ + export function helperString(input: TemplateStringsArray, ...args: string[]) { + return (uniqueName: EmitHelperUniqueNameCallback) => { + let result = ""; + for (let i = 0; i < args.length; i++) { + result += input[i]; + result += uniqueName(args[i]); + } + result += input[input.length - 1]; + return result; + }; + } + + /** + * Gets all the static or all the instance property declarations of a class + * + * @param node The class node. + * @param isStatic A value indicating whether to get properties from the static or instance side of the class. + */ + export function getProperties(node: ClassExpression | ClassDeclaration, requireInitializer: boolean, isStatic: boolean): readonly PropertyDeclaration[] { + return filter(node.members, m => isInitializedOrStaticProperty(m, requireInitializer, isStatic)) as PropertyDeclaration[]; + } + + /** + * Is a class element is either a static or an instance property declaration with an initializer? + * + * @param member The class element node. + * @param isStatic A value indicating whether the member should be a static or instance member. + */ + function isInitializedOrStaticProperty(member: ClassElement, requireInitializer: boolean, isStatic: boolean) { + return isPropertyDeclaration(member) + && !!member.initializer === requireInitializer + && hasStaticModifier(member) === isStatic; + } + + export function isInitializedProperty(member: ClassElement, requireInitializer: boolean): member is PropertyDeclaration { + return isPropertyDeclaration(member) && !!member.initializer === requireInitializer; + } + +} From 5028bfa5a366c25efb2c2604fe20959e06b75d8f Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 20 Sep 2019 09:48:56 -0700 Subject: [PATCH 34/44] Minor fix and code cleanup --- src/compiler/transformers/classFields.ts | 26 +++++++++++------------- src/compiler/types.ts | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index e2b372fd950eb..f14aeef654a90 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -422,30 +422,28 @@ namespace ts { * @param receiver The object receiving the property assignment. */ function transformInitializedProperty(property: PropertyDeclaration, receiver: LeftHandSideExpression) { - if (context.getCompilerOptions().legacyClassFields) { - // We generate a name here in order to reuse the value cached by the relocated computed name expression (which uses the same generated name) - const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) - ? updateComputedPropertyName(property.name, getGeneratedNameForNode(property.name)) - : property.name; + // We generate a name here in order to reuse the value cached by the relocated computed name expression (which uses the same generated name) + const emitAssignment = context.getCompilerOptions().legacyClassFields; + const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) + ? updateComputedPropertyName(property.name, getGeneratedNameForNode(property.name)) + : property.name; + const initializer = property.initializer || emitAssignment ? visitNode(property.initializer, visitor, isExpression) : createVoidZero() + if (emitAssignment) { const memberAccess = createMemberAccessForPropertyName(receiver, propertyName, /*location*/ propertyName); - const initializer = visitNode(property.initializer, visitor, isExpression); return createAssignment(memberAccess, initializer); } else { - // We generate a name here in order to reuse the value cached by the relocated computed name expression (which uses the same generated name) - const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) - ? updateComputedPropertyName(property.name, getGeneratedNameForNode(property.name)) - : property.name; - const initializer = property.initializer ? visitNode(property.initializer, visitor, isExpression) : createVoidZero() - return createObjectDefineForPropertyName(receiver, propertyName, initializer); + return createObjectDefineProperty(receiver, propertyName, initializer); } } - function createObjectDefineForPropertyName(target: Expression, name: PropertyName, initializer: Expression) { + function createObjectDefineProperty(target: Expression, name: PropertyName, initializer: Expression) { + const e = isComputedPropertyName(name) ? name.expression + : isIdentifier(name) ? createStringLiteral(unescapeLeadingUnderscores(name.escapedText)) : name; return createCall( createPropertyAccess(createIdentifier("Object"), createIdentifier("defineProperty")), undefined, - [target, isComputedPropertyName(name) ? name.expression : name, createObjectLiteral([createPropertyAssignment("value", initializer)])]); + [target, e, createObjectLiteral([createPropertyAssignment("value", initializer)])]); } function enableSubstitutionForClassAliases() { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ba8947c581bdc..5441a70e010ff 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4810,7 +4810,7 @@ namespace ts { export interface TypeAcquisition { /* @deprecated typingOptions.enableAutoDiscovery - * Use typeAcquisition.enable instead. + * Use typeAcquisition.enable instead. */ enableAutoDiscovery?: boolean; enable?: boolean; From 8053e0559a7764174ca00b81c4f4b1f2ca73b1fb Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 20 Sep 2019 10:16:16 -0700 Subject: [PATCH 35/44] New test case --- src/compiler/transformers/classFields.ts | 6 ++--- .../reference/accessorsOverrideProperty.js | 13 +++-------- .../reference/accessorsOverrideProperty2.js | 4 +--- .../reference/accessorsOverrideProperty3.js | 5 +---- .../reference/accessorsOverrideProperty4.js | 5 +---- .../derivedClassOverridesPrivates.js | 5 ++++- .../derivedClassOverridesProtectedMembers.js | 7 +++++- .../derivedClassOverridesProtectedMembers2.js | 7 +++++- .../derivedClassOverridesProtectedMembers3.js | 10 +++++++-- .../derivedClassOverridesProtectedMembers4.js | 9 ++++++-- .../derivedClassOverridesPublicMembers.js | 7 +++++- .../derivedClassOverridesWithoutSubtype.js | 5 ++++- .../reference/mixingApparentTypeOverrides.js | 1 + .../reference/propertyOverridesAccessors2.js | 5 +---- .../reference/propertyOverridesAccessors3.js | 9 ++------ .../propertyOverridesAccessors5.errors.txt | 15 +++++++++++++ .../reference/propertyOverridesAccessors5.js | 22 +++++++++++++++++++ .../propertyOverridesAccessors5.symbols | 19 ++++++++++++++++ .../propertyOverridesAccessors5.types | 21 ++++++++++++++++++ .../reference/propertyOverridesMethod.js | 5 +---- .../propertyOverridesAccessors5.ts | 9 ++++++++ 21 files changed, 141 insertions(+), 48 deletions(-) create mode 100644 tests/baselines/reference/propertyOverridesAccessors5.errors.txt create mode 100644 tests/baselines/reference/propertyOverridesAccessors5.js create mode 100644 tests/baselines/reference/propertyOverridesAccessors5.symbols create mode 100644 tests/baselines/reference/propertyOverridesAccessors5.types create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index f14aeef654a90..3dd5b6bfe0b2d 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -51,7 +51,6 @@ namespace ts { // [x] = 1 => Object.defineProperty(this, x, ...) // -vs- // [x] = 1 -> this[x] = 1 - // TODO: Unininitialised properties need to be emitted too. || !options.legacyClassFields && options.target === ScriptTarget.ESNext) { return node; } @@ -439,10 +438,11 @@ namespace ts { function createObjectDefineProperty(target: Expression, name: PropertyName, initializer: Expression) { const e = isComputedPropertyName(name) ? name.expression - : isIdentifier(name) ? createStringLiteral(unescapeLeadingUnderscores(name.escapedText)) : name; + : isIdentifier(name) ? createStringLiteral(unescapeLeadingUnderscores(name.escapedText)) + : name; return createCall( createPropertyAccess(createIdentifier("Object"), createIdentifier("defineProperty")), - undefined, + /*typeArguments*/ undefined, [target, e, createObjectLiteral([createPropertyAssignment("value", initializer)])]); } diff --git a/tests/baselines/reference/accessorsOverrideProperty.js b/tests/baselines/reference/accessorsOverrideProperty.js index 3a19b0f7fff33..5e9b94457ca41 100644 --- a/tests/baselines/reference/accessorsOverrideProperty.js +++ b/tests/baselines/reference/accessorsOverrideProperty.js @@ -17,23 +17,16 @@ class D extends C { //// [accessorsOverrideProperty.js] class A { - constructor() { - this.p = 'yep'; - } + p = 'yep'; } class B extends A { get p() { return 'oh no'; } // error } class C { - constructor() { - this.p = 101; - } + p = 101; } class D extends C { - constructor() { - super(...arguments); - this._secret = 11; - } + _secret = 11; get p() { return this._secret; } // error set p(value) { this._secret = value; } // error } diff --git a/tests/baselines/reference/accessorsOverrideProperty2.js b/tests/baselines/reference/accessorsOverrideProperty2.js index dcdb2308253a4..e16ae60363e36 100644 --- a/tests/baselines/reference/accessorsOverrideProperty2.js +++ b/tests/baselines/reference/accessorsOverrideProperty2.js @@ -14,9 +14,7 @@ console.log(obj.x); // 1 //// [accessorsOverrideProperty2.js] class Base { - constructor() { - this.x = 1; - } + x = 1; } class Derived extends Base { get x() { return 2; } // should be an error diff --git a/tests/baselines/reference/accessorsOverrideProperty3.js b/tests/baselines/reference/accessorsOverrideProperty3.js index 1f1b69ed6eece..2b061298ab9a3 100644 --- a/tests/baselines/reference/accessorsOverrideProperty3.js +++ b/tests/baselines/reference/accessorsOverrideProperty3.js @@ -11,10 +11,7 @@ class Lion extends Animal { //// [accessorsOverrideProperty3.js] class Lion extends Animal { - constructor() { - super(...arguments); - this._sound = 'grrr'; - } + _sound = 'grrr'; get sound() { return this._sound; } // error here set sound(val) { this._sound = val; } } diff --git a/tests/baselines/reference/accessorsOverrideProperty4.js b/tests/baselines/reference/accessorsOverrideProperty4.js index 43c07e0c3657c..28a0af827b7eb 100644 --- a/tests/baselines/reference/accessorsOverrideProperty4.js +++ b/tests/baselines/reference/accessorsOverrideProperty4.js @@ -11,10 +11,7 @@ class Lion extends Animal { //// [accessorsOverrideProperty4.js] class Lion extends Animal { - constructor() { - super(...arguments); - this._sound = 'roar'; - } + _sound = 'roar'; get sound() { return this._sound; } set sound(val) { this._sound = val; } } diff --git a/tests/baselines/reference/derivedClassOverridesPrivates.js b/tests/baselines/reference/derivedClassOverridesPrivates.js index d313a5b5647b3..8b23d0e4ed221 100644 --- a/tests/baselines/reference/derivedClassOverridesPrivates.js +++ b/tests/baselines/reference/derivedClassOverridesPrivates.js @@ -31,13 +31,16 @@ var __extends = (this && this.__extends) || (function () { })(); var Base = /** @class */ (function () { function Base() { + Object.defineProperty(this, "x", { value: void 0 }); } return Base; }()); var Derived = /** @class */ (function (_super) { __extends(Derived, _super); function Derived() { - return _super !== null && _super.apply(this, arguments) || this; + var _this = _super !== null && _super.apply(this, arguments) || this; + Object.defineProperty(_this, "x", { value: void 0 }); // error + return _this; } return Derived; }(Base)); diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers.js b/tests/baselines/reference/derivedClassOverridesProtectedMembers.js index f8f20fb6c00c4..f5f7c25b40cac 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers.js +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers.js @@ -53,6 +53,8 @@ var x; var y; var Base = /** @class */ (function () { function Base(a) { + Object.defineProperty(this, "a", { value: void 0 }); + Object.defineProperty(this, "d", { value: void 0 }); } Base.prototype.b = function (a) { }; Object.defineProperty(Base.prototype, "c", { @@ -73,7 +75,10 @@ var Base = /** @class */ (function () { var Derived = /** @class */ (function (_super) { __extends(Derived, _super); function Derived(a) { - return _super.call(this, x) || this; + var _this = _super.call(this, x) || this; + Object.defineProperty(_this, "a", { value: void 0 }); + Object.defineProperty(_this, "d", { value: void 0 }); + return _this; } Derived.prototype.b = function (a) { }; Object.defineProperty(Derived.prototype, "c", { diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers2.js b/tests/baselines/reference/derivedClassOverridesProtectedMembers2.js index 2b0e072f86531..70447421a9bea 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers2.js +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers2.js @@ -81,6 +81,8 @@ var x; var y; var Base = /** @class */ (function () { function Base(a) { + Object.defineProperty(this, "a", { value: void 0 }); + Object.defineProperty(this, "d", { value: void 0 }); } Base.prototype.b = function (a) { }; Object.defineProperty(Base.prototype, "c", { @@ -102,7 +104,10 @@ var Base = /** @class */ (function () { var Derived = /** @class */ (function (_super) { __extends(Derived, _super); function Derived(a) { - return _super.call(this, a) || this; + var _this = _super.call(this, a) || this; + Object.defineProperty(_this, "a", { value: void 0 }); + Object.defineProperty(_this, "d", { value: void 0 }); + return _this; } Derived.prototype.b = function (a) { }; Object.defineProperty(Derived.prototype, "c", { diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers3.js b/tests/baselines/reference/derivedClassOverridesProtectedMembers3.js index 568e7ecd32f10..07fd16a2726f7 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers3.js +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers3.js @@ -88,6 +88,8 @@ var x; var y; var Base = /** @class */ (function () { function Base(a) { + Object.defineProperty(this, "a", { value: void 0 }); + Object.defineProperty(this, "d", { value: void 0 }); } Base.prototype.b = function (a) { }; Object.defineProperty(Base.prototype, "c", { @@ -110,7 +112,9 @@ var Base = /** @class */ (function () { var Derived1 = /** @class */ (function (_super) { __extends(Derived1, _super); function Derived1(a) { - return _super.call(this, a) || this; + var _this = _super.call(this, a) || this; + Object.defineProperty(_this, "a", { value: void 0 }); + return _this; } return Derived1; }(Base)); @@ -149,7 +153,9 @@ var Derived4 = /** @class */ (function (_super) { var Derived5 = /** @class */ (function (_super) { __extends(Derived5, _super); function Derived5(a) { - return _super.call(this, a) || this; + var _this = _super.call(this, a) || this; + Object.defineProperty(_this, "d", { value: void 0 }); + return _this; } return Derived5; }(Base)); diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers4.js b/tests/baselines/reference/derivedClassOverridesProtectedMembers4.js index 099c450f6923d..098b457ced83f 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers4.js +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers4.js @@ -32,20 +32,25 @@ var x; var y; var Base = /** @class */ (function () { function Base() { + Object.defineProperty(this, "a", { value: void 0 }); } return Base; }()); var Derived1 = /** @class */ (function (_super) { __extends(Derived1, _super); function Derived1() { - return _super !== null && _super.apply(this, arguments) || this; + var _this = _super !== null && _super.apply(this, arguments) || this; + Object.defineProperty(_this, "a", { value: void 0 }); + return _this; } return Derived1; }(Base)); var Derived2 = /** @class */ (function (_super) { __extends(Derived2, _super); function Derived2() { - return _super !== null && _super.apply(this, arguments) || this; + var _this = _super !== null && _super.apply(this, arguments) || this; + Object.defineProperty(_this, "a", { value: void 0 }); // Error, parent was public + return _this; } return Derived2; }(Derived1)); diff --git a/tests/baselines/reference/derivedClassOverridesPublicMembers.js b/tests/baselines/reference/derivedClassOverridesPublicMembers.js index 6e6b27452cd12..12277988f7b4e 100644 --- a/tests/baselines/reference/derivedClassOverridesPublicMembers.js +++ b/tests/baselines/reference/derivedClassOverridesPublicMembers.js @@ -80,6 +80,8 @@ var x; var y; var Base = /** @class */ (function () { function Base(a) { + Object.defineProperty(this, "a", { value: void 0 }); + Object.defineProperty(this, "d", { value: void 0 }); } Base.prototype.b = function (a) { }; Object.defineProperty(Base.prototype, "c", { @@ -100,7 +102,10 @@ var Base = /** @class */ (function () { var Derived = /** @class */ (function (_super) { __extends(Derived, _super); function Derived(a) { - return _super.call(this, x) || this; + var _this = _super.call(this, x) || this; + Object.defineProperty(_this, "a", { value: void 0 }); + Object.defineProperty(_this, "d", { value: void 0 }); + return _this; } Derived.prototype.b = function (a) { }; Object.defineProperty(Derived.prototype, "c", { diff --git a/tests/baselines/reference/derivedClassOverridesWithoutSubtype.js b/tests/baselines/reference/derivedClassOverridesWithoutSubtype.js index e526f7d8d9bdd..ca091e5d6f258 100644 --- a/tests/baselines/reference/derivedClassOverridesWithoutSubtype.js +++ b/tests/baselines/reference/derivedClassOverridesWithoutSubtype.js @@ -39,13 +39,16 @@ var __extends = (this && this.__extends) || (function () { })(); var Base = /** @class */ (function () { function Base() { + Object.defineProperty(this, "x", { value: void 0 }); } return Base; }()); var Derived = /** @class */ (function (_super) { __extends(Derived, _super); function Derived() { - return _super !== null && _super.apply(this, arguments) || this; + var _this = _super !== null && _super.apply(this, arguments) || this; + Object.defineProperty(_this, "x", { value: void 0 }); + return _this; } return Derived; }(Base)); diff --git a/tests/baselines/reference/mixingApparentTypeOverrides.js b/tests/baselines/reference/mixingApparentTypeOverrides.js index 74f9afc83894d..0f9d181efede2 100644 --- a/tests/baselines/reference/mixingApparentTypeOverrides.js +++ b/tests/baselines/reference/mixingApparentTypeOverrides.js @@ -51,6 +51,7 @@ function Tagged(Base) { args[_i] = arguments[_i]; } var _this = _super.apply(this, args) || this; + Object.defineProperty(_this, "_tag", { value: void 0 }); _this._tag = ""; return _this; } diff --git a/tests/baselines/reference/propertyOverridesAccessors2.js b/tests/baselines/reference/propertyOverridesAccessors2.js index bf5825771ff06..bbd8e0fbecf3f 100644 --- a/tests/baselines/reference/propertyOverridesAccessors2.js +++ b/tests/baselines/reference/propertyOverridesAccessors2.js @@ -18,10 +18,7 @@ class Base { set x(value) { console.log(`x was set to ${value}`); } } class Derived extends Base { - constructor() { - super(...arguments); - this.x = 1; - } + x = 1; } const obj = new Derived(); // prints 'x was set to 1' console.log(obj.x); // 2 diff --git a/tests/baselines/reference/propertyOverridesAccessors3.js b/tests/baselines/reference/propertyOverridesAccessors3.js index 3df81827bc97f..ff96cdd19abd7 100644 --- a/tests/baselines/reference/propertyOverridesAccessors3.js +++ b/tests/baselines/reference/propertyOverridesAccessors3.js @@ -26,9 +26,7 @@ lion.makeSound() // with [[Define]]: Expected "RAWR!" but got "rustling noise in //// [propertyOverridesAccessors3.js] class Animal { - constructor() { - this._sound = 'rustling noise in the bushes'; - } + _sound = 'rustling noise in the bushes'; get sound() { return this._sound; } set sound(val) { this._sound = val; @@ -41,10 +39,7 @@ class Animal { const a = new Animal; a.makeSound(); // 'rustling noise in the bushes' class Lion extends Animal { - constructor() { - super(...arguments); - this.sound = 'RAWR!'; // error here - } + sound = 'RAWR!'; // error here } const lion = new Lion; lion.makeSound(); // with [[Define]]: Expected "RAWR!" but got "rustling noise in the bushes" diff --git a/tests/baselines/reference/propertyOverridesAccessors5.errors.txt b/tests/baselines/reference/propertyOverridesAccessors5.errors.txt new file mode 100644 index 0000000000000..5028138995693 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors5.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts(5,24): error TS2610: Class 'A' defines instance member accessor 'p', but extended class 'B' defines it as instance member property. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts (1 errors) ==== + class A { + get p() { return 'oh no' } + } + class B extends A { + constructor(public p: string) { + ~ +!!! error TS2610: Class 'A' defines instance member accessor 'p', but extended class 'B' defines it as instance member property. + super() + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/propertyOverridesAccessors5.js b/tests/baselines/reference/propertyOverridesAccessors5.js new file mode 100644 index 0000000000000..76e1296627074 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors5.js @@ -0,0 +1,22 @@ +//// [propertyOverridesAccessors5.ts] +class A { + get p() { return 'oh no' } +} +class B extends A { + constructor(public p: string) { + super() + } +} + + +//// [propertyOverridesAccessors5.js] +class A { + get p() { return 'oh no'; } +} +class B extends A { + p; + constructor(p) { + super(); + this.p = p; + } +} diff --git a/tests/baselines/reference/propertyOverridesAccessors5.symbols b/tests/baselines/reference/propertyOverridesAccessors5.symbols new file mode 100644 index 0000000000000..289021c0c7fb5 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors5.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts === +class A { +>A : Symbol(A, Decl(propertyOverridesAccessors5.ts, 0, 0)) + + get p() { return 'oh no' } +>p : Symbol(A.p, Decl(propertyOverridesAccessors5.ts, 0, 9)) +} +class B extends A { +>B : Symbol(B, Decl(propertyOverridesAccessors5.ts, 2, 1)) +>A : Symbol(A, Decl(propertyOverridesAccessors5.ts, 0, 0)) + + constructor(public p: string) { +>p : Symbol(B.p, Decl(propertyOverridesAccessors5.ts, 4, 16)) + + super() +>super : Symbol(A, Decl(propertyOverridesAccessors5.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/propertyOverridesAccessors5.types b/tests/baselines/reference/propertyOverridesAccessors5.types new file mode 100644 index 0000000000000..ebbe10d4b01e9 --- /dev/null +++ b/tests/baselines/reference/propertyOverridesAccessors5.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts === +class A { +>A : A + + get p() { return 'oh no' } +>p : string +>'oh no' : "oh no" +} +class B extends A { +>B : B +>A : A + + constructor(public p: string) { +>p : string + + super() +>super() : void +>super : typeof A + } +} + diff --git a/tests/baselines/reference/propertyOverridesMethod.js b/tests/baselines/reference/propertyOverridesMethod.js index f51fb16653527..f78971a38f7cf 100644 --- a/tests/baselines/reference/propertyOverridesMethod.js +++ b/tests/baselines/reference/propertyOverridesMethod.js @@ -12,8 +12,5 @@ class A { m() { } } class B extends A { - constructor() { - super(...arguments); - this.m = () => 1; - } + m = () => 1; } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts new file mode 100644 index 0000000000000..16601fcfe5a8a --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts @@ -0,0 +1,9 @@ +// @target: esnext +class A { + get p() { return 'oh no' } +} +class B extends A { + constructor(public p: string) { + super() + } +} From 7fdb423554eca853857a7a769a0fa90b32b480f5 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 23 Sep 2019 08:26:59 -0700 Subject: [PATCH 36/44] Fix bug in isInitializedProperty --- src/compiler/transformers/classFields.ts | 1 - src/compiler/transformers/utilities.ts | 4 ++-- tests/baselines/reference/propertyOverridesAccessors.js | 6 +++--- tests/baselines/reference/propertyOverridesAccessors4.js | 2 +- .../propertyOverridesAccessors.ts | 1 + 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 3dd5b6bfe0b2d..4345cf40aa088 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -342,7 +342,6 @@ namespace ts { // } // if (constructor && constructor.body) { - // TODO: Need to think about parameter property declarations let parameterPropertyDeclarationCount = 0; for (let i = indexOfFirstStatement; i < constructor.body.statements.length; i++) { if (isParameterPropertyDeclaration(getOriginalNode(constructor.body.statements[i]), constructor)) { diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index bcb72bce74e6b..90aa142192d3e 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -314,12 +314,12 @@ namespace ts { */ function isInitializedOrStaticProperty(member: ClassElement, requireInitializer: boolean, isStatic: boolean) { return isPropertyDeclaration(member) - && !!member.initializer === requireInitializer + && (!!member.initializer || !requireInitializer) && hasStaticModifier(member) === isStatic; } export function isInitializedProperty(member: ClassElement, requireInitializer: boolean): member is PropertyDeclaration { - return isPropertyDeclaration(member) && !!member.initializer === requireInitializer; + return isPropertyDeclaration(member) && (!!member.initializer || !requireInitializer); } } diff --git a/tests/baselines/reference/propertyOverridesAccessors.js b/tests/baselines/reference/propertyOverridesAccessors.js index bc69da6705a36..cb5882ab028bd 100644 --- a/tests/baselines/reference/propertyOverridesAccessors.js +++ b/tests/baselines/reference/propertyOverridesAccessors.js @@ -22,12 +22,12 @@ class A { class B extends A { constructor() { super(...arguments); - this.p = 'yep'; // error + Object.defineProperty(this, "p", { value: 'yep' }); // error } } class C { constructor() { - this._secret = 11; + Object.defineProperty(this, "_secret", { value: 11 }); } get p() { return this._secret; } set p(value) { this._secret = value; } @@ -35,6 +35,6 @@ class C { class D extends C { constructor() { super(...arguments); - this.p = 101; // error + Object.defineProperty(this, "p", { value: 101 }); // error } } diff --git a/tests/baselines/reference/propertyOverridesAccessors4.js b/tests/baselines/reference/propertyOverridesAccessors4.js index 0b0330de05668..c52ac26ab3e1a 100644 --- a/tests/baselines/reference/propertyOverridesAccessors4.js +++ b/tests/baselines/reference/propertyOverridesAccessors4.js @@ -26,7 +26,7 @@ var Lion = /** @class */ (function (_super) { __extends(Lion, _super); function Lion() { var _this = _super !== null && _super.apply(this, arguments) || this; - _this.sound = 'RAWR!'; // error here + Object.defineProperty(_this, "sound", { value: 'RAWR!' }); // error here return _this; } return Lion; diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts index e1c5f49d316af..c88fda4a4d7b2 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts @@ -1,4 +1,5 @@ // @target: es2015 +// @legacyClassFields: false class A { get p() { return 'oh no' } } From 18c622cdc50e6ce6d7c25fd2b88ffba128badcbc Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 23 Sep 2019 10:35:33 -0700 Subject: [PATCH 37/44] Updates from design meeting. 1. Change flag name to useDefineForClassFields (and flip polarity). 2. Forbid ES3 + useDefineForClassFields (since there is no defineProperty). 3. Forbid overriding an abstract property-with-initializer with an accessor. --- src/compiler/checker.ts | 4 +- src/compiler/commandLineParser.ts | 4 +- src/compiler/diagnosticMessages.json | 6 +- src/compiler/program.ts | 4 ++ src/compiler/transformers/classFields.ts | 11 ++- src/compiler/types.ts | 2 +- .../accessorsOverrideProperty7.errors.txt | 13 ++++ .../reference/accessorsOverrideProperty7.js | 42 +++++++++++ .../accessorsOverrideProperty7.symbols | 15 ++++ .../accessorsOverrideProperty7.types | 17 +++++ .../definePropertyOutputES3.errors.txt | 9 +++ .../reference/definePropertyOutputES3.js | 13 ++++ .../reference/definePropertyOutputES3.symbols | 8 +++ .../reference/definePropertyOutputES3.types | 9 +++ .../derivedClassOverridesPrivates.js | 5 +- ...dClassOverridesProtectedMembers.errors.txt | 44 ------------ .../derivedClassOverridesProtectedMembers.js | 7 +- ...ClassOverridesProtectedMembers2.errors.txt | 72 ------------------- .../derivedClassOverridesProtectedMembers2.js | 7 +- ...ClassOverridesProtectedMembers3.errors.txt | 8 +-- .../derivedClassOverridesProtectedMembers3.js | 10 +-- ...ClassOverridesProtectedMembers4.errors.txt | 8 +-- .../derivedClassOverridesProtectedMembers4.js | 9 +-- ...ivedClassOverridesPublicMembers.errors.txt | 8 +-- .../derivedClassOverridesPublicMembers.js | 7 +- ...vedClassOverridesWithoutSubtype.errors.txt | 29 -------- .../derivedClassOverridesWithoutSubtype.js | 5 +- .../reference/mixingApparentTypeOverrides.js | 1 - .../accessorsOverrideMethod.ts | 1 + .../accessorsOverrideProperty.ts | 1 + .../accessorsOverrideProperty2.ts | 1 + .../accessorsOverrideProperty3.ts | 1 + .../accessorsOverrideProperty4.ts | 1 + .../accessorsOverrideProperty5.ts | 2 +- .../accessorsOverrideProperty6.ts | 2 +- .../accessorsOverrideProperty7.ts | 8 +++ .../definePropertyOutputES3.ts | 5 ++ .../propertyOverridesAccessors.ts | 2 +- .../propertyOverridesAccessors2.ts | 1 + .../propertyOverridesAccessors3.ts | 1 + .../propertyOverridesAccessors4.ts | 2 + .../propertyOverridesAccessors5.ts | 1 + .../propertyOverridesMethod.ts | 1 + 43 files changed, 184 insertions(+), 223 deletions(-) create mode 100644 tests/baselines/reference/accessorsOverrideProperty7.errors.txt create mode 100644 tests/baselines/reference/accessorsOverrideProperty7.js create mode 100644 tests/baselines/reference/accessorsOverrideProperty7.symbols create mode 100644 tests/baselines/reference/accessorsOverrideProperty7.types create mode 100644 tests/baselines/reference/definePropertyOutputES3.errors.txt create mode 100644 tests/baselines/reference/definePropertyOutputES3.js create mode 100644 tests/baselines/reference/definePropertyOutputES3.symbols create mode 100644 tests/baselines/reference/definePropertyOutputES3.types delete mode 100644 tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt delete mode 100644 tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt delete mode 100644 tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty7.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyOutputES3.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d6b35244bdf1e..c4e6775090a09 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29517,8 +29517,8 @@ namespace ts { const derivedPropertyFlags = derived.flags & SymbolFlags.PropertyOrAccessor; if (basePropertyFlags && derivedPropertyFlags) { // property/accessor is overridden with property/accessor - if (compilerOptions.legacyClassFields - || baseDeclarationFlags & ModifierFlags.Abstract + if (!compilerOptions.useDefineForClassFields + || baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer) || base.valueDeclaration && base.valueDeclaration.parent.kind === SyntaxKind.InterfaceDeclaration || derived.valueDeclaration && isBinaryExpression(derived.valueDeclaration)) { // when the base property is abstract or from an interface, base/derived flags don't need to match diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index c834a937c9661..84a35668fad33 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -868,11 +868,11 @@ namespace ts { description: Diagnostics.Disable_strict_checking_of_generic_signatures_in_function_types, }, { - name: "legacyClassFields", + name: "useDefineForClassFields", type: "boolean", affectsSemanticDiagnostics: true, category: Diagnostics.Advanced_Options, - description: Diagnostics.Emit_legacy_class_fields, + description: Diagnostics.Emit_class_fields_with_Define_instead_of_Set, }, { name: "keyofStringsOnly", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9b3f8e0ed6f4e..eeb6b735630e1 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3093,6 +3093,10 @@ "category": "Error", "code": 5047 }, + "Option '{0}' cannot be specified when option 'target' is 'ES3'.": { + "category": "Error", + "code": 5048 + }, "Option '{0} can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.": { "category": "Error", "code": 5051 @@ -4024,7 +4028,7 @@ "category": "Message", "code": 6220 }, - "Emit legacy class fields.": { + "Emit class fields with Define instead of Set.": { "category": "Message", "code": 6221 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 68eccdff30726..58f1dbfbda16e 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -3003,6 +3003,10 @@ namespace ts { } } + if (options.useDefineForClassFields && languageVersion === ScriptTarget.ES3) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_when_option_target_is_ES3, "useDefineForClassFields"); + } + if (!options.noEmit && options.allowJs && getEmitDeclarations(options)) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", getEmitDeclarationOptionName(options)); } diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 4345cf40aa088..616fe9a7e9ac4 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -46,12 +46,11 @@ namespace ts { function transformSourceFile(node: SourceFile) { const options = context.getCompilerOptions(); if (node.isDeclarationFile - // TODO: ES3 target will still need to emit set semantics probably // TODO: Need to test computed proeprties too // [x] = 1 => Object.defineProperty(this, x, ...) // -vs- // [x] = 1 -> this[x] = 1 - || !options.legacyClassFields && options.target === ScriptTarget.ESNext) { + || options.useDefineForClassFields && options.target === ScriptTarget.ESNext) { return node; } const visited = visitEachChild(node, visitor, context); @@ -273,7 +272,7 @@ namespace ts { function transformConstructor(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { const constructor = visitNode(getFirstConstructorWithBody(node), visitor, isConstructorDeclaration); - const containsProperty = forEach(node.members, m => isInitializedProperty(m, !!context.getCompilerOptions().legacyClassFields)); + const containsProperty = forEach(node.members, m => isInitializedProperty(m, /*requireInitializer*/ !context.getCompilerOptions().useDefineForClassFields)); if (!containsProperty) { return constructor; } @@ -299,7 +298,7 @@ namespace ts { } function transformConstructorBody(node: ClassDeclaration | ClassExpression, constructor: ConstructorDeclaration | undefined, isDerivedClass: boolean) { - const properties = getProperties(node, /*requireInitializer*/ !!context.getCompilerOptions().legacyClassFields, /*isStatic*/ false); + const properties = getProperties(node, /*requireInitializer*/ !context.getCompilerOptions().useDefineForClassFields, /*isStatic*/ false); // Only generate synthetic constructor when there are property initializers to move. if (!constructor && !some(properties)) { @@ -421,11 +420,11 @@ namespace ts { */ function transformInitializedProperty(property: PropertyDeclaration, receiver: LeftHandSideExpression) { // We generate a name here in order to reuse the value cached by the relocated computed name expression (which uses the same generated name) - const emitAssignment = context.getCompilerOptions().legacyClassFields; + const emitAssignment = !context.getCompilerOptions().useDefineForClassFields; const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) ? updateComputedPropertyName(property.name, getGeneratedNameForNode(property.name)) : property.name; - const initializer = property.initializer || emitAssignment ? visitNode(property.initializer, visitor, isExpression) : createVoidZero() + const initializer = property.initializer || emitAssignment ? visitNode(property.initializer, visitor, isExpression) : createVoidZero(); if (emitAssignment) { const memberAccess = createMemberAccessForPropertyName(receiver, propertyName, /*location*/ propertyName); return createAssignment(memberAccess, initializer); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5441a70e010ff..e6b3ab3411273 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4803,7 +4803,7 @@ namespace ts { /*@internal*/ watch?: boolean; esModuleInterop?: boolean; /* @internal */ showConfig?: boolean; - legacyClassFields?: boolean; + useDefineForClassFields?: boolean; [option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined; } diff --git a/tests/baselines/reference/accessorsOverrideProperty7.errors.txt b/tests/baselines/reference/accessorsOverrideProperty7.errors.txt new file mode 100644 index 0000000000000..5ebeafe443d1b --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty7.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty7.ts(5,9): error TS2611: Class 'A' defines instance member property 'p', but extended class 'B' defines it as instance member accessor. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty7.ts (1 errors) ==== + abstract class A { + abstract p = 'yep' + } + class B extends A { + get p() { return 'oh no' } // error + ~ +!!! error TS2611: Class 'A' defines instance member property 'p', but extended class 'B' defines it as instance member accessor. + } + \ No newline at end of file diff --git a/tests/baselines/reference/accessorsOverrideProperty7.js b/tests/baselines/reference/accessorsOverrideProperty7.js new file mode 100644 index 0000000000000..55663405b7436 --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty7.js @@ -0,0 +1,42 @@ +//// [accessorsOverrideProperty7.ts] +abstract class A { + abstract p = 'yep' +} +class B extends A { + get p() { return 'oh no' } // error +} + + +//// [accessorsOverrideProperty7.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var A = /** @class */ (function () { + function A() { + Object.defineProperty(this, "p", { value: 'yep' }); + } + return A; +}()); +var B = /** @class */ (function (_super) { + __extends(B, _super); + function B() { + return _super !== null && _super.apply(this, arguments) || this; + } + Object.defineProperty(B.prototype, "p", { + get: function () { return 'oh no'; } // error + , + enumerable: true, + configurable: true + }); + return B; +}(A)); diff --git a/tests/baselines/reference/accessorsOverrideProperty7.symbols b/tests/baselines/reference/accessorsOverrideProperty7.symbols new file mode 100644 index 0000000000000..0ca99ab7abd6f --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty7.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty7.ts === +abstract class A { +>A : Symbol(A, Decl(accessorsOverrideProperty7.ts, 0, 0)) + + abstract p = 'yep' +>p : Symbol(A.p, Decl(accessorsOverrideProperty7.ts, 0, 18)) +} +class B extends A { +>B : Symbol(B, Decl(accessorsOverrideProperty7.ts, 2, 1)) +>A : Symbol(A, Decl(accessorsOverrideProperty7.ts, 0, 0)) + + get p() { return 'oh no' } // error +>p : Symbol(B.p, Decl(accessorsOverrideProperty7.ts, 3, 19)) +} + diff --git a/tests/baselines/reference/accessorsOverrideProperty7.types b/tests/baselines/reference/accessorsOverrideProperty7.types new file mode 100644 index 0000000000000..6e52715a3da6f --- /dev/null +++ b/tests/baselines/reference/accessorsOverrideProperty7.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty7.ts === +abstract class A { +>A : A + + abstract p = 'yep' +>p : string +>'yep' : "yep" +} +class B extends A { +>B : B +>A : A + + get p() { return 'oh no' } // error +>p : string +>'oh no' : "oh no" +} + diff --git a/tests/baselines/reference/definePropertyOutputES3.errors.txt b/tests/baselines/reference/definePropertyOutputES3.errors.txt new file mode 100644 index 0000000000000..c527477922545 --- /dev/null +++ b/tests/baselines/reference/definePropertyOutputES3.errors.txt @@ -0,0 +1,9 @@ +error TS5048: Option 'useDefineForClassFields' cannot be specified when option 'target' is 'ES3'. + + +!!! error TS5048: Option 'useDefineForClassFields' cannot be specified when option 'target' is 'ES3'. +==== tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyOutputES3.ts (0 errors) ==== + class A { + a = 12 + } + \ No newline at end of file diff --git a/tests/baselines/reference/definePropertyOutputES3.js b/tests/baselines/reference/definePropertyOutputES3.js new file mode 100644 index 0000000000000..1986c6aed6fd7 --- /dev/null +++ b/tests/baselines/reference/definePropertyOutputES3.js @@ -0,0 +1,13 @@ +//// [definePropertyOutputES3.ts] +class A { + a = 12 +} + + +//// [definePropertyOutputES3.js] +var A = /** @class */ (function () { + function A() { + Object.defineProperty(this, "a", { value: 12 }); + } + return A; +}()); diff --git a/tests/baselines/reference/definePropertyOutputES3.symbols b/tests/baselines/reference/definePropertyOutputES3.symbols new file mode 100644 index 0000000000000..d41600cd523b8 --- /dev/null +++ b/tests/baselines/reference/definePropertyOutputES3.symbols @@ -0,0 +1,8 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyOutputES3.ts === +class A { +>A : Symbol(A, Decl(definePropertyOutputES3.ts, 0, 0)) + + a = 12 +>a : Symbol(A.a, Decl(definePropertyOutputES3.ts, 0, 9)) +} + diff --git a/tests/baselines/reference/definePropertyOutputES3.types b/tests/baselines/reference/definePropertyOutputES3.types new file mode 100644 index 0000000000000..5912a50934371 --- /dev/null +++ b/tests/baselines/reference/definePropertyOutputES3.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyOutputES3.ts === +class A { +>A : A + + a = 12 +>a : number +>12 : 12 +} + diff --git a/tests/baselines/reference/derivedClassOverridesPrivates.js b/tests/baselines/reference/derivedClassOverridesPrivates.js index 8b23d0e4ed221..d313a5b5647b3 100644 --- a/tests/baselines/reference/derivedClassOverridesPrivates.js +++ b/tests/baselines/reference/derivedClassOverridesPrivates.js @@ -31,16 +31,13 @@ var __extends = (this && this.__extends) || (function () { })(); var Base = /** @class */ (function () { function Base() { - Object.defineProperty(this, "x", { value: void 0 }); } return Base; }()); var Derived = /** @class */ (function (_super) { __extends(Derived, _super); function Derived() { - var _this = _super !== null && _super.apply(this, arguments) || this; - Object.defineProperty(_this, "x", { value: void 0 }); // error - return _this; + return _super !== null && _super.apply(this, arguments) || this; } return Derived; }(Base)); diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt deleted file mode 100644 index 397c09dfd3ca0..0000000000000 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers.errors.txt +++ /dev/null @@ -1,44 +0,0 @@ -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts(21,15): error TS2612: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts(25,15): error TS2612: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts (2 errors) ==== - var x: { foo: string; } - var y: { foo: string; bar: string; } - - class Base { - protected a: typeof x; - protected b(a: typeof x) { } - protected get c() { return x; } - protected set c(v: typeof x) { } - protected d: (a: typeof x) => void; - - protected static r: typeof x; - protected static s(a: typeof x) { } - protected static get t() { return x; } - protected static set t(v: typeof x) { } - protected static u: (a: typeof x) => void; - - constructor(a: typeof x) { } - } - - class Derived extends Base { - protected a: typeof y; - ~ -!!! error TS2612: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - protected b(a: typeof y) { } - protected get c() { return y; } - protected set c(v: typeof y) { } - protected d: (a: typeof y) => void; - ~ -!!! error TS2612: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - - protected static r: typeof y; - protected static s(a: typeof y) { } - protected static get t() { return y; } - protected static set t(a: typeof y) { } - protected static u: (a: typeof y) => void; - - constructor(a: typeof y) { super(x) } - } - \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers.js b/tests/baselines/reference/derivedClassOverridesProtectedMembers.js index f5f7c25b40cac..f8f20fb6c00c4 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers.js +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers.js @@ -53,8 +53,6 @@ var x; var y; var Base = /** @class */ (function () { function Base(a) { - Object.defineProperty(this, "a", { value: void 0 }); - Object.defineProperty(this, "d", { value: void 0 }); } Base.prototype.b = function (a) { }; Object.defineProperty(Base.prototype, "c", { @@ -75,10 +73,7 @@ var Base = /** @class */ (function () { var Derived = /** @class */ (function (_super) { __extends(Derived, _super); function Derived(a) { - var _this = _super.call(this, x) || this; - Object.defineProperty(_this, "a", { value: void 0 }); - Object.defineProperty(_this, "d", { value: void 0 }); - return _this; + return _super.call(this, x) || this; } Derived.prototype.b = function (a) { }; Object.defineProperty(Derived.prototype, "c", { diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt deleted file mode 100644 index 8f2cc22c222c6..0000000000000 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers2.errors.txt +++ /dev/null @@ -1,72 +0,0 @@ -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts(22,5): error TS2612: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts(26,5): error TS2612: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts (2 errors) ==== - var x: { foo: string; } - var y: { foo: string; bar: string; } - - class Base { - protected a: typeof x; - protected b(a: typeof x) { } - protected get c() { return x; } - protected set c(v: typeof x) { } - protected d: (a: typeof x) => void ; - - protected static r: typeof x; - protected static s(a: typeof x) { } - protected static get t() { return x; } - protected static set t(v: typeof x) { } - protected static u: (a: typeof x) => void ; - - constructor(a: typeof x) { } - } - - // Increase visibility of all protected members to public - class Derived extends Base { - a: typeof y; - ~ -!!! error TS2612: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - b(a: typeof y) { } - get c() { return y; } - set c(v: typeof y) { } - d: (a: typeof y) => void; - ~ -!!! error TS2612: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - - static r: typeof y; - static s(a: typeof y) { } - static get t() { return y; } - static set t(a: typeof y) { } - static u: (a: typeof y) => void; - - constructor(a: typeof y) { super(a); } - } - - var d: Derived = new Derived(y); - var r1 = d.a; - var r2 = d.b(y); - var r3 = d.c; - var r3a = d.d; - d.c = y; - var r4 = Derived.r; - var r5 = Derived.s(y); - var r6 = Derived.t; - var r6a = Derived.u; - Derived.t = y; - - class Base2 { - [i: string]: Object; - [i: number]: typeof x; - } - - class Derived2 extends Base2 { - [i: string]: typeof x; - [i: number]: typeof y; - } - - var d2: Derived2; - var r7 = d2['']; - var r8 = d2[1]; - - \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers2.js b/tests/baselines/reference/derivedClassOverridesProtectedMembers2.js index 70447421a9bea..2b0e072f86531 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers2.js +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers2.js @@ -81,8 +81,6 @@ var x; var y; var Base = /** @class */ (function () { function Base(a) { - Object.defineProperty(this, "a", { value: void 0 }); - Object.defineProperty(this, "d", { value: void 0 }); } Base.prototype.b = function (a) { }; Object.defineProperty(Base.prototype, "c", { @@ -104,10 +102,7 @@ var Base = /** @class */ (function () { var Derived = /** @class */ (function (_super) { __extends(Derived, _super); function Derived(a) { - var _this = _super.call(this, a) || this; - Object.defineProperty(_this, "a", { value: void 0 }); - Object.defineProperty(_this, "d", { value: void 0 }); - return _this; + return _super.call(this, a) || this; } Derived.prototype.b = function (a) { }; Object.defineProperty(Derived.prototype, "c", { diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt index 6f9a180ed41be..faf228e8d55c2 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers3.errors.txt @@ -1,6 +1,5 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(22,7): error TS2415: Class 'Derived1' incorrectly extends base class 'Base'. Property 'a' is protected in type 'Derived1' but public in type 'Base'. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(23,15): error TS2612: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(27,7): error TS2415: Class 'Derived2' incorrectly extends base class 'Base'. Property 'b' is protected in type 'Derived2' but public in type 'Base'. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(32,7): error TS2415: Class 'Derived3' incorrectly extends base class 'Base'. @@ -9,7 +8,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve Property 'c' is protected in type 'Derived4' but public in type 'Base'. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(42,7): error TS2415: Class 'Derived5' incorrectly extends base class 'Base'. Property 'd' is protected in type 'Derived5' but public in type 'Base'. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(43,15): error TS2612: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(47,7): error TS2417: Class static side 'typeof Derived6' incorrectly extends base class static side 'typeof Base'. Property 'r' is protected in type 'typeof Derived6' but public in type 'typeof Base'. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(52,7): error TS2417: Class static side 'typeof Derived7' incorrectly extends base class static side 'typeof Base'. @@ -22,7 +20,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve Property 'u' is protected in type 'typeof Derived10' but public in type 'typeof Base'. -==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts (12 errors) ==== +==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts (10 errors) ==== var x: { foo: string; } var y: { foo: string; bar: string; } @@ -49,8 +47,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS2415: Class 'Derived1' incorrectly extends base class 'Base'. !!! error TS2415: Property 'a' is protected in type 'Derived1' but public in type 'Base'. protected a: typeof x; - ~ -!!! error TS2612: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. constructor(a: typeof x) { super(a); } } @@ -83,8 +79,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS2415: Class 'Derived5' incorrectly extends base class 'Base'. !!! error TS2415: Property 'd' is protected in type 'Derived5' but public in type 'Base'. protected d: (a: typeof x) => void ; - ~ -!!! error TS2612: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. constructor(a: typeof x) { super(a); } } diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers3.js b/tests/baselines/reference/derivedClassOverridesProtectedMembers3.js index 07fd16a2726f7..568e7ecd32f10 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers3.js +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers3.js @@ -88,8 +88,6 @@ var x; var y; var Base = /** @class */ (function () { function Base(a) { - Object.defineProperty(this, "a", { value: void 0 }); - Object.defineProperty(this, "d", { value: void 0 }); } Base.prototype.b = function (a) { }; Object.defineProperty(Base.prototype, "c", { @@ -112,9 +110,7 @@ var Base = /** @class */ (function () { var Derived1 = /** @class */ (function (_super) { __extends(Derived1, _super); function Derived1(a) { - var _this = _super.call(this, a) || this; - Object.defineProperty(_this, "a", { value: void 0 }); - return _this; + return _super.call(this, a) || this; } return Derived1; }(Base)); @@ -153,9 +149,7 @@ var Derived4 = /** @class */ (function (_super) { var Derived5 = /** @class */ (function (_super) { __extends(Derived5, _super); function Derived5(a) { - var _this = _super.call(this, a) || this; - Object.defineProperty(_this, "d", { value: void 0 }); - return _this; + return _super.call(this, a) || this; } return Derived5; }(Base)); diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt b/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt index bfba981ad6126..064e2e8d43c2f 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers4.errors.txt @@ -1,10 +1,8 @@ -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(9,12): error TS2612: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(12,7): error TS2415: Class 'Derived2' incorrectly extends base class 'Derived1'. Property 'a' is protected in type 'Derived2' but public in type 'Derived1'. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(13,15): error TS2612: Property 'a' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts (3 errors) ==== +==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts (1 errors) ==== var x: { foo: string; } var y: { foo: string; bar: string; } @@ -14,8 +12,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived1 extends Base { public a: typeof x; - ~ -!!! error TS2612: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class Derived2 extends Derived1 { @@ -23,6 +19,4 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve !!! error TS2415: Class 'Derived2' incorrectly extends base class 'Derived1'. !!! error TS2415: Property 'a' is protected in type 'Derived2' but public in type 'Derived1'. protected a: typeof x; // Error, parent was public - ~ -!!! error TS2612: Property 'a' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers4.js b/tests/baselines/reference/derivedClassOverridesProtectedMembers4.js index 098b457ced83f..099c450f6923d 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers4.js +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers4.js @@ -32,25 +32,20 @@ var x; var y; var Base = /** @class */ (function () { function Base() { - Object.defineProperty(this, "a", { value: void 0 }); } return Base; }()); var Derived1 = /** @class */ (function (_super) { __extends(Derived1, _super); function Derived1() { - var _this = _super !== null && _super.apply(this, arguments) || this; - Object.defineProperty(_this, "a", { value: void 0 }); - return _this; + return _super !== null && _super.apply(this, arguments) || this; } return Derived1; }(Base)); var Derived2 = /** @class */ (function (_super) { __extends(Derived2, _super); function Derived2() { - var _this = _super !== null && _super.apply(this, arguments) || this; - Object.defineProperty(_this, "a", { value: void 0 }); // Error, parent was public - return _this; + return _super !== null && _super.apply(this, arguments) || this; } return Derived2; }(Derived1)); diff --git a/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt b/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt index fd292ff444de0..9292ff64411d5 100644 --- a/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesPublicMembers.errors.txt @@ -2,15 +2,13 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(13,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(14,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(21,5): error TS2612: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(23,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(24,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(25,5): error TS2612: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(29,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts(30,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts (10 errors) ==== +==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesPublicMembers.ts (8 errors) ==== var x: { foo: string; } var y: { foo: string; bar: string; } @@ -40,8 +38,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve class Derived extends Base { a: typeof y; - ~ -!!! error TS2612: Property 'a' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. b(a: typeof y) { } get c() { return y; } ~ @@ -50,8 +46,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOve ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. d: (a: typeof y) => void; - ~ -!!! error TS2612: Property 'd' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. static r: typeof y; static s(a: typeof y) { } diff --git a/tests/baselines/reference/derivedClassOverridesPublicMembers.js b/tests/baselines/reference/derivedClassOverridesPublicMembers.js index 12277988f7b4e..6e6b27452cd12 100644 --- a/tests/baselines/reference/derivedClassOverridesPublicMembers.js +++ b/tests/baselines/reference/derivedClassOverridesPublicMembers.js @@ -80,8 +80,6 @@ var x; var y; var Base = /** @class */ (function () { function Base(a) { - Object.defineProperty(this, "a", { value: void 0 }); - Object.defineProperty(this, "d", { value: void 0 }); } Base.prototype.b = function (a) { }; Object.defineProperty(Base.prototype, "c", { @@ -102,10 +100,7 @@ var Base = /** @class */ (function () { var Derived = /** @class */ (function (_super) { __extends(Derived, _super); function Derived(a) { - var _this = _super.call(this, x) || this; - Object.defineProperty(_this, "a", { value: void 0 }); - Object.defineProperty(_this, "d", { value: void 0 }); - return _this; + return _super.call(this, x) || this; } Derived.prototype.b = function (a) { }; Object.defineProperty(Derived.prototype, "c", { diff --git a/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt b/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt deleted file mode 100644 index c0e780c643a30..0000000000000 --- a/tests/baselines/reference/derivedClassOverridesWithoutSubtype.errors.txt +++ /dev/null @@ -1,29 +0,0 @@ -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype.ts(8,5): error TS2612: Property 'x' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesWithoutSubtype.ts (1 errors) ==== - class Base { - x: { - foo: string; - } - } - - class Derived extends Base { - x: { - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - foo: any; - } - } - - class Base2 { - static y: { - foo: string; - } - } - - class Derived2 extends Base2 { - static y: { - foo: any; - } - } \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassOverridesWithoutSubtype.js b/tests/baselines/reference/derivedClassOverridesWithoutSubtype.js index ca091e5d6f258..e526f7d8d9bdd 100644 --- a/tests/baselines/reference/derivedClassOverridesWithoutSubtype.js +++ b/tests/baselines/reference/derivedClassOverridesWithoutSubtype.js @@ -39,16 +39,13 @@ var __extends = (this && this.__extends) || (function () { })(); var Base = /** @class */ (function () { function Base() { - Object.defineProperty(this, "x", { value: void 0 }); } return Base; }()); var Derived = /** @class */ (function (_super) { __extends(Derived, _super); function Derived() { - var _this = _super !== null && _super.apply(this, arguments) || this; - Object.defineProperty(_this, "x", { value: void 0 }); - return _this; + return _super !== null && _super.apply(this, arguments) || this; } return Derived; }(Base)); diff --git a/tests/baselines/reference/mixingApparentTypeOverrides.js b/tests/baselines/reference/mixingApparentTypeOverrides.js index 0f9d181efede2..74f9afc83894d 100644 --- a/tests/baselines/reference/mixingApparentTypeOverrides.js +++ b/tests/baselines/reference/mixingApparentTypeOverrides.js @@ -51,7 +51,6 @@ function Tagged(Base) { args[_i] = arguments[_i]; } var _this = _super.apply(this, args) || this; - Object.defineProperty(_this, "_tag", { value: void 0 }); _this._tag = ""; return _this; } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideMethod.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideMethod.ts index c06dd5d91a970..7090c4c6c2a20 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideMethod.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideMethod.ts @@ -1,4 +1,5 @@ // @target: esnext +// @useDefineForClassFields: true class A { m() { } } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts index 9365ea6bf9467..e23b28a18e9f1 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty.ts @@ -1,4 +1,5 @@ // @target: esnext +// @useDefineForClassFields: true class A { p = 'yep' } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts index 18a51bb1c11ab..a90b76ad23b99 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty2.ts @@ -1,4 +1,5 @@ // @target: esnext +// @useDefineForClassFields: true class Base { x = 1; } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts index 204286d2463d6..b081cef21e239 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty3.ts @@ -1,4 +1,5 @@ // @target: esnext +// @useDefineForClassFields: true declare class Animal { sound: string } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty4.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty4.ts index 4712b9c6f8d38..021f81ea7e96d 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty4.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty4.ts @@ -1,4 +1,5 @@ // @target: esnext +// @useDefineForClassFields: true declare class Animal { sound: string; } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts index 7db56312022ba..fe8620d6f77e3 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts @@ -1,5 +1,5 @@ // @target: esnext -// @legacyClassFields: false +// @useDefineForClassFields: true interface I { p: number } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty6.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty6.ts index 6c67a968ee913..b782496f3fb84 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty6.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty6.ts @@ -1,5 +1,5 @@ // @target: esnext -// @legacyClassFields: true +// @useDefineForClassFields: false class A { p = 'yep' } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty7.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty7.ts new file mode 100644 index 0000000000000..9be3dad44f832 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty7.ts @@ -0,0 +1,8 @@ +// @target: es5 +// @useDefineForClassFields: true +abstract class A { + abstract p = 'yep' +} +class B extends A { + get p() { return 'oh no' } // error +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyOutputES3.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyOutputES3.ts new file mode 100644 index 0000000000000..f6a62d32650fa --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyOutputES3.ts @@ -0,0 +1,5 @@ +// @target: es3 +// @useDefineForClassFields: true +class A { + a = 12 +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts index c88fda4a4d7b2..aa00b32f64a4a 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors.ts @@ -1,5 +1,5 @@ // @target: es2015 -// @legacyClassFields: false +// @useDefineForClassFields: true class A { get p() { return 'oh no' } } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors2.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors2.ts index 760658238a5ec..51424d7f099ac 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors2.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors2.ts @@ -1,4 +1,5 @@ // @target: esnext +// @useDefineForClassFields: true class Base { get x() { return 2; } set x(value) { console.log(`x was set to ${value}`); } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors3.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors3.ts index 5d61108fc99b7..3376155a1506a 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors3.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors3.ts @@ -1,4 +1,5 @@ // @target: esnext +// @useDefineForClassFields: true class Animal { _sound = 'rustling noise in the bushes' diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors4.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors4.ts index e34b08a9bbd77..f4357465676f0 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors4.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors4.ts @@ -1,3 +1,5 @@ +// @target: es5 +// @useDefineForClassFields: true declare class Animal { get sound(): string set sound(val: string) diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts index 16601fcfe5a8a..7f2947805013a 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts @@ -1,4 +1,5 @@ // @target: esnext +// @useDefineForClassFields: true class A { get p() { return 'oh no' } } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts index 9700f838663ec..ce0a03f15c68c 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesMethod.ts @@ -1,4 +1,5 @@ // @target: esnext +// @useDefineForClassFields: true class A { m() { } } From 8268f9a42028733ec466f5ac3248023df0b32eee Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 23 Sep 2019 10:57:50 -0700 Subject: [PATCH 38/44] Update baselines --- src/server/protocol.ts | 2 +- .../reference/api/tsserverlibrary.d.ts | 2 + tests/baselines/reference/api/typescript.d.ts | 1 + .../apparentTypeSubtyping.errors.txt | 8 +- .../apparentTypeSupertype.errors.txt | 5 +- ...baseClassImprovedMismatchErrors.errors.txt | 5 +- .../classIsSubtypeOfBaseType.errors.txt | 8 +- ...declarationEmitProtectedMembers.errors.txt | 55 ----- .../reference/derivedClassWithAny.errors.txt | 8 +- .../derivedGenericClassWithAny.errors.txt | 8 +- ...ninitializedPropertyDeclaration.errors.txt | 14 +- .../genericPrototypeProperty2.errors.txt | 24 --- .../genericPrototypeProperty3.errors.txt | 23 --- ...aceExtendingClassWithProtecteds.errors.txt | 5 +- .../reference/inheritance.errors.txt | 5 +- ...emberAccessorOverridingProperty.errors.txt | 5 +- ...emberPropertyOverridingAccessor.errors.txt | 5 +- ...emberPropertyOverridingProperty.errors.txt | 13 -- .../instanceSubtypeCheck2.errors.txt | 5 +- ...ExtendsObjectIntersectionErrors.errors.txt | 14 +- .../reference/multipleInheritance.errors.txt | 5 +- .../mutuallyRecursiveInference.errors.txt | 24 --- .../reference/protectedMembers.errors.txt | 11 +- .../baselines/reference/scopeTests.errors.txt | 5 +- .../useDefineForClassFields/tsconfig.json | 5 + .../subtypesOfTypeParameter.errors.txt | 5 +- ...OfTypeParameterWithConstraints4.errors.txt | 29 +-- ...rameterWithRecursiveConstraints.errors.txt | 56 +----- .../subtypingTransitivity.errors.txt | 28 --- .../subtypingWithObjectMembers.errors.txt | 38 +--- .../tsxGenericAttributesType5.errors.txt | 19 -- .../tsxGenericAttributesType6.errors.txt | 19 -- .../undefinedIsSubtypeOfEverything.errors.txt | 190 ------------------ .../codeFixAddMissingDeclareProperty.ts | 1 + .../codeFixAddMissingDeclareProperty2.ts | 1 + 35 files changed, 31 insertions(+), 620 deletions(-) delete mode 100644 tests/baselines/reference/declarationEmitProtectedMembers.errors.txt delete mode 100644 tests/baselines/reference/genericPrototypeProperty2.errors.txt delete mode 100644 tests/baselines/reference/genericPrototypeProperty3.errors.txt delete mode 100644 tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt delete mode 100644 tests/baselines/reference/mutuallyRecursiveInference.errors.txt create mode 100644 tests/baselines/reference/showConfig/Shows tsconfig for single option/useDefineForClassFields/tsconfig.json delete mode 100644 tests/baselines/reference/subtypingTransitivity.errors.txt delete mode 100644 tests/baselines/reference/tsxGenericAttributesType5.errors.txt delete mode 100644 tests/baselines/reference/tsxGenericAttributesType6.errors.txt delete mode 100644 tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 57c947409b2be..50e41a67cfd0c 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -3067,7 +3067,7 @@ namespace ts.server.protocol { strictNullChecks?: boolean; suppressExcessPropertyErrors?: boolean; suppressImplicitAnyIndexErrors?: boolean; - legacyClassFields?: boolean; + useDefineForClassFields?: boolean; target?: ScriptTarget | ts.ScriptTarget; traceResolution?: boolean; resolveJsonModule?: boolean; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 58d513b2e0a4b..f4aebf7cabc2c 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2605,6 +2605,7 @@ declare namespace ts { /** Paths used to compute primary types search locations */ typeRoots?: string[]; esModuleInterop?: boolean; + useDefineForClassFields?: boolean; [option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined; } export interface TypeAcquisition { @@ -8269,6 +8270,7 @@ declare namespace ts.server.protocol { strictNullChecks?: boolean; suppressExcessPropertyErrors?: boolean; suppressImplicitAnyIndexErrors?: boolean; + useDefineForClassFields?: boolean; target?: ScriptTarget | ts.ScriptTarget; traceResolution?: boolean; resolveJsonModule?: boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index bc71eaffa373f..00e5cd039dd6e 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2605,6 +2605,7 @@ declare namespace ts { /** Paths used to compute primary types search locations */ typeRoots?: string[]; esModuleInterop?: boolean; + useDefineForClassFields?: boolean; [option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined; } export interface TypeAcquisition { diff --git a/tests/baselines/reference/apparentTypeSubtyping.errors.txt b/tests/baselines/reference/apparentTypeSubtyping.errors.txt index c71164e351378..ca2f0765d6211 100644 --- a/tests/baselines/reference/apparentTypeSubtyping.errors.txt +++ b/tests/baselines/reference/apparentTypeSubtyping.errors.txt @@ -1,11 +1,9 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'Base'. Type 'String' is not assignable to type 'string'. 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. -tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2612: Property 'x' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(20,5): error TS2612: Property 'x' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts (3 errors) ==== +==== tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts (1 errors) ==== // subtype checks use the apparent type of the target type // S is a subtype of a type T, and T is a supertype of S, if one of the following is true, where S' denotes the apparent type (section 3.8.1) of S: @@ -20,8 +18,6 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtypi !!! error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'String' is not assignable to type 'string'. !!! error TS2416: 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class Base2 { @@ -32,6 +28,4 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtypi // is U extends String (S) a subtype of String (T)? Apparent type of U is String so it succeeds class Derived2 extends Base2 { // error because of the prototype's not matching, not because of the instance side x: U; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/apparentTypeSupertype.errors.txt b/tests/baselines/reference/apparentTypeSupertype.errors.txt index ea209aab4ac6b..a4a8ccc0a8bdd 100644 --- a/tests/baselines/reference/apparentTypeSupertype.errors.txt +++ b/tests/baselines/reference/apparentTypeSupertype.errors.txt @@ -2,10 +2,9 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSuperty Type 'U' is not assignable to type 'string'. Type 'String' is not assignable to type 'string'. 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. -tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts(10,5): error TS2612: Property 'x' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts (2 errors) ==== +==== tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts (1 errors) ==== // subtype checks use the apparent type of the target type // S is a subtype of a type T, and T is a supertype of S, if one of the following is true, where S' denotes the apparent type (section 3.8.1) of S: @@ -21,6 +20,4 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSuperty !!! error TS2416: Type 'U' is not assignable to type 'string'. !!! error TS2416: Type 'String' is not assignable to type 'string'. !!! error TS2416: 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible. - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt b/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt index d8c6861eec9fd..5f46ee70d2aaa 100644 --- a/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt +++ b/tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt @@ -5,7 +5,6 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2416: Prop Types of property 'n' are incompatible. Type 'string | Derived' is not assignable to type 'string | Base'. Type 'Derived' is not assignable to type 'string | Base'. -tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2612: Property 'n' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/compiler/baseClassImprovedMismatchErrors.ts(9,5): error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'. Type '() => string | number' is not assignable to type '() => number'. Type 'string | number' is not assignable to type 'number'. @@ -23,7 +22,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro Type 'string' is not assignable to type 'number'. -==== tests/cases/compiler/baseClassImprovedMismatchErrors.ts (5 errors) ==== +==== tests/cases/compiler/baseClassImprovedMismatchErrors.ts (4 errors) ==== class Base { n: Base | string; fn() { @@ -40,8 +39,6 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro !!! error TS2416: Types of property 'n' are incompatible. !!! error TS2416: Type 'string | Derived' is not assignable to type 'string | Base'. !!! error TS2416: Type 'Derived' is not assignable to type 'string | Base'. - ~ -!!! error TS2612: Property 'n' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. fn() { ~~ !!! error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'. diff --git a/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt b/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt index c7b996e71ebb9..8b84602b807c5 100644 --- a/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt +++ b/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt @@ -1,19 +1,15 @@ -tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(6,5): error TS2612: Property 'foo' will overwrite the base property in 'Base<{ bar: string; }>'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type 'Base<{ bar: string; }>'. Type '{ bar?: string; }' is not assignable to type '{ bar: string; }'. Property 'bar' is optional in type '{ bar?: string; }' but required in type '{ bar: string; }'. -tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2612: Property 'foo' will overwrite the base property in 'Base<{ bar: string; }>'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts (3 errors) ==== +==== tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts (1 errors) ==== class Base { foo: T; } class Derived extends Base<{ bar: string; }> { foo: { - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base<{ bar: string; }>'. Add a 'declare' modifier or an initializer to avoid this. bar: string; baz: number; // ok } } @@ -24,8 +20,6 @@ tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/cla !!! error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type 'Base<{ bar: string; }>'. !!! error TS2416: Type '{ bar?: string; }' is not assignable to type '{ bar: string; }'. !!! error TS2416: Property 'bar' is optional in type '{ bar?: string; }' but required in type '{ bar: string; }'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base<{ bar: string; }>'. Add a 'declare' modifier or an initializer to avoid this. bar?: string; // error } } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt b/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt deleted file mode 100644 index 8afd2d46a268c..0000000000000 --- a/tests/baselines/reference/declarationEmitProtectedMembers.errors.txt +++ /dev/null @@ -1,55 +0,0 @@ -tests/cases/compiler/declarationEmitProtectedMembers.ts(34,5): error TS2612: Property 'x' will overwrite the base property in 'C2'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/compiler/declarationEmitProtectedMembers.ts (1 errors) ==== - // Class with protected members - class C1 { - protected x: number; - - protected f() { - return this.x; - } - - protected set accessor(a: number) { } - protected get accessor() { return 0; } - - protected static sx: number; - - protected static sf() { - return this.sx; - } - - protected static set staticSetter(a: number) { } - protected static get staticGetter() { return 0; } - } - - // Derived class overriding protected members - class C2 extends C1 { - protected f() { - return super.f() + this.x; - } - protected static sf() { - return super.sf() + this.sx; - } - } - - // Derived class making protected members public - class C3 extends C2 { - x: number; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'C2'. Add a 'declare' modifier or an initializer to avoid this. - static sx: number; - f() { - return super.f(); - } - static sf() { - return super.sf(); - } - - static get staticGetter() { return 1; } - } - - // Protected properties in constructors - class C4 { - constructor(protected a: number, protected b) { } - } \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassWithAny.errors.txt b/tests/baselines/reference/derivedClassWithAny.errors.txt index c7165120faddf..aa91979706b51 100644 --- a/tests/baselines/reference/derivedClassWithAny.errors.txt +++ b/tests/baselines/reference/derivedClassWithAny.errors.txt @@ -1,9 +1,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(9,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(18,5): error TS2612: Property 'x' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(19,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(27,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(37,5): error TS2612: Property 'x' will overwrite the base property in 'D'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(38,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(44,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts(57,1): error TS2322: Type 'E' is not assignable to type 'C'. @@ -11,7 +9,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWit Type 'string' is not assignable to type 'number'. -==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts (9 errors) ==== +==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithAny.ts (7 errors) ==== class C { x: number; get X(): number { return 1; } @@ -34,8 +32,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWit class D extends C { x: any; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. get X(): any { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -59,8 +55,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWit // if D is a valid class definition than E is now not safe tranisitively through C class E extends D { x: string; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'D'. Add a 'declare' modifier or an initializer to avoid this. get X(): string{ return ''; } ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. diff --git a/tests/baselines/reference/derivedGenericClassWithAny.errors.txt b/tests/baselines/reference/derivedGenericClassWithAny.errors.txt index 8847b15d23ec4..e63849e4aa887 100644 --- a/tests/baselines/reference/derivedGenericClassWithAny.errors.txt +++ b/tests/baselines/reference/derivedGenericClassWithAny.errors.txt @@ -1,8 +1,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(10,5): error TS2612: Property 'x' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(11,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(19,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(29,5): error TS2612: Property 'x' will overwrite the base property in 'D'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,18): error TS2322: Type '""' is not assignable to type 'T'. '""' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'. @@ -13,7 +11,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC Type 'string' is not assignable to type 'number'. -==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts (9 errors) ==== +==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts (7 errors) ==== class C { x: T; get X(): T { return null; } @@ -26,8 +24,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC class D extends C { x: any; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. get X(): any { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -51,8 +47,6 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC // if D is a valid class definition than E is now not safe tranisitively through C class E extends D { x: T; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'D'. Add a 'declare' modifier or an initializer to avoid this. get X(): T { return ''; } // error ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. diff --git a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt index febf7f95d2021..f657e335a48cf 100644 --- a/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt +++ b/tests/baselines/reference/derivedUninitializedPropertyDeclaration.errors.txt @@ -1,24 +1,18 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(6,5): error TS2612: Property 'property' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(12,21): error TS1255: A definite assignment assertion '!' is not permitted in this context. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(15,5): error TS1031: 'declare' modifier cannot appear on a class element. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(15,17): error TS1183: An implementation cannot be declared in ambient contexts. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(17,24): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(24,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(27,5): error TS2612: Property 'p' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(39,5): error TS2612: Property 'p1' will overwrite the base property in 'E'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts(65,5): error TS2612: Property 'r' will overwrite the base property in 'J'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (10 errors) ==== +==== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts (6 errors) ==== class A { property = 'x'; m() { return 1 } } class B extends A { property: any; // error - ~~~~~~~~ -!!! error TS2612: Property 'property' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. } class BD extends A { declare property: any; // ok because it's implicitly initialised @@ -52,8 +46,6 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP p: 'hi'; // error ~ !!! error TS2564: Property 'p' has no initializer and is not definitely assigned in the constructor. - ~ -!!! error TS2612: Property 'p' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. } class DD extends C { declare p: 'bye'; // ok @@ -66,8 +58,6 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP } class F extends E { p1!: 'z' - ~~ -!!! error TS2612: Property 'p1' will overwrite the base property in 'E'. Add a 'declare' modifier or an initializer to avoid this. declare p2: 'alpha' } @@ -94,7 +84,5 @@ tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedP class K extends J { q!: 1 | 2 | 3 // ok, extends a property from an interface r!: 4 | 5 // error, from class - ~ -!!! error TS2612: Property 'r' will overwrite the base property in 'J'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/genericPrototypeProperty2.errors.txt b/tests/baselines/reference/genericPrototypeProperty2.errors.txt deleted file mode 100644 index 3983dbe192399..0000000000000 --- a/tests/baselines/reference/genericPrototypeProperty2.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -tests/cases/compiler/genericPrototypeProperty2.ts(7,5): error TS2612: Property 'target' will overwrite the base property in 'BaseEvent'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/compiler/genericPrototypeProperty2.ts(14,5): error TS2612: Property 't' will overwrite the base property in 'BaseEventWrapper'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/compiler/genericPrototypeProperty2.ts (2 errors) ==== - interface EventTarget { x } - class BaseEvent { - target: EventTarget; - } - - class MyEvent extends BaseEvent { - target: T; - ~~~~~~ -!!! error TS2612: Property 'target' will overwrite the base property in 'BaseEvent'. Add a 'declare' modifier or an initializer to avoid this. - } - class BaseEventWrapper { - t: BaseEvent; - } - - class MyEventWrapper extends BaseEventWrapper { - t: MyEvent; // any satisfies constraint and passes assignability check between 'target' properties - ~ -!!! error TS2612: Property 't' will overwrite the base property in 'BaseEventWrapper'. Add a 'declare' modifier or an initializer to avoid this. - } \ No newline at end of file diff --git a/tests/baselines/reference/genericPrototypeProperty3.errors.txt b/tests/baselines/reference/genericPrototypeProperty3.errors.txt deleted file mode 100644 index 3a7da6cd9837c..0000000000000 --- a/tests/baselines/reference/genericPrototypeProperty3.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -tests/cases/compiler/genericPrototypeProperty3.ts(6,5): error TS2612: Property 'target' will overwrite the base property in 'BaseEvent'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/compiler/genericPrototypeProperty3.ts(13,5): error TS2612: Property 't' will overwrite the base property in 'BaseEventWrapper'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/compiler/genericPrototypeProperty3.ts (2 errors) ==== - class BaseEvent { - target: {}; - } - - class MyEvent extends BaseEvent { // T is instantiated to any in the prototype, which is assignable to {} - target: T; - ~~~~~~ -!!! error TS2612: Property 'target' will overwrite the base property in 'BaseEvent'. Add a 'declare' modifier or an initializer to avoid this. - } - class BaseEventWrapper { - t: BaseEvent; - } - - class MyEventWrapper extends BaseEventWrapper { - t: MyEvent; - ~ -!!! error TS2612: Property 't' will overwrite the base property in 'BaseEventWrapper'. Add a 'declare' modifier or an initializer to avoid this. - } \ No newline at end of file diff --git a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt index 4a5836dbe4db1..ecb3e4664a470 100644 --- a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt +++ b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt @@ -10,10 +10,9 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInte Property 'y' is missing in type 'Bar5' but required in type 'I'. tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(29,7): error TS2420: Class 'Bar6' incorrectly implements interface 'I'. Property 'y' is protected in type 'Bar6' but public in type 'I'. -tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(38,5): error TS2612: Property 'x' will overwrite the base property in 'Foo'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts (7 errors) ==== +==== tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts (6 errors) ==== class Foo { protected x: string; } @@ -72,8 +71,6 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInte class Bar8 extends Foo implements I { x: string; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'Foo'. Add a 'declare' modifier or an initializer to avoid this. y: number; } \ No newline at end of file diff --git a/tests/baselines/reference/inheritance.errors.txt b/tests/baselines/reference/inheritance.errors.txt index b3a1190d10d70..b476f1399b445 100644 --- a/tests/baselines/reference/inheritance.errors.txt +++ b/tests/baselines/reference/inheritance.errors.txt @@ -1,10 +1,9 @@ -tests/cases/compiler/inheritance.ts(22,12): error TS2612: Property 'y' will overwrite the base property in 'N'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/compiler/inheritance.ts(31,12): error TS2425: Class 'Good' defines instance member property 'f', but extended class 'Baad' defines it as instance member function. tests/cases/compiler/inheritance.ts(32,12): error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type 'Good'. Type '(n: number) => number' is not assignable to type '() => number'. -==== tests/cases/compiler/inheritance.ts (3 errors) ==== +==== tests/cases/compiler/inheritance.ts (2 errors) ==== class B1 { public x; } @@ -27,8 +26,6 @@ tests/cases/compiler/inheritance.ts(32,12): error TS2416: Property 'g' in type ' class ND extends N { // any is assignable to number public y; - ~ -!!! error TS2612: Property 'y' will overwrite the base property in 'N'. Add a 'declare' modifier or an initializer to avoid this. } class Good { diff --git a/tests/baselines/reference/inheritanceMemberAccessorOverridingProperty.errors.txt b/tests/baselines/reference/inheritanceMemberAccessorOverridingProperty.errors.txt index fd71a37a6875d..98b9d349d64fe 100644 --- a/tests/baselines/reference/inheritanceMemberAccessorOverridingProperty.errors.txt +++ b/tests/baselines/reference/inheritanceMemberAccessorOverridingProperty.errors.txt @@ -1,9 +1,8 @@ tests/cases/compiler/inheritanceMemberAccessorOverridingProperty.ts(6,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/inheritanceMemberAccessorOverridingProperty.ts(6,9): error TS2611: Class 'a' defines instance member property 'x', but extended class 'b' defines it as instance member accessor. tests/cases/compiler/inheritanceMemberAccessorOverridingProperty.ts(9,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -==== tests/cases/compiler/inheritanceMemberAccessorOverridingProperty.ts (3 errors) ==== +==== tests/cases/compiler/inheritanceMemberAccessorOverridingProperty.ts (2 errors) ==== class a { x: string; } @@ -12,8 +11,6 @@ tests/cases/compiler/inheritanceMemberAccessorOverridingProperty.ts(9,9): error get x() { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~ -!!! error TS2611: Class 'a' defines instance member property 'x', but extended class 'b' defines it as instance member accessor. return "20"; } set x(aValue: string) { diff --git a/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt b/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt index 4b468181f96a3..ec8ec05a8aeb5 100644 --- a/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt +++ b/tests/baselines/reference/inheritanceMemberPropertyOverridingAccessor.errors.txt @@ -1,9 +1,8 @@ tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(6,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(12,5): error TS2610: Class 'a' defines instance member accessor 'x', but extended class 'b' defines it as instance member property. -==== tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts (3 errors) ==== +==== tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts (2 errors) ==== class a { private __x: () => string; get x() { @@ -20,6 +19,4 @@ tests/cases/compiler/inheritanceMemberPropertyOverridingAccessor.ts(12,5): error class b extends a { x: () => string; - ~ -!!! error TS2610: Class 'a' defines instance member accessor 'x', but extended class 'b' defines it as instance member property. } \ No newline at end of file diff --git a/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt b/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt deleted file mode 100644 index e88c45c3da1be..0000000000000 --- a/tests/baselines/reference/inheritanceMemberPropertyOverridingProperty.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -tests/cases/compiler/inheritanceMemberPropertyOverridingProperty.ts(6,5): error TS2612: Property 'x' will overwrite the base property in 'a'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/compiler/inheritanceMemberPropertyOverridingProperty.ts (1 errors) ==== - class a { - x: () => string; - } - - class b extends a { - x: () => string; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'a'. Add a 'declare' modifier or an initializer to avoid this. - } \ No newline at end of file diff --git a/tests/baselines/reference/instanceSubtypeCheck2.errors.txt b/tests/baselines/reference/instanceSubtypeCheck2.errors.txt index ec48a1176118d..84b454d7ea0a6 100644 --- a/tests/baselines/reference/instanceSubtypeCheck2.errors.txt +++ b/tests/baselines/reference/instanceSubtypeCheck2.errors.txt @@ -1,9 +1,8 @@ tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2416: Property 'x' in type 'C2' is not assignable to the same property in base type 'C1'. Type 'string' is not assignable to type 'C2'. -tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2612: Property 'x' will overwrite the base property in 'C1'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/compiler/instanceSubtypeCheck2.ts (2 errors) ==== +==== tests/cases/compiler/instanceSubtypeCheck2.ts (1 errors) ==== class C1 { x: C2; } @@ -13,6 +12,4 @@ tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2612: Property 'x' w ~ !!! error TS2416: Property 'x' in type 'C2' is not assignable to the same property in base type 'C1'. !!! error TS2416: Type 'string' is not assignable to type 'C2'. - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'C1'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt b/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt index cb3f6bae0e33e..17cb5585cf87e 100644 --- a/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt +++ b/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt @@ -16,18 +16,14 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI Type 'number' is not assignable to type 'string'. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(16,38): error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'T1'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(16,38): error TS2612: Property 'a' will overwrite the base property in 'T1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'T2'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2612: Property 'b' will overwrite the base property in 'T2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'. Type 'string' is not assignable to type 'number'. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2612: Property '0' will overwrite the base property in '[string, number]'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(20,38): error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'T5'. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(20,38): error TS2612: Property 'c' will overwrite the base property in 'T5'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(30,11): error TS2430: Interface 'I10' incorrectly extends interface 'typeof CX'. Types of property 'a' are incompatible. Type 'number' is not assignable to type 'string'. @@ -59,7 +55,7 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(47,26): error TS2312: An interface can only extend an object type or intersection of object types with statically known members. -==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts (27 errors) ==== +==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts (23 errors) ==== type T1 = { a: number }; type T2 = T1 & { b: number }; type T3 = number[]; @@ -100,14 +96,10 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI ~ !!! error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'T1'. !!! error TS2416: Type 'string' is not assignable to type 'number'. - ~ -!!! error TS2612: Property 'a' will overwrite the base property in 'T1'. Add a 'declare' modifier or an initializer to avoid this. class C2 extends Constructor() { b: string } ~ !!! error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'T2'. !!! error TS2416: Type 'string' is not assignable to type 'number'. - ~ -!!! error TS2612: Property 'b' will overwrite the base property in 'T2'. Add a 'declare' modifier or an initializer to avoid this. class C3 extends Constructor() { length: string } ~~~~~~ !!! error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'. @@ -116,14 +108,10 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI ~ !!! error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'. !!! error TS2416: Type 'number' is not assignable to type 'string'. - ~ -!!! error TS2612: Property '0' will overwrite the base property in '[string, number]'. Add a 'declare' modifier or an initializer to avoid this. class C5 extends Constructor() { c: number } ~ !!! error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'T5'. !!! error TS2416: Type 'number' is not assignable to type 'string'. - ~ -!!! error TS2612: Property 'c' will overwrite the base property in 'T5'. Add a 'declare' modifier or an initializer to avoid this. declare class CX { static a: string } declare enum EX { A, B, C } diff --git a/tests/baselines/reference/multipleInheritance.errors.txt b/tests/baselines/reference/multipleInheritance.errors.txt index f503fdb5457a8..c4a440d9a0ea5 100644 --- a/tests/baselines/reference/multipleInheritance.errors.txt +++ b/tests/baselines/reference/multipleInheritance.errors.txt @@ -1,12 +1,11 @@ tests/cases/compiler/multipleInheritance.ts(9,21): error TS1174: Classes can only extend a single class. tests/cases/compiler/multipleInheritance.ts(18,21): error TS1174: Classes can only extend a single class. -tests/cases/compiler/multipleInheritance.ts(26,12): error TS2612: Property 'y' will overwrite the base property in 'N'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/compiler/multipleInheritance.ts(35,12): error TS2425: Class 'Good' defines instance member property 'f', but extended class 'Baad' defines it as instance member function. tests/cases/compiler/multipleInheritance.ts(36,12): error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type 'Good'. Type '(n: number) => number' is not assignable to type '() => number'. -==== tests/cases/compiler/multipleInheritance.ts (5 errors) ==== +==== tests/cases/compiler/multipleInheritance.ts (4 errors) ==== class B1 { public x; } @@ -37,8 +36,6 @@ tests/cases/compiler/multipleInheritance.ts(36,12): error TS2416: Property 'g' i class ND extends N { // any is assignable to number public y; - ~ -!!! error TS2612: Property 'y' will overwrite the base property in 'N'. Add a 'declare' modifier or an initializer to avoid this. } class Good { diff --git a/tests/baselines/reference/mutuallyRecursiveInference.errors.txt b/tests/baselines/reference/mutuallyRecursiveInference.errors.txt deleted file mode 100644 index e750e8bc7ffc9..0000000000000 --- a/tests/baselines/reference/mutuallyRecursiveInference.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -tests/cases/compiler/mutuallyRecursiveInference.ts(9,5): error TS2612: Property 'a' will overwrite the base property in 'L'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/compiler/mutuallyRecursiveInference.ts(10,5): error TS2612: Property 'b' will overwrite the base property in 'L'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/compiler/mutuallyRecursiveInference.ts (2 errors) ==== - class T
{ - a: A; - b: any - } - class L extends T { - m() { this.a } - } - class X extends L { - a: 'a' | 'b' - ~ -!!! error TS2612: Property 'a' will overwrite the base property in 'L'. Add a 'declare' modifier or an initializer to avoid this. - b: number - ~ -!!! error TS2612: Property 'b' will overwrite the base property in 'L'. Add a 'declare' modifier or an initializer to avoid this. - m2() { - this.a - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/protectedMembers.errors.txt b/tests/baselines/reference/protectedMembers.errors.txt index c9cea91585229..9171df2a485b6 100644 --- a/tests/baselines/reference/protectedMembers.errors.txt +++ b/tests/baselines/reference/protectedMembers.errors.txt @@ -1,4 +1,3 @@ -tests/cases/compiler/protectedMembers.ts(25,5): error TS2612: Property 'x' will overwrite the base property in 'C2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/compiler/protectedMembers.ts(40,4): error TS2445: Property 'x' is protected and only accessible within class 'C1' and its subclasses. tests/cases/compiler/protectedMembers.ts(41,4): error TS2445: Property 'f' is protected and only accessible within class 'C1' and its subclasses. tests/cases/compiler/protectedMembers.ts(42,4): error TS2445: Property 'sx' is protected and only accessible within class 'C1' and its subclasses. @@ -13,13 +12,11 @@ tests/cases/compiler/protectedMembers.ts(97,1): error TS2322: Type 'B1' is not a Property 'x' is protected but type 'B1' is not a class derived from 'A1'. tests/cases/compiler/protectedMembers.ts(98,1): error TS2322: Type 'A1' is not assignable to type 'B1'. Property 'x' is protected in type 'A1' but public in type 'B1'. -tests/cases/compiler/protectedMembers.ts(104,5): error TS2612: Property 'x' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/compiler/protectedMembers.ts(111,7): error TS2415: Class 'B3' incorrectly extends base class 'A3'. Property 'x' is protected in type 'B3' but public in type 'A3'. -tests/cases/compiler/protectedMembers.ts(112,15): error TS2612: Property 'x' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/compiler/protectedMembers.ts (16 errors) ==== +==== tests/cases/compiler/protectedMembers.ts (13 errors) ==== // Class with protected members class C1 { protected x: number; @@ -45,8 +42,6 @@ tests/cases/compiler/protectedMembers.ts(112,15): error TS2612: Property 'x' wil // Derived class making protected members public class C3 extends C2 { x: number; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'C2'. Add a 'declare' modifier or an initializer to avoid this. static sx: number; f() { return super.f(); @@ -152,8 +147,6 @@ tests/cases/compiler/protectedMembers.ts(112,15): error TS2612: Property 'x' wil } class B2 extends A2 { x; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. } class A3 { @@ -165,8 +158,6 @@ tests/cases/compiler/protectedMembers.ts(112,15): error TS2612: Property 'x' wil !!! error TS2415: Class 'B3' incorrectly extends base class 'A3'. !!! error TS2415: Property 'x' is protected in type 'B3' but public in type 'A3'. protected x; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/scopeTests.errors.txt b/tests/baselines/reference/scopeTests.errors.txt index 5ef8c71ecc4ec..ce24301efc2bf 100644 --- a/tests/baselines/reference/scopeTests.errors.txt +++ b/tests/baselines/reference/scopeTests.errors.txt @@ -1,9 +1,8 @@ tests/cases/compiler/scopeTests.ts(2,7): error TS2415: Class 'D' incorrectly extends base class 'C'. Property 'v' is private in type 'C' but not in type 'D'. -tests/cases/compiler/scopeTests.ts(4,10): error TS2612: Property 'p' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/compiler/scopeTests.ts (2 errors) ==== +==== tests/cases/compiler/scopeTests.ts (1 errors) ==== class C { private v; public p; static s; } class D extends C { ~ @@ -11,8 +10,6 @@ tests/cases/compiler/scopeTests.ts(4,10): error TS2612: Property 'p' will overwr !!! error TS2415: Property 'v' is private in type 'C' but not in type 'D'. public v: number; public p: number - ~ -!!! error TS2612: Property 'p' will overwrite the base property in 'C'. Add a 'declare' modifier or an initializer to avoid this. constructor() { super() this.v = 1; diff --git a/tests/baselines/reference/showConfig/Shows tsconfig for single option/useDefineForClassFields/tsconfig.json b/tests/baselines/reference/showConfig/Shows tsconfig for single option/useDefineForClassFields/tsconfig.json new file mode 100644 index 0000000000000..608714e952871 --- /dev/null +++ b/tests/baselines/reference/showConfig/Shows tsconfig for single option/useDefineForClassFields/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "useDefineForClassFields": true + } +} diff --git a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt index 0a36cffdac65b..0ec8951fe9391 100644 --- a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt @@ -1,10 +1,9 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(8,5): error TS2416: Property 'foo' in type 'D1' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(8,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts (2 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts (1 errors) ==== // checking whether other types are subtypes of type parameters class C3 { @@ -17,8 +16,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D1' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } function f1(x: T, y: U) { diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt index f436466810cfd..03656c08c4ef2 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt @@ -1,36 +1,27 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(37,5): error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(42,5): error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'Foo'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(52,5): error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2416: Property 'foo' in type 'D5' is not assignable to the same property in base type 'B1'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. Type 'Foo' is not assignable to type 'T'. 'Foo' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'B1'. Type 'T' is not assignable to type 'U'. 'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. Type 'Foo' is not assignable to type 'U'. 'Foo' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(72,5): error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2416: Property 'foo' in type 'D9' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts (19 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts (10 errors) ==== // checking whether other types are subtypes of type parameters with constraints class Foo { foo: number; } @@ -68,15 +59,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D1 extends B1 { [x: string]: Foo; foo: T; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D2 extends B1 { [x: string]: Foo; foo: U; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D3 extends B1 { @@ -87,15 +74,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~ !!! error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'Foo'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D4 extends B1 { [x: string]: T; foo: T; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D5 extends B1 { @@ -109,8 +92,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. !!! error TS2416: 'Foo' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D6 extends B1 { @@ -121,8 +102,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~ !!! error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'T'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D7 extends B1 { @@ -136,15 +115,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: 'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. !!! error TS2416: 'Foo' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D8 extends B1 { [x: string]: U; foo: U; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } class D9 extends B1 { @@ -155,6 +130,4 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~ !!! error TS2416: Property 'foo' in type 'D9' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'U'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'B1'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt index 9eb8a073c4242..700076db4d190 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt @@ -1,84 +1,66 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(63,9): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2416: Property 'foo' in type 'D2' is not assignable to the same property in base type 'Base'. Type 'U' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base'. Type 'V' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2416: Property 'foo' in type 'D4' is not assignable to the same property in base type 'Base'. Type 'T' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(83,9): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base'. Type 'V' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base'. Type 'T' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base'. Type 'U' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(103,9): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(115,9): error TS2416: Property 'foo' in type 'D1' is not assignable to the same property in base type 'Base2'. Type 'T' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'U' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(115,9): error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(120,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(120,9): error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base2'. Type 'V' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'V' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(130,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(130,9): error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(135,9): error TS2416: Property 'foo' in type 'D5' is not assignable to the same property in base type 'Base2'. Type 'U' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'T' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(135,9): error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base2'. Type 'V' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'V' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base2'. Type 'T' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'U' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base2'. Type 'U' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'T' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(155,9): error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts (42 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts (24 errors) ==== // checking whether other types are subtypes of type parameters with constraints class Foo { foo: T; } @@ -142,8 +124,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D1, U extends Foo, V extends Foo> extends Base { [x: string]: T; foo: T - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D2, U extends Foo, V extends Foo> extends Base { @@ -155,8 +135,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D2' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D3, U extends Foo, V extends Foo> extends Base { @@ -168,8 +146,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D4, U extends Foo, V extends Foo> extends Base { @@ -181,15 +157,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D4' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'T' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D5, U extends Foo, V extends Foo> extends Base { [x: string]: U; foo: U - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D6, U extends Foo, V extends Foo> extends Base { @@ -201,8 +173,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'V' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D7, U extends Foo, V extends Foo> extends Base { @@ -214,8 +184,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'T' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D8, U extends Foo, V extends Foo> extends Base { @@ -227,15 +195,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'U' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } class D9, U extends Foo, V extends Foo> extends Base { [x: string]: V; foo: V - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. } } @@ -254,8 +218,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'Foo'. !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D2, U extends Foo, V extends Foo> extends Base2 { @@ -263,8 +225,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf foo: U ~~~ !!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D3, U extends Foo, V extends Foo> extends Base2 { @@ -278,8 +238,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'Foo'. !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: Type 'Foo' is not assignable to type 'T'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D4, U extends Foo, V extends Foo> extends Base2 { @@ -287,8 +245,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf foo: T ~~~ !!! error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D5, U extends Foo, V extends Foo> extends Base2 { @@ -300,8 +256,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'Foo'. !!! error TS2416: Type 'T' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D6, U extends Foo, V extends Foo> extends Base2 { @@ -315,8 +269,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'Foo'. !!! error TS2416: Type 'V' is not assignable to type 'U'. !!! error TS2416: Type 'Foo' is not assignable to type 'U'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D7, U extends Foo, V extends Foo> extends Base2 { @@ -330,8 +282,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'Foo'. !!! error TS2416: Type 'U' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D8, U extends Foo, V extends Foo> extends Base2 { @@ -345,14 +295,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Type 'Foo' is not assignable to type 'Foo'. !!! error TS2416: Type 'T' is not assignable to type 'V'. !!! error TS2416: Type 'Foo' is not assignable to type 'V'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } class D9, U extends Foo, V extends Foo> extends Base2 { [x: string]: V; foo: V - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base2'. Add a 'declare' modifier or an initializer to avoid this. } } \ No newline at end of file diff --git a/tests/baselines/reference/subtypingTransitivity.errors.txt b/tests/baselines/reference/subtypingTransitivity.errors.txt deleted file mode 100644 index 6aaa89bdc729d..0000000000000 --- a/tests/baselines/reference/subtypingTransitivity.errors.txt +++ /dev/null @@ -1,28 +0,0 @@ -tests/cases/compiler/subtypingTransitivity.ts(6,12): error TS2612: Property 'x' will overwrite the base property in 'B'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/compiler/subtypingTransitivity.ts(9,12): error TS2612: Property 'x' will overwrite the base property in 'B'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/compiler/subtypingTransitivity.ts (2 errors) ==== - class B { - x: Object; - } - - class D extends B { - public x: string; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'B'. Add a 'declare' modifier or an initializer to avoid this. - } - class D2 extends B { - public x: number; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'B'. Add a 'declare' modifier or an initializer to avoid this. - } - - var b: B; - var d: D; - var d2: D2; - - d.x = ''; - b = d; - b.x = 1; // assigned number to string - \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithObjectMembers.errors.txt b/tests/baselines/reference/subtypingWithObjectMembers.errors.txt index 73f8b2be41b9d..1e2f7bc9114f1 100644 --- a/tests/baselines/reference/subtypingWithObjectMembers.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembers.errors.txt @@ -1,30 +1,18 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(13,5): error TS2612: Property 'foo' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(14,5): error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(14,5): error TS2612: Property 'bar' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(23,5): error TS2612: Property '1' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(24,5): error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(24,5): error TS2612: Property '2.0' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(33,5): error TS2612: Property ''1'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(34,5): error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(34,5): error TS2612: Property ''2.0'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(44,9): error TS2612: Property 'foo' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(45,9): error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(45,9): error TS2612: Property 'bar' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(54,9): error TS2612: Property '1' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(55,9): error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(55,9): error TS2612: Property '2.0' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(64,9): error TS2612: Property ''1'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(65,9): error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. Type 'string' is not assignable to type 'Base'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(65,9): error TS2612: Property ''2.0'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts (18 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts (6 errors) ==== class Base { foo: string; } class Derived extends Base { bar: string; } class Derived2 extends Derived { baz: string; } @@ -38,14 +26,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { foo: Derived; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. bar: string; // error ~~~ !!! error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. - ~~~ -!!! error TS2612: Property 'bar' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. } class A2 { @@ -55,14 +39,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B2 extends A2 { 1: Derived; // ok - ~ -!!! error TS2612: Property '1' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. 2: string; // error ~ !!! error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. - ~ -!!! error TS2612: Property '2.0' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. } class A3 { @@ -72,14 +52,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A3 { '1': Derived; // ok - ~~~ -!!! error TS2612: Property ''1'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. '2.0': string; // error ~~~~~ !!! error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. - ~~~~~ -!!! error TS2612: Property ''2.0'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. } module TwoLevels { @@ -90,14 +66,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { foo: Derived2; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. bar: string; // error ~~~ !!! error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. - ~~~ -!!! error TS2612: Property 'bar' will overwrite the base property in 'A'. Add a 'declare' modifier or an initializer to avoid this. } class A2 { @@ -107,14 +79,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B2 extends A2 { 1: Derived2; // ok - ~ -!!! error TS2612: Property '1' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. 2: string; // error ~ !!! error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. - ~ -!!! error TS2612: Property '2.0' will overwrite the base property in 'A2'. Add a 'declare' modifier or an initializer to avoid this. } class A3 { @@ -124,13 +92,9 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A3 { '1': Derived2; // ok - ~~~ -!!! error TS2612: Property ''1'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. '2.0': string; // error ~~~~~ !!! error TS2416: Property ''2.0'' in type 'B3' is not assignable to the same property in base type 'A3'. !!! error TS2416: Type 'string' is not assignable to type 'Base'. - ~~~~~ -!!! error TS2612: Property ''2.0'' will overwrite the base property in 'A3'. Add a 'declare' modifier or an initializer to avoid this. } } \ No newline at end of file diff --git a/tests/baselines/reference/tsxGenericAttributesType5.errors.txt b/tests/baselines/reference/tsxGenericAttributesType5.errors.txt deleted file mode 100644 index e0caf96f4e633..0000000000000 --- a/tests/baselines/reference/tsxGenericAttributesType5.errors.txt +++ /dev/null @@ -1,19 +0,0 @@ -tests/cases/conformance/jsx/file.tsx(9,5): error TS2612: Property 'props' will overwrite the base property in 'Component'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== - import React = require('react'); - - class B1 extends React.Component { - render() { - return
hi
; - } - } - class B extends React.Component { - props: U; - ~~~~~ -!!! error TS2612: Property 'props' will overwrite the base property in 'Component'. Add a 'declare' modifier or an initializer to avoid this. - render() { - return ; - } - } \ No newline at end of file diff --git a/tests/baselines/reference/tsxGenericAttributesType6.errors.txt b/tests/baselines/reference/tsxGenericAttributesType6.errors.txt deleted file mode 100644 index ca5dd5ceb1f3d..0000000000000 --- a/tests/baselines/reference/tsxGenericAttributesType6.errors.txt +++ /dev/null @@ -1,19 +0,0 @@ -tests/cases/conformance/jsx/file.tsx(9,5): error TS2612: Property 'props' will overwrite the base property in 'Component'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== - import React = require('react'); - - class B1 extends React.Component { - render() { - return
hi
; - } - } - class B extends React.Component { - props: U; - ~~~~~ -!!! error TS2612: Property 'props' will overwrite the base property in 'Component'. Add a 'declare' modifier or an initializer to avoid this. - render() { - return ; - } - } \ No newline at end of file diff --git a/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt b/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt deleted file mode 100644 index fbaf5bb97dd32..0000000000000 --- a/tests/baselines/reference/undefinedIsSubtypeOfEverything.errors.txt +++ /dev/null @@ -1,190 +0,0 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(8,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(12,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(16,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(20,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(25,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(29,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(34,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(38,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(43,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(47,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(52,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(56,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(61,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(68,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(73,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(78,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(86,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(95,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(100,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(105,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(114,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts(119,5): error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts (22 errors) ==== - // undefined is a subtype of every other types, no errors expected below - - class Base { - foo: typeof undefined; - } - - class D0 extends Base { - foo: any; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - class DA extends Base { - foo: typeof undefined; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - class D1 extends Base { - foo: string; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - class D1A extends Base { - foo: String; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - - class D2 extends Base { - foo: number; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - class D2A extends Base { - foo: Number; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - - class D3 extends Base { - foo: boolean; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - class D3A extends Base { - foo: Boolean; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - - class D4 extends Base { - foo: RegExp; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - class D5 extends Base { - foo: Date; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - - class D6 extends Base { - foo: number[]; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - class D7 extends Base { - foo: { bar: number }; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - - class D8 extends Base { - foo: D7; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - interface I1 { - bar: string; - } - class D9 extends Base { - foo: I1; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - - class D10 extends Base { - foo: () => number; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - enum E { A } - class D11 extends Base { - foo: E; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - function f() { } - module f { - export var bar = 1; - } - class D12 extends Base { - foo: typeof f; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - - class c { baz: string } - module c { - export var bar = 1; - } - class D13 extends Base { - foo: typeof c; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - - class D14 extends Base { - foo: T; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - - class D15 extends Base { - foo: U; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - //class D15 extends Base { - // foo: U; - //} - - - class D16 extends Base { - foo: Object; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - - - class D17 extends Base { - foo: {}; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'Base'. Add a 'declare' modifier or an initializer to avoid this. - } - \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixAddMissingDeclareProperty.ts b/tests/cases/fourslash/codeFixAddMissingDeclareProperty.ts index 90dcbdd86ba8d..e4ebea338f6c3 100644 --- a/tests/cases/fourslash/codeFixAddMissingDeclareProperty.ts +++ b/tests/cases/fourslash/codeFixAddMissingDeclareProperty.ts @@ -1,4 +1,5 @@ /// +// @useDefineForClassFields: true ////class B { //// p = 1 diff --git a/tests/cases/fourslash/codeFixAddMissingDeclareProperty2.ts b/tests/cases/fourslash/codeFixAddMissingDeclareProperty2.ts index 32dc21d9a2753..5abf2b0e233fc 100644 --- a/tests/cases/fourslash/codeFixAddMissingDeclareProperty2.ts +++ b/tests/cases/fourslash/codeFixAddMissingDeclareProperty2.ts @@ -1,4 +1,5 @@ /// +// @useDefineForClassFields: true ////class B { //// p = 1 From 5eeb2b0fbe16854efd7c7b96e15278dde21f3c98 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 23 Sep 2019 11:32:27 -0700 Subject: [PATCH 39/44] Object.defineProperty for methods too Using code from Ron from his upcoming refactor of the factory functions. --- src/compiler/factory.ts | 48 ++++++++++++++++++- src/compiler/transformers/classFields.ts | 17 +++---- src/compiler/transformers/es2015.ts | 21 ++++---- src/compiler/types.ts | 10 ++++ .../reference/accessorsOverrideProperty7.js | 7 ++- .../baselines/reference/definePropertyES5.js | 32 +++++++++++++ .../reference/definePropertyES5.symbols | 14 ++++++ .../reference/definePropertyES5.types | 15 ++++++ .../reference/definePropertyOutputES3.js | 7 ++- .../reference/propertyOverridesAccessors.js | 21 ++++++-- .../reference/propertyOverridesAccessors4.js | 7 ++- .../definePropertyES5.ts | 7 +++ 12 files changed, 179 insertions(+), 27 deletions(-) create mode 100644 tests/baselines/reference/definePropertyES5.js create mode 100644 tests/baselines/reference/definePropertyES5.symbols create mode 100644 tests/baselines/reference/definePropertyES5.types create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyES5.ts diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 033299cd587f6..20887c1e0bd16 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -484,6 +484,47 @@ namespace ts { return node; } + function createMethodCall(object: Expression, methodName: string | Identifier, argumentsList: readonly Expression[]) { + return createCall( + createPropertyAccess(object, asName(methodName)), + /*typeArguments*/ undefined, + argumentsList + ); + } + + function createGlobalMethodCall(globalObjectName: string, methodName: string, argumentsList: readonly Expression[]) { + return createMethodCall(createIdentifier(globalObjectName), methodName, argumentsList); + } + + /* @internal */ + export function createObjectDefinePropertyCall(target: Expression, propertyName: string | Expression, attributes: Expression) { + return createGlobalMethodCall("Object", "defineProperty", [target, asExpression(propertyName), attributes]); + } + + function tryAddPropertyAssignment(properties: Push, propertyName: string, expression: Expression | undefined) { + if (expression) { + properties.push(createPropertyAssignment(propertyName, expression)); + return true; + } + return false; + } + + /* @internal */ + export function createPropertyDescriptor(attributes: PropertyDescriptorAttributes, singleLine?: boolean) { + const properties: PropertyAssignment[] = []; + tryAddPropertyAssignment(properties, "enumerable", asExpression(attributes.enumerable)); + tryAddPropertyAssignment(properties, "configurable", asExpression(attributes.configurable)); + + let isData = tryAddPropertyAssignment(properties, "writable", asExpression(attributes.writable)); + isData = tryAddPropertyAssignment(properties, "value", attributes.value) || isData; + + let isAccessor = tryAddPropertyAssignment(properties, "get", attributes.get); + isAccessor = tryAddPropertyAssignment(properties, "set", attributes.set) || isAccessor; + + Debug.assert(!(isData && isAccessor), "A PropertyDescriptor may not be both an accessor descriptor and a data descriptor."); + return createObjectLiteral(properties, !singleLine); + } + export function updateMethod( node: MethodDeclaration, decorators: readonly Decorator[] | undefined, @@ -3136,8 +3177,11 @@ namespace ts { return isString(name) ? createIdentifier(name) : name; } - function asExpression(value: string | number | Expression) { - return isString(value) || typeof value === "number" ? createLiteral(value) : value; + function asExpression(value: string | number | boolean | T): T | StringLiteral | NumericLiteral | BooleanLiteral { + return typeof value === "string" ? createStringLiteral(value) : + typeof value === "number" ? createNumericLiteral(""+value) : + typeof value === "boolean" ? value ? createTrue() : createFalse() : + value; } function asNodeArray(array: readonly T[]): NodeArray; diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 616fe9a7e9ac4..7887103c46d36 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -424,26 +424,21 @@ namespace ts { const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) ? updateComputedPropertyName(property.name, getGeneratedNameForNode(property.name)) : property.name; + const initializer = property.initializer || emitAssignment ? visitNode(property.initializer, visitor, isExpression) : createVoidZero(); if (emitAssignment) { const memberAccess = createMemberAccessForPropertyName(receiver, propertyName, /*location*/ propertyName); return createAssignment(memberAccess, initializer); } else { - return createObjectDefineProperty(receiver, propertyName, initializer); + const name = isComputedPropertyName(propertyName) ? propertyName.expression + : isIdentifier(propertyName) ? createStringLiteral(unescapeLeadingUnderscores(propertyName.escapedText)) + : propertyName; + const descriptor = createPropertyDescriptor({ value: initializer, configurable: true, writable: true, enumerable: true }); + return createObjectDefinePropertyCall(receiver, name, descriptor); } } - function createObjectDefineProperty(target: Expression, name: PropertyName, initializer: Expression) { - const e = isComputedPropertyName(name) ? name.expression - : isIdentifier(name) ? createStringLiteral(unescapeLeadingUnderscores(name.escapedText)) - : name; - return createCall( - createPropertyAccess(createIdentifier("Object"), createIdentifier("defineProperty")), - /*typeArguments*/ undefined, - [target, e, createObjectLiteral([createPropertyAssignment("value", initializer)])]); - } - function enableSubstitutionForClassAliases() { if ((enabledSubstitutions & ClassPropertySubstitutionFlags.ClassAliases) === 0) { enabledSubstitutions |= ClassPropertySubstitutionFlags.ClassAliases; diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 2a50943cb8082..2684b1acdd554 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -1591,17 +1591,22 @@ namespace ts { function transformClassMethodDeclarationToStatement(receiver: LeftHandSideExpression, member: MethodDeclaration, container: Node) { const commentRange = getCommentRange(member); const sourceMapRange = getSourceMapRange(member); - const memberName = createMemberAccessForPropertyName(receiver, visitNode(member.name, visitor, isPropertyName), /*location*/ member.name); const memberFunction = transformFunctionLikeToExpression(member, /*location*/ member, /*name*/ undefined, container); + let e: Expression; + if (context.getCompilerOptions().useDefineForClassFields) { + const propertyName = visitNode(member.name, visitor, isPropertyName); + const name = isComputedPropertyName(propertyName) ? propertyName.expression + : isIdentifier(propertyName) ? createStringLiteral(unescapeLeadingUnderscores(propertyName.escapedText)) + : propertyName; + e = createObjectDefinePropertyCall(receiver, name, createPropertyDescriptor({ value: memberFunction, enumerable: false, writable: true, configurable: true })); + } + else { + const memberName = createMemberAccessForPropertyName(receiver, visitNode(member.name, visitor, isPropertyName), /*location*/ member.name); + e = createAssignment(memberName, memberFunction); + } setEmitFlags(memberFunction, EmitFlags.NoComments); setSourceMapRange(memberFunction, sourceMapRange); - - const statement = setTextRange( - createExpressionStatement( - createAssignment(memberName, memberFunction) - ), - /*location*/ member - ); + const statement = setTextRange(createExpressionStatement(e), /*location*/ member); setOriginalNode(statement, member); setCommentRange(statement, commentRange); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e6b3ab3411273..e65a1c99645ec 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5494,6 +5494,16 @@ namespace ts { readonly redirectTargetsMap: RedirectTargetsMap; } + /* @internal */ + export interface PropertyDescriptorAttributes { + enumerable?: boolean | Expression; + configurable?: boolean | Expression; + writable?: boolean | Expression; + value?: Expression; + get?: Expression; + set?: Expression; + } + export interface TransformationContext { /*@internal*/ getEmitResolver(): EmitResolver; /*@internal*/ getEmitHost(): EmitHost; diff --git a/tests/baselines/reference/accessorsOverrideProperty7.js b/tests/baselines/reference/accessorsOverrideProperty7.js index 55663405b7436..5c5b0de250708 100644 --- a/tests/baselines/reference/accessorsOverrideProperty7.js +++ b/tests/baselines/reference/accessorsOverrideProperty7.js @@ -23,7 +23,12 @@ var __extends = (this && this.__extends) || (function () { })(); var A = /** @class */ (function () { function A() { - Object.defineProperty(this, "p", { value: 'yep' }); + Object.defineProperty(this, "p", { + enumerable: true, + configurable: true, + writable: true, + value: 'yep' + }); } return A; }()); diff --git a/tests/baselines/reference/definePropertyES5.js b/tests/baselines/reference/definePropertyES5.js new file mode 100644 index 0000000000000..8bbd5083c06d4 --- /dev/null +++ b/tests/baselines/reference/definePropertyES5.js @@ -0,0 +1,32 @@ +//// [definePropertyES5.ts] +class A { + a = 12 + b + m() { } +} + + +//// [definePropertyES5.js] +var A = /** @class */ (function () { + function A() { + Object.defineProperty(this, "a", { + enumerable: true, + configurable: true, + writable: true, + value: 12 + }); + Object.defineProperty(this, "b", { + enumerable: true, + configurable: true, + writable: true, + value: void 0 + }); + } + Object.defineProperty(A.prototype, "m", { + enumerable: false, + configurable: true, + writable: true, + value: function () { } + }); + return A; +}()); diff --git a/tests/baselines/reference/definePropertyES5.symbols b/tests/baselines/reference/definePropertyES5.symbols new file mode 100644 index 0000000000000..d678f3abde431 --- /dev/null +++ b/tests/baselines/reference/definePropertyES5.symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyES5.ts === +class A { +>A : Symbol(A, Decl(definePropertyES5.ts, 0, 0)) + + a = 12 +>a : Symbol(A.a, Decl(definePropertyES5.ts, 0, 9)) + + b +>b : Symbol(A.b, Decl(definePropertyES5.ts, 1, 10)) + + m() { } +>m : Symbol(A.m, Decl(definePropertyES5.ts, 2, 5)) +} + diff --git a/tests/baselines/reference/definePropertyES5.types b/tests/baselines/reference/definePropertyES5.types new file mode 100644 index 0000000000000..66705c3afd61e --- /dev/null +++ b/tests/baselines/reference/definePropertyES5.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyES5.ts === +class A { +>A : A + + a = 12 +>a : number +>12 : 12 + + b +>b : any + + m() { } +>m : () => void +} + diff --git a/tests/baselines/reference/definePropertyOutputES3.js b/tests/baselines/reference/definePropertyOutputES3.js index 1986c6aed6fd7..038a8818e0fda 100644 --- a/tests/baselines/reference/definePropertyOutputES3.js +++ b/tests/baselines/reference/definePropertyOutputES3.js @@ -7,7 +7,12 @@ class A { //// [definePropertyOutputES3.js] var A = /** @class */ (function () { function A() { - Object.defineProperty(this, "a", { value: 12 }); + Object.defineProperty(this, "a", { + enumerable: true, + configurable: true, + writable: true, + value: 12 + }); } return A; }()); diff --git a/tests/baselines/reference/propertyOverridesAccessors.js b/tests/baselines/reference/propertyOverridesAccessors.js index cb5882ab028bd..d9cc40acc6f39 100644 --- a/tests/baselines/reference/propertyOverridesAccessors.js +++ b/tests/baselines/reference/propertyOverridesAccessors.js @@ -22,12 +22,22 @@ class A { class B extends A { constructor() { super(...arguments); - Object.defineProperty(this, "p", { value: 'yep' }); // error + Object.defineProperty(this, "p", { + enumerable: true, + configurable: true, + writable: true, + value: 'yep' + }); // error } } class C { constructor() { - Object.defineProperty(this, "_secret", { value: 11 }); + Object.defineProperty(this, "_secret", { + enumerable: true, + configurable: true, + writable: true, + value: 11 + }); } get p() { return this._secret; } set p(value) { this._secret = value; } @@ -35,6 +45,11 @@ class C { class D extends C { constructor() { super(...arguments); - Object.defineProperty(this, "p", { value: 101 }); // error + Object.defineProperty(this, "p", { + enumerable: true, + configurable: true, + writable: true, + value: 101 + }); // error } } diff --git a/tests/baselines/reference/propertyOverridesAccessors4.js b/tests/baselines/reference/propertyOverridesAccessors4.js index c52ac26ab3e1a..1c284e6aa497c 100644 --- a/tests/baselines/reference/propertyOverridesAccessors4.js +++ b/tests/baselines/reference/propertyOverridesAccessors4.js @@ -26,7 +26,12 @@ var Lion = /** @class */ (function (_super) { __extends(Lion, _super); function Lion() { var _this = _super !== null && _super.apply(this, arguments) || this; - Object.defineProperty(_this, "sound", { value: 'RAWR!' }); // error here + Object.defineProperty(_this, "sound", { + enumerable: true, + configurable: true, + writable: true, + value: 'RAWR!' + }); // error here return _this; } return Lion; diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyES5.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyES5.ts new file mode 100644 index 0000000000000..8e818c0e8dfe4 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyES5.ts @@ -0,0 +1,7 @@ +// @target: es5 +// @useDefineForClassFields: true +class A { + a = 12 + b + m() { } +} From 5ea2bc1658c4bce3b3a70910f93052499f840ff1 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 23 Sep 2019 11:36:00 -0700 Subject: [PATCH 40/44] Update slow baselines --- .../reference/commentsInheritance.errors.txt | 159 ------------------ .../reference/parserAstSpans1.errors.txt | 8 +- .../reference/parserRealSource11.errors.txt | 8 +- .../reference/parserharness.errors.txt | 14 +- ...AccessibleWithinNestedSubclass1.errors.txt | 5 +- ...opertyAccessibleWithinSubclass2.errors.txt | 5 +- ...sOfTypeParameterWithConstraints.errors.txt | 89 +--------- 7 files changed, 6 insertions(+), 282 deletions(-) delete mode 100644 tests/baselines/reference/commentsInheritance.errors.txt diff --git a/tests/baselines/reference/commentsInheritance.errors.txt b/tests/baselines/reference/commentsInheritance.errors.txt deleted file mode 100644 index 08e02a19b2dcb..0000000000000 --- a/tests/baselines/reference/commentsInheritance.errors.txt +++ /dev/null @@ -1,159 +0,0 @@ -tests/cases/compiler/commentsInheritance.ts(90,12): error TS2612: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/compiler/commentsInheritance.ts(98,12): error TS2612: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. - - -==== tests/cases/compiler/commentsInheritance.ts (2 errors) ==== - /** i1 is interface with properties*/ - interface i1 { - /** i1_p1*/ - i1_p1: number; - /** i1_f1*/ - i1_f1(): void; - /** i1_l1*/ - i1_l1: () => void; - // il_nc_p1 - i1_nc_p1: number; - i1_nc_f1(): void; - i1_nc_l1: () => void; - p1: number; - f1(): void; - l1: () => void; - nc_p1: number; - nc_f1(): void; - nc_l1: () => void; - } - class c1 implements i1 { - public i1_p1: number; - // i1_f1 - public i1_f1() { - } - public i1_l1: () => void; - public i1_nc_p1: number; - public i1_nc_f1() { - } - public i1_nc_l1: () => void; - /** c1_p1*/ - public p1: number; - /** c1_f1*/ - public f1() { - } - /** c1_l1*/ - public l1: () => void; - /** c1_nc_p1*/ - public nc_p1: number; - /** c1_nc_f1*/ - public nc_f1() { - } - /** c1_nc_l1*/ - public nc_l1: () => void; - } - var i1_i: i1; - var c1_i = new c1(); - // assign to interface - i1_i = c1_i; - class c2 { - /** c2 c2_p1*/ - public c2_p1: number; - /** c2 c2_f1*/ - public c2_f1() { - } - /** c2 c2_prop*/ - public get c2_prop() { - return 10; - } - public c2_nc_p1: number; - public c2_nc_f1() { - } - public get c2_nc_prop() { - return 10; - } - /** c2 p1*/ - public p1: number; - /** c2 f1*/ - public f1() { - } - /** c2 prop*/ - public get prop() { - return 10; - } - public nc_p1: number; - public nc_f1() { - } - public get nc_prop() { - return 10; - } - /** c2 constructor*/ - constructor(a: number) { - this.c2_p1 = a; - } - } - class c3 extends c2 { - constructor() { - super(10); - } - /** c3 p1*/ - public p1: number; - ~~ -!!! error TS2612: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. - /** c3 f1*/ - public f1() { - } - /** c3 prop*/ - public get prop() { - return 10; - } - public nc_p1: number; - ~~~~~ -!!! error TS2612: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. - public nc_f1() { - } - public get nc_prop() { - return 10; - } - } - var c2_i = new c2(10); - var c3_i = new c3(); - // assign - c2_i = c3_i; - class c4 extends c2 { - } - var c4_i = new c4(10); - interface i2 { - /** i2_p1*/ - i2_p1: number; - /** i2_f1*/ - i2_f1(): void; - /** i2_l1*/ - i2_l1: () => void; - // i2_nc_p1 - i2_nc_p1: number; - i2_nc_f1(): void; - i2_nc_l1: () => void; - /** i2 p1*/ - p1: number; - /** i2 f1*/ - f1(): void; - /** i2 l1*/ - l1: () => void; - nc_p1: number; - nc_f1(): void; - nc_l1: () => void; - } - interface i3 extends i2 { - /** i3 p1 */ - p1: number; - /** - * i3 f1 - */ - f1(): void; - /** i3 l1*/ - l1: () => void; - nc_p1: number; - nc_f1(): void; - nc_l1: () => void; - } - var i2_i: i2; - var i3_i: i3; - // assign to interface - i2_i = i3_i; - \ No newline at end of file diff --git a/tests/baselines/reference/parserAstSpans1.errors.txt b/tests/baselines/reference/parserAstSpans1.errors.txt index e97f2f249f8c1..648929e974e3e 100644 --- a/tests/baselines/reference/parserAstSpans1.errors.txt +++ b/tests/baselines/reference/parserAstSpans1.errors.txt @@ -3,14 +3,12 @@ tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(85,16): error TS10 tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(94,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(100,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(111,25): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. -tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(114,12): error TS2612: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(119,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(122,12): error TS2612: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(125,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(217,24): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. -==== tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts (10 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts (8 errors) ==== /** i1 is interface with properties*/ interface i1 { /** i1_p1*/ @@ -135,8 +133,6 @@ tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(217,24): error TS2 } /** c3 p1*/ public p1: number; - ~~ -!!! error TS2612: Property 'p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. /** c3 f1*/ public f1() { } @@ -147,8 +143,6 @@ tests/cases/conformance/parser/ecmascript5/parserAstSpans1.ts(217,24): error TS2 return 10; } public nc_p1: number; - ~~~~~ -!!! error TS2612: Property 'nc_p1' will overwrite the base property in 'c2'. Add a 'declare' modifier or an initializer to avoid this. public nc_f1() { } public get nc_prop() { diff --git a/tests/baselines/reference/parserRealSource11.errors.txt b/tests/baselines/reference/parserRealSource11.errors.txt index af217668adef1..bb0a52e0a9997 100644 --- a/tests/baselines/reference/parserRealSource11.errors.txt +++ b/tests/baselines/reference/parserRealSource11.errors.txt @@ -288,8 +288,6 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1095,29): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1098,56): error TS2304: Cannot find name 'FncFlags'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1098,79): error TS2304: Cannot find name 'FncFlags'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1111,33): error TS2304: Cannot find name 'IFileReference'. -tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1120,16): error TS2612: Property 'vars' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1121,16): error TS2612: Property 'scopes' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1127,84): error TS2304: Cannot find name 'NodeType'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1132,36): error TS2304: Cannot find name 'TypeFlow'. tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1144,42): error TS2304: Cannot find name 'NodeType'. @@ -513,7 +511,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,30): error tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error TS2304: Cannot find name 'TokenID'. -==== tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts (513 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts (511 errors) ==== // Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. @@ -2214,11 +2212,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error public leftCurlyCount = 0; public rightCurlyCount = 0; public vars: ASTList; - ~~~~ -!!! error TS2612: Property 'vars' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. public scopes: ASTList; - ~~~~~~ -!!! error TS2612: Property 'scopes' will overwrite the base property in 'FuncDecl'. Add a 'declare' modifier or an initializer to avoid this. // Remember if the script contains Unicode chars, that is needed when generating code for this script object to decide the output file correct encoding. public containsUnicodeChar = false; public containsUnicodeCharInComment = false; diff --git a/tests/baselines/reference/parserharness.errors.txt b/tests/baselines/reference/parserharness.errors.txt index a62a8cc718884..990fa5816c787 100644 --- a/tests/baselines/reference/parserharness.errors.txt +++ b/tests/baselines/reference/parserharness.errors.txt @@ -12,10 +12,6 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(347,13): e tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(351,17): error TS2662: Cannot find name 'errorHandlerStack'. Did you mean the static member 'Runnable.errorHandlerStack'? tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(354,17): error TS2662: Cannot find name 'errorHandlerStack'. Did you mean the static member 'Runnable.errorHandlerStack'? tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(354,35): error TS2662: Cannot find name 'errorHandlerStack'. Did you mean the static member 'Runnable.errorHandlerStack'? -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(359,16): error TS2612: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(360,16): error TS2612: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(402,16): error TS2612: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(403,16): error TS2612: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(691,50): error TS2304: Cannot find name 'ITextWriter'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(716,47): error TS2503: Cannot find namespace 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(721,62): error TS2304: Cannot find name 'ITextWriter'. @@ -114,7 +110,7 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(1787,68): tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): error TS2304: Cannot find name 'Diff'. -==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (114 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (110 errors) ==== // // Copyright (c) Microsoft Corporation. All rights reserved. // @@ -502,11 +498,7 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): } export class TestCase extends Runnable { public description: string; - ~~~~~~~~~~~ -!!! error TS2612: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. public block; - ~~~~~ -!!! error TS2612: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. constructor(description: string, block: any) { super(description, block); @@ -549,11 +541,7 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): export class Scenario extends Runnable { public description: string; - ~~~~~~~~~~~ -!!! error TS2612: Property 'description' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. public block; - ~~~~~ -!!! error TS2612: Property 'block' will overwrite the base property in 'Runnable'. Add a 'declare' modifier or an initializer to avoid this. constructor(description: string, block: any) { super(description, block); diff --git a/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt b/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt index 5ea3f18aa0cfa..2d882681d7269 100644 --- a/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt +++ b/tests/baselines/reference/protectedClassPropertyAccessibleWithinNestedSubclass1.errors.txt @@ -6,7 +6,6 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(52,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(53,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(55,20): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. -tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(63,15): error TS2612: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(73,19): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(74,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(75,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. @@ -22,7 +21,7 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts(114,4): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses. -==== tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts (22 errors) ==== +==== tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinNestedSubclass1.ts (21 errors) ==== class Base { protected x: string; method() { @@ -102,8 +101,6 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce class Derived3 extends Derived1 { protected x: string; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. method3() { class D { method3d() { diff --git a/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass2.errors.txt b/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass2.errors.txt index 9ea7fbed191c4..996d62c165212 100644 --- a/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass2.errors.txt +++ b/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass2.errors.txt @@ -6,7 +6,6 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(42,11): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(43,12): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(45,12): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses. -tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(51,15): error TS2612: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(59,11): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(60,12): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(61,12): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'. @@ -22,7 +21,7 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(94,4): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses. -==== tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts (22 errors) ==== +==== tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts (21 errors) ==== class Base { protected x: string; method() { @@ -90,8 +89,6 @@ tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAcce class Derived3 extends Derived1 { protected x: string; - ~ -!!! error TS2612: Property 'x' will overwrite the base property in 'Derived1'. Add a 'declare' modifier or an initializer to avoid this. method3() { var b: Base; var d1: Derived1; diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt index 6376af99434dd..5fe0186e04a1b 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt @@ -1,39 +1,21 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(9,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(14,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(24,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(33,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(38,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(43,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. Type 'V' is not assignable to type 'T'. 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(55,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(60,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2416: Property 'foo' in type 'D11' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'T'. 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2416: Property 'foo' in type 'D12' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'U'. 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint '{}'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(77,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(85,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(90,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(95,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(100,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(107,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2416: Property 'foo' in type 'D19' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. @@ -42,44 +24,33 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. Type 'Date' is not assignable to type 'T'. 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(117,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(122,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(129,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2416: Property 'foo' in type 'D23' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'T'. 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. Type 'Date' is not assignable to type 'T'. 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2416: Property 'foo' in type 'D24' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'U'. 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. Type 'Date' is not assignable to type 'U'. 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(144,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(151,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2416: Property 'foo' in type 'D27' is not assignable to the same property in base type 'C3'. Type 'Date' is not assignable to type 'T'. 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2416: Property 'foo' in type 'D28' is not assignable to the same property in base type 'C3'. Type 'Date' is not assignable to type 'U'. 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2416: Property 'foo' in type 'D29' is not assignable to the same property in base type 'C3'. Type 'Date' is not assignable to type 'V'. 'Date' is assignable to the constraint of type 'V', but 'V' could be instantiated with a different subtype of constraint 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts (49 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts (20 errors) ==== // checking whether other types are subtypes of type parameters with constraints class C3 { @@ -89,15 +60,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D1 extends C3 { [x: string]: T; foo: T; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D2 extends C3 { [x: string]: U; foo: T; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D3 extends C3 { @@ -109,15 +76,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'U' is not assignable to type 'T'. !!! error TS2416: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D4 extends C3 { [x: string]: U; foo: U; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } @@ -127,22 +90,16 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D5 extends C3 { [x: string]: T; foo: T; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D6 extends C3 { [x: string]: U; foo: T; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D7 extends C3 { [x: string]: V; foo: T; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if U is a subtype of T, U, V @@ -158,22 +115,16 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D9 extends C3 { [x: string]: U; foo: U; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D10 extends C3 { [x: string]: V; foo: U; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if V is a subtype of T, U, V @@ -187,8 +138,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D11' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'V' is not assignable to type 'T'. !!! error TS2416: 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D12 extends C3 { @@ -200,15 +149,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D12' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'V' is not assignable to type 'U'. !!! error TS2416: 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint '{}'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D13 extends C3 { [x: string]: V; foo: V; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // Date > V > U > T @@ -217,29 +162,21 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D14 extends C3 { [x: string]: Date; foo: T; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D15 extends C3 { [x: string]: T; foo: T; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D16 extends C3 { [x: string]: U; foo: T; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D17 extends C3 { [x: string]: V; foo: T; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if U is a subtype of T, U, V, Date @@ -247,8 +184,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D18 extends C3 { [x: string]: Date; foo: T; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D19 extends C3 { @@ -264,22 +199,16 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. !!! error TS2416: Type 'Date' is not assignable to type 'T'. !!! error TS2416: 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D20 extends C3 { [x: string]: U; foo: U; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D21 extends C3 { [x: string]: V; foo: U; - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if V is a subtype of T, U, V, Date @@ -287,8 +216,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D22 extends C3 { [x: string]: Date; foo: T; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D23 extends C3 { @@ -302,8 +229,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. !!! error TS2416: Type 'Date' is not assignable to type 'T'. !!! error TS2416: 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D24 extends C3 { @@ -317,15 +242,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. !!! error TS2416: Type 'Date' is not assignable to type 'U'. !!! error TS2416: 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D25 extends C3 { [x: string]: V; foo: V; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } // test if Date is a subtype of T, U, V, Date @@ -333,8 +254,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class D26 extends C3 { [x: string]: Date; foo: Date; // ok - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D27 extends C3 { @@ -346,8 +265,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D27' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'Date' is not assignable to type 'T'. !!! error TS2416: 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D28 extends C3 { @@ -359,8 +276,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D28' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'Date' is not assignable to type 'U'. !!! error TS2416: 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } class D29 extends C3 { @@ -372,6 +287,4 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2416: Property 'foo' in type 'D29' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'Date' is not assignable to type 'V'. !!! error TS2416: 'Date' is assignable to the constraint of type 'V', but 'V' could be instantiated with a different subtype of constraint 'Date'. - ~~~ -!!! error TS2612: Property 'foo' will overwrite the base property in 'C3'. Add a 'declare' modifier or an initializer to avoid this. } \ No newline at end of file From 088daa8f1bda22909fc9bbfaf3914b7be646df3c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 23 Sep 2019 12:50:25 -0700 Subject: [PATCH 41/44] Improve error message --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- src/services/codefixes/addMissingDeclareProperty.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c4e6775090a09..6383fc29c3c2f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29545,7 +29545,7 @@ namespace ts { || !isIdentifier(propName) || !strictNullChecks || !isPropertyInitializedInConstructor(propName, type, constructor)) { - const errorMessage = Diagnostics.Property_0_will_overwrite_the_base_property_in_1_Add_a_declare_modifier_or_an_initializer_to_avoid_this; + const errorMessage = Diagnostics.Property_0_will_overwrite_the_base_property_in_1_If_this_is_intentional_add_an_initializer_Otherwise_add_a_declare_modifier_or_remove_the_redundant_declaration; error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, symbolToString(base), typeToString(baseType)); } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index eeb6b735630e1..91633099e6e50 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2212,7 +2212,7 @@ "category": "Error", "code": 2611 }, - "Property '{0}' will overwrite the base property in '{1}'. Add a 'declare' modifier or an initializer to avoid this.": { + "Property '{0}' will overwrite the base property in '{1}'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.": { "category": "Error", "code": 2612 }, diff --git a/src/services/codefixes/addMissingDeclareProperty.ts b/src/services/codefixes/addMissingDeclareProperty.ts index 002357239ead2..e08929b9dd132 100644 --- a/src/services/codefixes/addMissingDeclareProperty.ts +++ b/src/services/codefixes/addMissingDeclareProperty.ts @@ -2,7 +2,7 @@ namespace ts.codefix { const fixId = "addMissingDeclareProperty"; const errorCodes = [ - Diagnostics.Property_0_will_overwrite_the_base_property_in_1_Add_a_declare_modifier_or_an_initializer_to_avoid_this.code, + Diagnostics.Property_0_will_overwrite_the_base_property_in_1_If_this_is_intentional_add_an_initializer_Otherwise_add_a_declare_modifier_or_remove_the_redundant_declaration.code, ]; registerCodeFix({ From e600ebeefdfdfa4e88fdfc33b012c289ffe34763 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 23 Sep 2019 12:54:02 -0700 Subject: [PATCH 42/44] Update src/compiler/transformers/utilities.ts Co-Authored-By: Andrew Branch --- src/compiler/transformers/utilities.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index 90aa142192d3e..e2029ff7b602e 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -307,7 +307,7 @@ namespace ts { } /** - * Is a class element is either a static or an instance property declaration with an initializer? + * Is a class element either a static or an instance property declaration with an initializer? * * @param member The class element node. * @param isStatic A value indicating whether the member should be a static or instance member. From 6e3bf5ce800d693bd34b66307df5636afa676f61 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 23 Sep 2019 13:19:41 -0700 Subject: [PATCH 43/44] Add test of computed properties --- .../baselines/reference/definePropertyES5.js | 18 ++++++++++++++++++ .../reference/definePropertyES5.symbols | 19 +++++++++++++++---- .../reference/definePropertyES5.types | 14 ++++++++++++++ .../definePropertyES5.ts | 3 +++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/tests/baselines/reference/definePropertyES5.js b/tests/baselines/reference/definePropertyES5.js index 8bbd5083c06d4..a0bc4a64db48a 100644 --- a/tests/baselines/reference/definePropertyES5.js +++ b/tests/baselines/reference/definePropertyES5.js @@ -1,12 +1,17 @@ //// [definePropertyES5.ts] +var x: "p" = "p" class A { a = 12 b + ["computed"] = 13 + ;[x] = 14 m() { } } //// [definePropertyES5.js] +var _a; +var x = "p"; var A = /** @class */ (function () { function A() { Object.defineProperty(this, "a", { @@ -21,6 +26,18 @@ var A = /** @class */ (function () { writable: true, value: void 0 }); + Object.defineProperty(this, "computed", { + enumerable: true, + configurable: true, + writable: true, + value: 13 + }); + Object.defineProperty(this, _a, { + enumerable: true, + configurable: true, + writable: true, + value: 14 + }); } Object.defineProperty(A.prototype, "m", { enumerable: false, @@ -30,3 +47,4 @@ var A = /** @class */ (function () { }); return A; }()); +_a = x; diff --git a/tests/baselines/reference/definePropertyES5.symbols b/tests/baselines/reference/definePropertyES5.symbols index d678f3abde431..f9afa02868793 100644 --- a/tests/baselines/reference/definePropertyES5.symbols +++ b/tests/baselines/reference/definePropertyES5.symbols @@ -1,14 +1,25 @@ === tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyES5.ts === +var x: "p" = "p" +>x : Symbol(x, Decl(definePropertyES5.ts, 0, 3)) + class A { ->A : Symbol(A, Decl(definePropertyES5.ts, 0, 0)) +>A : Symbol(A, Decl(definePropertyES5.ts, 0, 16)) a = 12 ->a : Symbol(A.a, Decl(definePropertyES5.ts, 0, 9)) +>a : Symbol(A.a, Decl(definePropertyES5.ts, 1, 9)) b ->b : Symbol(A.b, Decl(definePropertyES5.ts, 1, 10)) +>b : Symbol(A.b, Decl(definePropertyES5.ts, 2, 10)) + + ["computed"] = 13 +>["computed"] : Symbol(A["computed"], Decl(definePropertyES5.ts, 3, 5)) +>"computed" : Symbol(A["computed"], Decl(definePropertyES5.ts, 3, 5)) + + ;[x] = 14 +>[x] : Symbol(A[x], Decl(definePropertyES5.ts, 5, 5)) +>x : Symbol(x, Decl(definePropertyES5.ts, 0, 3)) m() { } ->m : Symbol(A.m, Decl(definePropertyES5.ts, 2, 5)) +>m : Symbol(A.m, Decl(definePropertyES5.ts, 5, 13)) } diff --git a/tests/baselines/reference/definePropertyES5.types b/tests/baselines/reference/definePropertyES5.types index 66705c3afd61e..3f82787c13a34 100644 --- a/tests/baselines/reference/definePropertyES5.types +++ b/tests/baselines/reference/definePropertyES5.types @@ -1,4 +1,8 @@ === tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyES5.ts === +var x: "p" = "p" +>x : "p" +>"p" : "p" + class A { >A : A @@ -9,6 +13,16 @@ class A { b >b : any + ["computed"] = 13 +>["computed"] : number +>"computed" : "computed" +>13 : 13 + + ;[x] = 14 +>[x] : number +>x : "p" +>14 : 14 + m() { } >m : () => void } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyES5.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyES5.ts index 8e818c0e8dfe4..73e1ee515d1d8 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyES5.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/definePropertyES5.ts @@ -1,7 +1,10 @@ // @target: es5 // @useDefineForClassFields: true +var x: "p" = "p" class A { a = 12 b + ["computed"] = 13 + ;[x] = 14 m() { } } From ba876cf59d6d2b8151a2f7e39b47d27770f780a4 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 23 Sep 2019 13:23:40 -0700 Subject: [PATCH 44/44] Remove done TODO --- src/compiler/transformers/classFields.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 7887103c46d36..1424d29336945 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -46,10 +46,6 @@ namespace ts { function transformSourceFile(node: SourceFile) { const options = context.getCompilerOptions(); if (node.isDeclarationFile - // TODO: Need to test computed proeprties too - // [x] = 1 => Object.defineProperty(this, x, ...) - // -vs- - // [x] = 1 -> this[x] = 1 || options.useDefineForClassFields && options.target === ScriptTarget.ESNext) { return node; }