mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-08 02:46:15 -05:00
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
This commit is contained in:
@@ -2095,6 +2095,10 @@ namespace ts {
|
||||
canQualifySymbol(symbolFromSymbolTable, meaning);
|
||||
}
|
||||
|
||||
function isUMDExportSymbol(symbol: Symbol) {
|
||||
return symbol && symbol.declarations && symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]);
|
||||
}
|
||||
|
||||
function trySymbolTable(symbols: SymbolTable) {
|
||||
// If symbol is directly available by its name in the symbol table
|
||||
if (isAccessible(symbols.get(symbol.escapedName))) {
|
||||
@@ -2106,6 +2110,7 @@ namespace ts {
|
||||
if (symbolFromSymbolTable.flags & SymbolFlags.Alias
|
||||
&& symbolFromSymbolTable.escapedName !== "export="
|
||||
&& !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier)
|
||||
&& !(isUMDExportSymbol(symbolFromSymbolTable) && isExternalModule(getSourceFileOfNode(enclosingDeclaration)))
|
||||
// If `!useOnlyExternalAliasing`, we can use any type of alias to get the name
|
||||
&& (!useOnlyExternalAliasing || some(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration))) {
|
||||
|
||||
|
||||
@@ -5,5 +5,5 @@ export var X;
|
||||
>X : any
|
||||
|
||||
export as namespace N
|
||||
>N : typeof N
|
||||
>N : typeof "tests/cases/compiler/exportAsNamespace"
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
//// [tests/cases/compiler/importShouldNotBeElidedInDeclarationEmit.ts] ////
|
||||
|
||||
//// [umd.d.ts]
|
||||
export as namespace UMD;
|
||||
|
||||
export type Thing = {
|
||||
a: number;
|
||||
}
|
||||
|
||||
export declare function makeThing(): Thing;
|
||||
//// [index.ts]
|
||||
import { makeThing } from "umd";
|
||||
export const thing = makeThing();
|
||||
|
||||
|
||||
//// [index.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var umd_1 = require("umd");
|
||||
exports.thing = umd_1.makeThing();
|
||||
|
||||
|
||||
//// [index.d.ts]
|
||||
export declare const thing: {
|
||||
a: number;
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
=== tests/cases/compiler/node_modules/umd.d.ts ===
|
||||
export as namespace UMD;
|
||||
>UMD : Symbol(UMD, Decl(umd.d.ts, 0, 0))
|
||||
|
||||
export type Thing = {
|
||||
>Thing : Symbol(Thing, Decl(umd.d.ts, 0, 24))
|
||||
|
||||
a: number;
|
||||
>a : Symbol(a, Decl(umd.d.ts, 2, 21))
|
||||
}
|
||||
|
||||
export declare function makeThing(): Thing;
|
||||
>makeThing : Symbol(makeThing, Decl(umd.d.ts, 4, 1))
|
||||
>Thing : Symbol(Thing, Decl(umd.d.ts, 0, 24))
|
||||
|
||||
=== tests/cases/compiler/index.ts ===
|
||||
import { makeThing } from "umd";
|
||||
>makeThing : Symbol(makeThing, Decl(index.ts, 0, 8))
|
||||
|
||||
export const thing = makeThing();
|
||||
>thing : Symbol(thing, Decl(index.ts, 1, 12))
|
||||
>makeThing : Symbol(makeThing, Decl(index.ts, 0, 8))
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
=== tests/cases/compiler/node_modules/umd.d.ts ===
|
||||
export as namespace UMD;
|
||||
>UMD : typeof "tests/cases/compiler/node_modules/umd"
|
||||
|
||||
export type Thing = {
|
||||
>Thing : Thing
|
||||
|
||||
a: number;
|
||||
>a : number
|
||||
}
|
||||
|
||||
export declare function makeThing(): Thing;
|
||||
>makeThing : () => Thing
|
||||
>Thing : Thing
|
||||
|
||||
=== tests/cases/compiler/index.ts ===
|
||||
import { makeThing } from "umd";
|
||||
>makeThing : () => { a: number; }
|
||||
|
||||
export const thing = makeThing();
|
||||
>thing : { a: number; }
|
||||
>makeThing() : { a: number; }
|
||||
>makeThing : () => { a: number; }
|
||||
|
||||
@@ -47,7 +47,7 @@ var t = p.x;
|
||||
|
||||
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
|
||||
export as namespace Math2d;
|
||||
>Math2d : typeof Math2d
|
||||
>Math2d : typeof "tests/cases/conformance/externalModules/node_modules/math2d/index"
|
||||
|
||||
export interface Point {
|
||||
>Point : Point
|
||||
|
||||
@@ -45,7 +45,7 @@ var t = p.x;
|
||||
|
||||
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
|
||||
export as namespace Math2d;
|
||||
>Math2d : typeof Math2d
|
||||
>Math2d : typeof "tests/cases/conformance/externalModules/node_modules/math2d/index"
|
||||
|
||||
export interface Point {
|
||||
>Point : Point
|
||||
|
||||
@@ -44,7 +44,7 @@ export = M2D;
|
||||
>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13))
|
||||
|
||||
declare namespace M2D {
|
||||
>M2D : Symbol(Math2d, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33))
|
||||
>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33))
|
||||
|
||||
interface Point {
|
||||
>Point : Symbol(Point, Decl(index.d.ts, 4, 23))
|
||||
|
||||
@@ -47,13 +47,13 @@ var t = p.x;
|
||||
|
||||
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
|
||||
export as namespace Math2d;
|
||||
>Math2d : typeof Math2d
|
||||
>Math2d : typeof M2D
|
||||
|
||||
export = M2D;
|
||||
>M2D : typeof M2D
|
||||
|
||||
declare namespace M2D {
|
||||
>M2D : typeof Math2d
|
||||
>M2D : typeof M2D
|
||||
|
||||
interface Point {
|
||||
>Point : Point
|
||||
|
||||
@@ -42,7 +42,7 @@ export = M2D;
|
||||
>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13))
|
||||
|
||||
declare namespace M2D {
|
||||
>M2D : Symbol(Math2d, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33))
|
||||
>M2D : Symbol(M2D, Decl(index.d.ts, 2, 13), Decl(math2d-augment.d.ts, 0, 33))
|
||||
|
||||
interface Point {
|
||||
>Point : Symbol(Point, Decl(index.d.ts, 4, 23))
|
||||
|
||||
@@ -45,13 +45,13 @@ var t = p.x;
|
||||
|
||||
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
|
||||
export as namespace Math2d;
|
||||
>Math2d : typeof Math2d
|
||||
>Math2d : typeof M2D
|
||||
|
||||
export = M2D;
|
||||
>M2D : typeof M2D
|
||||
|
||||
declare namespace M2D {
|
||||
>M2D : typeof Math2d
|
||||
>M2D : typeof M2D
|
||||
|
||||
interface Point {
|
||||
>Point : Point
|
||||
|
||||
@@ -30,5 +30,5 @@ export interface Thing { n: typeof x }
|
||||
>x : number
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : typeof Foo
|
||||
>Foo : typeof "tests/cases/conformance/externalModules/foo"
|
||||
|
||||
|
||||
@@ -32,5 +32,5 @@ export interface Thing { n: typeof x }
|
||||
>x : number
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : typeof Foo
|
||||
>Foo : typeof "tests/cases/conformance/externalModules/foo"
|
||||
|
||||
|
||||
@@ -32,5 +32,5 @@ export interface Thing { n: typeof x }
|
||||
>x : number
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : typeof Foo
|
||||
>Foo : typeof "tests/cases/conformance/externalModules/foo"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
=== tests/cases/compiler/v1/index.d.ts ===
|
||||
export as namespace Alpha;
|
||||
>Alpha : typeof Alpha
|
||||
>Alpha : typeof "tests/cases/compiler/v1/index"
|
||||
|
||||
export var x: string;
|
||||
>x : string
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// @declaration: true
|
||||
// @filename: node_modules/umd.d.ts
|
||||
export as namespace UMD;
|
||||
|
||||
export type Thing = {
|
||||
a: number;
|
||||
}
|
||||
|
||||
export declare function makeThing(): Thing;
|
||||
// @filename: index.ts
|
||||
import { makeThing } from "umd";
|
||||
export const thing = makeThing();
|
||||
Reference in New Issue
Block a user