Skip to content

Commit c3e0906

Browse files
authored
Do not consider UMD alias symbols as visible within external modules (#18049)
* Do not consider UMD alias symbols as visible within external modules in the symbol writer * Minimal repro
1 parent 72884b8 commit c3e0906

16 files changed

+103
-13
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,10 @@ namespace ts {
20952095
canQualifySymbol(symbolFromSymbolTable, meaning);
20962096
}
20972097

2098+
function isUMDExportSymbol(symbol: Symbol) {
2099+
return symbol && symbol.declarations && symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]);
2100+
}
2101+
20982102
function trySymbolTable(symbols: SymbolTable) {
20992103
// If symbol is directly available by its name in the symbol table
21002104
if (isAccessible(symbols.get(symbol.escapedName))) {
@@ -2106,6 +2110,7 @@ namespace ts {
21062110
if (symbolFromSymbolTable.flags & SymbolFlags.Alias
21072111
&& symbolFromSymbolTable.escapedName !== "export="
21082112
&& !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier)
2113+
&& !(isUMDExportSymbol(symbolFromSymbolTable) && isExternalModule(getSourceFileOfNode(enclosingDeclaration)))
21092114
// If `!useOnlyExternalAliasing`, we can use any type of alias to get the name
21102115
&& (!useOnlyExternalAliasing || some(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration))) {
21112116

tests/baselines/reference/exportAsNamespace.d.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export var X;
55
>X : any
66

77
export as namespace N
8-
>N : typeof N
8+
>N : typeof "tests/cases/compiler/exportAsNamespace"
99

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [tests/cases/compiler/importShouldNotBeElidedInDeclarationEmit.ts] ////
2+
3+
//// [umd.d.ts]
4+
export as namespace UMD;
5+
6+
export type Thing = {
7+
a: number;
8+
}
9+
10+
export declare function makeThing(): Thing;
11+
//// [index.ts]
12+
import { makeThing } from "umd";
13+
export const thing = makeThing();
14+
15+
16+
//// [index.js]
17+
"use strict";
18+
exports.__esModule = true;
19+
var umd_1 = require("umd");
20+
exports.thing = umd_1.makeThing();
21+
22+
23+
//// [index.d.ts]
24+
export declare const thing: {
25+
a: number;
26+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== tests/cases/compiler/node_modules/umd.d.ts ===
2+
export as namespace UMD;
3+
>UMD : Symbol(UMD, Decl(umd.d.ts, 0, 0))
4+
5+
export type Thing = {
6+
>Thing : Symbol(Thing, Decl(umd.d.ts, 0, 24))
7+
8+
a: number;
9+
>a : Symbol(a, Decl(umd.d.ts, 2, 21))
10+
}
11+
12+
export declare function makeThing(): Thing;
13+
>makeThing : Symbol(makeThing, Decl(umd.d.ts, 4, 1))
14+
>Thing : Symbol(Thing, Decl(umd.d.ts, 0, 24))
15+
16+
=== tests/cases/compiler/index.ts ===
17+
import { makeThing } from "umd";
18+
>makeThing : Symbol(makeThing, Decl(index.ts, 0, 8))
19+
20+
export const thing = makeThing();
21+
>thing : Symbol(thing, Decl(index.ts, 1, 12))
22+
>makeThing : Symbol(makeThing, Decl(index.ts, 0, 8))
23+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/compiler/node_modules/umd.d.ts ===
2+
export as namespace UMD;
3+
>UMD : typeof "tests/cases/compiler/node_modules/umd"
4+
5+
export type Thing = {
6+
>Thing : Thing
7+
8+
a: number;
9+
>a : number
10+
}
11+
12+
export declare function makeThing(): Thing;
13+
>makeThing : () => Thing
14+
>Thing : Thing
15+
16+
=== tests/cases/compiler/index.ts ===
17+
import { makeThing } from "umd";
18+
>makeThing : () => { a: number; }
19+
20+
export const thing = makeThing();
21+
>thing : { a: number; }
22+
>makeThing() : { a: number; }
23+
>makeThing : () => { a: number; }
24+

tests/baselines/reference/umd-augmentation-1.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var t = p.x;
4747

4848
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
4949
export as namespace Math2d;
50-
>Math2d : typeof Math2d
50+
>Math2d : typeof "tests/cases/conformance/externalModules/node_modules/math2d/index"
5151

5252
export interface Point {
5353
>Point : Point

tests/baselines/reference/umd-augmentation-2.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var t = p.x;
4545

4646
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
4747
export as namespace Math2d;
48-
>Math2d : typeof Math2d
48+
>Math2d : typeof "tests/cases/conformance/externalModules/node_modules/math2d/index"
4949

5050
export interface Point {
5151
>Point : Point

tests/baselines/reference/umd-augmentation-3.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export = M2D;
4444
>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13))
4545

4646
declare namespace M2D {
47-
>M2D : Symbol(Math2d, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33))
47+
>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33))
4848

4949
interface Point {
5050
>Point : Symbol(Point, Decl(index.d.ts, 4, 23))

tests/baselines/reference/umd-augmentation-3.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ var t = p.x;
4747

4848
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
4949
export as namespace Math2d;
50-
>Math2d : typeof Math2d
50+
>Math2d : typeof M2D
5151

5252
export = M2D;
5353
>M2D : typeof M2D
5454

5555
declare namespace M2D {
56-
>M2D : typeof Math2d
56+
>M2D : typeof M2D
5757

5858
interface Point {
5959
>Point : Point

tests/baselines/reference/umd-augmentation-4.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export = M2D;
4242
>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13))
4343

4444
declare namespace M2D {
45-
>M2D : Symbol(Math2d, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33))
45+
>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33))
4646

4747
interface Point {
4848
>Point : Symbol(Point, Decl(index.d.ts, 4, 23))

tests/baselines/reference/umd-augmentation-4.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ var t = p.x;
4545

4646
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
4747
export as namespace Math2d;
48-
>Math2d : typeof Math2d
48+
>Math2d : typeof M2D
4949

5050
export = M2D;
5151
>M2D : typeof M2D
5252

5353
declare namespace M2D {
54-
>M2D : typeof Math2d
54+
>M2D : typeof M2D
5555

5656
interface Point {
5757
>Point : Point

tests/baselines/reference/umd1.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ export interface Thing { n: typeof x }
3030
>x : number
3131

3232
export as namespace Foo;
33-
>Foo : typeof Foo
33+
>Foo : typeof "tests/cases/conformance/externalModules/foo"
3434

tests/baselines/reference/umd3.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ export interface Thing { n: typeof x }
3232
>x : number
3333

3434
export as namespace Foo;
35-
>Foo : typeof Foo
35+
>Foo : typeof "tests/cases/conformance/externalModules/foo"
3636

tests/baselines/reference/umd4.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ export interface Thing { n: typeof x }
3232
>x : number
3333

3434
export as namespace Foo;
35-
>Foo : typeof Foo
35+
>Foo : typeof "tests/cases/conformance/externalModules/foo"
3636

tests/baselines/reference/umdGlobalConflict.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=== tests/cases/compiler/v1/index.d.ts ===
22
export as namespace Alpha;
3-
>Alpha : typeof Alpha
3+
>Alpha : typeof "tests/cases/compiler/v1/index"
44

55
export var x: string;
66
>x : string
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @declaration: true
2+
// @filename: node_modules/umd.d.ts
3+
export as namespace UMD;
4+
5+
export type Thing = {
6+
a: number;
7+
}
8+
9+
export declare function makeThing(): Thing;
10+
// @filename: index.ts
11+
import { makeThing } from "umd";
12+
export const thing = makeThing();

0 commit comments

Comments
 (0)