Skip to content

Commit 36c489c

Browse files
committed
address PR feedback
1 parent e90db46 commit 36c489c

34 files changed

+136
-118
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,7 @@ namespace ts {
24902490
// Every class automatically contains a static property member named 'prototype',
24912491
// the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter.
24922492
// It is an error to explicitly declare a static property member with the name 'prototype'.
2493-
const classType = <InterfaceType>getDeclaredTypeOfSymbol(prototype.parent);
2493+
const classType = <InterfaceType>getDeclaredTypeOfSymbol(getMergedSymbol(prototype.parent));
24942494
return classType.typeParameters ? createTypeReference(<GenericType>classType, map(classType.typeParameters, _ => anyType)) : classType;
24952495
}
24962496

@@ -14364,9 +14364,6 @@ namespace ts {
1436414364
reportError = symbol.parent !== undefined;
1436514365
}
1436614366
else {
14367-
// this symbol contains only merged content from external modules and augmentations so it should always be exported (parent !== undefined)
14368-
// and parent should have value side (valueDeclaration !== undefined)
14369-
Debug.assert(symbol.parent !== undefined && symbol.parent.valueDeclaration !== undefined);
1437014367
// symbol should not originate in augmentation
1437114368
reportError = isExternalModuleAugmentation(symbol.parent.valueDeclaration);
1437214369
}
@@ -15714,20 +15711,22 @@ namespace ts {
1571415711
bindSourceFile(file, compilerOptions);
1571515712
});
1571615713

15717-
let mergeAugmentations = false;
15714+
let augmentations: LiteralExpression[][];
1571815715
// Initialize global symbol table
1571915716
forEach(host.getSourceFiles(), file => {
1572015717
if (!isExternalOrCommonJsModule(file)) {
1572115718
mergeSymbolTable(globals, file.locals);
1572215719
}
15723-
mergeAugmentations = mergeAugmentations || file.moduleAugmentations.length > 0;
15720+
if (file.moduleAugmentations) {
15721+
(augmentations || (augmentations = [])).push(file.moduleAugmentations);
15722+
}
1572415723
});
1572515724

