@@ -498,15 +498,13 @@ 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
}
505
505
// obtain item referenced by 'export='
506
506
mainModule = resolveExternalModuleSymbol(mainModule);
507
507
if (mainModule.flags & SymbolFlags.Namespace) {
508
- // if module symbol has already been merged - it is safe to use it.
509
- // otherwise clone it
510
508
mainModule = mainModule.flags & SymbolFlags.Merged ? mainModule : cloneSymbol(mainModule);
511
509
mergeSymbol(mainModule, moduleAugmentation.symbol);
512
510
}
@@ -1351,16 +1349,16 @@ namespace ts {
1351
1349
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, Diagnostics.Cannot_find_module_0);
1352
1350
}
1353
1351
1354
- function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage): Symbol {
1352
+ function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage, isForAugmentation = false ): Symbol {
1355
1353
if (moduleReferenceExpression.kind !== SyntaxKind.StringLiteral) {
1356
1354
return;
1357
1355
}
1358
1356
1359
1357
const moduleReferenceLiteral = <LiteralExpression>moduleReferenceExpression;
1360
- return resolveExternalModule(location, moduleReferenceLiteral.text, moduleNotFoundError, moduleReferenceLiteral);
1358
+ return resolveExternalModule(location, moduleReferenceLiteral.text, moduleNotFoundError, moduleReferenceLiteral, isForAugmentation );
1361
1359
}
1362
1360
1363
- function resolveExternalModule(location: Node, moduleReference: string, moduleNotFoundError: DiagnosticMessage, errorNode: Node): Symbol {
1361
+ function resolveExternalModule(location: Node, moduleReference: string, moduleNotFoundError: DiagnosticMessage, errorNode: Node, isForAugmentation = false ): Symbol {
1364
1362
// Module names are escaped in our symbol table. However, string literal values aren't.
1365
1363
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
1366
1364
const moduleName = escapeIdentifier(moduleReference);
@@ -1380,7 +1378,7 @@ namespace ts {
1380
1378
}
1381
1379
1382
1380
const resolvedModule = getResolvedModule(getSourceFileOfNode(location), moduleReference);
1383
- const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule);
1381
+ let resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule);
1384
1382
const sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName);
1385
1383
if (sourceFile) {
1386
1384
if (sourceFile.symbol) {
@@ -1403,7 +1401,10 @@ namespace ts {
1403
1401
1404
1402
// May be an untyped module. If so, ignore resolutionDiagnostic.
1405
1403
if (!isRelative && resolvedModule && !extensionIsTypeScript(resolvedModule.extension)) {
1406
- if (compilerOptions.noImplicitAny) {
1404
+ if (isForAugmentation) {
1405
+ resolutionDiagnostic = Diagnostics.Invalid_module_name_in_augmentation_module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented;
1406
+ }
1407
+ else if (compilerOptions.noImplicitAny) {
1407
1408
if (moduleNotFoundError) {
1408
1409
error(errorNode,
1409
1410
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
@@ -1412,15 +1413,17 @@ namespace ts {
1412
1413
}
1413
1414
return undefined;
1414
1415
}
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;
1416
+ else {
1417
+ // Create a new symbol to represent the untyped module and store it in globals.
1418
+ // This provides a name to the module. See the test tests/cases/fourslash/untypedModuleImport.ts
1419
+ const newSymbol = createSymbol(SymbolFlags.ValueModule, quotedName);
1420
+ //newSymbol.declarations = []; //want this?
1421
+ // Module symbols are expected to have 'exports', although since this is an untyped module it can be empty.
1422
+ newSymbol.exports = createMap<Symbol>();
1423
+ // Cache it so subsequent accesses will return the same module.
1424
+ globals[quotedName] = newSymbol;
1425
+ return newSymbol;
1426
+ }
1424
1427
}
1425
1428
1426
1429
if (moduleNotFoundError) {
0 commit comments