Skip to content

Commit 90d5c29

Browse files
committed
Remove special symbol for untyped modules
Extending symbols from untyped modules is no longer an error, so #12532 didn't get us anything except slightly better quick info.
1 parent 441e54c commit 90d5c29

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

src/compiler/checker.ts

+6-11
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ namespace ts {
203203
const evolvingArrayTypes: EvolvingArrayType[] = [];
204204

205205
const unknownSymbol = createSymbol(SymbolFlags.Property, "unknown");
206-
const untypedModuleSymbol = createSymbol(SymbolFlags.ValueModule, "<untyped>");
207-
untypedModuleSymbol.exports = createMap<Symbol>();
208206
const resolvingSymbol = createSymbol(0, "__resolving__");
209207

210208
const anyType = createIntrinsicType(TypeFlags.Any, "any");
@@ -1253,7 +1251,7 @@ namespace ts {
12531251

12541252
if (moduleSymbol) {
12551253
let exportDefaultSymbol: Symbol;
1256-
if (isUntypedOrShorthandAmbientModuleSymbol(moduleSymbol)) {
1254+
if (isShorthandAmbientModuleSymbol(moduleSymbol)) {
12571255
exportDefaultSymbol = moduleSymbol;
12581256
}
12591257
else {
@@ -1333,7 +1331,7 @@ namespace ts {
13331331
if (targetSymbol) {
13341332
const name = specifier.propertyName || specifier.name;
13351333
if (name.text) {
1336-
if (isUntypedOrShorthandAmbientModuleSymbol(moduleSymbol)) {
1334+
if (isShorthandAmbientModuleSymbol(moduleSymbol)) {
13371335
return moduleSymbol;
13381336
}
13391337

@@ -1586,18 +1584,15 @@ namespace ts {
15861584
if (isForAugmentation) {
15871585
const diag = Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented;
15881586
error(errorNode, diag, moduleReference, resolvedModule.resolvedFileName);
1589-
return undefined;
15901587
}
15911588
else if (noImplicitAny && moduleNotFoundError) {
15921589
error(errorNode,
15931590
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
15941591
moduleReference,
15951592
resolvedModule.resolvedFileName);
1596-
return undefined;
15971593
}
1598-
// Unlike a failed import, an untyped module produces a dummy symbol.
1599-
// This is checked for by `isUntypedOrShorthandAmbientModuleSymbol`.
1600-
return untypedModuleSymbol;
1594+
// Failed imports and untyped modules are both treated in an untyped manner; only difference is whether we give a diagnostic first.
1595+
return undefined;
16011596
}
16021597

16031598
if (moduleNotFoundError) {
@@ -4367,7 +4362,7 @@ namespace ts {
43674362
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
43684363
const links = getSymbolLinks(symbol);
43694364
if (!links.type) {
4370-
if (symbol.flags & SymbolFlags.Module && isUntypedOrShorthandAmbientModuleSymbol(symbol)) {
4365+
if (symbol.flags & SymbolFlags.Module && isShorthandAmbientModuleSymbol(symbol)) {
43714366
links.type = anyType;
43724367
}
43734368
else {
@@ -22063,7 +22058,7 @@ namespace ts {
2206322058

2206422059
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
2206522060
let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
22066-
if (!moduleSymbol || isUntypedOrShorthandAmbientModuleSymbol(moduleSymbol)) {
22061+
if (!moduleSymbol || isShorthandAmbientModuleSymbol(moduleSymbol)) {
2206722062
// If the module is not found or is shorthand, assume that it may export a value.
2206822063
return true;
2206922064
}

src/compiler/utilities.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ namespace ts {
439439
}
440440

441441
/** Given a symbol for a module, checks that it is either an untyped import or a shorthand ambient module. */
442-
export function isUntypedOrShorthandAmbientModuleSymbol(moduleSymbol: Symbol): boolean {
443-
return !moduleSymbol.declarations || isShorthandAmbientModule(moduleSymbol.valueDeclaration);
442+
export function isShorthandAmbientModuleSymbol(moduleSymbol: Symbol): boolean {
443+
return isShorthandAmbientModule(moduleSymbol.valueDeclaration);
444444
}
445445

446446
function isShorthandAmbientModule(node: Node): boolean {

src/services/findAllReferences.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ namespace ts.FindAllReferences {
187187
return { symbol };
188188
}
189189

190-
if (ts.isUntypedOrShorthandAmbientModuleSymbol(aliasedSymbol)) {
190+
if (ts.isShorthandAmbientModuleSymbol(aliasedSymbol)) {
191191
return { symbol, shorthandModuleSymbol: aliasedSymbol };
192192
}
193193

tests/cases/fourslash/untypedModuleImport.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ verify.numberOfErrorsInCurrentFile(0);
1212

1313
goTo.marker("fooModule");
1414
verify.goToDefinitionIs([]);
15-
verify.quickInfoIs("module <untyped>");
15+
verify.quickInfoIs("");
1616
verify.noReferences();
1717

1818
goTo.marker("foo");

0 commit comments

Comments
 (0)