mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
allow augmentation for entities exported via 'export='
This commit is contained in:
@@ -395,10 +395,17 @@ namespace ts {
|
||||
if (!mainModule) {
|
||||
return;
|
||||
}
|
||||
// if module symbol has already been merged - it is safe to use it.
|
||||
// otherwise clone it
|
||||
mainModule = mainModule.flags & SymbolFlags.Merged ? mainModule : cloneSymbol(mainModule);
|
||||
mergeSymbol(mainModule, moduleAugmentation.symbol);
|
||||
// obtain item referenced by 'export='
|
||||
mainModule = resolveExternalModuleSymbol(mainModule);
|
||||
if (mainModule.flags & SymbolFlags.Namespace) {
|
||||
// if module symbol has already been merged - it is safe to use it.
|
||||
// otherwise clone it
|
||||
mainModule = mainModule.flags & SymbolFlags.Merged ? mainModule : cloneSymbol(mainModule);
|
||||
mergeSymbol(mainModule, moduleAugmentation.symbol);
|
||||
}
|
||||
else {
|
||||
error(moduleName, Diagnostics.Cannot_augment_module_0_that_resolves_to_a_non_module_entity, moduleName.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -891,7 +898,7 @@ namespace ts {
|
||||
error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
|
||||
}
|
||||
else if (!exportDefaultSymbol && allowSyntheticDefaultImports) {
|
||||
return resolveSymbol(moduleSymbol.exports["export="]) || resolveSymbol(moduleSymbol);
|
||||
return resolveExternalModuleSymbol(moduleSymbol) || resolveSymbol(moduleSymbol);
|
||||
}
|
||||
return exportDefaultSymbol;
|
||||
}
|
||||
@@ -1182,7 +1189,7 @@ namespace ts {
|
||||
// An external module with an 'export =' declaration resolves to the target of the 'export =' declaration,
|
||||
// and an external module with no 'export =' declaration resolves to the module itself.
|
||||
function resolveExternalModuleSymbol(moduleSymbol: Symbol): Symbol {
|
||||
return moduleSymbol && resolveSymbol(moduleSymbol.exports["export="]) || moduleSymbol;
|
||||
return moduleSymbol && getMergedSymbol(resolveSymbol(moduleSymbol.exports["export="])) || moduleSymbol;
|
||||
}
|
||||
|
||||
// An external module with an 'export =' declaration may be referenced as an ES6 module provided the 'export ='
|
||||
@@ -1197,8 +1204,8 @@ namespace ts {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
function getExportAssignmentSymbol(moduleSymbol: Symbol): Symbol {
|
||||
return moduleSymbol.exports["export="];
|
||||
function hasExportAssignmentSymbol(moduleSymbol: Symbol): boolean {
|
||||
return moduleSymbol.exports["export="] !== undefined;
|
||||
}
|
||||
|
||||
function getExportsOfModuleAsArray(moduleSymbol: Symbol): Symbol[] {
|
||||
@@ -14845,7 +14852,7 @@ namespace ts {
|
||||
else {
|
||||
// export * from "foo"
|
||||
const moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
|
||||
if (moduleSymbol && moduleSymbol.exports["export="]) {
|
||||
if (moduleSymbol && hasExportAssignmentSymbol(moduleSymbol)) {
|
||||
error(node.moduleSpecifier, Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol));
|
||||
}
|
||||
}
|
||||
@@ -15683,7 +15690,7 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
|
||||
const hasExportAssignment = getExportAssignmentSymbol(moduleSymbol) !== undefined;
|
||||
const hasExportAssignment = hasExportAssignmentSymbol(moduleSymbol);
|
||||
// if module has export assignment then 'resolveExternalModuleSymbol' will return resolved symbol for export assignment
|
||||
// otherwise it will return moduleSymbol itself
|
||||
moduleSymbol = resolveExternalModuleSymbol(moduleSymbol);
|
||||
@@ -16042,7 +16049,7 @@ namespace ts {
|
||||
if (!isExternalOrCommonJsModule(file)) {
|
||||
mergeSymbolTable(globals, file.locals);
|
||||
}
|
||||
if (file.moduleAugmentations) {
|
||||
if (file.moduleAugmentations.length) {
|
||||
(augmentations || (augmentations = [])).push(file.moduleAugmentations);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1819,6 +1819,10 @@
|
||||
"category": "Error",
|
||||
"code": 2670
|
||||
},
|
||||
"Cannot augment module '{0}' that resolves to a non-module entity.": {
|
||||
"category": "Error",
|
||||
"code": 2671
|
||||
},
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4000
|
||||
|
||||
Reference in New Issue
Block a user