Skip to content

Commit 126c1ee

Browse files
authored
[Release-2.0] fix 9802: fix language service for UMD module alias (#10016)
* Treat namespaceExportDeclaration as declaration * Update baselines * wip - add tests * Add tests * Show "export namespace" for quick-info
1 parent 8ceeb4b commit 126c1ee

28 files changed

+96
-16
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19267,7 +19267,7 @@ namespace ts {
1926719267
}
1926819268

1926919269
function checkGrammarTopLevelElementForRequiredDeclareModifier(node: Node): boolean {
19270-
// A declare modifier is required for any top level .d.ts declaration except export=, export default,
19270+
// A declare modifier is required for any top level .d.ts declaration except export=, export default, export as namespace
1927119271
// interfaces and imports categories:
1927219272
//
1927319273
// DeclarationElement:
@@ -19285,6 +19285,7 @@ namespace ts {
1928519285
node.kind === SyntaxKind.ImportEqualsDeclaration ||
1928619286
node.kind === SyntaxKind.ExportDeclaration ||
1928719287
node.kind === SyntaxKind.ExportAssignment ||
19288+
node.kind === SyntaxKind.NamespaceExportDeclaration ||
1928819289
(node.flags & NodeFlags.Ambient) ||
1928919290
(node.flags & (NodeFlags.Export | NodeFlags.Default))) {
1929019291

src/compiler/utilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,7 @@ namespace ts {
15691569
case SyntaxKind.MethodSignature:
15701570
case SyntaxKind.ModuleDeclaration:
15711571
case SyntaxKind.NamespaceImport:
1572+
case SyntaxKind.NamespaceExportDeclaration:
15721573
case SyntaxKind.Parameter:
15731574
case SyntaxKind.PropertyAssignment:
15741575
case SyntaxKind.PropertyDeclaration:

src/services/services.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4724,7 +4724,14 @@ namespace ts {
47244724
}
47254725
if (symbolFlags & SymbolFlags.Alias) {
47264726
addNewLineIfDisplayPartsExist();
4727-
displayParts.push(keywordPart(SyntaxKind.ImportKeyword));
4727+
if (symbol.declarations[0].kind === SyntaxKind.NamespaceExportDeclaration) {
4728+
displayParts.push(keywordPart(SyntaxKind.ExportKeyword));
4729+
displayParts.push(spacePart());
4730+
displayParts.push(keywordPart(SyntaxKind.NamespaceKeyword));
4731+
}
4732+
else {
4733+
displayParts.push(keywordPart(SyntaxKind.ImportKeyword));
4734+
}
47284735
displayParts.push(spacePart());
47294736
addFullSymbolName(symbol);
47304737
ts.forEach(symbol.declarations, declaration => {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var t = p.x;
3939
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
4040

4141
export as namespace Math2d;
42+
>Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0))
4243

4344
export interface Point {
4445
>Point : Symbol(Point, Decl(index.d.ts, 1, 27))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var t = p.x;
4848
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
4949

5050
export as namespace Math2d;
51-
>Math2d : any
51+
>Math2d : typeof Math2d
5252

5353
export interface Point {
5454
>Point : Point

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var t = p.x;
3737
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
3838

3939
export as namespace Math2d;
40+
>Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0))
4041

4142
export interface Point {
4243
>Point : Symbol(Point, Decl(index.d.ts, 1, 27))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var t = p.x;
4646
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
4747

4848
export as namespace Math2d;
49-
>Math2d : any
49+
>Math2d : typeof Math2d
5050

5151
export interface Point {
5252
>Point : Point

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var t = p.x;
3939
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
4040

4141
export as namespace Math2d;
42+
>Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0))
4243

4344
export = M2D;
4445
>M2D : Symbol(M2D, Decl(index.d.ts, 3, 13))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var t = p.x;
4848
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
4949

5050
export as namespace Math2d;
51-
>Math2d : any
51+
>Math2d : typeof Math2d
5252

5353
export = M2D;
5454
>M2D : typeof M2D

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var t = p.x;
3737
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
3838

3939
export as namespace Math2d;
40+
>Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0))
4041

4142
export = M2D;
4243
>M2D : Symbol(M2D, Decl(index.d.ts, 3, 13))

0 commit comments

Comments
 (0)