From 12b7a998e9a22c811994a23ca4480c8ce5a3f78a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 6 Oct 2015 09:47:16 -0700 Subject: [PATCH 1/3] Add test case --- .../reference/moduleMergeConstructor.js | 38 +++++++++++++++ .../reference/moduleMergeConstructor.symbols | 45 ++++++++++++++++++ .../reference/moduleMergeConstructor.types | 47 +++++++++++++++++++ .../cases/compiler/moduleMergeConstructor.ts | 26 ++++++++++ 4 files changed, 156 insertions(+) create mode 100644 tests/baselines/reference/moduleMergeConstructor.js create mode 100644 tests/baselines/reference/moduleMergeConstructor.symbols create mode 100644 tests/baselines/reference/moduleMergeConstructor.types create mode 100644 tests/cases/compiler/moduleMergeConstructor.ts diff --git a/tests/baselines/reference/moduleMergeConstructor.js b/tests/baselines/reference/moduleMergeConstructor.js new file mode 100644 index 00000000000..9922a4c06ae --- /dev/null +++ b/tests/baselines/reference/moduleMergeConstructor.js @@ -0,0 +1,38 @@ +//// [tests/cases/compiler/moduleMergeConstructor.ts] //// + +//// [foo.d.ts] + +declare module "foo" { + export class Foo { + // constructor(): Foo; + method1(): any; + } +} + +//// [foo-ext.d.ts] +declare module "foo" { + export interface Foo { + method2(): any; + } +} + +//// [index.ts] +import * as foo from "foo"; + +class Test { + bar: foo.Foo; + constructor() { + this.bar = new foo.Foo(); + } +} + + +//// [index.js] +define(["require", "exports", "foo"], function (require, exports, foo) { + var Test = (function () { + function Test() { + this.bar = new foo.Foo(); + } + return Test; + })(); +}); diff --git a/tests/baselines/reference/moduleMergeConstructor.symbols b/tests/baselines/reference/moduleMergeConstructor.symbols new file mode 100644 index 00000000000..2cea885f8c2 --- /dev/null +++ b/tests/baselines/reference/moduleMergeConstructor.symbols @@ -0,0 +1,45 @@ +=== tests/cases/compiler/foo.d.ts === + +declare module "foo" { + export class Foo { +>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22)) + + // constructor(): Foo; + method1(): any; +>method1 : Symbol(method1, Decl(foo.d.ts, 2, 22)) + } +} + +=== tests/cases/compiler/foo-ext.d.ts === +declare module "foo" { + export interface Foo { +>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22)) + + method2(): any; +>method2 : Symbol(method2, Decl(foo-ext.d.ts, 1, 26)) + } +} + +=== tests/cases/compiler/index.ts === +import * as foo from "foo"; +>foo : Symbol(foo, Decl(index.ts, 0, 6)) + +class Test { +>Test : Symbol(Test, Decl(index.ts, 0, 27)) + + bar: foo.Foo; +>bar : Symbol(bar, Decl(index.ts, 2, 12)) +>foo : Symbol(foo, Decl(index.ts, 0, 6)) +>Foo : Symbol(foo.Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22)) + + constructor() { + this.bar = new foo.Foo(); +>this.bar : Symbol(bar, Decl(index.ts, 2, 12)) +>this : Symbol(Test, Decl(index.ts, 0, 27)) +>bar : Symbol(bar, Decl(index.ts, 2, 12)) +>foo.Foo : Symbol(foo.Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22)) +>foo : Symbol(foo, Decl(index.ts, 0, 6)) +>Foo : Symbol(foo.Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22)) + } +} + diff --git a/tests/baselines/reference/moduleMergeConstructor.types b/tests/baselines/reference/moduleMergeConstructor.types new file mode 100644 index 00000000000..bec91285f03 --- /dev/null +++ b/tests/baselines/reference/moduleMergeConstructor.types @@ -0,0 +1,47 @@ +=== tests/cases/compiler/foo.d.ts === + +declare module "foo" { + export class Foo { +>Foo : Foo + + // constructor(): Foo; + method1(): any; +>method1 : () => any + } +} + +=== tests/cases/compiler/foo-ext.d.ts === +declare module "foo" { + export interface Foo { +>Foo : Foo + + method2(): any; +>method2 : () => any + } +} + +=== tests/cases/compiler/index.ts === +import * as foo from "foo"; +>foo : typeof foo + +class Test { +>Test : Test + + bar: foo.Foo; +>bar : foo.Foo +>foo : any +>Foo : foo.Foo + + constructor() { + this.bar = new foo.Foo(); +>this.bar = new foo.Foo() : foo.Foo +>this.bar : foo.Foo +>this : this +>bar : foo.Foo +>new foo.Foo() : foo.Foo +>foo.Foo : typeof foo.Foo +>foo : typeof foo +>Foo : typeof foo.Foo + } +} + diff --git a/tests/cases/compiler/moduleMergeConstructor.ts b/tests/cases/compiler/moduleMergeConstructor.ts new file mode 100644 index 00000000000..cb312ba6327 --- /dev/null +++ b/tests/cases/compiler/moduleMergeConstructor.ts @@ -0,0 +1,26 @@ +// @module: amd + +// @filename: foo.d.ts +declare module "foo" { + export class Foo { + // constructor(): Foo; + method1(): any; + } +} + +// @filename: foo-ext.d.ts +declare module "foo" { + export interface Foo { + method2(): any; + } +} + +// @filename: index.ts +import * as foo from "foo"; + +class Test { + bar: foo.Foo; + constructor() { + this.bar = new foo.Foo(); + } +} From e964cb10ca56e81cf8daa2f2a1a019f66087781f Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 14 Oct 2015 12:16:14 -0700 Subject: [PATCH 2/3] Make constructor use merged parent symbol Previously in getSignatureFromDeclaration, it just used the parent symbol without checking whether it was merged. --- src/compiler/checker.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fe203ac52c9..cd1574fa581 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3679,7 +3679,9 @@ namespace ts { function getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature { let links = getNodeLinks(declaration); if (!links.resolvedSignature) { - let classType = declaration.kind === SyntaxKind.Constructor ? getDeclaredTypeOfClassOrInterface((declaration.parent).symbol) : undefined; + let classType = declaration.kind === SyntaxKind.Constructor ? + getDeclaredTypeOfClassOrInterface(getMergedSymbol((declaration.parent).symbol)) + : undefined; let typeParameters = classType ? classType.localTypeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; let parameters: Symbol[] = []; From c66bbd8cea670d7cc5533f1d5d542bff72374ad0 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 14 Oct 2015 12:43:56 -0700 Subject: [PATCH 3/3] Tests now correctly include a constructor --- tests/baselines/reference/moduleMergeConstructor.js | 2 +- tests/baselines/reference/moduleMergeConstructor.symbols | 4 ++-- tests/baselines/reference/moduleMergeConstructor.types | 2 +- tests/cases/compiler/moduleMergeConstructor.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/baselines/reference/moduleMergeConstructor.js b/tests/baselines/reference/moduleMergeConstructor.js index 9922a4c06ae..f47e5791117 100644 --- a/tests/baselines/reference/moduleMergeConstructor.js +++ b/tests/baselines/reference/moduleMergeConstructor.js @@ -4,7 +4,7 @@ declare module "foo" { export class Foo { - // constructor(): Foo; + constructor(); method1(): any; } } diff --git a/tests/baselines/reference/moduleMergeConstructor.symbols b/tests/baselines/reference/moduleMergeConstructor.symbols index 2cea885f8c2..a960ad07e7e 100644 --- a/tests/baselines/reference/moduleMergeConstructor.symbols +++ b/tests/baselines/reference/moduleMergeConstructor.symbols @@ -4,9 +4,9 @@ declare module "foo" { export class Foo { >Foo : Symbol(Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22)) - // constructor(): Foo; + constructor(); method1(): any; ->method1 : Symbol(method1, Decl(foo.d.ts, 2, 22)) +>method1 : Symbol(method1, Decl(foo.d.ts, 3, 22)) } } diff --git a/tests/baselines/reference/moduleMergeConstructor.types b/tests/baselines/reference/moduleMergeConstructor.types index bec91285f03..48a2f010293 100644 --- a/tests/baselines/reference/moduleMergeConstructor.types +++ b/tests/baselines/reference/moduleMergeConstructor.types @@ -4,7 +4,7 @@ declare module "foo" { export class Foo { >Foo : Foo - // constructor(): Foo; + constructor(); method1(): any; >method1 : () => any } diff --git a/tests/cases/compiler/moduleMergeConstructor.ts b/tests/cases/compiler/moduleMergeConstructor.ts index cb312ba6327..018dc867df6 100644 --- a/tests/cases/compiler/moduleMergeConstructor.ts +++ b/tests/cases/compiler/moduleMergeConstructor.ts @@ -3,7 +3,7 @@ // @filename: foo.d.ts declare module "foo" { export class Foo { - // constructor(): Foo; + constructor(); method1(): any; } }