mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Fix binder performance regression
This commit is contained in:
parent
454b4280b1
commit
57a8ee1507
@ -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);
|
||||
@ -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);
|
||||
@ -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) {
|
||||
@ -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);
|
||||
|
||||
7
tests/baselines/reference/globalThisCollision.errors.txt
Normal file
7
tests/baselines/reference/globalThisCollision.errors.txt
Normal file
@ -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
tests/baselines/reference/globalThisCollision.symbols
Normal file
4
tests/baselines/reference/globalThisCollision.symbols
Normal file
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/es2019/globalThisCollision.js ===
|
||||
var globalThis;
|
||||
>globalThis : Symbol(globalThis, Decl(globalThisCollision.js, 0, 3))
|
||||
|
||||
4
tests/baselines/reference/globalThisCollision.types
Normal file
4
tests/baselines/reference/globalThisCollision.types
Normal file
@ -0,0 +1,4 @@
|
||||
=== tests/cases/conformance/es2019/globalThisCollision.js ===
|
||||
var globalThis;
|
||||
>globalThis : any
|
||||
|
||||
5
tests/cases/conformance/es2019/globalThisCollision.ts
Normal file
5
tests/cases/conformance/es2019/globalThisCollision.ts
Normal file
@ -0,0 +1,5 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
// @filename: globalThisCollision.js
|
||||
var globalThis;
|
||||
Loading…
x
Reference in New Issue
Block a user