@@ -391,10 +391,17 @@ namespace ts {
391
391
if (!mainModule) {
392
392
return;
393
393
}
394
- // if module symbol has already been merged - it is safe to use it.
395
- // otherwise clone it
396
- mainModule = mainModule.flags & SymbolFlags.Merged ? mainModule : cloneSymbol(mainModule);
397
- mergeSymbol(mainModule, moduleAugmentation.symbol);
394
+ // obtain item referenced by 'export='
395
+ mainModule = resolveExternalModuleSymbol(mainModule);
396
+ if (mainModule.flags & SymbolFlags.Namespace) {
397
+ // if module symbol has already been merged - it is safe to use it.
398
+ // otherwise clone it
399
+ mainModule = mainModule.flags & SymbolFlags.Merged ? mainModule : cloneSymbol(mainModule);
400
+ mergeSymbol(mainModule, moduleAugmentation.symbol);
401
+ }
402
+ else {
403
+ error(moduleName, Diagnostics.Cannot_augment_module_0_because_it_resolves_to_a_non_module_entity, moduleName.text);
404
+ }
398
405
}
399
406
}
400
407
@@ -887,7 +894,7 @@ namespace ts {
887
894
error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
888
895
}
889
896
else if (!exportDefaultSymbol && allowSyntheticDefaultImports) {
890
- return resolveSymbol (moduleSymbol.exports["export="] ) || resolveSymbol(moduleSymbol);
897
+ return resolveExternalModuleSymbol (moduleSymbol) || resolveSymbol(moduleSymbol);
891
898
}
892
899
return exportDefaultSymbol;
893
900
}
@@ -1178,7 +1185,7 @@ namespace ts {
1178
1185
// An external module with an 'export =' declaration resolves to the target of the 'export =' declaration,
1179
1186
// and an external module with no 'export =' declaration resolves to the module itself.
1180
1187
function resolveExternalModuleSymbol(moduleSymbol: Symbol): Symbol {
1181
- return moduleSymbol && resolveSymbol(moduleSymbol.exports["export="]) || moduleSymbol;
1188
+ return moduleSymbol && getMergedSymbol( resolveSymbol(moduleSymbol.exports["export="]) ) || moduleSymbol;
1182
1189
}
1183
1190
1184
1191
// An external module with an 'export =' declaration may be referenced as an ES6 module provided the 'export ='
@@ -1193,8 +1200,8 @@ namespace ts {
1193
1200
return symbol;
1194
1201
}
1195
1202
1196
- function getExportAssignmentSymbol (moduleSymbol: Symbol): Symbol {
1197
- return moduleSymbol.exports["export="];
1203
+ function hasExportAssignmentSymbol (moduleSymbol: Symbol): boolean {
1204
+ return moduleSymbol.exports["export="] !== undefined ;
1198
1205
}
1199
1206
1200
1207
function getExportsOfModuleAsArray(moduleSymbol: Symbol): Symbol[] {
@@ -14836,7 +14843,7 @@ namespace ts {
14836
14843
else {
14837
14844
// export * from "foo"
14838
14845
const moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
14839
- if (moduleSymbol && moduleSymbol.exports["export="] ) {
14846
+ if (moduleSymbol && hasExportAssignmentSymbol( moduleSymbol) ) {
14840
14847
error(node.moduleSpecifier, Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol));
14841
14848
}
14842
14849
}
@@ -15660,7 +15667,7 @@ namespace ts {
15660
15667
return true;
15661
15668
}
15662
15669
15663
- const hasExportAssignment = getExportAssignmentSymbol (moduleSymbol) !== undefined ;
15670
+ const hasExportAssignment = hasExportAssignmentSymbol (moduleSymbol);
15664
15671
// if module has export assignment then 'resolveExternalModuleSymbol' will return resolved symbol for export assignment
15665
15672
// otherwise it will return moduleSymbol itself
15666
15673
moduleSymbol = resolveExternalModuleSymbol(moduleSymbol);
@@ -16019,7 +16026,7 @@ namespace ts {
16019
16026
if (!isExternalOrCommonJsModule(file)) {
16020
16027
mergeSymbolTable(globals, file.locals);
16021
16028
}
16022
- if (file.moduleAugmentations) {
16029
+ if (file.moduleAugmentations.length ) {
16023
16030
(augmentations || (augmentations = [])).push(file.moduleAugmentations);
16024
16031
}
16025
16032
});
0 commit comments