Skip to content

Commit 4801c34

Browse files
committed
Emit the declarations for the chained import usage in the export assignment
1 parent 2654eed commit 4801c34

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,30 +1064,31 @@ module ts {
10641064
// This is export assigned symbol node
10651065
var externalModuleSymbol = getSymbolOfNode(externalModule);
10661066
var exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol);
1067+
var resolvedExportSymbol: Symbol;
10671068
var symbolOfNode = getSymbolOfNode(node);
1068-
if (exportAssignmentSymbol === symbolOfNode) {
1069+
if (isSymbolUsedInExportAssignment(symbolOfNode)) {
1070+
return true;
1071+
}
1072+
1073+
// if symbolOfNode is import declaration, resolve the symbol declaration and check
1074+
if (symbolOfNode.flags & SymbolFlags.Import) {
1075+
return isSymbolUsedInExportAssignment(resolveImport(symbolOfNode));
1076+
}
1077+
}
1078+
1079+
// Check if the symbol is used in export assignment
1080+
function isSymbolUsedInExportAssignment(symbol: Symbol) {
1081+
if (exportAssignmentSymbol === symbol) {
10691082
return true;
10701083
}
10711084

10721085
if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & SymbolFlags.Import)) {
10731086
// if export assigned symbol is import declaration, resolve the import
1074-
var resolvedExportSymbol = resolveImport(exportAssignmentSymbol);
1075-
if (resolvedExportSymbol === symbolOfNode) {
1087+
resolvedExportSymbol = resolvedExportSymbol || resolveImport(exportAssignmentSymbol);
1088+
if (resolvedExportSymbol === symbol) {
10761089
return true;
10771090
}
10781091

1079-
// TODO(shkamat): Chained import assignment
1080-
// eg. a should be visible too.
1081-
//module m {
1082-
// export module c {
1083-
// export class c {
1084-
// }
1085-
// }
1086-
//}
1087-
//import a = m.c;
1088-
//import b = a;
1089-
//export = b;
1090-
10911092
// Container of resolvedExportSymbol is visible
10921093
return forEach(resolvedExportSymbol.declarations, declaration => {
10931094
while (declaration) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//// [declFileImportChainInExportAssignment.ts]
2+
module m {
3+
export module c {
4+
export class c {
5+
}
6+
}
7+
}
8+
import a = m.c;
9+
import b = a;
10+
export = b;
11+
12+
//// [declFileImportChainInExportAssignment.js]
13+
var m;
14+
(function (m) {
15+
(function (_c) {
16+
var c = (function () {
17+
function c() {
18+
}
19+
return c;
20+
})();
21+
_c.c = c;
22+
})(m.c || (m.c = {}));
23+
var c = m.c;
24+
})(m || (m = {}));
25+
var a = m.c;
26+
var b = a;
27+
module.exports = b;
28+
29+
30+
//// [declFileImportChainInExportAssignment.d.ts]
31+
declare module m {
32+
module c {
33+
class c {
34+
}
35+
}
36+
}
37+
import a = m.c;
38+
import b = a;
39+
export = b;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @declaration: true
2+
// @module: commonjs
3+
module m {
4+
export module c {
5+
export class c {
6+
}
7+
}
8+
}
9+
import a = m.c;
10+
import b = a;
11+
export = b;

0 commit comments

Comments
 (0)