@@ -380,6 +380,7 @@ namespace ts {
380
380
}
381
381
382
382
function mergeSymbol(target: Symbol, source: Symbol) {
383
+ //TODO: how to merge w/ shorthand ambient module?
383
384
if (!(target.flags & getExcludedSymbolFlags(source.flags))) {
384
385
if (source.flags & SymbolFlags.ValueModule && target.flags & SymbolFlags.ValueModule && target.constEnumOnlyModule && !source.constEnumOnlyModule) {
385
386
// reset flag when merging instantiated module into value module that has only const enums
@@ -986,7 +987,9 @@ namespace ts {
986
987
const moduleSymbol = resolveExternalModuleName(node, (<ImportDeclaration>node.parent).moduleSpecifier);
987
988
988
989
if (moduleSymbol) {
989
- const exportDefaultSymbol = moduleSymbol.exports["export="] ?
990
+ const exportDefaultSymbol = isShorthandAmbientModuleSymbol(moduleSymbol) ?
991
+ moduleSymbol :
992
+ moduleSymbol.exports["export="] ?
990
993
getPropertyOfType(getTypeOfSymbol(moduleSymbol.exports["export="]), "default") :
991
994
resolveSymbol(moduleSymbol.exports["default"]);
992
995
@@ -1044,6 +1047,15 @@ namespace ts {
1044
1047
}
1045
1048
}
1046
1049
}
1050
+
1051
+ //move
1052
+ function isShorthandAmbientModuleSymbol(symbol: Symbol): boolean {
1053
+ const module = symbol.valueDeclaration;
1054
+ return module.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModule(<ModuleDeclaration>module);
1055
+ }
1056
+ function isShorthandAmbientModule(module: ModuleDeclaration): boolean {
1057
+ return !module.body;
1058
+ }
1047
1059
1048
1060
function getPropertyOfVariable(symbol: Symbol, name: string): Symbol {
1049
1061
if (symbol.flags & SymbolFlags.Variable) {
@@ -1060,6 +1072,10 @@ namespace ts {
1060
1072
if (targetSymbol) {
1061
1073
const name = specifier.propertyName || specifier.name;
1062
1074
if (name.text) {
1075
+ if (isShorthandAmbientModuleSymbol(moduleSymbol)) {
1076
+ return moduleSymbol;
1077
+ }
1078
+
1063
1079
let symbolFromVariable: Symbol;
1064
1080
// First check if module was specified with "export=". If so, get the member from the resolved type
1065
1081
if (moduleSymbol && moduleSymbol.exports && moduleSymbol.exports["export="]) {
@@ -3220,9 +3236,14 @@ namespace ts {
3220
3236
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
3221
3237
const links = getSymbolLinks(symbol);
3222
3238
if (!links.type) {
3223
- const type = createObjectType(TypeFlags.Anonymous, symbol);
3224
- links.type = strictNullChecks && symbol.flags & SymbolFlags.Optional ?
3225
- addNullableKind(type, TypeFlags.Undefined) : type;
3239
+ if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModule(<ModuleDeclaration>symbol.valueDeclaration)) {
3240
+ links.type = anyType;
3241
+ }
3242
+ else {
3243
+ const type = createObjectType(TypeFlags.Anonymous, symbol);
3244
+ links.type = strictNullChecks && symbol.flags & SymbolFlags.Optional ?
3245
+ addNullableKind(type, TypeFlags.Undefined) : type;
3246
+ }
3226
3247
}
3227
3248
return links.type;
3228
3249
}
@@ -16010,7 +16031,7 @@ namespace ts {
16010
16031
// - augmentation for a global scope is always applied
16011
16032
// - augmentation for some external module is applied if symbol for augmentation is merged (it was combined with target module).
16012
16033
const checkBody = isGlobalAugmentation || (getSymbolOfNode(node).flags & SymbolFlags.Merged);
16013
- if (checkBody) {
16034
+ if (checkBody && node.body ) {
16014
16035
// body of ambient external module is always a module block
16015
16036
for (const statement of (<ModuleBlock>node.body).statements) {
16016
16037
checkModuleAugmentationElement(statement, isGlobalAugmentation);
@@ -16037,7 +16058,9 @@ namespace ts {
16037
16058
}
16038
16059
}
16039
16060
}
16040
- checkSourceElement(node.body);
16061
+ if (node.body) {
16062
+ checkSourceElement(node.body);
16063
+ }
16041
16064
}
16042
16065
16043
16066
function checkModuleAugmentationElement(node: Node, isGlobalAugmentation: boolean): void {
0 commit comments