From 4df4a2bbc7a1a71a440636f3bb18e5d9495569c8 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 25 Jan 2017 06:53:07 -0800 Subject: [PATCH] Use a single 'untypedModuleSymbol' for all untyped modules instead of creating a new one for each module. --- src/compiler/checker.ts | 10 ++++++---- .../baselines/reference/extendsUntypedModule.js | 17 +++++++++++------ tests/cases/fourslash/untypedModuleImport.ts | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 332031903db..224da5e69c2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -132,6 +132,8 @@ namespace ts { const evolvingArrayTypes: EvolvingArrayType[] = []; const unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown"); + const untypedModuleSymbol = createSymbol(SymbolFlags.ValueModule, ""); + untypedModuleSymbol.exports = createMap(); const resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__"); const anyType = createIntrinsicType(TypeFlags.Any, "any"); @@ -1490,10 +1492,10 @@ namespace ts { resolvedModule.resolvedFileName); return undefined; } - // Unlike a failed import, an untyped module produces a dummy symbol. This is checked for by `isUntypedOrShorthandAmbientModuleSymbol`. - const untypedSymbol = createSymbol(SymbolFlags.ValueModule, `"${moduleName}"`); - untypedSymbol.exports = createMap(); - return untypedSymbol; + // Unlike a failed import, an untyped module produces a dummy symbol. + // This is checked for by `isUntypedOrShorthandAmbientModuleSymbol`. + // This must be different than `unknownSymbol` because `getBaseConstructorTypeOfClass` won't fail for `unknownSymbol`. + return untypedModuleSymbol; } if (moduleNotFoundError) { diff --git a/tests/baselines/reference/extendsUntypedModule.js b/tests/baselines/reference/extendsUntypedModule.js index 0804595c08e..ad35e4abaac 100644 --- a/tests/baselines/reference/extendsUntypedModule.js +++ b/tests/baselines/reference/extendsUntypedModule.js @@ -12,16 +12,21 @@ class A extends Foo { } //// [a.js] "use strict"; -var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); -}; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); var foo_1 = require("foo"); var A = (function (_super) { __extends(A, _super); function A() { - return _super.apply(this, arguments) || this; + return _super !== null && _super.apply(this, arguments) || this; } return A; }(foo_1["default"])); diff --git a/tests/cases/fourslash/untypedModuleImport.ts b/tests/cases/fourslash/untypedModuleImport.ts index c09f710177b..276277102b0 100644 --- a/tests/cases/fourslash/untypedModuleImport.ts +++ b/tests/cases/fourslash/untypedModuleImport.ts @@ -12,7 +12,7 @@ verify.numberOfErrorsInCurrentFile(0); goTo.marker("fooModule"); verify.goToDefinitionIs([]); -verify.quickInfoIs('module "foo"'); +verify.quickInfoIs('module '); verify.referencesAre([]) goTo.marker("foo");