From 35d6e98e98f49de24ff7e443f589fc19fd9cfd2b Mon Sep 17 00:00:00 2001 From: vvakame Date: Thu, 30 Apr 2015 13:27:07 +0900 Subject: [PATCH 01/22] type narrowing by constructor signiture of interface --- src/compiler/checker.ts | 40 +++-- ...nstanceOfByConstructorSignature.errors.txt | 111 ++++++++++++++ ...rdsWithInstanceOfByConstructorSignature.js | 137 ++++++++++++++++++ ...rdsWithInstanceOfByConstructorSignature.ts | 89 ++++++++++++ 4 files changed, 368 insertions(+), 9 deletions(-) create mode 100644 tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt create mode 100644 tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js create mode 100644 tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 469ecf80c84..36f9bbb654b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5351,17 +5351,39 @@ module ts { } // Target type is type of prototype property let prototypeProperty = getPropertyOfType(rightType, "prototype"); - if (!prototypeProperty) { - return type; + if (prototypeProperty) { + let targetType = getTypeOfSymbol(prototypeProperty); + if (targetType !== anyType) { + // Narrow to target type if it is a subtype of current type + if (isTypeSubtypeOf(targetType, type)) { + return targetType; + } + // If current type is a union type, remove all constituents that aren't subtypes of target type + if (type.flags & TypeFlags.Union) { + return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, targetType))); + } + } } - let targetType = getTypeOfSymbol(prototypeProperty); - // Narrow to target type if it is a subtype of current type - if (isTypeSubtypeOf(targetType, type)) { - return targetType; + // Target type is type of constructor signiture + let constructorSignitures: Signature[]; + if (rightType.flags & TypeFlags.Interface) { + constructorSignitures = (rightType).declaredConstructSignatures; } - // If current type is a union type, remove all constituents that aren't subtypes of target type - if (type.flags & TypeFlags.Union) { - return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, targetType))); + if (rightType.flags & TypeFlags.Anonymous) { + constructorSignitures = (rightType).constructSignatures; + } + if (constructorSignitures) { + let constructorType = getUnionType(map(constructorSignitures, constructorSignature => { + if (constructorSignature.typeParameters && constructorSignature.typeParameters.length !== 0) { + // TODO convert type parameters to any or empty object types. e.g. Sample -> Sample or Sample<{}>. + } + return constructorSignature.resolvedReturnType; + })); + // Pickup type from union types + if (type.flags & TypeFlags.Union) { + return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, constructorType))); + } + return constructorType; } return type; } diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt new file mode 100644 index 00000000000..c7146541705 --- /dev/null +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt @@ -0,0 +1,111 @@ +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(12,10): error TS2339: Property 'bar' does not exist on type 'A'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(32,10): error TS2339: Property 'foo' does not exist on type '{}'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(33,10): error TS2339: Property 'foo' does not exist on type '{}'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(34,10): error TS2339: Property 'bar' does not exist on type '{}'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(63,10): error TS2339: Property 'bar2' does not exist on type 'C1'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(82,10): error TS2339: Property 'bar' does not exist on type 'D'. + + +==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts (6 errors) ==== + interface AConstructor { + new (): A; + } + interface A { + foo: string; + } + declare var A: AConstructor; + + var obj1: A | string; + if (obj1 instanceof A) { // narrowed to A. + obj1.foo; + obj1.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type 'A'. + } + + var obj2: any; + if (obj2 instanceof A) { // can't type narrowing from any. + obj2.foo; + obj2.bar; + } + + // with generics + interface BConstructor { + new (): B; + } + interface B { + foo: T; + } + declare var B: BConstructor; + + var obj3: B | A; + if (obj3 instanceof B) { // narrowed to B. + obj3.foo = "str"; + ~~~ +!!! error TS2339: Property 'foo' does not exist on type '{}'. + obj3.foo = 1; + ~~~ +!!! error TS2339: Property 'foo' does not exist on type '{}'. + obj3.bar = "str"; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type '{}'. + } + + var obj4: any; + if (obj4 instanceof B) { // can't type narrowing from any. + obj4.foo = "str"; + obj4.foo = 1; + obj4.bar = "str"; + } + + // has multiple constructor signature + interface CConstructor { + new (value: string): C1; + new (value: number): C2; + } + interface C1 { + foo: string; + bar1: number; + } + interface C2 { + foo: string; + bar2: number; + } + declare var C: CConstructor; + + var obj5: C1 | A; + if (obj5 instanceof C) { // narrowed to C1. + obj5.foo; + obj5.bar1; + obj5.bar2; + ~~~~ +!!! error TS2339: Property 'bar2' does not exist on type 'C1'. + } + + var obj6: any; + if (obj6 instanceof C) { // can't type narrowing from any. + obj6.foo; + obj6.bar1; + obj6.bar2; + } + + // with object type literal + interface D { + foo: string; + } + declare var D: { new (): D; }; + + var obj7: D | string; + if (obj7 instanceof D) { // narrowed to D. + obj7.foo; + obj7.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type 'D'. + } + + var obj8: any; + if (obj8 instanceof D) { // can't type narrowing from any. + obj8.foo; + obj8.bar; + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js new file mode 100644 index 00000000000..c795126b0ff --- /dev/null +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js @@ -0,0 +1,137 @@ +//// [typeGuardsWithInstanceOfByConstructorSignature.ts] +interface AConstructor { + new (): A; +} +interface A { + foo: string; +} +declare var A: AConstructor; + +var obj1: A | string; +if (obj1 instanceof A) { // narrowed to A. + obj1.foo; + obj1.bar; +} + +var obj2: any; +if (obj2 instanceof A) { // can't type narrowing from any. + obj2.foo; + obj2.bar; +} + +// with generics +interface BConstructor { + new (): B; +} +interface B { + foo: T; +} +declare var B: BConstructor; + +var obj3: B | A; +if (obj3 instanceof B) { // narrowed to B. + obj3.foo = "str"; + obj3.foo = 1; + obj3.bar = "str"; +} + +var obj4: any; +if (obj4 instanceof B) { // can't type narrowing from any. + obj4.foo = "str"; + obj4.foo = 1; + obj4.bar = "str"; +} + +// has multiple constructor signature +interface CConstructor { + new (value: string): C1; + new (value: number): C2; +} +interface C1 { + foo: string; + bar1: number; +} +interface C2 { + foo: string; + bar2: number; +} +declare var C: CConstructor; + +var obj5: C1 | A; +if (obj5 instanceof C) { // narrowed to C1. + obj5.foo; + obj5.bar1; + obj5.bar2; +} + +var obj6: any; +if (obj6 instanceof C) { // can't type narrowing from any. + obj6.foo; + obj6.bar1; + obj6.bar2; +} + +// with object type literal +interface D { + foo: string; +} +declare var D: { new (): D; }; + +var obj7: D | string; +if (obj7 instanceof D) { // narrowed to D. + obj7.foo; + obj7.bar; +} + +var obj8: any; +if (obj8 instanceof D) { // can't type narrowing from any. + obj8.foo; + obj8.bar; +} + + +//// [typeGuardsWithInstanceOfByConstructorSignature.js] +var obj1; +if (obj1 instanceof A) { + obj1.foo; + obj1.bar; +} +var obj2; +if (obj2 instanceof A) { + obj2.foo; + obj2.bar; +} +var obj3; +if (obj3 instanceof B) { + obj3.foo = "str"; + obj3.foo = 1; + obj3.bar = "str"; +} +var obj4; +if (obj4 instanceof B) { + obj4.foo = "str"; + obj4.foo = 1; + obj4.bar = "str"; +} +var obj5; +if (obj5 instanceof C) { + obj5.foo; + obj5.bar1; + obj5.bar2; +} +var obj6; +if (obj6 instanceof C) { + obj6.foo; + obj6.bar1; + obj6.bar2; +} +var obj7; +if (obj7 instanceof D) { + obj7.foo; + obj7.bar; +} +var obj8; +if (obj8 instanceof D) { + obj8.foo; + obj8.bar; +} diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts new file mode 100644 index 00000000000..b28d92e2c8e --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts @@ -0,0 +1,89 @@ +interface AConstructor { + new (): A; +} +interface A { + foo: string; +} +declare var A: AConstructor; + +var obj1: A | string; +if (obj1 instanceof A) { // narrowed to A. + obj1.foo; + obj1.bar; +} + +var obj2: any; +if (obj2 instanceof A) { // can't type narrowing from any. + obj2.foo; + obj2.bar; +} + +// with generics +interface BConstructor { + new (): B; +} +interface B { + foo: T; +} +declare var B: BConstructor; + +var obj3: B | A; +if (obj3 instanceof B) { // narrowed to B. + obj3.foo = "str"; + obj3.foo = 1; + obj3.bar = "str"; +} + +var obj4: any; +if (obj4 instanceof B) { // can't type narrowing from any. + obj4.foo = "str"; + obj4.foo = 1; + obj4.bar = "str"; +} + +// has multiple constructor signature +interface CConstructor { + new (value: string): C1; + new (value: number): C2; +} +interface C1 { + foo: string; + bar1: number; +} +interface C2 { + foo: string; + bar2: number; +} +declare var C: CConstructor; + +var obj5: C1 | A; +if (obj5 instanceof C) { // narrowed to C1. + obj5.foo; + obj5.bar1; + obj5.bar2; +} + +var obj6: any; +if (obj6 instanceof C) { // can't type narrowing from any. + obj6.foo; + obj6.bar1; + obj6.bar2; +} + +// with object type literal +interface D { + foo: string; +} +declare var D: { new (): D; }; + +var obj7: D | string; +if (obj7 instanceof D) { // narrowed to D. + obj7.foo; + obj7.bar; +} + +var obj8: any; +if (obj8 instanceof D) { // can't type narrowing from any. + obj8.foo; + obj8.bar; +} From ab10d509f5368137af5c50e532616e1d0fb9e45a Mon Sep 17 00:00:00 2001 From: vvakame Date: Sat, 2 May 2015 15:27:06 +0900 Subject: [PATCH 02/22] support instantiate signature, it has type parameters. --- src/compiler/checker.ts | 20 +-- ...nstanceOfByConstructorSignature.errors.txt | 137 ++++++++++++++-- ...rdsWithInstanceOfByConstructorSignature.js | 151 +++++++++++++++++- ...rdsWithInstanceOfByConstructorSignature.ts | 107 ++++++++++++- 4 files changed, 380 insertions(+), 35 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 36f9bbb654b..c864a8aa76a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5365,25 +5365,25 @@ module ts { } } // Target type is type of constructor signiture - let constructorSignitures: Signature[]; + let constructSignitures: Signature[]; if (rightType.flags & TypeFlags.Interface) { - constructorSignitures = (rightType).declaredConstructSignatures; + constructSignitures = (rightType).declaredConstructSignatures; } if (rightType.flags & TypeFlags.Anonymous) { - constructorSignitures = (rightType).constructSignatures; + constructSignitures = (rightType).constructSignatures; } - if (constructorSignitures) { - let constructorType = getUnionType(map(constructorSignitures, constructorSignature => { - if (constructorSignature.typeParameters && constructorSignature.typeParameters.length !== 0) { - // TODO convert type parameters to any or empty object types. e.g. Sample -> Sample or Sample<{}>. + if (constructSignitures) { + let instanceType = getUnionType(map(constructSignitures, constructSignature => { + if (constructSignature.typeParameters && constructSignature.typeParameters.length !== 0) { + constructSignature = instantiateSignature(constructSignature, createTypeMapper(constructSignature.typeParameters, map(constructSignature.typeParameters, _ => anyType)), true) } - return constructorSignature.resolvedReturnType; + return constructSignature.resolvedReturnType; })); // Pickup type from union types if (type.flags & TypeFlags.Union) { - return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, constructorType))); + return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, instanceType))); } - return constructorType; + return instanceType; } return type; } diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt index c7146541705..1816ef77fc2 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt @@ -1,12 +1,16 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(12,10): error TS2339: Property 'bar' does not exist on type 'A'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(32,10): error TS2339: Property 'foo' does not exist on type '{}'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(33,10): error TS2339: Property 'foo' does not exist on type '{}'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(34,10): error TS2339: Property 'bar' does not exist on type '{}'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(33,5): error TS2322: Type 'string' is not assignable to type 'number'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(34,10): error TS2339: Property 'bar' does not exist on type 'B'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(63,10): error TS2339: Property 'bar2' does not exist on type 'C1'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(82,10): error TS2339: Property 'bar' does not exist on type 'D'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(109,10): error TS2339: Property 'bar2' does not exist on type 'E1'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(131,11): error TS2339: Property 'foo' does not exist on type 'string | F'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(132,11): error TS2339: Property 'bar' does not exist on type 'string | F'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(157,11): error TS2339: Property 'foo2' does not exist on type 'G1'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(179,11): error TS2339: Property 'bar' does not exist on type 'H'. -==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts (6 errors) ==== +==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts (10 errors) ==== interface AConstructor { new (): A; } @@ -29,7 +33,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru obj2.bar; } - // with generics + // a construct signature with generics interface BConstructor { new (): B; } @@ -38,17 +42,15 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru } declare var B: BConstructor; - var obj3: B | A; - if (obj3 instanceof B) { // narrowed to B. - obj3.foo = "str"; - ~~~ -!!! error TS2339: Property 'foo' does not exist on type '{}'. + var obj3: B | string; + if (obj3 instanceof B) { // narrowed to B. obj3.foo = 1; - ~~~ -!!! error TS2339: Property 'foo' does not exist on type '{}'. + obj3.foo = "str"; + ~~~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. obj3.bar = "str"; ~~~ -!!! error TS2339: Property 'bar' does not exist on type '{}'. +!!! error TS2339: Property 'bar' does not exist on type 'B'. } var obj4: any; @@ -58,7 +60,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru obj4.bar = "str"; } - // has multiple constructor signature + // has multiple construct signature interface CConstructor { new (value: string): C1; new (value: number): C2; @@ -108,4 +110,111 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru obj8.foo; obj8.bar; } + + // a construct signature that returns a union type + interface EConstructor { + new (): E1 | E2; + } + interface E1 { + foo: string; + bar1: number; + } + interface E2 { + foo: string; + bar2: number; + } + declare var E: EConstructor; + + var obj9: E1 | A; + if (obj9 instanceof E) { // narrowed to E1. + obj9.foo; + obj9.bar1; + obj9.bar2; + ~~~~ +!!! error TS2339: Property 'bar2' does not exist on type 'E1'. + } + + var obj10: any; + if (obj10 instanceof E) { // can't type narrowing from any. + obj10.foo; + obj10.bar1; + obj10.bar2; + } + + // a construct signature that returns any + interface FConstructor { + new (): any; + } + interface F { + foo: string; + bar: number; + } + declare var F: FConstructor; + + var obj11: F | string; + if (obj11 instanceof F) { // can't type narrowing, construct signiture returns any. + obj11.foo; + ~~~ +!!! error TS2339: Property 'foo' does not exist on type 'string | F'. + obj11.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type 'string | F'. + } + + var obj12: any; + if (obj12 instanceof F) { // can't type narrowing from any. + obj12.foo; + obj12.bar; + } + + // a type with a prototype, it overrides the construct signiture + interface GConstructor { + prototype: G1; // high priority + new (): G2; // low priority + } + interface G1 { + foo1: number; + } + interface G2 { + foo2: boolean; + } + declare var G: GConstructor; + + var obj13: G1 | G2; + if (obj13 instanceof G) { // narrowed to G1. G1 is return type of prototype property. + obj13.foo1; + obj13.foo2; + ~~~~ +!!! error TS2339: Property 'foo2' does not exist on type 'G1'. + } + + var obj14: any; + if (obj14 instanceof G) { // can't type narrowing from any. + obj14.foo1; + obj14.foo2; + } + + // a type with a prototype that has any type + interface HConstructor { + prototype: any; // high priority, but any type is ignored. interface has implicit `prototype: any`. + new (): H; // low priority + } + interface H { + foo: number; + } + declare var H: HConstructor; + + var obj15: H | string; + if (obj15 instanceof H) { // narrowed to H. + obj15.foo; + obj15.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type 'H'. + } + + var obj16: any; + if (obj16 instanceof H) { // can't type narrowing from any. + obj16.foo1; + obj16.foo2; + } \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js index c795126b0ff..395a5e96e05 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js @@ -19,7 +19,7 @@ if (obj2 instanceof A) { // can't type narrowing from any. obj2.bar; } -// with generics +// a construct signature with generics interface BConstructor { new (): B; } @@ -28,10 +28,10 @@ interface B { } declare var B: BConstructor; -var obj3: B | A; -if (obj3 instanceof B) { // narrowed to B. - obj3.foo = "str"; +var obj3: B | string; +if (obj3 instanceof B) { // narrowed to B. obj3.foo = 1; + obj3.foo = "str"; obj3.bar = "str"; } @@ -42,7 +42,7 @@ if (obj4 instanceof B) { // can't type narrowing from any. obj4.bar = "str"; } -// has multiple constructor signature +// has multiple construct signature interface CConstructor { new (value: string): C1; new (value: number): C2; @@ -89,6 +89,103 @@ if (obj8 instanceof D) { // can't type narrowing from any. obj8.bar; } +// a construct signature that returns a union type +interface EConstructor { + new (): E1 | E2; +} +interface E1 { + foo: string; + bar1: number; +} +interface E2 { + foo: string; + bar2: number; +} +declare var E: EConstructor; + +var obj9: E1 | A; +if (obj9 instanceof E) { // narrowed to E1. + obj9.foo; + obj9.bar1; + obj9.bar2; +} + +var obj10: any; +if (obj10 instanceof E) { // can't type narrowing from any. + obj10.foo; + obj10.bar1; + obj10.bar2; +} + +// a construct signature that returns any +interface FConstructor { + new (): any; +} +interface F { + foo: string; + bar: number; +} +declare var F: FConstructor; + +var obj11: F | string; +if (obj11 instanceof F) { // can't type narrowing, construct signiture returns any. + obj11.foo; + obj11.bar; +} + +var obj12: any; +if (obj12 instanceof F) { // can't type narrowing from any. + obj12.foo; + obj12.bar; +} + +// a type with a prototype, it overrides the construct signiture +interface GConstructor { + prototype: G1; // high priority + new (): G2; // low priority +} +interface G1 { + foo1: number; +} +interface G2 { + foo2: boolean; +} +declare var G: GConstructor; + +var obj13: G1 | G2; +if (obj13 instanceof G) { // narrowed to G1. G1 is return type of prototype property. + obj13.foo1; + obj13.foo2; +} + +var obj14: any; +if (obj14 instanceof G) { // can't type narrowing from any. + obj14.foo1; + obj14.foo2; +} + +// a type with a prototype that has any type +interface HConstructor { + prototype: any; // high priority, but any type is ignored. interface has implicit `prototype: any`. + new (): H; // low priority +} +interface H { + foo: number; +} +declare var H: HConstructor; + +var obj15: H | string; +if (obj15 instanceof H) { // narrowed to H. + obj15.foo; + obj15.bar; +} + +var obj16: any; +if (obj16 instanceof H) { // can't type narrowing from any. + obj16.foo1; + obj16.foo2; +} + //// [typeGuardsWithInstanceOfByConstructorSignature.js] var obj1; @@ -103,8 +200,8 @@ if (obj2 instanceof A) { } var obj3; if (obj3 instanceof B) { - obj3.foo = "str"; obj3.foo = 1; + obj3.foo = "str"; obj3.bar = "str"; } var obj4; @@ -135,3 +232,45 @@ if (obj8 instanceof D) { obj8.foo; obj8.bar; } +var obj9; +if (obj9 instanceof E) { + obj9.foo; + obj9.bar1; + obj9.bar2; +} +var obj10; +if (obj10 instanceof E) { + obj10.foo; + obj10.bar1; + obj10.bar2; +} +var obj11; +if (obj11 instanceof F) { + obj11.foo; + obj11.bar; +} +var obj12; +if (obj12 instanceof F) { + obj12.foo; + obj12.bar; +} +var obj13; +if (obj13 instanceof G) { + obj13.foo1; + obj13.foo2; +} +var obj14; +if (obj14 instanceof G) { + obj14.foo1; + obj14.foo2; +} +var obj15; +if (obj15 instanceof H) { + obj15.foo; + obj15.bar; +} +var obj16; +if (obj16 instanceof H) { + obj16.foo1; + obj16.foo2; +} diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts index b28d92e2c8e..c432ceb2bda 100644 --- a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts @@ -18,7 +18,7 @@ if (obj2 instanceof A) { // can't type narrowing from any. obj2.bar; } -// with generics +// a construct signature with generics interface BConstructor { new (): B; } @@ -27,10 +27,10 @@ interface B { } declare var B: BConstructor; -var obj3: B | A; -if (obj3 instanceof B) { // narrowed to B. - obj3.foo = "str"; +var obj3: B | string; +if (obj3 instanceof B) { // narrowed to B. obj3.foo = 1; + obj3.foo = "str"; obj3.bar = "str"; } @@ -41,7 +41,7 @@ if (obj4 instanceof B) { // can't type narrowing from any. obj4.bar = "str"; } -// has multiple constructor signature +// has multiple construct signature interface CConstructor { new (value: string): C1; new (value: number): C2; @@ -87,3 +87,100 @@ if (obj8 instanceof D) { // can't type narrowing from any. obj8.foo; obj8.bar; } + +// a construct signature that returns a union type +interface EConstructor { + new (): E1 | E2; +} +interface E1 { + foo: string; + bar1: number; +} +interface E2 { + foo: string; + bar2: number; +} +declare var E: EConstructor; + +var obj9: E1 | A; +if (obj9 instanceof E) { // narrowed to E1. + obj9.foo; + obj9.bar1; + obj9.bar2; +} + +var obj10: any; +if (obj10 instanceof E) { // can't type narrowing from any. + obj10.foo; + obj10.bar1; + obj10.bar2; +} + +// a construct signature that returns any +interface FConstructor { + new (): any; +} +interface F { + foo: string; + bar: number; +} +declare var F: FConstructor; + +var obj11: F | string; +if (obj11 instanceof F) { // can't type narrowing, construct signiture returns any. + obj11.foo; + obj11.bar; +} + +var obj12: any; +if (obj12 instanceof F) { // can't type narrowing from any. + obj12.foo; + obj12.bar; +} + +// a type with a prototype, it overrides the construct signiture +interface GConstructor { + prototype: G1; // high priority + new (): G2; // low priority +} +interface G1 { + foo1: number; +} +interface G2 { + foo2: boolean; +} +declare var G: GConstructor; + +var obj13: G1 | G2; +if (obj13 instanceof G) { // narrowed to G1. G1 is return type of prototype property. + obj13.foo1; + obj13.foo2; +} + +var obj14: any; +if (obj14 instanceof G) { // can't type narrowing from any. + obj14.foo1; + obj14.foo2; +} + +// a type with a prototype that has any type +interface HConstructor { + prototype: any; // high priority, but any type is ignored. interface has implicit `prototype: any`. + new (): H; // low priority +} +interface H { + foo: number; +} +declare var H: HConstructor; + +var obj15: H | string; +if (obj15 instanceof H) { // narrowed to H. + obj15.foo; + obj15.bar; +} + +var obj16: any; +if (obj16 instanceof H) { // can't type narrowing from any. + obj16.foo1; + obj16.foo2; +} From b7f4480656ad10221d4f87fa8150e73a03eaa0dc Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 26 Mar 2015 16:48:17 -0700 Subject: [PATCH 03/22] unify file extension resolution logic --- src/compiler/checker.ts | 5 +++-- src/compiler/core.ts | 10 ++++++---- src/compiler/program.ts | 14 ++++++-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 04766f22c4e..c16b7ccda02 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -853,10 +853,11 @@ module ts { return symbol; } } + let fileName: string; let sourceFile: SourceFile; while (true) { - let fileName = normalizePath(combinePaths(searchPath, moduleName)); - sourceFile = host.getSourceFile(fileName + ".ts") || host.getSourceFile(fileName + ".d.ts"); + fileName = normalizePath(combinePaths(searchPath, moduleName)); + sourceFile = forEach(supportedExtensions, extension => host.getSourceFile(fileName + extension)); if (sourceFile || isRelative) { break; } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 9b987ba77c6..92dc412889d 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -640,16 +640,18 @@ module ts { return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; } - let supportedExtensions = [".d.ts", ".ts", ".js"]; + /** + * List of supported extensions in order of file resolution precedence. + */ + export const supportedExtensions = [".ts", ".d.ts"]; + const extensitionsToRemove = [".d.ts", ".ts", ".js"]; export function removeFileExtension(path: string): string { - for (let ext of supportedExtensions) { - + for (let ext of extensitionsToRemove) { if (fileExtensionIs(path, ext)) { return path.substr(0, path.length - ext.length); } } - return path; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 3ebd8740faa..28fcdb73642 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -313,7 +313,7 @@ module ts { } let diagnostic: DiagnosticMessage; if (hasExtension(fileName)) { - if (!options.allowNonTsExtensions && !fileExtensionIs(host.getCanonicalFileName(fileName), ".ts")) { + if (!options.allowNonTsExtensions && !forEach(supportedExtensions, extension => fileExtensionIs(host.getCanonicalFileName(fileName), extension))) { diagnostic = Diagnostics.File_0_must_have_extension_ts_or_d_ts; } else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { @@ -327,7 +327,7 @@ module ts { if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { diagnostic = Diagnostics.File_0_not_found; } - else if (!findSourceFile(fileName + ".ts", isDefaultLib, refFile, refPos, refEnd) && !findSourceFile(fileName + ".d.ts", isDefaultLib, refFile, refPos, refEnd)) { + else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd))) { diagnostic = Diagnostics.File_0_not_found; fileName += ".ts"; } @@ -417,9 +417,10 @@ module ts { let moduleNameText = (moduleNameExpr).text; if (moduleNameText) { let searchPath = basePath; + let searchName: string; while (true) { - let searchName = normalizePath(combinePaths(searchPath, moduleNameText)); - if (findModuleSourceFile(searchName + ".ts", moduleNameExpr) || findModuleSourceFile(searchName + ".d.ts", moduleNameExpr)) { + searchName = normalizePath(combinePaths(searchPath, moduleNameText)); + if (forEach(supportedExtensions, extension => findModuleSourceFile(searchName + extension, moduleNameExpr))) { break; } let parentPath = getDirectoryPath(searchPath); @@ -448,10 +449,7 @@ module ts { // An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules // only through top - level external module names. Relative external module names are not permitted. let searchName = normalizePath(combinePaths(basePath, moduleName)); - let tsFile = findModuleSourceFile(searchName + ".ts", nameLiteral); - if (!tsFile) { - findModuleSourceFile(searchName + ".d.ts", nameLiteral); - } + forEach(supportedExtensions, extension => findModuleSourceFile(searchName + extension, nameLiteral)); } } }); From cc41daab61785507ba46c7c9bb307444617f85ed Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 4 May 2015 23:30:01 -0700 Subject: [PATCH 04/22] Fix typo --- src/compiler/core.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 92dc412889d..9fe9747fb57 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -645,9 +645,9 @@ module ts { */ export const supportedExtensions = [".ts", ".d.ts"]; - const extensitionsToRemove = [".d.ts", ".ts", ".js"]; + const extensionsToRemove = [".d.ts", ".ts", ".js"]; export function removeFileExtension(path: string): string { - for (let ext of extensitionsToRemove) { + for (let ext of extensionsToRemove) { if (fileExtensionIs(path, ext)) { return path.substr(0, path.length - ext.length); } From 19933870a4d23bad8e97d4085f9db854504831ea Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 4 May 2015 23:30:43 -0700 Subject: [PATCH 05/22] Update error message --- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- src/compiler/program.ts | 13 ++++++++++--- .../invalidRootFile/amd/invalidRootFile.errors.txt | 4 ++-- .../invalidRootFile/node/invalidRootFile.errors.txt | 4 ++-- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 14163e81195..0160a8dc46c 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -496,7 +496,7 @@ module ts { Corrupted_locale_file_0: { code: 6051, category: DiagnosticCategory.Error, key: "Corrupted locale file {0}." }, Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." }, File_0_not_found: { code: 6053, category: DiagnosticCategory.Error, key: "File '{0}' not found." }, - File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, + File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, Preserve_new_lines_when_emitting_code: { code: 6057, category: DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 18c98928dda..d3255ff4aff 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1974,7 +1974,7 @@ "category": "Error", "code": 6053 }, - "File '{0}' must have extension '.ts' or '.d.ts'.": { + "File '{0}' has unsupported extension. The only supported extensions are {1}.": { "category": "Error", "code": 6054 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 28fcdb73642..98b6927fc4c 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -307,6 +307,8 @@ module ts { function processSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) { let start: number; let length: number; + let extensions: string; + let diagnosticArgument: string[]; if (refEnd !== undefined && refPos !== undefined) { start = refPos; length = refEnd - refPos; @@ -314,31 +316,36 @@ module ts { let diagnostic: DiagnosticMessage; if (hasExtension(fileName)) { if (!options.allowNonTsExtensions && !forEach(supportedExtensions, extension => fileExtensionIs(host.getCanonicalFileName(fileName), extension))) { - diagnostic = Diagnostics.File_0_must_have_extension_ts_or_d_ts; + diagnostic = Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1; + diagnosticArgument = [fileName, "'" + supportedExtensions.join("', '") + "'"]; } else if (!findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { diagnostic = Diagnostics.File_0_not_found; + diagnosticArgument = [fileName]; } else if (refFile && host.getCanonicalFileName(fileName) === host.getCanonicalFileName(refFile.fileName)) { diagnostic = Diagnostics.A_file_cannot_have_a_reference_to_itself; + diagnosticArgument = [fileName]; } } else { if (options.allowNonTsExtensions && !findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd)) { diagnostic = Diagnostics.File_0_not_found; + diagnosticArgument = [fileName]; } else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, isDefaultLib, refFile, refPos, refEnd))) { diagnostic = Diagnostics.File_0_not_found; fileName += ".ts"; + diagnosticArgument = [fileName]; } } if (diagnostic) { if (refFile) { - diagnostics.add(createFileDiagnostic(refFile, start, length, diagnostic, fileName)); + diagnostics.add(createFileDiagnostic(refFile, start, length, diagnostic, ...diagnosticArgument)); } else { - diagnostics.add(createCompilerDiagnostic(diagnostic, fileName)); + diagnostics.add(createCompilerDiagnostic(diagnostic, ...diagnosticArgument)); } } } diff --git a/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt b/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt index 25059478bf5..1bda32a0b4c 100644 --- a/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt +++ b/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt @@ -1,6 +1,6 @@ -error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'. +error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'. error TS6053: File 'a.ts' not found. -!!! error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'. +!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'. !!! error TS6053: File 'a.ts' not found. \ No newline at end of file diff --git a/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt b/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt index 25059478bf5..1bda32a0b4c 100644 --- a/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt +++ b/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt @@ -1,6 +1,6 @@ -error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'. +error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'. error TS6053: File 'a.ts' not found. -!!! error TS6054: File 'a.t' must have extension '.ts' or '.d.ts'. +!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.d.ts'. !!! error TS6053: File 'a.ts' not found. \ No newline at end of file From 880ccf0221f482322d97da238abc26f64b731381 Mon Sep 17 00:00:00 2001 From: vvakame Date: Tue, 5 May 2015 20:29:43 +0900 Subject: [PATCH 06/22] PR feedback --- src/compiler/checker.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c864a8aa76a..eac5d563357 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3599,6 +3599,10 @@ module ts { return type; } + function getUnionTypeOfSubtypeConstituents(source: UnionType, target: Type): Type { + return getUnionType(filter(source.types, t => isTypeSubtypeOf(t, target))); + } + function getReducedTypeOfUnionType(type: UnionType): Type { // If union type was created without subtype reduction, perform the deferred reduction now if (!type.reducedType) { @@ -5354,26 +5358,26 @@ module ts { if (prototypeProperty) { let targetType = getTypeOfSymbol(prototypeProperty); if (targetType !== anyType) { - // Narrow to target type if it is a subtype of current type + // Narrow to the target type if it's a subtype of the current type if (isTypeSubtypeOf(targetType, type)) { return targetType; } - // If current type is a union type, remove all constituents that aren't subtypes of target type + // If the current type is a union type, remove all constituents that aren't subtypes of the target. if (type.flags & TypeFlags.Union) { - return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, targetType))); + return getUnionTypeOfSubtypeConstituents(type, targetType); } } } // Target type is type of constructor signiture - let constructSignitures: Signature[]; + let constructSignatures: Signature[]; if (rightType.flags & TypeFlags.Interface) { - constructSignitures = (rightType).declaredConstructSignatures; + constructSignatures = (rightType).declaredConstructSignatures; + } else if (rightType.flags & TypeFlags.Anonymous) { + constructSignatures = (rightType).constructSignatures; } - if (rightType.flags & TypeFlags.Anonymous) { - constructSignitures = (rightType).constructSignatures; - } - if (constructSignitures) { - let instanceType = getUnionType(map(constructSignitures, constructSignature => { + + if (constructSignatures) { + let instanceType = getUnionType(map(constructSignatures, constructSignature => { if (constructSignature.typeParameters && constructSignature.typeParameters.length !== 0) { constructSignature = instantiateSignature(constructSignature, createTypeMapper(constructSignature.typeParameters, map(constructSignature.typeParameters, _ => anyType)), true) } @@ -5381,7 +5385,7 @@ module ts { })); // Pickup type from union types if (type.flags & TypeFlags.Union) { - return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, instanceType))); + return getUnionTypeOfSubtypeConstituents(type, instanceType); } return instanceType; } From e342c955625b10523cf753fa63982c1092502bee Mon Sep 17 00:00:00 2001 From: vvakame Date: Wed, 6 May 2015 01:00:17 +0900 Subject: [PATCH 07/22] fix code styling --- src/compiler/checker.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index eac5d563357..c279786c686 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5372,7 +5372,8 @@ module ts { let constructSignatures: Signature[]; if (rightType.flags & TypeFlags.Interface) { constructSignatures = (rightType).declaredConstructSignatures; - } else if (rightType.flags & TypeFlags.Anonymous) { + } + else if (rightType.flags & TypeFlags.Anonymous) { constructSignatures = (rightType).constructSignatures; } From 776f390786f1dc71236b4c124084a20da225d0ae Mon Sep 17 00:00:00 2001 From: vvakame Date: Wed, 6 May 2015 20:28:03 +0900 Subject: [PATCH 08/22] PR feedback --- src/compiler/checker.ts | 15 +- ...nstanceOfByConstructorSignature.errors.txt | 438 +++++++++--------- ...rdsWithInstanceOfByConstructorSignature.js | 200 ++++---- ...rdsWithInstanceOfByConstructorSignature.ts | 20 +- 4 files changed, 334 insertions(+), 339 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c279786c686..eba6c954671 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5368,22 +5368,17 @@ module ts { } } } - // Target type is type of constructor signiture + // Target type is type of construct signature let constructSignatures: Signature[]; if (rightType.flags & TypeFlags.Interface) { - constructSignatures = (rightType).declaredConstructSignatures; + constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; } else if (rightType.flags & TypeFlags.Anonymous) { - constructSignatures = (rightType).constructSignatures; + constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct); } - if (constructSignatures) { - let instanceType = getUnionType(map(constructSignatures, constructSignature => { - if (constructSignature.typeParameters && constructSignature.typeParameters.length !== 0) { - constructSignature = instantiateSignature(constructSignature, createTypeMapper(constructSignature.typeParameters, map(constructSignature.typeParameters, _ => anyType)), true) - } - return constructSignature.resolvedReturnType; - })); + if (constructSignatures && constructSignatures.length !== 0) { + let instanceType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature)))); // Pickup type from union types if (type.flags & TypeFlags.Union) { return getUnionTypeOfSubtypeConstituents(type, instanceType); diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt index 1816ef77fc2..b963b2c33ae 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt @@ -1,220 +1,220 @@ -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(12,10): error TS2339: Property 'bar' does not exist on type 'A'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(33,5): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(34,10): error TS2339: Property 'bar' does not exist on type 'B'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(63,10): error TS2339: Property 'bar2' does not exist on type 'C1'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(82,10): error TS2339: Property 'bar' does not exist on type 'D'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(109,10): error TS2339: Property 'bar2' does not exist on type 'E1'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(131,11): error TS2339: Property 'foo' does not exist on type 'string | F'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(132,11): error TS2339: Property 'bar' does not exist on type 'string | F'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(157,11): error TS2339: Property 'foo2' does not exist on type 'G1'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(179,11): error TS2339: Property 'bar' does not exist on type 'H'. - - -==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts (10 errors) ==== - interface AConstructor { - new (): A; - } - interface A { - foo: string; - } - declare var A: AConstructor; - - var obj1: A | string; - if (obj1 instanceof A) { // narrowed to A. - obj1.foo; - obj1.bar; - ~~~ -!!! error TS2339: Property 'bar' does not exist on type 'A'. - } - - var obj2: any; - if (obj2 instanceof A) { // can't type narrowing from any. - obj2.foo; - obj2.bar; - } - - // a construct signature with generics - interface BConstructor { - new (): B; - } - interface B { - foo: T; - } - declare var B: BConstructor; - - var obj3: B | string; - if (obj3 instanceof B) { // narrowed to B. - obj3.foo = 1; - obj3.foo = "str"; - ~~~~~~~~ -!!! error TS2322: Type 'string' is not assignable to type 'number'. - obj3.bar = "str"; - ~~~ -!!! error TS2339: Property 'bar' does not exist on type 'B'. - } - - var obj4: any; - if (obj4 instanceof B) { // can't type narrowing from any. - obj4.foo = "str"; - obj4.foo = 1; - obj4.bar = "str"; - } - - // has multiple construct signature - interface CConstructor { - new (value: string): C1; - new (value: number): C2; - } - interface C1 { - foo: string; - bar1: number; - } - interface C2 { - foo: string; - bar2: number; - } - declare var C: CConstructor; - - var obj5: C1 | A; - if (obj5 instanceof C) { // narrowed to C1. - obj5.foo; - obj5.bar1; - obj5.bar2; - ~~~~ -!!! error TS2339: Property 'bar2' does not exist on type 'C1'. - } - - var obj6: any; - if (obj6 instanceof C) { // can't type narrowing from any. - obj6.foo; - obj6.bar1; - obj6.bar2; - } - - // with object type literal - interface D { - foo: string; - } - declare var D: { new (): D; }; - - var obj7: D | string; - if (obj7 instanceof D) { // narrowed to D. - obj7.foo; - obj7.bar; - ~~~ -!!! error TS2339: Property 'bar' does not exist on type 'D'. - } - - var obj8: any; - if (obj8 instanceof D) { // can't type narrowing from any. - obj8.foo; - obj8.bar; - } - - // a construct signature that returns a union type - interface EConstructor { - new (): E1 | E2; - } - interface E1 { - foo: string; - bar1: number; - } - interface E2 { - foo: string; - bar2: number; - } - declare var E: EConstructor; - - var obj9: E1 | A; - if (obj9 instanceof E) { // narrowed to E1. - obj9.foo; - obj9.bar1; - obj9.bar2; - ~~~~ -!!! error TS2339: Property 'bar2' does not exist on type 'E1'. - } - - var obj10: any; - if (obj10 instanceof E) { // can't type narrowing from any. - obj10.foo; - obj10.bar1; - obj10.bar2; - } - - // a construct signature that returns any - interface FConstructor { - new (): any; - } - interface F { - foo: string; - bar: number; - } - declare var F: FConstructor; - - var obj11: F | string; - if (obj11 instanceof F) { // can't type narrowing, construct signiture returns any. - obj11.foo; - ~~~ -!!! error TS2339: Property 'foo' does not exist on type 'string | F'. - obj11.bar; - ~~~ -!!! error TS2339: Property 'bar' does not exist on type 'string | F'. - } - - var obj12: any; - if (obj12 instanceof F) { // can't type narrowing from any. - obj12.foo; - obj12.bar; - } - - // a type with a prototype, it overrides the construct signiture - interface GConstructor { - prototype: G1; // high priority - new (): G2; // low priority - } - interface G1 { - foo1: number; - } - interface G2 { - foo2: boolean; - } - declare var G: GConstructor; - - var obj13: G1 | G2; - if (obj13 instanceof G) { // narrowed to G1. G1 is return type of prototype property. - obj13.foo1; - obj13.foo2; - ~~~~ -!!! error TS2339: Property 'foo2' does not exist on type 'G1'. - } - - var obj14: any; - if (obj14 instanceof G) { // can't type narrowing from any. - obj14.foo1; - obj14.foo2; - } - - // a type with a prototype that has any type - interface HConstructor { - prototype: any; // high priority, but any type is ignored. interface has implicit `prototype: any`. - new (): H; // low priority - } - interface H { - foo: number; - } - declare var H: HConstructor; - - var obj15: H | string; - if (obj15 instanceof H) { // narrowed to H. - obj15.foo; - obj15.bar; - ~~~ -!!! error TS2339: Property 'bar' does not exist on type 'H'. - } - - var obj16: any; - if (obj16 instanceof H) { // can't type narrowing from any. - obj16.foo1; - obj16.foo2; - } +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(12,10): error TS2339: Property 'bar' does not exist on type 'A'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(33,5): error TS2322: Type 'string' is not assignable to type 'number'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(34,10): error TS2339: Property 'bar' does not exist on type 'B'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(63,10): error TS2339: Property 'bar2' does not exist on type 'C1'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(82,10): error TS2339: Property 'bar' does not exist on type 'D'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(109,10): error TS2339: Property 'bar2' does not exist on type 'E1'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(131,11): error TS2339: Property 'foo' does not exist on type 'string | F'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(132,11): error TS2339: Property 'bar' does not exist on type 'string | F'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(157,11): error TS2339: Property 'foo2' does not exist on type 'G1'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(179,11): error TS2339: Property 'bar' does not exist on type 'H'. + + +==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts (10 errors) ==== + interface AConstructor { + new (): A; + } + interface A { + foo: string; + } + declare var A: AConstructor; + + var obj1: A | string; + if (obj1 instanceof A) { // narrowed to A. + obj1.foo; + obj1.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type 'A'. + } + + var obj2: any; + if (obj2 instanceof A) { // can't narrow type from 'any' + obj2.foo; + obj2.bar; + } + + // a construct signature with generics + interface BConstructor { + new (): B; + } + interface B { + foo: T; + } + declare var B: BConstructor; + + var obj3: B | string; + if (obj3 instanceof B) { // narrowed to B. + obj3.foo = 1; + obj3.foo = "str"; + ~~~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. + obj3.bar = "str"; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type 'B'. + } + + var obj4: any; + if (obj4 instanceof B) { // can't narrow type from 'any' + obj4.foo = "str"; + obj4.foo = 1; + obj4.bar = "str"; + } + + // has multiple construct signature + interface CConstructor { + new (value: string): C1; + new (value: number): C2; + } + interface C1 { + foo: string; + bar1: number; + } + interface C2 { + foo: string; + bar2: number; + } + declare var C: CConstructor; + + var obj5: C1 | A; + if (obj5 instanceof C) { // narrowed to C1. + obj5.foo; + obj5.bar1; + obj5.bar2; + ~~~~ +!!! error TS2339: Property 'bar2' does not exist on type 'C1'. + } + + var obj6: any; + if (obj6 instanceof C) { // can't narrow type from 'any' + obj6.foo; + obj6.bar1; + obj6.bar2; + } + + // with object type literal + interface D { + foo: string; + } + declare var D: { new (): D; }; + + var obj7: D | string; + if (obj7 instanceof D) { // narrowed to D. + obj7.foo; + obj7.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type 'D'. + } + + var obj8: any; + if (obj8 instanceof D) { // can't narrow type from 'any' + obj8.foo; + obj8.bar; + } + + // a construct signature that returns a union type + interface EConstructor { + new (): E1 | E2; + } + interface E1 { + foo: string; + bar1: number; + } + interface E2 { + foo: string; + bar2: number; + } + declare var E: EConstructor; + + var obj9: E1 | A; + if (obj9 instanceof E) { // narrowed to E1. + obj9.foo; + obj9.bar1; + obj9.bar2; + ~~~~ +!!! error TS2339: Property 'bar2' does not exist on type 'E1'. + } + + var obj10: any; + if (obj10 instanceof E) { // can't narrow type from 'any' + obj10.foo; + obj10.bar1; + obj10.bar2; + } + + // a construct signature that returns any + interface FConstructor { + new (): any; + } + interface F { + foo: string; + bar: number; + } + declare var F: FConstructor; + + var obj11: F | string; + if (obj11 instanceof F) { // can't type narrowing, construct signature returns any. + obj11.foo; + ~~~ +!!! error TS2339: Property 'foo' does not exist on type 'string | F'. + obj11.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type 'string | F'. + } + + var obj12: any; + if (obj12 instanceof F) { // can't narrow type from 'any' + obj12.foo; + obj12.bar; + } + + // a type with a prototype, it overrides the construct signature + interface GConstructor { + prototype: G1; // high priority + new (): G2; // low priority + } + interface G1 { + foo1: number; + } + interface G2 { + foo2: boolean; + } + declare var G: GConstructor; + + var obj13: G1 | G2; + if (obj13 instanceof G) { // narrowed to G1. G1 is return type of prototype property. + obj13.foo1; + obj13.foo2; + ~~~~ +!!! error TS2339: Property 'foo2' does not exist on type 'G1'. + } + + var obj14: any; + if (obj14 instanceof G) { // can't narrow type from 'any' + obj14.foo1; + obj14.foo2; + } + + // a type with a prototype that has any type + interface HConstructor { + prototype: any; // high priority, but any type is ignored. interface has implicit `prototype: any`. + new (): H; // low priority + } + interface H { + foo: number; + } + declare var H: HConstructor; + + var obj15: H | string; + if (obj15 instanceof H) { // narrowed to H. + obj15.foo; + obj15.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type 'H'. + } + + var obj16: any; + if (obj16 instanceof H) { // can't narrow type from 'any' + obj16.foo1; + obj16.foo2; + } \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js index 395a5e96e05..e5b12bacb1f 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js @@ -1,4 +1,4 @@ -//// [typeGuardsWithInstanceOfByConstructorSignature.ts] +//// [typeGuardsWithInstanceOfByConstructorSignature.ts] interface AConstructor { new (): A; } @@ -14,7 +14,7 @@ if (obj1 instanceof A) { // narrowed to A. } var obj2: any; -if (obj2 instanceof A) { // can't type narrowing from any. +if (obj2 instanceof A) { // can't narrow type from 'any' obj2.foo; obj2.bar; } @@ -36,7 +36,7 @@ if (obj3 instanceof B) { // narrowed to B. } var obj4: any; -if (obj4 instanceof B) { // can't type narrowing from any. +if (obj4 instanceof B) { // can't narrow type from 'any' obj4.foo = "str"; obj4.foo = 1; obj4.bar = "str"; @@ -65,7 +65,7 @@ if (obj5 instanceof C) { // narrowed to C1. } var obj6: any; -if (obj6 instanceof C) { // can't type narrowing from any. +if (obj6 instanceof C) { // can't narrow type from 'any' obj6.foo; obj6.bar1; obj6.bar2; @@ -84,7 +84,7 @@ if (obj7 instanceof D) { // narrowed to D. } var obj8: any; -if (obj8 instanceof D) { // can't type narrowing from any. +if (obj8 instanceof D) { // can't narrow type from 'any' obj8.foo; obj8.bar; } @@ -111,7 +111,7 @@ if (obj9 instanceof E) { // narrowed to E1. } var obj10: any; -if (obj10 instanceof E) { // can't type narrowing from any. +if (obj10 instanceof E) { // can't narrow type from 'any' obj10.foo; obj10.bar1; obj10.bar2; @@ -128,18 +128,18 @@ interface F { declare var F: FConstructor; var obj11: F | string; -if (obj11 instanceof F) { // can't type narrowing, construct signiture returns any. +if (obj11 instanceof F) { // can't type narrowing, construct signature returns any. obj11.foo; obj11.bar; } var obj12: any; -if (obj12 instanceof F) { // can't type narrowing from any. +if (obj12 instanceof F) { // can't narrow type from 'any' obj12.foo; obj12.bar; } -// a type with a prototype, it overrides the construct signiture +// a type with a prototype, it overrides the construct signature interface GConstructor { prototype: G1; // high priority new (): G2; // low priority @@ -159,7 +159,7 @@ if (obj13 instanceof G) { // narrowed to G1. G1 is return type of prototype prop } var obj14: any; -if (obj14 instanceof G) { // can't type narrowing from any. +if (obj14 instanceof G) { // can't narrow type from 'any' obj14.foo1; obj14.foo2; } @@ -181,96 +181,96 @@ if (obj15 instanceof H) { // narrowed to H. } var obj16: any; -if (obj16 instanceof H) { // can't type narrowing from any. - obj16.foo1; - obj16.foo2; -} - - -//// [typeGuardsWithInstanceOfByConstructorSignature.js] -var obj1; -if (obj1 instanceof A) { - obj1.foo; - obj1.bar; -} -var obj2; -if (obj2 instanceof A) { - obj2.foo; - obj2.bar; -} -var obj3; -if (obj3 instanceof B) { - obj3.foo = 1; - obj3.foo = "str"; - obj3.bar = "str"; -} -var obj4; -if (obj4 instanceof B) { - obj4.foo = "str"; - obj4.foo = 1; - obj4.bar = "str"; -} -var obj5; -if (obj5 instanceof C) { - obj5.foo; - obj5.bar1; - obj5.bar2; -} -var obj6; -if (obj6 instanceof C) { - obj6.foo; - obj6.bar1; - obj6.bar2; -} -var obj7; -if (obj7 instanceof D) { - obj7.foo; - obj7.bar; -} -var obj8; -if (obj8 instanceof D) { - obj8.foo; - obj8.bar; -} -var obj9; -if (obj9 instanceof E) { - obj9.foo; - obj9.bar1; - obj9.bar2; -} -var obj10; -if (obj10 instanceof E) { - obj10.foo; - obj10.bar1; - obj10.bar2; -} -var obj11; -if (obj11 instanceof F) { - obj11.foo; - obj11.bar; -} -var obj12; -if (obj12 instanceof F) { - obj12.foo; - obj12.bar; -} -var obj13; -if (obj13 instanceof G) { - obj13.foo1; - obj13.foo2; -} -var obj14; -if (obj14 instanceof G) { - obj14.foo1; - obj14.foo2; -} -var obj15; -if (obj15 instanceof H) { - obj15.foo; - obj15.bar; -} -var obj16; -if (obj16 instanceof H) { +if (obj16 instanceof H) { // can't narrow type from 'any' obj16.foo1; obj16.foo2; } + + +//// [typeGuardsWithInstanceOfByConstructorSignature.js] +var obj1; +if (obj1 instanceof A) { + obj1.foo; + obj1.bar; +} +var obj2; +if (obj2 instanceof A) { + obj2.foo; + obj2.bar; +} +var obj3; +if (obj3 instanceof B) { + obj3.foo = 1; + obj3.foo = "str"; + obj3.bar = "str"; +} +var obj4; +if (obj4 instanceof B) { + obj4.foo = "str"; + obj4.foo = 1; + obj4.bar = "str"; +} +var obj5; +if (obj5 instanceof C) { + obj5.foo; + obj5.bar1; + obj5.bar2; +} +var obj6; +if (obj6 instanceof C) { + obj6.foo; + obj6.bar1; + obj6.bar2; +} +var obj7; +if (obj7 instanceof D) { + obj7.foo; + obj7.bar; +} +var obj8; +if (obj8 instanceof D) { + obj8.foo; + obj8.bar; +} +var obj9; +if (obj9 instanceof E) { + obj9.foo; + obj9.bar1; + obj9.bar2; +} +var obj10; +if (obj10 instanceof E) { + obj10.foo; + obj10.bar1; + obj10.bar2; +} +var obj11; +if (obj11 instanceof F) { + obj11.foo; + obj11.bar; +} +var obj12; +if (obj12 instanceof F) { + obj12.foo; + obj12.bar; +} +var obj13; +if (obj13 instanceof G) { + obj13.foo1; + obj13.foo2; +} +var obj14; +if (obj14 instanceof G) { + obj14.foo1; + obj14.foo2; +} +var obj15; +if (obj15 instanceof H) { + obj15.foo; + obj15.bar; +} +var obj16; +if (obj16 instanceof H) { + obj16.foo1; + obj16.foo2; +} diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts index c432ceb2bda..fee92ff10ca 100644 --- a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts @@ -13,7 +13,7 @@ if (obj1 instanceof A) { // narrowed to A. } var obj2: any; -if (obj2 instanceof A) { // can't type narrowing from any. +if (obj2 instanceof A) { // can't narrow type from 'any' obj2.foo; obj2.bar; } @@ -35,7 +35,7 @@ if (obj3 instanceof B) { // narrowed to B. } var obj4: any; -if (obj4 instanceof B) { // can't type narrowing from any. +if (obj4 instanceof B) { // can't narrow type from 'any' obj4.foo = "str"; obj4.foo = 1; obj4.bar = "str"; @@ -64,7 +64,7 @@ if (obj5 instanceof C) { // narrowed to C1. } var obj6: any; -if (obj6 instanceof C) { // can't type narrowing from any. +if (obj6 instanceof C) { // can't narrow type from 'any' obj6.foo; obj6.bar1; obj6.bar2; @@ -83,7 +83,7 @@ if (obj7 instanceof D) { // narrowed to D. } var obj8: any; -if (obj8 instanceof D) { // can't type narrowing from any. +if (obj8 instanceof D) { // can't narrow type from 'any' obj8.foo; obj8.bar; } @@ -110,7 +110,7 @@ if (obj9 instanceof E) { // narrowed to E1. } var obj10: any; -if (obj10 instanceof E) { // can't type narrowing from any. +if (obj10 instanceof E) { // can't narrow type from 'any' obj10.foo; obj10.bar1; obj10.bar2; @@ -127,18 +127,18 @@ interface F { declare var F: FConstructor; var obj11: F | string; -if (obj11 instanceof F) { // can't type narrowing, construct signiture returns any. +if (obj11 instanceof F) { // can't type narrowing, construct signature returns any. obj11.foo; obj11.bar; } var obj12: any; -if (obj12 instanceof F) { // can't type narrowing from any. +if (obj12 instanceof F) { // can't narrow type from 'any' obj12.foo; obj12.bar; } -// a type with a prototype, it overrides the construct signiture +// a type with a prototype, it overrides the construct signature interface GConstructor { prototype: G1; // high priority new (): G2; // low priority @@ -158,7 +158,7 @@ if (obj13 instanceof G) { // narrowed to G1. G1 is return type of prototype prop } var obj14: any; -if (obj14 instanceof G) { // can't type narrowing from any. +if (obj14 instanceof G) { // can't narrow type from 'any' obj14.foo1; obj14.foo2; } @@ -180,7 +180,7 @@ if (obj15 instanceof H) { // narrowed to H. } var obj16: any; -if (obj16 instanceof H) { // can't type narrowing from any. +if (obj16 instanceof H) { // can't narrow type from 'any' obj16.foo1; obj16.foo2; } From 0a28a3ec80c9b5e4f5bb5590598ba86ade2d1b02 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 6 May 2015 13:05:12 -0700 Subject: [PATCH 09/22] Remove getUnionTypeOfSubtypeConstituents --- src/compiler/checker.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a3ce22bbed1..4c5712299da 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3634,10 +3634,6 @@ module ts { return type; } - function getUnionTypeOfSubtypeConstituents(source: UnionType, target: Type): Type { - return getUnionType(filter(source.types, t => isTypeSubtypeOf(t, target))); - } - function getReducedTypeOfUnionType(type: UnionType): Type { // If union type was created without subtype reduction, perform the deferred reduction now if (!type.reducedType) { @@ -5399,7 +5395,7 @@ module ts { } // If the current type is a union type, remove all constituents that aren't subtypes of the target. if (type.flags & TypeFlags.Union) { - return getUnionTypeOfSubtypeConstituents(type, targetType); + return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, targetType))); } } } @@ -5416,7 +5412,7 @@ module ts { let instanceType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature)))); // Pickup type from union types if (type.flags & TypeFlags.Union) { - return getUnionTypeOfSubtypeConstituents(type, instanceType); + return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, instanceType))); } return instanceType; } From 498f315256b7e2d041c398ee25bbce08f2d5d1f9 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 6 May 2015 15:53:01 -0700 Subject: [PATCH 10/22] Fix typing for Promises so that a void error callback doesn't mess up inference --- src/lib/es6.d.ts | 2 + .../reference/promiseVoidErrorCallback.js | 43 +++++++++ .../promiseVoidErrorCallback.symbols | 75 ++++++++++++++++ .../reference/promiseVoidErrorCallback.types | 89 +++++++++++++++++++ .../compiler/promiseVoidErrorCallback.ts | 28 ++++++ 5 files changed, 237 insertions(+) create mode 100644 tests/baselines/reference/promiseVoidErrorCallback.js create mode 100644 tests/baselines/reference/promiseVoidErrorCallback.symbols create mode 100644 tests/baselines/reference/promiseVoidErrorCallback.types create mode 100644 tests/cases/compiler/promiseVoidErrorCallback.ts diff --git a/src/lib/es6.d.ts b/src/lib/es6.d.ts index fb0c64f8495..dc082c8f0a6 100644 --- a/src/lib/es6.d.ts +++ b/src/lib/es6.d.ts @@ -3580,6 +3580,7 @@ interface PromiseLike { * @returns A Promise for the completion of which ever callback is executed. */ then(onfulfilled?: (value: T) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; + then(onfulfilled?: (value: T) => TResult | PromiseLike, onrejected?: (reason: any) => void): PromiseLike; } /** @@ -3593,6 +3594,7 @@ interface Promise { * @returns A Promise for the completion of which ever callback is executed. */ then(onfulfilled?: (value: T) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): Promise; + then(onfulfilled?: (value: T) => TResult | PromiseLike, onrejected?: (reason: any) => void): Promise; /** * Attaches a callback for only the rejection of the Promise. diff --git a/tests/baselines/reference/promiseVoidErrorCallback.js b/tests/baselines/reference/promiseVoidErrorCallback.js new file mode 100644 index 00000000000..a9aa0f1b5d0 --- /dev/null +++ b/tests/baselines/reference/promiseVoidErrorCallback.js @@ -0,0 +1,43 @@ +//// [promiseVoidErrorCallback.ts] +interface T1 { + __t1: string; +} + +interface T2 { + __t2: string; +} + +interface T3 { + __t3: string; +} + +function f1(): Promise { + return Promise.resolve({ __t1: "foo_t1" }); +} + +function f2(x: T1): T2 { + return { __t2: x.__t1 + ":foo_21" }; +} + +var x3 = f1() + .then(f2, (e: Error) => { + throw e; +}) + .then((x: T2) => { + return { __t3: x.__t2 + "bar" }; +}); + +//// [promiseVoidErrorCallback.js] +function f1() { + return Promise.resolve({ __t1: "foo_t1" }); +} +function f2(x) { + return { __t2: x.__t1 + ":foo_21" }; +} +var x3 = f1() + .then(f2, (e) => { + throw e; +}) + .then((x) => { + return { __t3: x.__t2 + "bar" }; +}); diff --git a/tests/baselines/reference/promiseVoidErrorCallback.symbols b/tests/baselines/reference/promiseVoidErrorCallback.symbols new file mode 100644 index 00000000000..78faacdb1f1 --- /dev/null +++ b/tests/baselines/reference/promiseVoidErrorCallback.symbols @@ -0,0 +1,75 @@ +=== tests/cases/compiler/promiseVoidErrorCallback.ts === +interface T1 { +>T1 : Symbol(T1, Decl(promiseVoidErrorCallback.ts, 0, 0)) + + __t1: string; +>__t1 : Symbol(__t1, Decl(promiseVoidErrorCallback.ts, 0, 14)) +} + +interface T2 { +>T2 : Symbol(T2, Decl(promiseVoidErrorCallback.ts, 2, 1)) + + __t2: string; +>__t2 : Symbol(__t2, Decl(promiseVoidErrorCallback.ts, 4, 14)) +} + +interface T3 { +>T3 : Symbol(T3, Decl(promiseVoidErrorCallback.ts, 6, 1)) + + __t3: string; +>__t3 : Symbol(__t3, Decl(promiseVoidErrorCallback.ts, 8, 14)) +} + +function f1(): Promise { +>f1 : Symbol(f1, Decl(promiseVoidErrorCallback.ts, 10, 1)) +>Promise : Symbol(Promise, Decl(lib.d.ts, 4769, 1), Decl(lib.d.ts, 4854, 11)) +>T1 : Symbol(T1, Decl(promiseVoidErrorCallback.ts, 0, 0)) + + return Promise.resolve({ __t1: "foo_t1" }); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.d.ts, 4836, 39), Decl(lib.d.ts, 4843, 54)) +>Promise : Symbol(Promise, Decl(lib.d.ts, 4769, 1), Decl(lib.d.ts, 4854, 11)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.d.ts, 4836, 39), Decl(lib.d.ts, 4843, 54)) +>__t1 : Symbol(__t1, Decl(promiseVoidErrorCallback.ts, 13, 28)) +} + +function f2(x: T1): T2 { +>f2 : Symbol(f2, Decl(promiseVoidErrorCallback.ts, 14, 1)) +>x : Symbol(x, Decl(promiseVoidErrorCallback.ts, 16, 12)) +>T1 : Symbol(T1, Decl(promiseVoidErrorCallback.ts, 0, 0)) +>T2 : Symbol(T2, Decl(promiseVoidErrorCallback.ts, 2, 1)) + + return { __t2: x.__t1 + ":foo_21" }; +>__t2 : Symbol(__t2, Decl(promiseVoidErrorCallback.ts, 17, 12)) +>x.__t1 : Symbol(T1.__t1, Decl(promiseVoidErrorCallback.ts, 0, 14)) +>x : Symbol(x, Decl(promiseVoidErrorCallback.ts, 16, 12)) +>__t1 : Symbol(T1.__t1, Decl(promiseVoidErrorCallback.ts, 0, 14)) +} + +var x3 = f1() +>x3 : Symbol(x3, Decl(promiseVoidErrorCallback.ts, 20, 3)) +>f1() .then(f2, (e: Error) => { throw e;}) .then : Symbol(Promise.then, Decl(lib.d.ts, 4774, 22), Decl(lib.d.ts, 4781, 158)) +>f1() .then : Symbol(Promise.then, Decl(lib.d.ts, 4774, 22), Decl(lib.d.ts, 4781, 158)) +>f1 : Symbol(f1, Decl(promiseVoidErrorCallback.ts, 10, 1)) + + .then(f2, (e: Error) => { +>then : Symbol(Promise.then, Decl(lib.d.ts, 4774, 22), Decl(lib.d.ts, 4781, 158)) +>f2 : Symbol(f2, Decl(promiseVoidErrorCallback.ts, 14, 1)) +>e : Symbol(e, Decl(promiseVoidErrorCallback.ts, 21, 15)) +>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) + + throw e; +>e : Symbol(e, Decl(promiseVoidErrorCallback.ts, 21, 15)) + +}) + .then((x: T2) => { +>then : Symbol(Promise.then, Decl(lib.d.ts, 4774, 22), Decl(lib.d.ts, 4781, 158)) +>x : Symbol(x, Decl(promiseVoidErrorCallback.ts, 24, 11)) +>T2 : Symbol(T2, Decl(promiseVoidErrorCallback.ts, 2, 1)) + + return { __t3: x.__t2 + "bar" }; +>__t3 : Symbol(__t3, Decl(promiseVoidErrorCallback.ts, 25, 12)) +>x.__t2 : Symbol(T2.__t2, Decl(promiseVoidErrorCallback.ts, 4, 14)) +>x : Symbol(x, Decl(promiseVoidErrorCallback.ts, 24, 11)) +>__t2 : Symbol(T2.__t2, Decl(promiseVoidErrorCallback.ts, 4, 14)) + +}); diff --git a/tests/baselines/reference/promiseVoidErrorCallback.types b/tests/baselines/reference/promiseVoidErrorCallback.types new file mode 100644 index 00000000000..82b248f64bd --- /dev/null +++ b/tests/baselines/reference/promiseVoidErrorCallback.types @@ -0,0 +1,89 @@ +=== tests/cases/compiler/promiseVoidErrorCallback.ts === +interface T1 { +>T1 : T1 + + __t1: string; +>__t1 : string +} + +interface T2 { +>T2 : T2 + + __t2: string; +>__t2 : string +} + +interface T3 { +>T3 : T3 + + __t3: string; +>__t3 : string +} + +function f1(): Promise { +>f1 : () => Promise +>Promise : Promise +>T1 : T1 + + return Promise.resolve({ __t1: "foo_t1" }); +>Promise.resolve({ __t1: "foo_t1" }) : Promise<{ __t1: string; }> +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>{ __t1: "foo_t1" } : { __t1: string; } +>__t1 : string +>"foo_t1" : string +} + +function f2(x: T1): T2 { +>f2 : (x: T1) => T2 +>x : T1 +>T1 : T1 +>T2 : T2 + + return { __t2: x.__t1 + ":foo_21" }; +>{ __t2: x.__t1 + ":foo_21" } : { __t2: string; } +>__t2 : string +>x.__t1 + ":foo_21" : string +>x.__t1 : string +>x : T1 +>__t1 : string +>":foo_21" : string +} + +var x3 = f1() +>x3 : Promise<{ __t3: string; }> +>f1() .then(f2, (e: Error) => { throw e;}) .then((x: T2) => { return { __t3: x.__t2 + "bar" };}) : Promise<{ __t3: string; }> +>f1() .then(f2, (e: Error) => { throw e;}) .then : { (onfulfilled?: (value: T2) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): Promise; (onfulfilled?: (value: T2) => TResult | PromiseLike, onrejected?: (reason: any) => void): Promise; } +>f1() .then(f2, (e: Error) => { throw e;}) : Promise +>f1() .then : { (onfulfilled?: (value: T1) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): Promise; (onfulfilled?: (value: T1) => TResult | PromiseLike, onrejected?: (reason: any) => void): Promise; } +>f1() : Promise +>f1 : () => Promise + + .then(f2, (e: Error) => { +>then : { (onfulfilled?: (value: T1) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): Promise; (onfulfilled?: (value: T1) => TResult | PromiseLike, onrejected?: (reason: any) => void): Promise; } +>f2 : (x: T1) => T2 +>(e: Error) => { throw e;} : (e: Error) => void +>e : Error +>Error : Error + + throw e; +>e : Error + +}) + .then((x: T2) => { +>then : { (onfulfilled?: (value: T2) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): Promise; (onfulfilled?: (value: T2) => TResult | PromiseLike, onrejected?: (reason: any) => void): Promise; } +>(x: T2) => { return { __t3: x.__t2 + "bar" };} : (x: T2) => { __t3: string; } +>x : T2 +>T2 : T2 + + return { __t3: x.__t2 + "bar" }; +>{ __t3: x.__t2 + "bar" } : { __t3: string; } +>__t3 : string +>x.__t2 + "bar" : string +>x.__t2 : string +>x : T2 +>__t2 : string +>"bar" : string + +}); diff --git a/tests/cases/compiler/promiseVoidErrorCallback.ts b/tests/cases/compiler/promiseVoidErrorCallback.ts new file mode 100644 index 00000000000..3169288f79a --- /dev/null +++ b/tests/cases/compiler/promiseVoidErrorCallback.ts @@ -0,0 +1,28 @@ +//@target: ES6 +interface T1 { + __t1: string; +} + +interface T2 { + __t2: string; +} + +interface T3 { + __t3: string; +} + +function f1(): Promise { + return Promise.resolve({ __t1: "foo_t1" }); +} + +function f2(x: T1): T2 { + return { __t2: x.__t1 + ":foo_21" }; +} + +var x3 = f1() + .then(f2, (e: Error) => { + throw e; +}) + .then((x: T2) => { + return { __t3: x.__t2 + "bar" }; +}); \ No newline at end of file From a33bb6bb199a26529e99419cf4d1dc9159c188dc Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 6 May 2015 16:00:50 -0700 Subject: [PATCH 11/22] use canonical file name when asking the host if file exists --- src/services/services.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 1333f2a13cb..ede6fb8ca7b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1632,7 +1632,7 @@ module ts { private fileNameToEntry: Map; private _compilationSettings: CompilerOptions; - constructor(private host: LanguageServiceHost) { + constructor(private host: LanguageServiceHost, private getCanonicalFileName: (fileName: string) => string) { // script id => script index this.fileNameToEntry = {}; @@ -1650,6 +1650,10 @@ module ts { return this._compilationSettings; } + private normalizeFileName(fileName: string): string { + return this.getCanonicalFileName(normalizeSlashes(fileName)); + } + private createEntry(fileName: string) { let entry: HostFileInformation; let scriptSnapshot = this.host.getScriptSnapshot(fileName); @@ -1661,15 +1665,15 @@ module ts { }; } - return this.fileNameToEntry[normalizeSlashes(fileName)] = entry; + return this.fileNameToEntry[this.normalizeFileName(fileName)] = entry; } - public getEntry(fileName: string): HostFileInformation { - return lookUp(this.fileNameToEntry, normalizeSlashes(fileName)); + private getEntry(fileName: string): HostFileInformation { + return lookUp(this.fileNameToEntry, this.normalizeFileName(fileName)); } - public contains(fileName: string): boolean { - return hasProperty(this.fileNameToEntry, normalizeSlashes(fileName)); + private contains(fileName: string): boolean { + return hasProperty(this.fileNameToEntry, this.normalizeFileName(fileName)); } public getOrCreateEntry(fileName: string): HostFileInformation { @@ -1684,8 +1688,10 @@ module ts { let fileNames: string[] = []; forEachKey(this.fileNameToEntry, key => { - if (hasProperty(this.fileNameToEntry, key) && this.fileNameToEntry[key]) - fileNames.push(key); + let entry = this.getEntry(key); + if (entry) { + fileNames.push(entry.hostFileName); + } }); return fileNames; @@ -2387,7 +2393,7 @@ module ts { function synchronizeHostData(): void { // Get a fresh cache of the host information - let hostCache = new HostCache(host); + let hostCache = new HostCache(host, getCanonicalFileName); // If the program is already up-to-date, we can reuse it if (programUpToDate()) { @@ -2408,7 +2414,7 @@ module ts { let newProgram = createProgram(hostCache.getRootFileNames(), newSettings, { getSourceFile: getOrCreateSourceFile, getCancellationToken: () => cancellationToken, - getCanonicalFileName: (fileName) => useCaseSensitivefileNames ? fileName : fileName.toLowerCase(), + getCanonicalFileName, useCaseSensitiveFileNames: () => useCaseSensitivefileNames, getNewLine: () => host.getNewLine ? host.getNewLine() : "\r\n", getDefaultLibFileName: (options) => host.getDefaultLibFileName(options), From 7acc48875780ba4e59f28434db95943adb2875ce Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 6 May 2015 17:23:04 -0700 Subject: [PATCH 12/22] Removed Object.defineProperty for function name --- src/compiler/emitter.ts | 11 ++--------- .../reference/decoratedClassFromExternalModule.js | 1 - 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5a9a654ce60..6d5146a6801 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3898,6 +3898,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitToken(SyntaxKind.CloseBraceToken, node.members.end); scopeEmitEnd(); + // TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now. + // For a decorated class, we need to assign its name (if it has one). This is because we emit // the class as a class expression to avoid the double-binding of the identifier: // @@ -3907,15 +3909,6 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // if (thisNodeIsDecorated) { write(";"); - if (node.name) { - writeLine(); - write("Object.defineProperty("); - emitDeclarationName(node); - write(", \"name\", { value: \""); - emitDeclarationName(node); - write("\", configurable: true });"); - writeLine(); - } } // Emit static property assignment. Because classDeclaration is lexically evaluated, diff --git a/tests/baselines/reference/decoratedClassFromExternalModule.js b/tests/baselines/reference/decoratedClassFromExternalModule.js index 36cffbb6677..163a4a094b4 100644 --- a/tests/baselines/reference/decoratedClassFromExternalModule.js +++ b/tests/baselines/reference/decoratedClassFromExternalModule.js @@ -21,7 +21,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, function decorate() { } let Decorated = class { }; -Object.defineProperty(Decorated, "name", { value: "Decorated", configurable: true }); Decorated = __decorate([ decorate ], Decorated); From 6be18f821eb0543de0d8a32f026a504780d4fbd3 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 6 May 2015 17:30:41 -0700 Subject: [PATCH 13/22] Updated LKG --- bin/tsc.js | 38 +++++++++++++++++++-------------- bin/tsserver.js | 38 +++++++++++++++++++-------------- bin/typescript.js | 45 +++++++++++++++++++++++---------------- bin/typescriptServices.js | 45 +++++++++++++++++++++++---------------- 4 files changed, 98 insertions(+), 68 deletions(-) diff --git a/bin/tsc.js b/bin/tsc.js index 8a47fd26443..2bde9314b4d 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -13005,15 +13005,30 @@ var ts; return type; } var prototypeProperty = getPropertyOfType(rightType, "prototype"); - if (!prototypeProperty) { - return type; + if (prototypeProperty) { + var targetType = getTypeOfSymbol(prototypeProperty); + if (targetType !== anyType) { + if (isTypeSubtypeOf(targetType, type)) { + return targetType; + } + if (type.flags & 16384) { + return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); })); + } + } } - var targetType = getTypeOfSymbol(prototypeProperty); - if (isTypeSubtypeOf(targetType, type)) { - return targetType; + var constructSignatures; + if (rightType.flags & 2048) { + constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; } - if (type.flags & 16384) { - return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); })); + else if (rightType.flags & 32768) { + constructSignatures = getSignaturesOfType(rightType, 1); + } + if (constructSignatures && constructSignatures.length !== 0) { + var instanceType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); })); + if (type.flags & 16384) { + return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, instanceType); })); + } + return instanceType; } return type; } @@ -23260,15 +23275,6 @@ var ts; scopeEmitEnd(); if (thisNodeIsDecorated) { write(";"); - if (node.name) { - writeLine(); - write("Object.defineProperty("); - emitDeclarationName(node); - write(", \"name\", { value: \""); - emitDeclarationName(node); - write("\", configurable: true });"); - writeLine(); - } } if (isClassExpressionWithStaticProperties) { for (var _a = 0; _a < staticProperties.length; _a++) { diff --git a/bin/tsserver.js b/bin/tsserver.js index 7538e43029a..1707ef70411 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -13389,15 +13389,30 @@ var ts; return type; } var prototypeProperty = getPropertyOfType(rightType, "prototype"); - if (!prototypeProperty) { - return type; + if (prototypeProperty) { + var targetType = getTypeOfSymbol(prototypeProperty); + if (targetType !== anyType) { + if (isTypeSubtypeOf(targetType, type)) { + return targetType; + } + if (type.flags & 16384) { + return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); })); + } + } } - var targetType = getTypeOfSymbol(prototypeProperty); - if (isTypeSubtypeOf(targetType, type)) { - return targetType; + var constructSignatures; + if (rightType.flags & 2048) { + constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; } - if (type.flags & 16384) { - return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); })); + else if (rightType.flags & 32768) { + constructSignatures = getSignaturesOfType(rightType, 1); + } + if (constructSignatures && constructSignatures.length !== 0) { + var instanceType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); })); + if (type.flags & 16384) { + return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, instanceType); })); + } + return instanceType; } return type; } @@ -23644,15 +23659,6 @@ var ts; scopeEmitEnd(); if (thisNodeIsDecorated) { write(";"); - if (node.name) { - writeLine(); - write("Object.defineProperty("); - emitDeclarationName(node); - write(", \"name\", { value: \""); - emitDeclarationName(node); - write("\", configurable: true });"); - writeLine(); - } } if (isClassExpressionWithStaticProperties) { for (var _a = 0; _a < staticProperties.length; _a++) { diff --git a/bin/typescript.js b/bin/typescript.js index 9cee921f435..ba375bc4096 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -15732,17 +15732,34 @@ var ts; } // Target type is type of prototype property var prototypeProperty = getPropertyOfType(rightType, "prototype"); - if (!prototypeProperty) { - return type; + if (prototypeProperty) { + var targetType = getTypeOfSymbol(prototypeProperty); + if (targetType !== anyType) { + // Narrow to the target type if it's a subtype of the current type + if (isTypeSubtypeOf(targetType, type)) { + return targetType; + } + // If the current type is a union type, remove all constituents that aren't subtypes of the target. + if (type.flags & 16384 /* Union */) { + return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); })); + } + } } - var targetType = getTypeOfSymbol(prototypeProperty); - // Narrow to target type if it is a subtype of current type - if (isTypeSubtypeOf(targetType, type)) { - return targetType; + // Target type is type of construct signature + var constructSignatures; + if (rightType.flags & 2048 /* Interface */) { + constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; } - // If current type is a union type, remove all constituents that aren't subtypes of target type - if (type.flags & 16384 /* Union */) { - return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); })); + else if (rightType.flags & 32768 /* Anonymous */) { + constructSignatures = getSignaturesOfType(rightType, 1 /* Construct */); + } + if (constructSignatures && constructSignatures.length !== 0) { + var instanceType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); })); + // Pickup type from union types + if (type.flags & 16384 /* Union */) { + return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, instanceType); })); + } + return instanceType; } return type; } @@ -27577,6 +27594,7 @@ var ts; writeLine(); emitToken(15 /* CloseBraceToken */, node.members.end); scopeEmitEnd(); + // TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now. // For a decorated class, we need to assign its name (if it has one). This is because we emit // the class as a class expression to avoid the double-binding of the identifier: // @@ -27586,15 +27604,6 @@ var ts; // if (thisNodeIsDecorated) { write(";"); - if (node.name) { - writeLine(); - write("Object.defineProperty("); - emitDeclarationName(node); - write(", \"name\", { value: \""); - emitDeclarationName(node); - write("\", configurable: true });"); - writeLine(); - } } // Emit static property assignment. Because classDeclaration is lexically evaluated, // it is safe to emit static property assignment after classDeclaration diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 9cee921f435..ba375bc4096 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -15732,17 +15732,34 @@ var ts; } // Target type is type of prototype property var prototypeProperty = getPropertyOfType(rightType, "prototype"); - if (!prototypeProperty) { - return type; + if (prototypeProperty) { + var targetType = getTypeOfSymbol(prototypeProperty); + if (targetType !== anyType) { + // Narrow to the target type if it's a subtype of the current type + if (isTypeSubtypeOf(targetType, type)) { + return targetType; + } + // If the current type is a union type, remove all constituents that aren't subtypes of the target. + if (type.flags & 16384 /* Union */) { + return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); })); + } + } } - var targetType = getTypeOfSymbol(prototypeProperty); - // Narrow to target type if it is a subtype of current type - if (isTypeSubtypeOf(targetType, type)) { - return targetType; + // Target type is type of construct signature + var constructSignatures; + if (rightType.flags & 2048 /* Interface */) { + constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; } - // If current type is a union type, remove all constituents that aren't subtypes of target type - if (type.flags & 16384 /* Union */) { - return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); })); + else if (rightType.flags & 32768 /* Anonymous */) { + constructSignatures = getSignaturesOfType(rightType, 1 /* Construct */); + } + if (constructSignatures && constructSignatures.length !== 0) { + var instanceType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); })); + // Pickup type from union types + if (type.flags & 16384 /* Union */) { + return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, instanceType); })); + } + return instanceType; } return type; } @@ -27577,6 +27594,7 @@ var ts; writeLine(); emitToken(15 /* CloseBraceToken */, node.members.end); scopeEmitEnd(); + // TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now. // For a decorated class, we need to assign its name (if it has one). This is because we emit // the class as a class expression to avoid the double-binding of the identifier: // @@ -27586,15 +27604,6 @@ var ts; // if (thisNodeIsDecorated) { write(";"); - if (node.name) { - writeLine(); - write("Object.defineProperty("); - emitDeclarationName(node); - write(", \"name\", { value: \""); - emitDeclarationName(node); - write("\", configurable: true });"); - writeLine(); - } } // Emit static property assignment. Because classDeclaration is lexically evaluated, // it is safe to emit static property assignment after classDeclaration From ac9b16cff351909866c23155f2d6c4b9d8f534c1 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 6 May 2015 20:11:31 -0700 Subject: [PATCH 14/22] refactor narrowTypeByInstanceof --- src/compiler/checker.ts | 54 ++++++++++--------- ...nstanceOfByConstructorSignature.errors.txt | 16 ++++-- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4c5712299da..d43661c97b6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5384,38 +5384,42 @@ module ts { if (!isTypeSubtypeOf(rightType, globalFunctionType)) { return type; } - // Target type is type of prototype property + + let targetType: Type; let prototypeProperty = getPropertyOfType(rightType, "prototype"); if (prototypeProperty) { - let targetType = getTypeOfSymbol(prototypeProperty); - if (targetType !== anyType) { - // Narrow to the target type if it's a subtype of the current type - if (isTypeSubtypeOf(targetType, type)) { - return targetType; - } - // If the current type is a union type, remove all constituents that aren't subtypes of the target. - if (type.flags & TypeFlags.Union) { - return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, targetType))); - } + // Target type is type of the protoype property + let prototypePropertyType = getTypeOfSymbol(prototypeProperty); + if (prototypePropertyType !== anyType) { + targetType = prototypePropertyType; } } - // Target type is type of construct signature - let constructSignatures: Signature[]; - if (rightType.flags & TypeFlags.Interface) { - constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; - } - else if (rightType.flags & TypeFlags.Anonymous) { - constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct); - } - if (constructSignatures && constructSignatures.length !== 0) { - let instanceType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature)))); - // Pickup type from union types - if (type.flags & TypeFlags.Union) { - return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, instanceType))); + if (!targetType) { + // Target type is type of construct signature + let constructSignatures: Signature[]; + if (rightType.flags & TypeFlags.Interface) { + constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; + } + else if (rightType.flags & TypeFlags.Anonymous) { + constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct); + } + if (constructSignatures && constructSignatures.length) { + targetType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature)))); } - return instanceType; } + + if (targetType) { + // Narrow to the target type if it's a subtype of the current type + if (isTypeSubtypeOf(targetType, type)) { + return targetType; + } + // If the current type is a union type, remove all constituents that aren't subtypes of the target. + if (type.flags & TypeFlags.Union) { + return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, targetType))); + } + } + return type; } diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt index b963b2c33ae..be1a0e5a2c3 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt @@ -1,16 +1,18 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(12,10): error TS2339: Property 'bar' does not exist on type 'A'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(33,5): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(34,10): error TS2339: Property 'bar' does not exist on type 'B'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(63,10): error TS2339: Property 'bar2' does not exist on type 'C1'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(62,10): error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(63,10): error TS2339: Property 'bar2' does not exist on type 'C1 | C2'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(82,10): error TS2339: Property 'bar' does not exist on type 'D'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(109,10): error TS2339: Property 'bar2' does not exist on type 'E1'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(108,10): error TS2339: Property 'bar1' does not exist on type 'E1 | E2'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(109,10): error TS2339: Property 'bar2' does not exist on type 'E1 | E2'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(131,11): error TS2339: Property 'foo' does not exist on type 'string | F'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(132,11): error TS2339: Property 'bar' does not exist on type 'string | F'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(157,11): error TS2339: Property 'foo2' does not exist on type 'G1'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(179,11): error TS2339: Property 'bar' does not exist on type 'H'. -==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts (10 errors) ==== +==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts (12 errors) ==== interface AConstructor { new (): A; } @@ -79,9 +81,11 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru if (obj5 instanceof C) { // narrowed to C1. obj5.foo; obj5.bar1; + ~~~~ +!!! error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. obj5.bar2; ~~~~ -!!! error TS2339: Property 'bar2' does not exist on type 'C1'. +!!! error TS2339: Property 'bar2' does not exist on type 'C1 | C2'. } var obj6: any; @@ -129,9 +133,11 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru if (obj9 instanceof E) { // narrowed to E1. obj9.foo; obj9.bar1; + ~~~~ +!!! error TS2339: Property 'bar1' does not exist on type 'E1 | E2'. obj9.bar2; ~~~~ -!!! error TS2339: Property 'bar2' does not exist on type 'E1'. +!!! error TS2339: Property 'bar2' does not exist on type 'E1 | E2'. } var obj10: any; From 8b43b3d18c65a355c2e54d76cf20ccb424bd156e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 6 May 2015 20:18:32 -0700 Subject: [PATCH 15/22] Update test --- ...nstanceOfByConstructorSignature.errors.txt | 25 +++++++++++-------- ...rdsWithInstanceOfByConstructorSignature.js | 8 ++++-- ...rdsWithInstanceOfByConstructorSignature.ts | 7 ++++-- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt index be1a0e5a2c3..4960940d3ab 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt @@ -1,15 +1,15 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(12,10): error TS2339: Property 'bar' does not exist on type 'A'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(33,5): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(34,10): error TS2339: Property 'bar' does not exist on type 'B'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(62,10): error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(63,10): error TS2339: Property 'bar2' does not exist on type 'C1 | C2'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(82,10): error TS2339: Property 'bar' does not exist on type 'D'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(108,10): error TS2339: Property 'bar1' does not exist on type 'E1 | E2'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(109,10): error TS2339: Property 'bar2' does not exist on type 'E1 | E2'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(131,11): error TS2339: Property 'foo' does not exist on type 'string | F'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(132,11): error TS2339: Property 'bar' does not exist on type 'string | F'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(157,11): error TS2339: Property 'foo2' does not exist on type 'G1'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(179,11): error TS2339: Property 'bar' does not exist on type 'H'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(65,10): error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(66,10): error TS2339: Property 'bar2' does not exist on type 'C1 | C2'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(85,10): error TS2339: Property 'bar' does not exist on type 'D'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(111,10): error TS2339: Property 'bar1' does not exist on type 'E1 | E2'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(112,10): error TS2339: Property 'bar2' does not exist on type 'E1 | E2'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(134,11): error TS2339: Property 'foo' does not exist on type 'string | F'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(135,11): error TS2339: Property 'bar' does not exist on type 'string | F'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(160,11): error TS2339: Property 'foo2' does not exist on type 'G1'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(182,11): error TS2339: Property 'bar' does not exist on type 'H'. ==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts (12 errors) ==== @@ -69,17 +69,20 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru } interface C1 { foo: string; + c: string; bar1: number; } interface C2 { foo: string; + c: string; bar2: number; } declare var C: CConstructor; var obj5: C1 | A; - if (obj5 instanceof C) { // narrowed to C1. + if (obj5 instanceof C) { // narrowed to C1|C2. obj5.foo; + obj5.c; obj5.bar1; ~~~~ !!! error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. @@ -130,7 +133,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru declare var E: EConstructor; var obj9: E1 | A; - if (obj9 instanceof E) { // narrowed to E1. + if (obj9 instanceof E) { // narrowed to E1 | E2 obj9.foo; obj9.bar1; ~~~~ diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js index e5b12bacb1f..7e6b3324470 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js @@ -49,17 +49,20 @@ interface CConstructor { } interface C1 { foo: string; + c: string; bar1: number; } interface C2 { foo: string; + c: string; bar2: number; } declare var C: CConstructor; var obj5: C1 | A; -if (obj5 instanceof C) { // narrowed to C1. +if (obj5 instanceof C) { // narrowed to C1|C2. obj5.foo; + obj5.c; obj5.bar1; obj5.bar2; } @@ -104,7 +107,7 @@ interface E2 { declare var E: EConstructor; var obj9: E1 | A; -if (obj9 instanceof E) { // narrowed to E1. +if (obj9 instanceof E) { // narrowed to E1 | E2 obj9.foo; obj9.bar1; obj9.bar2; @@ -213,6 +216,7 @@ if (obj4 instanceof B) { var obj5; if (obj5 instanceof C) { obj5.foo; + obj5.c; obj5.bar1; obj5.bar2; } diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts index fee92ff10ca..b81dd26652b 100644 --- a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts @@ -48,17 +48,20 @@ interface CConstructor { } interface C1 { foo: string; + c: string; bar1: number; } interface C2 { foo: string; + c: string; bar2: number; } declare var C: CConstructor; var obj5: C1 | A; -if (obj5 instanceof C) { // narrowed to C1. +if (obj5 instanceof C) { // narrowed to C1|C2. obj5.foo; + obj5.c; obj5.bar1; obj5.bar2; } @@ -103,7 +106,7 @@ interface E2 { declare var E: EConstructor; var obj9: E1 | A; -if (obj9 instanceof E) { // narrowed to E1. +if (obj9 instanceof E) { // narrowed to E1 | E2 obj9.foo; obj9.bar1; obj9.bar2; From 42b56cf671030a552e5f68c906fca7c07800cf2c Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 6 May 2015 20:25:12 -0700 Subject: [PATCH 16/22] Add a regression test --- .../reference/narrowTypeByInstanceof.js | 53 ++++++++++++ .../reference/narrowTypeByInstanceof.symbols | 72 ++++++++++++++++ .../reference/narrowTypeByInstanceof.types | 86 +++++++++++++++++++ .../cases/compiler/narrowTypeByInstanceof.ts | 24 ++++++ 4 files changed, 235 insertions(+) create mode 100644 tests/baselines/reference/narrowTypeByInstanceof.js create mode 100644 tests/baselines/reference/narrowTypeByInstanceof.symbols create mode 100644 tests/baselines/reference/narrowTypeByInstanceof.types create mode 100644 tests/cases/compiler/narrowTypeByInstanceof.ts diff --git a/tests/baselines/reference/narrowTypeByInstanceof.js b/tests/baselines/reference/narrowTypeByInstanceof.js new file mode 100644 index 00000000000..11f55089bda --- /dev/null +++ b/tests/baselines/reference/narrowTypeByInstanceof.js @@ -0,0 +1,53 @@ +//// [narrowTypeByInstanceof.ts] + class Match { + public range(): any { + return undefined; + } + } + + class FileMatch { + public resource(): any { + return undefined; + } + } + +type FileMatchOrMatch = FileMatch | Match; + + +let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch; + +if (elementA instanceof FileMatch && elementB instanceof FileMatch) { + let a = elementA.resource().path; + let b = elementB.resource().path; +} else if (elementA instanceof Match && elementB instanceof Match) { + let a = elementA.range(); + let b = elementB.range(); +} + + +//// [narrowTypeByInstanceof.js] +var Match = (function () { + function Match() { + } + Match.prototype.range = function () { + return undefined; + }; + return Match; +})(); +var FileMatch = (function () { + function FileMatch() { + } + FileMatch.prototype.resource = function () { + return undefined; + }; + return FileMatch; +})(); +var elementA, elementB; +if (elementA instanceof FileMatch && elementB instanceof FileMatch) { + var a = elementA.resource().path; + var b = elementB.resource().path; +} +else if (elementA instanceof Match && elementB instanceof Match) { + var a = elementA.range(); + var b = elementB.range(); +} diff --git a/tests/baselines/reference/narrowTypeByInstanceof.symbols b/tests/baselines/reference/narrowTypeByInstanceof.symbols new file mode 100644 index 00000000000..3e620fd105c --- /dev/null +++ b/tests/baselines/reference/narrowTypeByInstanceof.symbols @@ -0,0 +1,72 @@ +=== tests/cases/compiler/narrowTypeByInstanceof.ts === + class Match { +>Match : Symbol(Match, Decl(narrowTypeByInstanceof.ts, 0, 0)) + + public range(): any { +>range : Symbol(range, Decl(narrowTypeByInstanceof.ts, 0, 17)) + + return undefined; +>undefined : Symbol(undefined) + } + } + + class FileMatch { +>FileMatch : Symbol(FileMatch, Decl(narrowTypeByInstanceof.ts, 4, 5)) + + public resource(): any { +>resource : Symbol(resource, Decl(narrowTypeByInstanceof.ts, 6, 21)) + + return undefined; +>undefined : Symbol(undefined) + } + } + +type FileMatchOrMatch = FileMatch | Match; +>FileMatchOrMatch : Symbol(FileMatchOrMatch, Decl(narrowTypeByInstanceof.ts, 10, 5)) +>FileMatch : Symbol(FileMatch, Decl(narrowTypeByInstanceof.ts, 4, 5)) +>Match : Symbol(Match, Decl(narrowTypeByInstanceof.ts, 0, 0)) + + +let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch; +>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3)) +>FileMatchOrMatch : Symbol(FileMatchOrMatch, Decl(narrowTypeByInstanceof.ts, 10, 5)) +>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31)) +>FileMatchOrMatch : Symbol(FileMatchOrMatch, Decl(narrowTypeByInstanceof.ts, 10, 5)) + +if (elementA instanceof FileMatch && elementB instanceof FileMatch) { +>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3)) +>FileMatch : Symbol(FileMatch, Decl(narrowTypeByInstanceof.ts, 4, 5)) +>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31)) +>FileMatch : Symbol(FileMatch, Decl(narrowTypeByInstanceof.ts, 4, 5)) + + let a = elementA.resource().path; +>a : Symbol(a, Decl(narrowTypeByInstanceof.ts, 18, 7)) +>elementA.resource : Symbol(FileMatch.resource, Decl(narrowTypeByInstanceof.ts, 6, 21)) +>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3)) +>resource : Symbol(FileMatch.resource, Decl(narrowTypeByInstanceof.ts, 6, 21)) + + let b = elementB.resource().path; +>b : Symbol(b, Decl(narrowTypeByInstanceof.ts, 19, 7)) +>elementB.resource : Symbol(FileMatch.resource, Decl(narrowTypeByInstanceof.ts, 6, 21)) +>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31)) +>resource : Symbol(FileMatch.resource, Decl(narrowTypeByInstanceof.ts, 6, 21)) + +} else if (elementA instanceof Match && elementB instanceof Match) { +>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3)) +>Match : Symbol(Match, Decl(narrowTypeByInstanceof.ts, 0, 0)) +>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31)) +>Match : Symbol(Match, Decl(narrowTypeByInstanceof.ts, 0, 0)) + + let a = elementA.range(); +>a : Symbol(a, Decl(narrowTypeByInstanceof.ts, 21, 7)) +>elementA.range : Symbol(Match.range, Decl(narrowTypeByInstanceof.ts, 0, 17)) +>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3)) +>range : Symbol(Match.range, Decl(narrowTypeByInstanceof.ts, 0, 17)) + + let b = elementB.range(); +>b : Symbol(b, Decl(narrowTypeByInstanceof.ts, 22, 7)) +>elementB.range : Symbol(Match.range, Decl(narrowTypeByInstanceof.ts, 0, 17)) +>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31)) +>range : Symbol(Match.range, Decl(narrowTypeByInstanceof.ts, 0, 17)) +} + diff --git a/tests/baselines/reference/narrowTypeByInstanceof.types b/tests/baselines/reference/narrowTypeByInstanceof.types new file mode 100644 index 00000000000..b98b1e4d234 --- /dev/null +++ b/tests/baselines/reference/narrowTypeByInstanceof.types @@ -0,0 +1,86 @@ +=== tests/cases/compiler/narrowTypeByInstanceof.ts === + class Match { +>Match : Match + + public range(): any { +>range : () => any + + return undefined; +>undefined : undefined + } + } + + class FileMatch { +>FileMatch : FileMatch + + public resource(): any { +>resource : () => any + + return undefined; +>undefined : undefined + } + } + +type FileMatchOrMatch = FileMatch | Match; +>FileMatchOrMatch : Match | FileMatch +>FileMatch : FileMatch +>Match : Match + + +let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch; +>elementA : Match | FileMatch +>FileMatchOrMatch : Match | FileMatch +>elementB : Match | FileMatch +>FileMatchOrMatch : Match | FileMatch + +if (elementA instanceof FileMatch && elementB instanceof FileMatch) { +>elementA instanceof FileMatch && elementB instanceof FileMatch : boolean +>elementA instanceof FileMatch : boolean +>elementA : Match | FileMatch +>FileMatch : typeof FileMatch +>elementB instanceof FileMatch : boolean +>elementB : Match | FileMatch +>FileMatch : typeof FileMatch + + let a = elementA.resource().path; +>a : any +>elementA.resource().path : any +>elementA.resource() : any +>elementA.resource : () => any +>elementA : FileMatch +>resource : () => any +>path : any + + let b = elementB.resource().path; +>b : any +>elementB.resource().path : any +>elementB.resource() : any +>elementB.resource : () => any +>elementB : FileMatch +>resource : () => any +>path : any + +} else if (elementA instanceof Match && elementB instanceof Match) { +>elementA instanceof Match && elementB instanceof Match : boolean +>elementA instanceof Match : boolean +>elementA : Match | FileMatch +>Match : typeof Match +>elementB instanceof Match : boolean +>elementB : Match | FileMatch +>Match : typeof Match + + let a = elementA.range(); +>a : any +>elementA.range() : any +>elementA.range : () => any +>elementA : Match +>range : () => any + + let b = elementB.range(); +>b : any +>elementB.range() : any +>elementB.range : () => any +>elementB : Match +>range : () => any +} + diff --git a/tests/cases/compiler/narrowTypeByInstanceof.ts b/tests/cases/compiler/narrowTypeByInstanceof.ts new file mode 100644 index 00000000000..6fe6693dd96 --- /dev/null +++ b/tests/cases/compiler/narrowTypeByInstanceof.ts @@ -0,0 +1,24 @@ + class Match { + public range(): any { + return undefined; + } + } + + class FileMatch { + public resource(): any { + return undefined; + } + } + +type FileMatchOrMatch = FileMatch | Match; + + +let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch; + +if (elementA instanceof FileMatch && elementB instanceof FileMatch) { + let a = elementA.resource().path; + let b = elementB.resource().path; +} else if (elementA instanceof Match && elementB instanceof Match) { + let a = elementA.range(); + let b = elementB.range(); +} From 4381d1655d4b72db4f93b4b915999e62102b04b1 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 7 May 2015 11:27:38 -0700 Subject: [PATCH 17/22] Add new line --- src/compiler/checker.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d43661c97b6..79ef7612059 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5404,6 +5404,7 @@ module ts { else if (rightType.flags & TypeFlags.Anonymous) { constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct); } + if (constructSignatures && constructSignatures.length) { targetType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature)))); } From 05892b1993f691bfbdb5227f872a72e0adebc5a3 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 7 May 2015 12:29:47 -0700 Subject: [PATCH 18/22] remove duplicate case labels --- src/compiler/utilities.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 0bb0065d1b0..f63007bddba 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -484,9 +484,6 @@ module ts { case SyntaxKind.IndexSignature: case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - case SyntaxKind.FunctionDeclaration: return true; } } From 4c809eddfb7ffaca8c3c64d2b1cdd160a81baa21 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 8 May 2015 09:55:59 -0700 Subject: [PATCH 19/22] Don't wrap an array of errors in an additional array. --- src/services/shims.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index dc19b8eb79b..869c707d175 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -883,7 +883,7 @@ module ts { return { options: configFile.options, files: configFile.fileNames, - errors: [realizeDiagnostics(configFile.errors, '\r\n')] + errors: realizeDiagnostics(configFile.errors, '\r\n') }; }); } From 286f0150a6d2e819950ca80145945cf61232c166 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 8 May 2015 10:54:00 -0700 Subject: [PATCH 20/22] Prevent infinite loop when classifying. --- src/services/services.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index ede6fb8ca7b..bec00b9a66a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -6039,11 +6039,13 @@ module ts { let end = triviaScanner.getTextPos(); let width = end - start; - if (textSpanIntersectsWith(span, start, width)) { - if (!isTrivia(kind)) { - return; - } + // The moment we get something that isn't trivia, then stop processing. + if (!isTrivia(kind)) { + return; + } + // Only bother with the trivia if it at least intersects the span of interest. + if (textSpanIntersectsWith(span, start, width)) { if (isComment(kind)) { // Simple comment. Just add as is. pushClassification(start, width, ClassificationType.comment); From 80f33dd3eaab28d2cae996e04998725dd32c4818 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 8 May 2015 13:43:13 -0700 Subject: [PATCH 21/22] Make boolean compiler options in harness true only if they say 'true' --- src/harness/fourslash.ts | 10 +- src/harness/harness.ts | 16 +- .../reference/emptyFile-declaration.js | 2 +- .../reference/emptyFile-declaration.js.map | 2 - .../emptyFile-declaration.sourcemap.txt | 7 - .../baselines/reference/emptyFile-souremap.js | 4 +- tests/baselines/reference/es3-amd.js | 7 - tests/baselines/reference/es3-amd.js.map | 2 - .../baselines/reference/es3-amd.sourcemap.txt | 115 -------------- .../reference/es3-declaration-amd.js | 2 +- .../reference/es3-declaration-amd.js.map | 2 - .../es3-declaration-amd.sourcemap.txt | 115 -------------- tests/baselines/reference/es5-amd.js | 7 - tests/baselines/reference/es5-amd.js.map | 2 - .../baselines/reference/es5-amd.sourcemap.txt | 115 -------------- .../reference/es5-declaration-amd.js | 2 +- .../reference/es5-declaration-amd.js.map | 2 - .../es5-declaration-amd.sourcemap.txt | 115 -------------- tests/baselines/reference/es5-umd.js | 7 - tests/baselines/reference/es5-umd.js.map | 2 - .../baselines/reference/es5-umd.sourcemap.txt | 115 -------------- tests/baselines/reference/es5-umd2.js | 7 - tests/baselines/reference/es5-umd2.js.map | 2 - .../reference/es5-umd2.sourcemap.txt | 149 ------------------ tests/baselines/reference/es5-umd3.js | 7 - tests/baselines/reference/es5-umd3.js.map | 2 - .../reference/es5-umd3.sourcemap.txt | 146 ----------------- tests/baselines/reference/es5-umd4.js | 8 - tests/baselines/reference/es5-umd4.js.map | 2 - .../reference/es5-umd4.sourcemap.txt | 143 ----------------- tests/baselines/reference/es6-amd.js | 7 - tests/baselines/reference/es6-amd.js.map | 2 - .../baselines/reference/es6-amd.sourcemap.txt | 91 ----------- .../reference/es6-declaration-amd.js | 2 +- .../reference/es6-declaration-amd.js.map | 2 - .../es6-declaration-amd.sourcemap.txt | 91 ----------- tests/baselines/reference/es6-umd.js | 7 - tests/baselines/reference/es6-umd.js.map | 2 - .../baselines/reference/es6-umd.sourcemap.txt | 91 ----------- tests/baselines/reference/es6-umd2.js | 7 - tests/baselines/reference/es6-umd2.js.map | 2 - .../reference/es6-umd2.sourcemap.txt | 91 ----------- .../compiler/separateCompilationSourceMap.ts | 2 +- 43 files changed, 19 insertions(+), 1495 deletions(-) delete mode 100644 tests/baselines/reference/emptyFile-declaration.js.map delete mode 100644 tests/baselines/reference/emptyFile-declaration.sourcemap.txt delete mode 100644 tests/baselines/reference/es3-amd.js.map delete mode 100644 tests/baselines/reference/es3-amd.sourcemap.txt delete mode 100644 tests/baselines/reference/es3-declaration-amd.js.map delete mode 100644 tests/baselines/reference/es3-declaration-amd.sourcemap.txt delete mode 100644 tests/baselines/reference/es5-amd.js.map delete mode 100644 tests/baselines/reference/es5-amd.sourcemap.txt delete mode 100644 tests/baselines/reference/es5-declaration-amd.js.map delete mode 100644 tests/baselines/reference/es5-declaration-amd.sourcemap.txt delete mode 100644 tests/baselines/reference/es5-umd.js.map delete mode 100644 tests/baselines/reference/es5-umd.sourcemap.txt delete mode 100644 tests/baselines/reference/es5-umd2.js.map delete mode 100644 tests/baselines/reference/es5-umd2.sourcemap.txt delete mode 100644 tests/baselines/reference/es5-umd3.js.map delete mode 100644 tests/baselines/reference/es5-umd3.sourcemap.txt delete mode 100644 tests/baselines/reference/es5-umd4.js.map delete mode 100644 tests/baselines/reference/es5-umd4.sourcemap.txt delete mode 100644 tests/baselines/reference/es6-amd.js.map delete mode 100644 tests/baselines/reference/es6-amd.sourcemap.txt delete mode 100644 tests/baselines/reference/es6-declaration-amd.js.map delete mode 100644 tests/baselines/reference/es6-declaration-amd.sourcemap.txt delete mode 100644 tests/baselines/reference/es6-umd.js.map delete mode 100644 tests/baselines/reference/es6-umd.sourcemap.txt delete mode 100644 tests/baselines/reference/es6-umd2.js.map delete mode 100644 tests/baselines/reference/es6-umd2.sourcemap.txt diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 1f5807c1249..ef4410b3e33 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -144,10 +144,10 @@ module FourSlash { if (globalOptions.hasOwnProperty(prop)) { switch (prop) { case metadataOptionNames.allowNonTsExtensions: - settings.allowNonTsExtensions = true; + settings.allowNonTsExtensions = globalOptions[prop] === "true"; break; case metadataOptionNames.declaration: - settings.declaration = true; + settings.declaration = globalOptions[prop] === "true"; break; case metadataOptionNames.mapRoot: settings.mapRoot = globalOptions[prop]; @@ -174,7 +174,7 @@ module FourSlash { settings.outDir = globalOptions[prop]; break; case metadataOptionNames.sourceMap: - settings.sourceMap = true; + settings.sourceMap = globalOptions[prop] === "true"; break; case metadataOptionNames.sourceRoot: settings.sourceRoot = globalOptions[prop]; @@ -308,7 +308,7 @@ module FourSlash { ts.forEach(testData.files, file => { // Create map between fileName and its content for easily looking up when resolveReference flag is specified this.inputFiles[file.fileName] = file.content; - if (!startResolveFileRef && file.fileOptions[metadataOptionNames.resolveReference]) { + if (!startResolveFileRef && file.fileOptions[metadataOptionNames.resolveReference] === "true") { startResolveFileRef = file; } else if (startResolveFileRef) { // If entry point for resolving file references is already specified, report duplication error @@ -1158,7 +1158,7 @@ module FourSlash { var allFourSlashFiles = this.testData.files; for (var idx = 0; idx < allFourSlashFiles.length; ++idx) { var file = allFourSlashFiles[idx]; - if (file.fileOptions[metadataOptionNames.emitThisFile]) { + if (file.fileOptions[metadataOptionNames.emitThisFile] === "true") { // Find a file with the flag emitThisFile turned on emitFiles.push(file); } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 97d53a6b75e..9ed515eb5b6 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1008,19 +1008,19 @@ module Harness { break; case 'noemitonerror': - options.noEmitOnError = !!setting.value; + options.noEmitOnError = setting.value === 'true'; break; case 'noresolve': - options.noResolve = !!setting.value; + options.noResolve = setting.value === 'true'; break; case 'noimplicitany': - options.noImplicitAny = !!setting.value; + options.noImplicitAny = setting.value === 'true'; break; case 'nolib': - options.noLib = !!setting.value; + options.noLib = setting.value === 'true'; break; case 'out': @@ -1042,11 +1042,11 @@ module Harness { break; case 'sourcemap': - options.sourceMap = !!setting.value; + options.sourceMap = setting.value === 'true'; break; case 'declaration': - options.declaration = !!setting.value; + options.declaration = setting.value === 'true'; break; case 'newline': @@ -1070,7 +1070,7 @@ module Harness { break; case 'stripinternal': - options.stripInternal = !!setting.value; + options.stripInternal = setting.value === 'true'; case 'usecasesensitivefilenames': useCaseSensitiveFileNames = setting.value === 'true'; @@ -1081,7 +1081,7 @@ module Harness { break; case 'emitbom': - options.emitBOM = !!setting.value; + options.emitBOM = setting.value === 'true'; break; case 'errortruncation': diff --git a/tests/baselines/reference/emptyFile-declaration.js b/tests/baselines/reference/emptyFile-declaration.js index 83f47258925..f395099d73c 100644 --- a/tests/baselines/reference/emptyFile-declaration.js +++ b/tests/baselines/reference/emptyFile-declaration.js @@ -2,6 +2,6 @@ //// [emptyFile-declaration.js] -//# sourceMappingURL=emptyFile-declaration.js.map + //// [emptyFile-declaration.d.ts] diff --git a/tests/baselines/reference/emptyFile-declaration.js.map b/tests/baselines/reference/emptyFile-declaration.js.map deleted file mode 100644 index 2b96d268327..00000000000 --- a/tests/baselines/reference/emptyFile-declaration.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [emptyFile-declaration.js.map] -{"version":3,"file":"emptyFile-declaration.js","sourceRoot":"","sources":["emptyFile-declaration.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/tests/baselines/reference/emptyFile-declaration.sourcemap.txt b/tests/baselines/reference/emptyFile-declaration.sourcemap.txt deleted file mode 100644 index 027af4c7ba0..00000000000 --- a/tests/baselines/reference/emptyFile-declaration.sourcemap.txt +++ /dev/null @@ -1,7 +0,0 @@ -=================================================================== -JsFile: emptyFile-declaration.js -mapUrl: emptyFile-declaration.js.map -sourceRoot: -sources: emptyFile-declaration.ts -=================================================================== ->>>//# sourceMappingURL=emptyFile-declaration.js.map \ No newline at end of file diff --git a/tests/baselines/reference/emptyFile-souremap.js b/tests/baselines/reference/emptyFile-souremap.js index 677037d8689..6de7361731a 100644 --- a/tests/baselines/reference/emptyFile-souremap.js +++ b/tests/baselines/reference/emptyFile-souremap.js @@ -2,6 +2,4 @@ //// [emptyFile-souremap.js] -//# sourceMappingURL=emptyFile-souremap.js.map - -//// [emptyFile-souremap.d.ts] +//# sourceMappingURL=emptyFile-souremap.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es3-amd.js b/tests/baselines/reference/es3-amd.js index 4e9fcdf7a9e..03d4a53e9c5 100644 --- a/tests/baselines/reference/es3-amd.js +++ b/tests/baselines/reference/es3-amd.js @@ -22,10 +22,3 @@ var A = (function () { }; return A; })(); -//# sourceMappingURL=es3-amd.js.map - -//// [es3-amd.d.ts] -declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es3-amd.js.map b/tests/baselines/reference/es3-amd.js.map deleted file mode 100644 index a1ccff476c6..00000000000 --- a/tests/baselines/reference/es3-amd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es3-amd.js.map] -{"version":3,"file":"es3-amd.js","sourceRoot":"","sources":["es3-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es3-amd.sourcemap.txt b/tests/baselines/reference/es3-amd.sourcemap.txt deleted file mode 100644 index 86ef55a1f58..00000000000 --- a/tests/baselines/reference/es3-amd.sourcemap.txt +++ /dev/null @@ -1,115 +0,0 @@ -=================================================================== -JsFile: es3-amd.js -mapUrl: es3-amd.js.map -sourceRoot: -sources: es3-amd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es3-amd.js -sourceFile:es3-amd.ts -------------------------------------------------------------------- ->>>var A = (function () { -1 > -2 >^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); -1 > -2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > -2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) ---- ->>>//# sourceMappingURL=es3-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es3-declaration-amd.js b/tests/baselines/reference/es3-declaration-amd.js index 2b4995d8544..12dd009cc0e 100644 --- a/tests/baselines/reference/es3-declaration-amd.js +++ b/tests/baselines/reference/es3-declaration-amd.js @@ -22,7 +22,7 @@ var A = (function () { }; return A; })(); -//# sourceMappingURL=es3-declaration-amd.js.map + //// [es3-declaration-amd.d.ts] declare class A { diff --git a/tests/baselines/reference/es3-declaration-amd.js.map b/tests/baselines/reference/es3-declaration-amd.js.map deleted file mode 100644 index 612763299c9..00000000000 --- a/tests/baselines/reference/es3-declaration-amd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es3-declaration-amd.js.map] -{"version":3,"file":"es3-declaration-amd.js","sourceRoot":"","sources":["es3-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es3-declaration-amd.sourcemap.txt b/tests/baselines/reference/es3-declaration-amd.sourcemap.txt deleted file mode 100644 index 7ad6f48d3ad..00000000000 --- a/tests/baselines/reference/es3-declaration-amd.sourcemap.txt +++ /dev/null @@ -1,115 +0,0 @@ -=================================================================== -JsFile: es3-declaration-amd.js -mapUrl: es3-declaration-amd.js.map -sourceRoot: -sources: es3-declaration-amd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es3-declaration-amd.js -sourceFile:es3-declaration-amd.ts -------------------------------------------------------------------- ->>>var A = (function () { -1 > -2 >^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); -1 > -2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > -2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) ---- ->>>//# sourceMappingURL=es3-declaration-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-amd.js b/tests/baselines/reference/es5-amd.js index cef85a00744..e33fecaed64 100644 --- a/tests/baselines/reference/es5-amd.js +++ b/tests/baselines/reference/es5-amd.js @@ -22,10 +22,3 @@ var A = (function () { }; return A; })(); -//# sourceMappingURL=es5-amd.js.map - -//// [es5-amd.d.ts] -declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es5-amd.js.map b/tests/baselines/reference/es5-amd.js.map deleted file mode 100644 index 6201673cb34..00000000000 --- a/tests/baselines/reference/es5-amd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es5-amd.js.map] -{"version":3,"file":"es5-amd.js","sourceRoot":"","sources":["es5-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-amd.sourcemap.txt b/tests/baselines/reference/es5-amd.sourcemap.txt deleted file mode 100644 index a5902f03982..00000000000 --- a/tests/baselines/reference/es5-amd.sourcemap.txt +++ /dev/null @@ -1,115 +0,0 @@ -=================================================================== -JsFile: es5-amd.js -mapUrl: es5-amd.js.map -sourceRoot: -sources: es5-amd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es5-amd.js -sourceFile:es5-amd.ts -------------------------------------------------------------------- ->>>var A = (function () { -1 > -2 >^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); -1 > -2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > -2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) ---- ->>>//# sourceMappingURL=es5-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-declaration-amd.js b/tests/baselines/reference/es5-declaration-amd.js index d942382ff2e..e180e88d514 100644 --- a/tests/baselines/reference/es5-declaration-amd.js +++ b/tests/baselines/reference/es5-declaration-amd.js @@ -22,7 +22,7 @@ var A = (function () { }; return A; })(); -//# sourceMappingURL=es5-declaration-amd.js.map + //// [es5-declaration-amd.d.ts] declare class A { diff --git a/tests/baselines/reference/es5-declaration-amd.js.map b/tests/baselines/reference/es5-declaration-amd.js.map deleted file mode 100644 index d4dfe8ac244..00000000000 --- a/tests/baselines/reference/es5-declaration-amd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es5-declaration-amd.js.map] -{"version":3,"file":"es5-declaration-amd.js","sourceRoot":"","sources":["es5-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-declaration-amd.sourcemap.txt b/tests/baselines/reference/es5-declaration-amd.sourcemap.txt deleted file mode 100644 index 59b6ba6bb0a..00000000000 --- a/tests/baselines/reference/es5-declaration-amd.sourcemap.txt +++ /dev/null @@ -1,115 +0,0 @@ -=================================================================== -JsFile: es5-declaration-amd.js -mapUrl: es5-declaration-amd.js.map -sourceRoot: -sources: es5-declaration-amd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es5-declaration-amd.js -sourceFile:es5-declaration-amd.ts -------------------------------------------------------------------- ->>>var A = (function () { -1 > -2 >^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); -1 > -2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > -2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) ---- ->>>//# sourceMappingURL=es5-declaration-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd.js b/tests/baselines/reference/es5-umd.js index 0175e8e9fe8..8c68092cbc6 100644 --- a/tests/baselines/reference/es5-umd.js +++ b/tests/baselines/reference/es5-umd.js @@ -23,10 +23,3 @@ var A = (function () { }; return A; })(); -//# sourceMappingURL=es5-umd.js.map - -//// [es5-umd.d.ts] -declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es5-umd.js.map b/tests/baselines/reference/es5-umd.js.map deleted file mode 100644 index 5e29a48796e..00000000000 --- a/tests/baselines/reference/es5-umd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es5-umd.js.map] -{"version":3,"file":"es5-umd.js","sourceRoot":"","sources":["es5-umd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd.sourcemap.txt b/tests/baselines/reference/es5-umd.sourcemap.txt deleted file mode 100644 index bdbdec5fa9e..00000000000 --- a/tests/baselines/reference/es5-umd.sourcemap.txt +++ /dev/null @@ -1,115 +0,0 @@ -=================================================================== -JsFile: es5-umd.js -mapUrl: es5-umd.js.map -sourceRoot: -sources: es5-umd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es5-umd.js -sourceFile:es5-umd.ts -------------------------------------------------------------------- ->>>var A = (function () { -1 > -2 >^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); -1 > -2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > -2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) ---- ->>>//# sourceMappingURL=es5-umd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd2.js b/tests/baselines/reference/es5-umd2.js index cb0265bf92f..4267e7a3331 100644 --- a/tests/baselines/reference/es5-umd2.js +++ b/tests/baselines/reference/es5-umd2.js @@ -33,10 +33,3 @@ export class A })(); exports.A = A; }); -//# sourceMappingURL=es5-umd2.js.map - -//// [es5-umd2.d.ts] -export declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es5-umd2.js.map b/tests/baselines/reference/es5-umd2.js.map deleted file mode 100644 index 13a785b2edc..00000000000 --- a/tests/baselines/reference/es5-umd2.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es5-umd2.js.map] -{"version":3,"file":"es5-umd2.js","sourceRoot":"","sources":["es5-umd2.ts"],"names":["A","A.constructor","A.B"],"mappings":";;;;;;;;IACA;QAEIA;QAGAC,CAACA;QAEMD,aAACA,GAARA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;QACLF,QAACA;IAADA,CAACA,AAXD,IAWC;IAXY,SAAC,IAWb,CAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd2.sourcemap.txt b/tests/baselines/reference/es5-umd2.sourcemap.txt deleted file mode 100644 index bfadd9615f3..00000000000 --- a/tests/baselines/reference/es5-umd2.sourcemap.txt +++ /dev/null @@ -1,149 +0,0 @@ -=================================================================== -JsFile: es5-umd2.js -mapUrl: es5-umd2.js.map -sourceRoot: -sources: es5-umd2.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es5-umd2.js -sourceFile:es5-umd2.ts -------------------------------------------------------------------- ->>>(function (deps, factory) { ->>> if (typeof module === 'object' && typeof module.exports === 'object') { ->>> var v = factory(require, exports); if (v !== undefined) module.exports = v; ->>> } ->>> else if (typeof define === 'function' && define.amd) { ->>> define(deps, factory); ->>> } ->>>})(["require", "exports"], function (require, exports) { ->>> var A = (function () { -1 >^^^^ -2 > ^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(9, 5) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^^^^^ -2 > ^^-> -1->export class A - >{ - > -1->Emitted(10, 9) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(11, 9) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(11, 10) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(12, 9) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(12, 22) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(12, 25) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(13, 13) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(13, 19) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(13, 20) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(13, 22) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(13, 23) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(14, 9) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(14, 10) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(15, 9) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(15, 17) Source(13, 2) + SourceIndex(0) name (A) ---- ->>> })(); -1 >^^^^ -2 > ^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^-> -1 > -2 > } -3 > -4 > export class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(16, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(16, 6) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(16, 6) Source(2, 1) + SourceIndex(0) -4 >Emitted(16, 10) Source(13, 2) + SourceIndex(0) ---- ->>> exports.A = A; -1->^^^^ -2 > ^^^^^^^^^ -3 > ^^^^ -4 > ^ -1-> -2 > A -3 > - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -4 > -1->Emitted(17, 5) Source(2, 14) + SourceIndex(0) -2 >Emitted(17, 14) Source(2, 15) + SourceIndex(0) -3 >Emitted(17, 18) Source(13, 2) + SourceIndex(0) -4 >Emitted(17, 19) Source(13, 2) + SourceIndex(0) ---- ->>>}); ->>>//# sourceMappingURL=es5-umd2.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd3.js b/tests/baselines/reference/es5-umd3.js index 2d18e2eecc3..3abb92f816f 100644 --- a/tests/baselines/reference/es5-umd3.js +++ b/tests/baselines/reference/es5-umd3.js @@ -33,10 +33,3 @@ export default class A })(); exports.default = A; }); -//# sourceMappingURL=es5-umd3.js.map - -//// [es5-umd3.d.ts] -export default class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es5-umd3.js.map b/tests/baselines/reference/es5-umd3.js.map deleted file mode 100644 index 8b955f11936..00000000000 --- a/tests/baselines/reference/es5-umd3.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es5-umd3.js.map] -{"version":3,"file":"es5-umd3.js","sourceRoot":"","sources":["es5-umd3.ts"],"names":["A","A.constructor","A.B"],"mappings":";;;;;;;;IACA;QAEIA;QAGAC,CAACA;QAEMD,aAACA,GAARA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;QACLF,QAACA;IAADA,CAACA,AAXD,IAWC;IAXD,mBAWC,CAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd3.sourcemap.txt b/tests/baselines/reference/es5-umd3.sourcemap.txt deleted file mode 100644 index afb879ac713..00000000000 --- a/tests/baselines/reference/es5-umd3.sourcemap.txt +++ /dev/null @@ -1,146 +0,0 @@ -=================================================================== -JsFile: es5-umd3.js -mapUrl: es5-umd3.js.map -sourceRoot: -sources: es5-umd3.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es5-umd3.js -sourceFile:es5-umd3.ts -------------------------------------------------------------------- ->>>(function (deps, factory) { ->>> if (typeof module === 'object' && typeof module.exports === 'object') { ->>> var v = factory(require, exports); if (v !== undefined) module.exports = v; ->>> } ->>> else if (typeof define === 'function' && define.amd) { ->>> define(deps, factory); ->>> } ->>>})(["require", "exports"], function (require, exports) { ->>> var A = (function () { -1 >^^^^ -2 > ^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(9, 5) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^^^^^ -2 > ^^-> -1->export default class A - >{ - > -1->Emitted(10, 9) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(11, 9) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(11, 10) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(12, 9) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(12, 22) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(12, 25) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(13, 13) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(13, 19) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(13, 20) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(13, 22) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(13, 23) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(14, 9) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(14, 10) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(15, 9) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(15, 17) Source(13, 2) + SourceIndex(0) name (A) ---- ->>> })(); -1 >^^^^ -2 > ^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^-> -1 > -2 > } -3 > -4 > export default class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(16, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(16, 6) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(16, 6) Source(2, 1) + SourceIndex(0) -4 >Emitted(16, 10) Source(13, 2) + SourceIndex(0) ---- ->>> exports.default = A; -1->^^^^ -2 > ^^^^^^^^^^^^^^^^^^^ -3 > ^ -1-> -2 > export default class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -3 > -1->Emitted(17, 5) Source(2, 1) + SourceIndex(0) -2 >Emitted(17, 24) Source(13, 2) + SourceIndex(0) -3 >Emitted(17, 25) Source(13, 2) + SourceIndex(0) ---- ->>>}); ->>>//# sourceMappingURL=es5-umd3.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd4.js b/tests/baselines/reference/es5-umd4.js index 85683f8f3c2..058ad545f42 100644 --- a/tests/baselines/reference/es5-umd4.js +++ b/tests/baselines/reference/es5-umd4.js @@ -35,11 +35,3 @@ export = A; })(); return A; }); -//# sourceMappingURL=es5-umd4.js.map - -//// [es5-umd4.d.ts] -declare class A { - constructor(); - B(): number; -} -export = A; diff --git a/tests/baselines/reference/es5-umd4.js.map b/tests/baselines/reference/es5-umd4.js.map deleted file mode 100644 index 0a47d679ed9..00000000000 --- a/tests/baselines/reference/es5-umd4.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es5-umd4.js.map] -{"version":3,"file":"es5-umd4.js","sourceRoot":"","sources":["es5-umd4.ts"],"names":["A","A.constructor","A.B"],"mappings":";;;;;;;;IACA;QAEIA;QAGAC,CAACA;QAEMD,aAACA,GAARA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;QACLF,QAACA;IAADA,CAACA,AAXD,IAWC;IAEU,AAAX,OAAS,CAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd4.sourcemap.txt b/tests/baselines/reference/es5-umd4.sourcemap.txt deleted file mode 100644 index 9afd8effecf..00000000000 --- a/tests/baselines/reference/es5-umd4.sourcemap.txt +++ /dev/null @@ -1,143 +0,0 @@ -=================================================================== -JsFile: es5-umd4.js -mapUrl: es5-umd4.js.map -sourceRoot: -sources: es5-umd4.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es5-umd4.js -sourceFile:es5-umd4.ts -------------------------------------------------------------------- ->>>(function (deps, factory) { ->>> if (typeof module === 'object' && typeof module.exports === 'object') { ->>> var v = factory(require, exports); if (v !== undefined) module.exports = v; ->>> } ->>> else if (typeof define === 'function' && define.amd) { ->>> define(deps, factory); ->>> } ->>>})(["require", "exports"], function (require, exports) { ->>> var A = (function () { -1 >^^^^ -2 > ^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(9, 5) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(10, 9) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(11, 9) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(11, 10) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> A.prototype.B = function () { -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ -1-> - > - > public -2 > B -3 > -1->Emitted(12, 9) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(12, 22) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(12, 25) Source(9, 5) + SourceIndex(0) name (A) ---- ->>> return 42; -1 >^^^^^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1 >public B() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1 >Emitted(13, 13) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(13, 19) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(13, 20) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(13, 22) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(13, 23) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> }; -1 >^^^^^^^^ -2 > ^ -3 > ^^^^^^^^^-> -1 > - > -2 > } -1 >Emitted(14, 9) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(14, 10) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>> return A; -1->^^^^^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(15, 9) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(15, 17) Source(13, 2) + SourceIndex(0) name (A) ---- ->>> })(); -1 >^^^^ -2 > ^ -3 > -4 > ^^^^ -5 > ^^^^^-> -1 > -2 > } -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(16, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(16, 6) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(16, 6) Source(2, 1) + SourceIndex(0) -4 >Emitted(16, 10) Source(13, 2) + SourceIndex(0) ---- ->>> return A; -1->^^^^ -2 > -3 > ^^^^^^^ -4 > ^ -5 > ^ -1-> - > - >export = A; -2 > -3 > export = -4 > A -5 > ; -1->Emitted(17, 5) Source(15, 12) + SourceIndex(0) -2 >Emitted(17, 5) Source(15, 1) + SourceIndex(0) -3 >Emitted(17, 12) Source(15, 10) + SourceIndex(0) -4 >Emitted(17, 13) Source(15, 11) + SourceIndex(0) -5 >Emitted(17, 14) Source(15, 12) + SourceIndex(0) ---- ->>>}); ->>>//# sourceMappingURL=es5-umd4.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.js b/tests/baselines/reference/es6-amd.js index 74f3037303e..b09f074e59f 100644 --- a/tests/baselines/reference/es6-amd.js +++ b/tests/baselines/reference/es6-amd.js @@ -21,10 +21,3 @@ class A { return 42; } } -//# sourceMappingURL=es6-amd.js.map - -//// [es6-amd.d.ts] -declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es6-amd.js.map b/tests/baselines/reference/es6-amd.js.map deleted file mode 100644 index fe234f8424b..00000000000 --- a/tests/baselines/reference/es6-amd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es6-amd.js.map] -{"version":3,"file":"es6-amd.js","sourceRoot":"","sources":["es6-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.sourcemap.txt b/tests/baselines/reference/es6-amd.sourcemap.txt deleted file mode 100644 index 1ab547073c6..00000000000 --- a/tests/baselines/reference/es6-amd.sourcemap.txt +++ /dev/null @@ -1,91 +0,0 @@ -=================================================================== -JsFile: es6-amd.js -mapUrl: es6-amd.js.map -sourceRoot: -sources: es6-amd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es6-amd.js -sourceFile:es6-amd.ts -------------------------------------------------------------------- ->>>class A { -1 > -2 >^^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> constructor() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> B() { -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^-> -1-> - > - > public -2 > B -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) ---- ->>> return 42; -1->^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1->() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> } -1 >^^^^ -2 > ^ -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>>} -1 > -2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > - > -2 >} -1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>//# sourceMappingURL=es6-amd.js.map1-> -2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1-> -1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) ---- \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.js b/tests/baselines/reference/es6-declaration-amd.js index aeba23e0b6e..b1f54086969 100644 --- a/tests/baselines/reference/es6-declaration-amd.js +++ b/tests/baselines/reference/es6-declaration-amd.js @@ -21,7 +21,7 @@ class A { return 42; } } -//# sourceMappingURL=es6-declaration-amd.js.map + //// [es6-declaration-amd.d.ts] declare class A { diff --git a/tests/baselines/reference/es6-declaration-amd.js.map b/tests/baselines/reference/es6-declaration-amd.js.map deleted file mode 100644 index ca1899e03f5..00000000000 --- a/tests/baselines/reference/es6-declaration-amd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es6-declaration-amd.js.map] -{"version":3,"file":"es6-declaration-amd.js","sourceRoot":"","sources":["es6-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.sourcemap.txt b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt deleted file mode 100644 index 9061bc1ed7c..00000000000 --- a/tests/baselines/reference/es6-declaration-amd.sourcemap.txt +++ /dev/null @@ -1,91 +0,0 @@ -=================================================================== -JsFile: es6-declaration-amd.js -mapUrl: es6-declaration-amd.js.map -sourceRoot: -sources: es6-declaration-amd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es6-declaration-amd.js -sourceFile:es6-declaration-amd.ts -------------------------------------------------------------------- ->>>class A { -1 > -2 >^^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> constructor() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> B() { -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^-> -1-> - > - > public -2 > B -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) ---- ->>> return 42; -1->^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1->() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> } -1 >^^^^ -2 > ^ -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>>} -1 > -2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > - > -2 >} -1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>//# sourceMappingURL=es6-declaration-amd.js.map1-> -2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1-> -1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) ---- \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd.js b/tests/baselines/reference/es6-umd.js index 74cd671f5ef..af8159eeb3e 100644 --- a/tests/baselines/reference/es6-umd.js +++ b/tests/baselines/reference/es6-umd.js @@ -21,10 +21,3 @@ class A { return 42; } } -//# sourceMappingURL=es6-umd.js.map - -//// [es6-umd.d.ts] -declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es6-umd.js.map b/tests/baselines/reference/es6-umd.js.map deleted file mode 100644 index a5e82f7ccfd..00000000000 --- a/tests/baselines/reference/es6-umd.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es6-umd.js.map] -{"version":3,"file":"es6-umd.js","sourceRoot":"","sources":["es6-umd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd.sourcemap.txt b/tests/baselines/reference/es6-umd.sourcemap.txt deleted file mode 100644 index bb8281ce741..00000000000 --- a/tests/baselines/reference/es6-umd.sourcemap.txt +++ /dev/null @@ -1,91 +0,0 @@ -=================================================================== -JsFile: es6-umd.js -mapUrl: es6-umd.js.map -sourceRoot: -sources: es6-umd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es6-umd.js -sourceFile:es6-umd.ts -------------------------------------------------------------------- ->>>class A { -1 > -2 >^^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> constructor() { -1->^^^^ -2 > ^^-> -1->class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> B() { -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^-> -1-> - > - > public -2 > B -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) ---- ->>> return 42; -1->^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1->() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> } -1 >^^^^ -2 > ^ -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>>} -1 > -2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > - > -2 >} -1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>//# sourceMappingURL=es6-umd.js.map1-> -2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1-> -1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) ---- \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd2.js b/tests/baselines/reference/es6-umd2.js index b12d35aacf8..416932d89bc 100644 --- a/tests/baselines/reference/es6-umd2.js +++ b/tests/baselines/reference/es6-umd2.js @@ -21,10 +21,3 @@ export class A { return 42; } } -//# sourceMappingURL=es6-umd2.js.map - -//// [es6-umd2.d.ts] -export declare class A { - constructor(); - B(): number; -} diff --git a/tests/baselines/reference/es6-umd2.js.map b/tests/baselines/reference/es6-umd2.js.map deleted file mode 100644 index 81f3d85a6cd..00000000000 --- a/tests/baselines/reference/es6-umd2.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [es6-umd2.js.map] -{"version":3,"file":"es6-umd2.js","sourceRoot":"","sources":["es6-umd2.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd2.sourcemap.txt b/tests/baselines/reference/es6-umd2.sourcemap.txt deleted file mode 100644 index d032aa3d6c7..00000000000 --- a/tests/baselines/reference/es6-umd2.sourcemap.txt +++ /dev/null @@ -1,91 +0,0 @@ -=================================================================== -JsFile: es6-umd2.js -mapUrl: es6-umd2.js.map -sourceRoot: -sources: es6-umd2.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es6-umd2.js -sourceFile:es6-umd2.ts -------------------------------------------------------------------- ->>>export class A { -1 > -2 >^^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> constructor() { -1->^^^^ -2 > ^^-> -1->export class A - >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^-> -1->constructor () - > { - > - > -2 > } -1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) -2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) ---- ->>> B() { -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^-> -1-> - > - > public -2 > B -1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) ---- ->>> return 42; -1->^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -1->() - > { - > -2 > return -3 > -4 > 42 -5 > ; -1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) -2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) -3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) -4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) -5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) ---- ->>> } -1 >^^^^ -2 > ^ -1 > - > -2 > } -1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) -2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) ---- ->>>} -1 > -2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > - > -2 >} -1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>//# sourceMappingURL=es6-umd2.js.map1-> -2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1-> -1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) ---- \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationSourceMap.ts b/tests/cases/compiler/separateCompilationSourceMap.ts index 7becf7cbdaf..84c6290caf5 100644 --- a/tests/cases/compiler/separateCompilationSourceMap.ts +++ b/tests/cases/compiler/separateCompilationSourceMap.ts @@ -1,5 +1,5 @@ // @separateCompilation: true -// @sourceMap:sourcemap.map +// @sourceMap:true // @target: es6 // @filename: file1.ts From e0931d8629880e6f4bc4639bd0daee468a89a7a1 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 8 May 2015 13:58:20 -0700 Subject: [PATCH 22/22] Type check all files when emitting a file under -out --- src/compiler/program.ts | 7 +++++- .../reference/getEmitOutputOut.baseline | 12 ++++++++++ tests/cases/fourslash/getEmitOutputOut.ts | 23 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/getEmitOutputOut.baseline create mode 100644 tests/cases/fourslash/getEmitOutputOut.ts diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 98b6927fc4c..29dcd1d4932 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -219,7 +219,12 @@ module ts { // Create the emit resolver outside of the "emitTime" tracking code below. That way // any cost associated with it (like type checking) are appropriate associated with // the type-checking counter. - let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); + // + // If the -out option is specified, we should not pass the source file to getEmitResolver. + // This is because in the -out scenario all files need to be emitted, and therefore all + // files need to be type checked. And the way to specify that all files need to be type + // checked is to not pass the file to getEmitResolver. + let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(options.out ? undefined : sourceFile); let start = new Date().getTime(); diff --git a/tests/baselines/reference/getEmitOutputOut.baseline b/tests/baselines/reference/getEmitOutputOut.baseline new file mode 100644 index 00000000000..9508b6d5570 --- /dev/null +++ b/tests/baselines/reference/getEmitOutputOut.baseline @@ -0,0 +1,12 @@ +EmitSkipped: false +FileName : out.js +/// +var foo; +(function (foo) { + var bar; + (function (bar) { + var baz1 = bar.Baz.prototype; // Should emit as bar.Baz.prototype + })(bar = foo.bar || (foo.bar = {})); +})(foo || (foo = {})); +var x; + diff --git a/tests/cases/fourslash/getEmitOutputOut.ts b/tests/cases/fourslash/getEmitOutputOut.ts new file mode 100644 index 00000000000..077b257e4de --- /dev/null +++ b/tests/cases/fourslash/getEmitOutputOut.ts @@ -0,0 +1,23 @@ +/// + +// @BaselineFile: getEmitOutputOut.baseline +// @out: out.js + +// @Filename: my.d.ts +// @emitThisFile: false +////declare module foo.bar { +//// class Baz { } +////} + +// @Filename: input0.ts +// @emitThisFile: false +/////// +////module foo.bar { +//// var baz1 = Baz.prototype; // Should emit as bar.Baz.prototype +////} + +// @Filename: input1.ts +// @emitThisFile: true +////var x; + +verify.baselineGetEmitOutput(); \ No newline at end of file