Skip ambient modules in globalThis (#48938)

* Skip ambient modules in globalThis

Previously, globalThis mistakenly included ambient modules, even though
these are not values:

```ts
declare module "ambientModule" {
  export type typ = 1
  export var val: typ
}
type Oops = (typeof globalThis)[\"ambientModule\"]
```

This PR adds ambient modules to the kinds of things that are skipped
when constructing `globalThis`' properties, along with block-scoped
variables.

* Skip only modules with every declaration ambient

The modules are required to have at least one declaration so that our
treatment of `globalThis` stays the same, and
`globalThis.globalThis.globalThis` remains legal.
This commit is contained in:
Nathan Shively-Sanders
2022-05-05 09:33:32 -07:00
committed by GitHub
parent 7d60dc1f5d
commit 46e8306050
6 changed files with 128 additions and 1 deletions

View File

@@ -11504,7 +11504,7 @@ namespace ts {
if (symbol === globalThisSymbol) {
const varsOnly = new Map<string, Symbol>() as SymbolTable;
members.forEach(p => {
if (!(p.flags & SymbolFlags.BlockScoped)) {
if (!(p.flags & SymbolFlags.BlockScoped) && !(p.flags & SymbolFlags.ValueModule && p.declarations?.length && every(p.declarations, isAmbientModule))) {
varsOnly.set(p.escapedName, p);
}
});