@@ -498,7 +498,7 @@ namespace ts {
498
498
const moduleNotFoundError = !isInAmbientContext(moduleName.parent.parent)
499
499
? Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found
500
500
: undefined;
501
- let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, moduleNotFoundError);
501
+ let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, moduleNotFoundError, /*isForAugmentation*/ true );
502
502
if (!mainModule) {
503
503
return;
504
504
}
@@ -1074,7 +1074,7 @@ namespace ts {
1074
1074
const moduleSymbol = resolveExternalModuleName(node, (<ImportDeclaration>node.parent).moduleSpecifier);
1075
1075
1076
1076
if (moduleSymbol) {
1077
- const exportDefaultSymbol = isUntypedModuleSymbol (moduleSymbol) ?
1077
+ const exportDefaultSymbol = isShorthandAmbientModuleSymbol (moduleSymbol) ?
1078
1078
moduleSymbol :
1079
1079
moduleSymbol.exports["export="] ?
1080
1080
getPropertyOfType(getTypeOfSymbol(moduleSymbol.exports["export="]), "default") :
@@ -1150,7 +1150,7 @@ namespace ts {
1150
1150
if (targetSymbol) {
1151
1151
const name = specifier.propertyName || specifier.name;
1152
1152
if (name.text) {
1153
- if (isUntypedModuleSymbol (moduleSymbol)) {
1153
+ if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
1154
1154
return moduleSymbol;
1155
1155
}
1156
1156
@@ -1351,16 +1351,16 @@ namespace ts {
1351
1351
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, Diagnostics.Cannot_find_module_0);
1352
1352
}
1353
1353
1354
- function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage): Symbol {
1354
+ function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage, isForAugmentation = false ): Symbol {
1355
1355
if (moduleReferenceExpression.kind !== SyntaxKind.StringLiteral) {
1356
1356
return;
1357
1357
}
1358
1358
1359
1359
const moduleReferenceLiteral = <LiteralExpression>moduleReferenceExpression;
1360
- return resolveExternalModule(location, moduleReferenceLiteral.text, moduleNotFoundError, moduleReferenceLiteral);
1360
+ return resolveExternalModule(location, moduleReferenceLiteral.text, moduleNotFoundError, moduleReferenceLiteral, isForAugmentation );
1361
1361
}
1362
1362
1363
- function resolveExternalModule(location: Node, moduleReference: string, moduleNotFoundError: DiagnosticMessage, errorNode: Node): Symbol {
1363
+ function resolveExternalModule(location: Node, moduleReference: string, moduleNotFoundError: DiagnosticMessage, errorNode: Node, isForAugmentation = false ): Symbol {
1364
1364
// Module names are escaped in our symbol table. However, string literal values aren't.
1365
1365
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
1366
1366
const moduleName = escapeIdentifier(moduleReference);
@@ -1403,24 +1403,19 @@ namespace ts {
1403
1403
1404
1404
// May be an untyped module. If so, ignore resolutionDiagnostic.
1405
1405
if (!isRelative && resolvedModule && !extensionIsTypeScript(resolvedModule.extension)) {
1406
- if (compilerOptions.noImplicitAny) {
1407
- if (moduleNotFoundError) {
1408
- error(errorNode,
1409
- Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
1410
- moduleReference,
1411
- resolvedModule.resolvedFileName);
1412
- }
1413
- return undefined;
1414
- }
1415
-
1416
- // Create a new symbol to represent the untyped module and store it in globals.
1417
- // This provides a name to the module. See the test tests/cases/fourslash/untypedModuleImport.ts
1418
- const newSymbol = createSymbol(SymbolFlags.ValueModule, quotedName);
1419
- // Module symbols are expected to have 'exports', although since this is an untyped module it can be empty.
1420
- newSymbol.exports = createMap<Symbol>();
1421
- // Cache it so subsequent accesses will return the same module.
1422
- globals[quotedName] = newSymbol;
1423
- return newSymbol;
1406
+ if (isForAugmentation) {
1407
+ Debug.assert(!!moduleNotFoundError);
1408
+ const diag = Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented;
1409
+ error(errorNode, diag, moduleName, resolvedModule.resolvedFileName);
1410
+ }
1411
+ else if (compilerOptions.noImplicitAny && moduleNotFoundError) {
1412
+ error(errorNode,
1413
+ Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
1414
+ moduleReference,
1415
+ resolvedModule.resolvedFileName);
1416
+ }
1417
+ // Failed imports and untyped modules are both treated in an untyped manner; only difference is whether we give a diagnostic first.
1418
+ return undefined;
1424
1419
}
1425
1420
1426
1421
if (moduleNotFoundError) {
@@ -3490,7 +3485,7 @@ namespace ts {
3490
3485
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
3491
3486
const links = getSymbolLinks(symbol);
3492
3487
if (!links.type) {
3493
- if (symbol.flags & SymbolFlags.Module && isUntypedModuleSymbol (symbol)) {
3488
+ if (symbol.flags & SymbolFlags.Module && isShorthandAmbientModuleSymbol (symbol)) {
3494
3489
links.type = anyType;
3495
3490
}
3496
3491
else {
@@ -19063,7 +19058,7 @@ namespace ts {
19063
19058
19064
19059
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
19065
19060
let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
19066
- if (!moduleSymbol || isUntypedModuleSymbol (moduleSymbol)) {
19061
+ if (!moduleSymbol || isShorthandAmbientModuleSymbol (moduleSymbol)) {
19067
19062
// If the module is not found or is shorthand, assume that it may export a value.
19068
19063
return true;
19069
19064
}
0 commit comments