@@ -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
}
@@ -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);
@@ -1380,7 +1380,7 @@ namespace ts {
1380
1380
}
1381
1381
1382
1382
const resolvedModule = getResolvedModule(getSourceFileOfNode(location), moduleReference);
1383
- const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule);
1383
+ let resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule);
1384
1384
const sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName);
1385
1385
if (sourceFile) {
1386
1386
if (sourceFile.symbol) {
@@ -1403,7 +1403,10 @@ 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) {
1406
+ if (isForAugmentation) {
1407
+ resolutionDiagnostic = Diagnostics.Invalid_module_name_in_augmentation_module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented;
1408
+ }
1409
+ else if (compilerOptions.noImplicitAny) {
1407
1410
if (moduleNotFoundError) {
1408
1411
error(errorNode,
1409
1412
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
@@ -1412,15 +1415,17 @@ namespace ts {
1412
1415
}
1413
1416
return undefined;
1414
1417
}
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;
1418
+ else {
1419
+ // Create a new symbol to represent the untyped module and store it in globals.
1420
+ // This provides a name to the module. See the test tests/cases/fourslash/untypedModuleImport.ts
1421
+ const newSymbol = createSymbol(SymbolFlags.ValueModule, quotedName);
1422
+ //newSymbol.declarations = []; //want this?
1423
+ // Module symbols are expected to have 'exports', although since this is an untyped module it can be empty.
1424
+ newSymbol.exports = createMap<Symbol>();
1425
+ // Cache it so subsequent accesses will return the same module.
1426
+ globals[quotedName] = newSymbol;
1427
+ return newSymbol;
1428
+ }
1424
1429
}
1425
1430
1426
1431
if (moduleNotFoundError) {
0 commit comments