@@ -1069,7 +1069,7 @@ namespace ts {
1069
1069
const moduleSymbol = resolveExternalModuleName(node, (<ImportDeclaration>node.parent).moduleSpecifier);
1070
1070
1071
1071
if (moduleSymbol) {
1072
- const exportDefaultSymbol = isShorthandAmbientModuleSymbol (moduleSymbol) ?
1072
+ const exportDefaultSymbol = isUntypedModuleSymbol (moduleSymbol) ?
1073
1073
moduleSymbol :
1074
1074
moduleSymbol.exports["export="] ?
1075
1075
getPropertyOfType(getTypeOfSymbol(moduleSymbol.exports["export="]), "default") :
@@ -1145,7 +1145,7 @@ namespace ts {
1145
1145
if (targetSymbol) {
1146
1146
const name = specifier.propertyName || specifier.name;
1147
1147
if (name.text) {
1148
- if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
1148
+ if (isUntypedModuleSymbol (moduleSymbol)) {
1149
1149
return moduleSymbol;
1150
1150
}
1151
1151
@@ -1365,8 +1365,9 @@ namespace ts {
1365
1365
}
1366
1366
1367
1367
const isRelative = isExternalModuleNameRelative(moduleName);
1368
+ const quotedName = '"' + moduleName + '"';
1368
1369
if (!isRelative) {
1369
- const symbol = getSymbol(globals, '"' + moduleName + '"' , SymbolFlags.ValueModule);
1370
+ const symbol = getSymbol(globals, quotedName , SymbolFlags.ValueModule);
1370
1371
if (symbol) {
1371
1372
// merged symbol is module declaration symbol combined with all augmentations
1372
1373
return getMergedSymbol(symbol);
@@ -1395,6 +1396,28 @@ namespace ts {
1395
1396
}
1396
1397
}
1397
1398
1399
+ // May be an untyped module. If so, ignore resolutionDiagnostic.
1400
+ if (!isRelative && resolvedModule && !extensionIsTypeScript(resolvedModule.extension)) {
1401
+ if (compilerOptions.noImplicitAny) {
1402
+ if (moduleNotFoundError) {
1403
+ error(errorNode,
1404
+ Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
1405
+ moduleReference,
1406
+ resolvedModule.resolvedFileName);
1407
+ }
1408
+ return undefined;
1409
+ }
1410
+
1411
+ // Create a new symbol to represent the untyped module and store it in globals.
1412
+ // This provides a name to the module. See the test tests/cases/fourslash/untypedModuleImport.ts
1413
+ const newSymbol = createSymbol(SymbolFlags.ValueModule, quotedName);
1414
+ // Module symbols are expected to have 'exports', although since this is an untyped module it can be empty.
1415
+ newSymbol.exports = createMap<Symbol>();
1416
+ // Cache it so subsequent accesses will return the same module.
1417
+ globals[quotedName] = newSymbol;
1418
+ return newSymbol;
1419
+ }
1420
+
1398
1421
if (moduleNotFoundError) {
1399
1422
// report errors only if it was requested
1400
1423
if (resolutionDiagnostic) {
@@ -3462,7 +3485,7 @@ namespace ts {
3462
3485
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
3463
3486
const links = getSymbolLinks(symbol);
3464
3487
if (!links.type) {
3465
- if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModuleSymbol (symbol)) {
3488
+ if (symbol.flags & SymbolFlags.Module && isUntypedModuleSymbol (symbol)) {
3466
3489
links.type = anyType;
3467
3490
}
3468
3491
else {
@@ -19011,7 +19034,7 @@ namespace ts {
19011
19034
19012
19035
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
19013
19036
let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
19014
- if (!moduleSymbol || isShorthandAmbientModuleSymbol (moduleSymbol)) {
19037
+ if (!moduleSymbol || isUntypedModuleSymbol (moduleSymbol)) {
19015
19038
// If the module is not found or is shorthand, assume that it may export a value.
19016
19039
return true;
19017
19040
}
@@ -19512,7 +19535,7 @@ namespace ts {
19512
19535
(typeReferenceDirectives || (typeReferenceDirectives = [])).push(typeReferenceDirective);
19513
19536
}
19514
19537
else {
19515
- // found at least one entry that does not originate from type reference directive
19538
+ // found at least one entry that does not originate from type reference directive
19516
19539
return undefined;
19517
19540
}
19518
19541
}
0 commit comments