@@ -1071,7 +1071,7 @@ namespace ts {
1071
1071
1072
1072
if (moduleSymbol) {
1073
1073
let exportDefaultSymbol: Symbol;
1074
- if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
1074
+ if (isUntypedModuleSymbol (moduleSymbol)) {
1075
1075
exportDefaultSymbol = moduleSymbol;
1076
1076
}
1077
1077
else {
@@ -1151,7 +1151,7 @@ namespace ts {
1151
1151
if (targetSymbol) {
1152
1152
const name = specifier.propertyName || specifier.name;
1153
1153
if (name.text) {
1154
- if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
1154
+ if (isUntypedModuleSymbol (moduleSymbol)) {
1155
1155
return moduleSymbol;
1156
1156
}
1157
1157
@@ -1371,8 +1371,9 @@ namespace ts {
1371
1371
}
1372
1372
1373
1373
const isRelative = isExternalModuleNameRelative(moduleName);
1374
+ const quotedName = '"' + moduleName + '"';
1374
1375
if (!isRelative) {
1375
- const symbol = getSymbol(globals, '"' + moduleName + '"' , SymbolFlags.ValueModule);
1376
+ const symbol = getSymbol(globals, quotedName , SymbolFlags.ValueModule);
1376
1377
if (symbol) {
1377
1378
// merged symbol is module declaration symbol combined with all augmentations
1378
1379
return getMergedSymbol(symbol);
@@ -1401,6 +1402,28 @@ namespace ts {
1401
1402
}
1402
1403
}
1403
1404
1405
+ // May be an untyped module. If so, ignore resolutionDiagnostic.
1406
+ if (!isRelative && resolvedModule && !extensionIsTypeScript(resolvedModule.extension)) {
1407
+ if (compilerOptions.noImplicitAny) {
1408
+ if (moduleNotFoundError) {
1409
+ error(errorNode,
1410
+ Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
1411
+ moduleReference,
1412
+ resolvedModule.resolvedFileName);
1413
+ }
1414
+ return undefined;
1415
+ }
1416
+
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
+ // Module symbols are expected to have 'exports', although since this is an untyped module it can be empty.
1421
+ newSymbol.exports = new StringMap<Symbol>();
1422
+ // Cache it so subsequent accesses will return the same module.
1423
+ globals.set(quotedName, newSymbol);
1424
+ return newSymbol;
1425
+ }
1426
+
1404
1427
if (moduleNotFoundError) {
1405
1428
// report errors only if it was requested
1406
1429
if (resolutionDiagnostic) {
@@ -3470,7 +3493,7 @@ namespace ts {
3470
3493
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
3471
3494
const links = getSymbolLinks(symbol);
3472
3495
if (!links.type) {
3473
- if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModuleSymbol (symbol)) {
3496
+ if (symbol.flags & SymbolFlags.Module && isUntypedModuleSymbol (symbol)) {
3474
3497
links.type = anyType;
3475
3498
}
3476
3499
else {
@@ -19014,7 +19037,7 @@ namespace ts {
19014
19037
19015
19038
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
19016
19039
let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
19017
- if (!moduleSymbol || isShorthandAmbientModuleSymbol (moduleSymbol)) {
19040
+ if (!moduleSymbol || isUntypedModuleSymbol (moduleSymbol)) {
19018
19041
// If the module is not found or is shorthand, assume that it may export a value.
19019
19042
return true;
19020
19043
}
@@ -19514,7 +19537,7 @@ namespace ts {
19514
19537
(typeReferenceDirectives || (typeReferenceDirectives = [])).push(typeReferenceDirective);
19515
19538
}
19516
19539
else {
19517
- // found at least one entry that does not originate from type reference directive
19540
+ // found at least one entry that does not originate from type reference directive
19518
19541
return undefined;
19519
19542
}
19520
19543
}
0 commit comments