Skip to content

Commit 4df4a2b

Browse files
author
Andy Hanson
committed
Use a single 'untypedModuleSymbol' for all untyped modules instead of creating a new one for each module.
1 parent acf317c commit 4df4a2b

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ namespace ts {
132132
const evolvingArrayTypes: EvolvingArrayType[] = [];
133133

134134
const unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown");
135+
const untypedModuleSymbol = createSymbol(SymbolFlags.ValueModule, "<untyped>");
136+
untypedModuleSymbol.exports = createMap<Symbol>();
135137
const resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__");
136138

137139
const anyType = createIntrinsicType(TypeFlags.Any, "any");
@@ -1490,10 +1492,10 @@ namespace ts {
14901492
resolvedModule.resolvedFileName);
14911493
return undefined;
14921494
}
1493-
// Unlike a failed import, an untyped module produces a dummy symbol. This is checked for by `isUntypedOrShorthandAmbientModuleSymbol`.
1494-
const untypedSymbol = createSymbol(SymbolFlags.ValueModule, `"${moduleName}"`);
1495-
untypedSymbol.exports = createMap<Symbol>();
1496-
return untypedSymbol;
1495+
// Unlike a failed import, an untyped module produces a dummy symbol.
1496+
// This is checked for by `isUntypedOrShorthandAmbientModuleSymbol`.
1497+
// This must be different than `unknownSymbol` because `getBaseConstructorTypeOfClass` won't fail for `unknownSymbol`.
1498+
return untypedModuleSymbol;
14971499
}
14981500

14991501
if (moduleNotFoundError) {

tests/baselines/reference/extendsUntypedModule.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@ class A extends Foo { }
1212

1313
//// [a.js]
1414
"use strict";
15-
var __extends = (this && this.__extends) || function (d, b) {
16-
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
17-
function __() { this.constructor = d; }
18-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
19-
};
15+
var __extends = (this && this.__extends) || (function () {
16+
var extendStatics = Object.setPrototypeOf ||
17+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
18+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
19+
return function (d, b) {
20+
extendStatics(d, b);
21+
function __() { this.constructor = d; }
22+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
23+
};
24+
})();
2025
var foo_1 = require("foo");
2126
var A = (function (_super) {
2227
__extends(A, _super);
2328
function A() {
24-
return _super.apply(this, arguments) || this;
29+
return _super !== null && _super.apply(this, arguments) || this;
2530
}
2631
return A;
2732
}(foo_1["default"]));

tests/cases/fourslash/untypedModuleImport.ts

Lines changed: 1 addition & 1 deletion
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 "foo"');
15+
verify.quickInfoIs('module <untyped>');
1616
verify.referencesAre([])
1717

1818
goTo.marker("foo");

0 commit comments

Comments
 (0)