Skip to content

Commit ceab31c

Browse files
authored
Port PR #10016 to Master (#10100)
* Treat namespaceExportDeclaration as declaration * Update baselines * wip - add tests * Add tests * Show "export namespace" for quick-info
1 parent b54aec1 commit ceab31c

28 files changed

+96
-16
lines changed

src/compiler/checker.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -19691,7 +19691,7 @@ namespace ts {
1969119691
}
1969219692

1969319693
function checkGrammarTopLevelElementForRequiredDeclareModifier(node: Node): boolean {
19694-
// A declare modifier is required for any top level .d.ts declaration except export=, export default,
19694+
// A declare modifier is required for any top level .d.ts declaration except export=, export default, export as namespace
1969519695
// interfaces and imports categories:
1969619696
//
1969719697
// DeclarationElement:
@@ -19709,6 +19709,7 @@ namespace ts {
1970919709
node.kind === SyntaxKind.ImportEqualsDeclaration ||
1971019710
node.kind === SyntaxKind.ExportDeclaration ||
1971119711
node.kind === SyntaxKind.ExportAssignment ||
19712+
node.kind === SyntaxKind.NamespaceExportDeclaration ||
1971219713
(node.flags & NodeFlags.Ambient) ||
1971319714
(node.flags & (NodeFlags.Export | NodeFlags.Default))) {
1971419715

src/compiler/utilities.ts

+1
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

+8-1
Original file line numberDiff line numberDiff line change
@@ -4830,7 +4830,14 @@ namespace ts {
48304830
}
48314831
if (symbolFlags & SymbolFlags.Alias) {
48324832
addNewLineIfDisplayPartsExist();
4833-
displayParts.push(keywordPart(SyntaxKind.ImportKeyword));
4833+
if (symbol.declarations[0].kind === SyntaxKind.NamespaceExportDeclaration) {
4834+
displayParts.push(keywordPart(SyntaxKind.ExportKeyword));
4835+
displayParts.push(spacePart());
4836+
displayParts.push(keywordPart(SyntaxKind.NamespaceKeyword));
4837+
}
4838+
else {
4839+
displayParts.push(keywordPart(SyntaxKind.ImportKeyword));
4840+
}
48344841
displayParts.push(spacePart());
48354842
addFullSymbolName(symbol);
48364843
ts.forEach(symbol.declarations, declaration => {

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

+1
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

+1-1
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

+1
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

+1-1
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

+1
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

+1-1
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

+1
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))

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

+1-1
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 = M2D;
5252
>M2D : typeof M2D

tests/baselines/reference/umd1.symbols

+1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ export interface Thing { n: typeof x }
3030
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
3131

3232
export as namespace Foo;
33+
>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 38))
3334

tests/baselines/reference/umd1.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ export interface Thing { n: typeof x }
3131
>x : number
3232

3333
export as namespace Foo;
34-
>Foo : any
34+
>Foo : typeof Foo
3535

tests/baselines/reference/umd3.symbols

+1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ export interface Thing { n: typeof x }
3232
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
3333

3434
export as namespace Foo;
35+
>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 38))
3536

tests/baselines/reference/umd3.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ export interface Thing { n: typeof x }
3333
>x : number
3434

3535
export as namespace Foo;
36-
>Foo : any
36+
>Foo : typeof Foo
3737

tests/baselines/reference/umd4.symbols

+1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ export interface Thing { n: typeof x }
3232
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
3333

3434
export as namespace Foo;
35+
>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 38))
3536

tests/baselines/reference/umd4.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ export interface Thing { n: typeof x }
3333
>x : number
3434

3535
export as namespace Foo;
36-
>Foo : any
36+
>Foo : typeof Foo
3737

tests/baselines/reference/umd6.symbols

+1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ export = Thing;
1818
>Thing : Symbol(Thing, Decl(foo.d.ts, 0, 0))
1919

2020
export as namespace Foo;
21+
>Foo : Symbol(Foo, Decl(foo.d.ts, 4, 15))
2122

tests/baselines/reference/umd6.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ export = Thing;
1919
>Thing : typeof Thing
2020

2121
export as namespace Foo;
22-
>Foo : any
22+
>Foo : typeof Thing
2323

tests/baselines/reference/umd7.symbols

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export = Thing;
1313
>Thing : Symbol(Thing, Decl(foo.d.ts, 0, 0))
1414

1515
export as namespace Foo;
16+
>Foo : Symbol(Foo, Decl(foo.d.ts, 2, 15))
1617

tests/baselines/reference/umd7.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ export = Thing;
1414
>Thing : () => number
1515

1616
export as namespace Foo;
17-
>Foo : any
17+
>Foo : () => number
1818

tests/baselines/reference/umd8.symbols

+1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ export = Thing;
2222
>Thing : Symbol(Thing, Decl(foo.d.ts, 0, 0))
2323

2424
export as namespace Foo;
25+
>Foo : Symbol(Foo, Decl(foo.d.ts, 4, 15))
2526

tests/baselines/reference/umd8.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ export = Thing;
2323
>Thing : Thing
2424

2525
export as namespace Foo;
26-
>Foo : any
26+
>Foo : typeof Thing
2727

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: 0.d.ts
4+
//// export function doThing(): string;
5+
//// export function doTheOtherThing(): void;
6+
7+
//// export as namespace [|myLib|];
8+
9+
// @Filename: 1.ts
10+
//// /// <reference path="0.d.ts" />
11+
//// [|myLib|].doThing();
12+
13+
verify.rangesReferenceEachOther();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: 0.d.ts
4+
//// export function doThing(): string;
5+
//// export function doTheOtherThing(): void;
6+
7+
//// export as namespace /*0*/myLib;
8+
9+
// @Filename: 1.ts
10+
//// /// <reference path="0.d.ts" />
11+
//// /*1*/myLib.doThing();
12+
13+
goTo.marker("0");
14+
verify.quickInfoIs("export namespace myLib");
15+
16+
goTo.marker("1");
17+
verify.quickInfoIs("export namespace myLib");

tests/cases/fourslash/renameAlias.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
////import [|M|] = SomeModule;
55
////import C = [|M|].SomeClass;
66

7-
let ranges = test.ranges()
8-
for (let range of ranges) {
9-
goTo.position(range.start);
10-
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
7+
let ranges = test.ranges()
8+
for (let range of ranges) {
9+
goTo.position(range.start);
10+
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
1111
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: 0.d.ts
4+
//// export function doThing(): string;
5+
//// export function doTheOtherThing(): void;
6+
7+
//// export as namespace [|myLib|];
8+
9+
// @Filename: 1.ts
10+
//// /// <reference path="0.d.ts" />
11+
//// [|myLib|].doThing();
12+
13+
const ranges = test.ranges()
14+
for (const range of ranges) {
15+
goTo.position(range.start);
16+
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: 0.d.ts
4+
//// export function doThing(): string;
5+
//// export function doTheOtherThing(): void;
6+
7+
//// export as namespace /**/[|myLib|];
8+
9+
// @Filename: 1.ts
10+
//// /// <reference path="0.d.ts" />
11+
//// myLib.doThing();
12+
13+
goTo.marker();
14+
verify.renameInfoSucceeded("myLib");

0 commit comments

Comments
 (0)