Skip to content

Commit

Permalink
Merge pull request #31142 from Microsoft/binderPerf
Browse files Browse the repository at this point in the history
Fix binder performance regression
  • Loading branch information
rbuckton committed Apr 29, 2019
2 parents 47d9081 + 57a8ee1 commit 7423c69
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/compiler/checker.ts
Expand Up @@ -94,8 +94,6 @@ namespace ts {

const globalThisSymbol = createSymbol(SymbolFlags.Module, "globalThis" as __String, CheckFlags.Readonly);
globalThisSymbol.exports = globals;
globalThisSymbol.valueDeclaration = createNode(SyntaxKind.Identifier) as Identifier;
(globalThisSymbol.valueDeclaration as Identifier).escapedText = "globalThis" as __String;
globals.set(globalThisSymbol.escapedName, globalThisSymbol);

const argumentsSymbol = createSymbol(SymbolFlags.Property, "arguments" as __String);
Expand Down Expand Up @@ -926,7 +924,12 @@ namespace ts {
recordMergedSymbol(target, source);
}
else if (target.flags & SymbolFlags.NamespaceModule) {
error(getNameOfDeclaration(source.declarations[0]), Diagnostics.Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity, symbolToString(target));
// Do not report an error when merging `var globalThis` with the built-in `globalThis`,
// as we will already report a "Declaration name conflicts..." error, and this error
// won't make much sense.
if (target !== globalThisSymbol) {
error(getNameOfDeclaration(source.declarations[0]), Diagnostics.Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity, symbolToString(target));
}
}
else { // error
const isEitherEnum = !!(target.flags & SymbolFlags.Enum || source.flags & SymbolFlags.Enum);
Expand Down Expand Up @@ -30456,6 +30459,14 @@ namespace ts {
continue;
}
if (!isExternalOrCommonJsModule(file)) {
// It is an error for a non-external-module (i.e. script) to declare its own `globalThis`.
// We can't use `builtinGlobals` for this due to synthetic expando-namespace generation in JS files.
const fileGlobalThisSymbol = file.locals!.get("globalThis" as __String);
if (fileGlobalThisSymbol) {
for (const declaration of fileGlobalThisSymbol.declarations) {
diagnostics.add(createDiagnosticForNode(declaration, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0, "globalThis"));
}
}
mergeSymbolTable(globals, file.locals!);
}
if (file.jsGlobalAugmentations) {
Expand Down Expand Up @@ -30501,6 +30512,7 @@ namespace ts {
getSymbolLinks(undefinedSymbol).type = undefinedWideningType;
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments" as __String, /*arity*/ 0, /*reportErrors*/ true);
getSymbolLinks(unknownSymbol).type = errorType;
getSymbolLinks(globalThisSymbol).type = createObjectType(ObjectFlags.Anonymous, globalThisSymbol);

// Initialize special types
globalArrayType = getGlobalType("Array" as __String, /*arity*/ 1, /*reportErrors*/ true);
Expand Down
7 changes: 7 additions & 0 deletions tests/baselines/reference/globalThisCollision.errors.txt
@@ -0,0 +1,7 @@
tests/cases/conformance/es2019/globalThisCollision.js(1,5): error TS2397: Declaration name conflicts with built-in global identifier 'globalThis'.


==== tests/cases/conformance/es2019/globalThisCollision.js (1 errors) ====
var globalThis;
~~~~~~~~~~
!!! error TS2397: Declaration name conflicts with built-in global identifier 'globalThis'.
4 changes: 4 additions & 0 deletions tests/baselines/reference/globalThisCollision.symbols
@@ -0,0 +1,4 @@
=== tests/cases/conformance/es2019/globalThisCollision.js ===
var globalThis;
>globalThis : Symbol(globalThis, Decl(globalThisCollision.js, 0, 3))

4 changes: 4 additions & 0 deletions tests/baselines/reference/globalThisCollision.types
@@ -0,0 +1,4 @@
=== tests/cases/conformance/es2019/globalThisCollision.js ===
var globalThis;
>globalThis : any

5 changes: 5 additions & 0 deletions tests/cases/conformance/es2019/globalThisCollision.ts
@@ -0,0 +1,5 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @filename: globalThisCollision.js
var globalThis;

0 comments on commit 7423c69

Please sign in to comment.