15726-
if (mergeAugmentations) {
15725+
if (augmentations) {
1572715726
// merge module augmentations.
15728-
// this needs to be done after global symbol table is initialized to make sure that all ambient modules are indexed
15729-
for (const file of host.getSourceFiles()) {
15730-
for (const augmentation of file.moduleAugmentations) {
15727+
// this needs to be done after global symbol table is initialized to make sure that all ambient modules are indexed
15728+
for (const list of augmentations) {
15729+
for (const augmentation of list) {
1573115730
mergeModuleAugmentation(augmentation);
1573215731
}
1573315732
}

tests/baselines/reference/moduleAugmentationImportsAndExports1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class B {
1313
import {A} from "./f1";
1414
import {B} from "./f2";
1515

16-
(<any>A.prototype).foo = function () {}
16+
A.prototype.foo = function () { return undefined; }
1717
declare module "./f1" {
1818
interface A {
1919
foo(): B;
@@ -46,7 +46,7 @@ exports.B = B;
4646
//// [f3.js]
4747
"use strict";
4848
var f1_1 = require("./f1");
49-
f1_1.A.prototype.foo = function () { };
49+
f1_1.A.prototype.foo = function () { return undefined; };
5050
//// [f4.js]
5151
"use strict";
5252
require("./f3");

tests/baselines/reference/moduleAugmentationImportsAndExports1.symbols

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ import {A} from "./f1";
1818
import {B} from "./f2";
1919
>B : Symbol(B, Decl(f3.ts, 1, 8))
2020

21-
(<any>A.prototype).foo = function () {}
21+
A.prototype.foo = function () { return undefined; }
22+
>A.prototype.foo : Symbol(A.foo, Decl(f3.ts, 5, 17))
2223
>A.prototype : Symbol(A.prototype)
2324
>A : Symbol(A, Decl(f3.ts, 0, 8))
2425
>prototype : Symbol(A.prototype)
26+
>foo : Symbol(A.foo, Decl(f3.ts, 5, 17))
27+
>undefined : Symbol(undefined)
2528

2629
declare module "./f1" {
2730
interface A {

tests/baselines/reference/moduleAugmentationImportsAndExports1.types

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ import {A} from "./f1";
1818
import {B} from "./f2";
1919
>B : typeof B
2020

21-
(<any>A.prototype).foo = function () {}
22-
>(<any>A.prototype).foo = function () {} : () => void
23-
>(<any>A.prototype).foo : any
24-
>(<any>A.prototype) : any
25-
><any>A.prototype : any
21+
A.prototype.foo = function () { return undefined; }
22+
>A.prototype.foo = function () { return undefined; } : () => any
23+
>A.prototype.foo : () => B
2624
>A.prototype : A
2725
>A : typeof A
2826
>prototype : A
29-
>foo : any
30-
>function () {} : () => void
27+
>foo : () => B
28+
>function () { return undefined; } : () => any
29+
>undefined : undefined
3130

3231
declare module "./f1" {
3332
interface A {

tests/baselines/reference/moduleAugmentationImportsAndExports2.errors.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
tests/cases/compiler/f3.ts(3,13): error TS2339: Property 'foo' does not exist on type 'A'.
12
tests/cases/compiler/f3.ts(11,5): error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.
23
tests/cases/compiler/f3.ts(11,21): error TS2307: Cannot find module './f2'.
34
tests/cases/compiler/f3.ts(12,5): error TS2666: Exports and export assignments are not permitted in module augmentations.
@@ -19,10 +20,12 @@ tests/cases/compiler/f4.ts(5,11): error TS2339: Property 'foo' does not exist on
1920
n: number;
2021
}
2122

22-
==== tests/cases/compiler/f3.ts (9 errors) ====
23+
==== tests/cases/compiler/f3.ts (10 errors) ====
2324
import {A} from "./f1";
2425

25-
(<any>A.prototype).foo = function () {}
26+
A.prototype.foo = function () { return undefined; }
27+
~~~
28+
!!! error TS2339: Property 'foo' does not exist on type 'A'.
2629

2730
namespace N {
2831
export interface Ifc { a }

tests/baselines/reference/moduleAugmentationImportsAndExports2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class B {
1212
//// [f3.ts]
1313
import {A} from "./f1";
1414

15-
(<any>A.prototype).foo = function () {}
15+
A.prototype.foo = function () { return undefined; }
1616

1717
namespace N {
1818
export interface Ifc { a }
@@ -58,7 +58,7 @@ exports.B = B;
5858
//// [f3.js]
5959
"use strict";
6060
var f1_1 = require("./f1");
61-
f1_1.A.prototype.foo = function () { };
61+
f1_1.A.prototype.foo = function () { return undefined; };
6262
//// [f4.js]
6363
"use strict";
6464
require("./f3");

tests/baselines/reference/moduleAugmentationImportsAndExports3.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ tests/cases/compiler/f3.ts(13,16): error TS4000: Import declaration 'C' is using
1818
==== tests/cases/compiler/f3.ts (6 errors) ====
1919
import {A} from "./f1";
2020

21-
(<any>A.prototype).foo = function () {}
21+
A.prototype.foo = function () { return undefined; }
2222

2323
namespace N {
2424
export interface Ifc { a }

tests/baselines/reference/moduleAugmentationImportsAndExports3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class B {
1212
//// [f3.ts]
1313
import {A} from "./f1";
1414

15-
(<any>A.prototype).foo = function () {}
15+
A.prototype.foo = function () { return undefined; }
1616

1717
namespace N {
1818
export interface Ifc { a }
@@ -56,7 +56,7 @@ exports.B = B;
5656
//// [f3.js]
5757
"use strict";
5858
var f1_1 = require("./f1");
59-
f1_1.A.prototype.foo = function () { };
59+
f1_1.A.prototype.foo = function () { return undefined; };
6060
//// [f4.js]
6161
"use strict";
6262
require("./f3");

tests/baselines/reference/moduleAugmentationImportsAndExports4.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class B {
1313
import {A} from "./f1";
1414
import {B} from "./f2";
1515

16-
(<any>A.prototype).foo = function () {}
16+
A.prototype.foo = function () { return undefined; }
1717

1818
namespace N {
1919
export interface Ifc { a: number; }
@@ -58,7 +58,7 @@ exports.B = B;
5858
//// [f3.js]
5959
"use strict";
6060
var f1_1 = require("./f1");
61-
f1_1.A.prototype.foo = function () { };
61+
f1_1.A.prototype.foo = function () { return undefined; };
6262
//// [f4.js]
6363
"use strict";
6464
require("./f3");

tests/baselines/reference/moduleAugmentationImportsAndExports4.symbols

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ import {A} from "./f1";
1818
import {B} from "./f2";
1919
>B : Symbol(B, Decl(f3.ts, 1, 8))
2020

21-
(<any>A.prototype).foo = function () {}
21+
A.prototype.foo = function () { return undefined; }
22+
>A.prototype.foo : Symbol(A.foo, Decl(f3.ts, 13, 17))
2223
>A.prototype : Symbol(A.prototype)
2324
>A : Symbol(A, Decl(f3.ts, 0, 8))
2425
>prototype : Symbol(A.prototype)
26+
>foo : Symbol(A.foo, Decl(f3.ts, 13, 17))
27+
>undefined : Symbol(undefined)
2528

2629
namespace N {
27-
>N : Symbol(N, Decl(f3.ts, 3, 39))
30+
>N : Symbol(N, Decl(f3.ts, 3, 51))
2831

2932
export interface Ifc { a: number; }
3033
>Ifc : Symbol(Ifc, Decl(f3.ts, 5, 13))
@@ -36,12 +39,12 @@ namespace N {
3639
}
3740
import I = N.Ifc;
3841
>I : Symbol(I, Decl(f3.ts, 8, 1))
39-
>N : Symbol(N, Decl(f3.ts, 3, 39))
42+
>N : Symbol(N, Decl(f3.ts, 3, 51))
4043
>Ifc : Symbol(I, Decl(f3.ts, 5, 13))
4144

4245
import C = N.Cls;
4346
>C : Symbol(C, Decl(f3.ts, 9, 17))
44-
>N : Symbol(N, Decl(f3.ts, 3, 39))
47+
>N : Symbol(N, Decl(f3.ts, 3, 51))
4548
>Cls : Symbol(C, Decl(f3.ts, 6, 39))
4649

4750
declare module "./f1" {

tests/baselines/reference/moduleAugmentationImportsAndExports4.types

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ import {A} from "./f1";
1818
import {B} from "./f2";
1919
>B : typeof B
2020

21-
(<any>A.prototype).foo = function () {}
22-
>(<any>A.prototype).foo = function () {} : () => void
23-
>(<any>A.prototype).foo : any
24-
>(<any>A.prototype) : any
25-
><any>A.prototype : any
21+
A.prototype.foo = function () { return undefined; }
22+
>A.prototype.foo = function () { return undefined; } : () => any
23+
>A.prototype.foo : () => B
2624
>A.prototype : A
2725
>A : typeof A
2826
>prototype : A
29-
>foo : any
30-
>function () {} : () => void
27+
>foo : () => B
28+
>function () { return undefined; } : () => any
29+
>undefined : undefined
3130

3231
namespace N {
3332
>N : any

tests/baselines/reference/moduleAugmentationImportsAndExports5.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tests/cases/compiler/f3.ts(11,12): error TS4000: Import declaration 'C' is using
1515
import {A} from "./f1";
1616
import {B} from "./f2";
1717

18-
(<any>A.prototype).foo = function () {}
18+
A.prototype.foo = function () { return undefined; }
1919

2020
namespace N {
2121
export interface Ifc { a: number; }

tests/baselines/reference/moduleAugmentationImportsAndExports5.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class B {
1313
import {A} from "./f1";
1414
import {B} from "./f2";
1515

16-
(<any>A.prototype).foo = function () {}
16+
A.prototype.foo = function () { return undefined; }
1717

1818
namespace N {
1919
export interface Ifc { a: number; }
@@ -58,7 +58,7 @@ exports.B = B;
5858
//// [f3.js]
5959
"use strict";
6060
var f1_1 = require("./f1");
61-
f1_1.A.prototype.foo = function () { };
61+
f1_1.A.prototype.foo = function () { return undefined; };
6262
//// [f4.js]
6363
"use strict";
6464
require("./f3");

tests/baselines/reference/moduleAugmentationImportsAndExports6.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class B {
1313
import {A} from "./f1";
1414
import {B} from "./f2";
1515

16-
(<any>A.prototype).foo = function () {}
16+
A.prototype.foo = function () { return undefined; }
1717

1818
export namespace N {
1919
export interface Ifc { a: number; }
@@ -58,7 +58,7 @@ exports.B = B;
5858
//// [f3.js]
5959
"use strict";
6060
var f1_1 = require("./f1");
61-
f1_1.A.prototype.foo = function () { };
61+
f1_1.A.prototype.foo = function () { return undefined; };
6262
//// [f4.js]
6363
"use strict";
6464
require("./f3");

tests/baselines/reference/moduleAugmentationImportsAndExports6.symbols

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ import {A} from "./f1";
1818
import {B} from "./f2";
1919
>B : Symbol(B, Decl(f3.ts, 1, 8))
2020

21-
(<any>A.prototype).foo = function () {}
21+
A.prototype.foo = function () { return undefined; }
22+
>A.prototype.foo : Symbol(A.foo, Decl(f3.ts, 13, 17))
2223
>A.prototype : Symbol(A.prototype)
2324
>A : Symbol(A, Decl(f3.ts, 0, 8))
2425
>prototype : Symbol(A.prototype)
26+
>foo : Symbol(A.foo, Decl(f3.ts, 13, 17))
27+
>undefined : Symbol(undefined)
2528

2629
export namespace N {
27-
>N : Symbol(N, Decl(f3.ts, 3, 39))
30+
>N : Symbol(N, Decl(f3.ts, 3, 51))
2831

2932
export interface Ifc { a: number; }
3033
>Ifc : Symbol(Ifc, Decl(f3.ts, 5, 20))
@@ -36,12 +39,12 @@ export namespace N {
3639
}
3740
import I = N.Ifc;
3841
>I : Symbol(I, Decl(f3.ts, 8, 1))
39-
>N : Symbol(N, Decl(f3.ts, 3, 39))
42+
>N : Symbol(N, Decl(f3.ts, 3, 51))
4043
>Ifc : Symbol(I, Decl(f3.ts, 5, 20))
4144

4245
import C = N.Cls;
4346
>C : Symbol(C, Decl(f3.ts, 9, 17))
44-
>N : Symbol(N, Decl(f3.ts, 3, 39))
47+
>N : Symbol(N, Decl(f3.ts, 3, 51))
4548
>Cls : Symbol(C, Decl(f3.ts, 6, 39))
4649

4750
declare module "./f1" {

tests/baselines/reference/moduleAugmentationImportsAndExports6.types

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ import {A} from "./f1";
1818
import {B} from "./f2";
1919
>B : typeof B
2020

21-
(<any>A.prototype).foo = function () {}
22-
>(<any>A.prototype).foo = function () {} : () => void
23-
>(<any>A.prototype).foo : any
24-
>(<any>A.prototype) : any
25-
><any>A.prototype : any
21+
A.prototype.foo = function () { return undefined; }
22+
>A.prototype.foo = function () { return undefined; } : () => any
23+
>A.prototype.foo : () => B
2624
>A.prototype : A
2725
>A : typeof A
2826
>prototype : A
29-
>foo : any
30-
>function () {} : () => void
27+
>foo : () => B
28+
>function () { return undefined; } : () => any
29+
>undefined : undefined
3130

3231
export namespace N {
3332
>N : any

tests/baselines/reference/moduleAugmentationsImports1.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import {A} from "./a";
1919
import {B} from "./b";
2020
import {Cls} from "C";
2121

22-
(<any>A.prototype).getB = function () {};
23-
(<any>A.prototype).getCls = function () {}
22+
A.prototype.getB = function () { return undefined; }
23+
A.prototype.getCls = function () { return undefined; }
2424

2525
declare module "./a" {
2626
interface A {
@@ -64,8 +64,8 @@ define("b", ["require", "exports"], function (require, exports) {
6464
/// <reference path="c.d.ts"/>
6565
define("d", ["require", "exports", "a"], function (require, exports, a_1) {
6666
"use strict";
67-
a_1.A.prototype.getB = function () { };
68-
a_1.A.prototype.getCls = function () { };
67+
a_1.A.prototype.getB = function () { return undefined; };
68+
a_1.A.prototype.getCls = function () { return undefined; };
6969
});
7070
define("main", ["require", "exports", "d"], function (require, exports) {
7171
"use strict";

tests/baselines/reference/moduleAugmentationsImports1.symbols

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,21 @@ import {B} from "./b";
2727
import {Cls} from "C";
2828
>Cls : Symbol(Cls, Decl(d.ts, 4, 8))
2929

30-
(<any>A.prototype).getB = function () {};
30+
A.prototype.getB = function () { return undefined; }
31+
>A.prototype.getB : Symbol(A.getB, Decl(d.ts, 10, 17))
3132
>A.prototype : Symbol(A.prototype)
3233
>A : Symbol(A, Decl(d.ts, 2, 8))
3334
>prototype : Symbol(A.prototype)
35+
>getB : Symbol(A.getB, Decl(d.ts, 10, 17))
36+
>undefined : Symbol(undefined)
3437

35-
(<any>A.prototype).getCls = function () {}
38+
A.prototype.getCls = function () { return undefined; }
39+
>A.prototype.getCls : Symbol(A.getCls, Decl(d.ts, 16, 17))
3640
>A.prototype : Symbol(A.prototype)
3741
>A : Symbol(A, Decl(d.ts, 2, 8))
3842
>prototype : Symbol(A.prototype)
43+
>getCls : Symbol(A.getCls, Decl(d.ts, 16, 17))
44+
>undefined : Symbol(undefined)
3945

4046
declare module "./a" {
4147
interface A {

0 commit comments

Comments
 (0)