mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 10:55:15 -06:00
[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
This commit is contained in:
parent
8ceeb4bdc4
commit
126c1eeb59
@ -19267,7 +19267,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkGrammarTopLevelElementForRequiredDeclareModifier(node: Node): boolean {
|
||||
// A declare modifier is required for any top level .d.ts declaration except export=, export default,
|
||||
// A declare modifier is required for any top level .d.ts declaration except export=, export default, export as namespace
|
||||
// interfaces and imports categories:
|
||||
//
|
||||
// DeclarationElement:
|
||||
@ -19285,6 +19285,7 @@ namespace ts {
|
||||
node.kind === SyntaxKind.ImportEqualsDeclaration ||
|
||||
node.kind === SyntaxKind.ExportDeclaration ||
|
||||
node.kind === SyntaxKind.ExportAssignment ||
|
||||
node.kind === SyntaxKind.NamespaceExportDeclaration ||
|
||||
(node.flags & NodeFlags.Ambient) ||
|
||||
(node.flags & (NodeFlags.Export | NodeFlags.Default))) {
|
||||
|
||||
|
||||
@ -1569,6 +1569,7 @@ namespace ts {
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.NamespaceImport:
|
||||
case SyntaxKind.NamespaceExportDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
|
||||
@ -4724,7 +4724,14 @@ namespace ts {
|
||||
}
|
||||
if (symbolFlags & SymbolFlags.Alias) {
|
||||
addNewLineIfDisplayPartsExist();
|
||||
displayParts.push(keywordPart(SyntaxKind.ImportKeyword));
|
||||
if (symbol.declarations[0].kind === SyntaxKind.NamespaceExportDeclaration) {
|
||||
displayParts.push(keywordPart(SyntaxKind.ExportKeyword));
|
||||
displayParts.push(spacePart());
|
||||
displayParts.push(keywordPart(SyntaxKind.NamespaceKeyword));
|
||||
}
|
||||
else {
|
||||
displayParts.push(keywordPart(SyntaxKind.ImportKeyword));
|
||||
}
|
||||
displayParts.push(spacePart());
|
||||
addFullSymbolName(symbol);
|
||||
ts.forEach(symbol.declarations, declaration => {
|
||||
|
||||
@ -39,6 +39,7 @@ var t = p.x;
|
||||
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
|
||||
|
||||
export as namespace Math2d;
|
||||
>Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0))
|
||||
|
||||
export interface Point {
|
||||
>Point : Symbol(Point, Decl(index.d.ts, 1, 27))
|
||||
|
||||
@ -48,7 +48,7 @@ var t = p.x;
|
||||
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
|
||||
|
||||
export as namespace Math2d;
|
||||
>Math2d : any
|
||||
>Math2d : typeof Math2d
|
||||
|
||||
export interface Point {
|
||||
>Point : Point
|
||||
|
||||
@ -37,6 +37,7 @@ var t = p.x;
|
||||
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
|
||||
|
||||
export as namespace Math2d;
|
||||
>Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0))
|
||||
|
||||
export interface Point {
|
||||
>Point : Symbol(Point, Decl(index.d.ts, 1, 27))
|
||||
|
||||
@ -46,7 +46,7 @@ var t = p.x;
|
||||
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
|
||||
|
||||
export as namespace Math2d;
|
||||
>Math2d : any
|
||||
>Math2d : typeof Math2d
|
||||
|
||||
export interface Point {
|
||||
>Point : Point
|
||||
|
||||
@ -39,6 +39,7 @@ var t = p.x;
|
||||
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
|
||||
|
||||
export as namespace Math2d;
|
||||
>Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0))
|
||||
|
||||
export = M2D;
|
||||
>M2D : Symbol(M2D, Decl(index.d.ts, 3, 13))
|
||||
|
||||
@ -48,7 +48,7 @@ var t = p.x;
|
||||
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
|
||||
|
||||
export as namespace Math2d;
|
||||
>Math2d : any
|
||||
>Math2d : typeof Math2d
|
||||
|
||||
export = M2D;
|
||||
>M2D : typeof M2D
|
||||
|
||||
@ -37,6 +37,7 @@ var t = p.x;
|
||||
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
|
||||
|
||||
export as namespace Math2d;
|
||||
>Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0))
|
||||
|
||||
export = M2D;
|
||||
>M2D : Symbol(M2D, Decl(index.d.ts, 3, 13))
|
||||
|
||||
@ -46,7 +46,7 @@ var t = p.x;
|
||||
=== tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts ===
|
||||
|
||||
export as namespace Math2d;
|
||||
>Math2d : any
|
||||
>Math2d : typeof Math2d
|
||||
|
||||
export = M2D;
|
||||
>M2D : typeof M2D
|
||||
|
||||
@ -30,4 +30,5 @@ export interface Thing { n: typeof x }
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 38))
|
||||
|
||||
|
||||
@ -31,5 +31,5 @@ export interface Thing { n: typeof x }
|
||||
>x : number
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : any
|
||||
>Foo : typeof Foo
|
||||
|
||||
|
||||
@ -32,4 +32,5 @@ export interface Thing { n: typeof x }
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 38))
|
||||
|
||||
|
||||
@ -33,5 +33,5 @@ export interface Thing { n: typeof x }
|
||||
>x : number
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : any
|
||||
>Foo : typeof Foo
|
||||
|
||||
|
||||
@ -32,4 +32,5 @@ export interface Thing { n: typeof x }
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 38))
|
||||
|
||||
|
||||
@ -33,5 +33,5 @@ export interface Thing { n: typeof x }
|
||||
>x : number
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : any
|
||||
>Foo : typeof Foo
|
||||
|
||||
|
||||
@ -18,4 +18,5 @@ export = Thing;
|
||||
>Thing : Symbol(Thing, Decl(foo.d.ts, 0, 0))
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : Symbol(Foo, Decl(foo.d.ts, 4, 15))
|
||||
|
||||
|
||||
@ -19,5 +19,5 @@ export = Thing;
|
||||
>Thing : typeof Thing
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : any
|
||||
>Foo : typeof Thing
|
||||
|
||||
|
||||
@ -13,4 +13,5 @@ export = Thing;
|
||||
>Thing : Symbol(Thing, Decl(foo.d.ts, 0, 0))
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : Symbol(Foo, Decl(foo.d.ts, 2, 15))
|
||||
|
||||
|
||||
@ -14,5 +14,5 @@ export = Thing;
|
||||
>Thing : () => number
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : any
|
||||
>Foo : () => number
|
||||
|
||||
|
||||
@ -22,4 +22,5 @@ export = Thing;
|
||||
>Thing : Symbol(Thing, Decl(foo.d.ts, 0, 0))
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : Symbol(Foo, Decl(foo.d.ts, 4, 15))
|
||||
|
||||
|
||||
@ -23,5 +23,5 @@ export = Thing;
|
||||
>Thing : Thing
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : any
|
||||
>Foo : typeof Thing
|
||||
|
||||
|
||||
13
tests/cases/fourslash/findAllRefsForUMDModuleAlias1.ts
Normal file
13
tests/cases/fourslash/findAllRefsForUMDModuleAlias1.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: 0.d.ts
|
||||
//// export function doThing(): string;
|
||||
//// export function doTheOtherThing(): void;
|
||||
|
||||
//// export as namespace [|myLib|];
|
||||
|
||||
// @Filename: 1.ts
|
||||
//// /// <reference path="0.d.ts" />
|
||||
//// [|myLib|].doThing();
|
||||
|
||||
verify.rangesReferenceEachOther();
|
||||
17
tests/cases/fourslash/quickInfoForUMDModuleAlias.ts
Normal file
17
tests/cases/fourslash/quickInfoForUMDModuleAlias.ts
Normal file
@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: 0.d.ts
|
||||
//// export function doThing(): string;
|
||||
//// export function doTheOtherThing(): void;
|
||||
|
||||
//// export as namespace /*0*/myLib;
|
||||
|
||||
// @Filename: 1.ts
|
||||
//// /// <reference path="0.d.ts" />
|
||||
//// /*1*/myLib.doThing();
|
||||
|
||||
goTo.marker("0");
|
||||
verify.quickInfoIs("export namespace myLib");
|
||||
|
||||
goTo.marker("1");
|
||||
verify.quickInfoIs("export namespace myLib");
|
||||
@ -4,8 +4,8 @@
|
||||
////import [|M|] = SomeModule;
|
||||
////import C = [|M|].SomeClass;
|
||||
|
||||
let ranges = test.ranges()
|
||||
for (let range of ranges) {
|
||||
goTo.position(range.start);
|
||||
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
|
||||
let ranges = test.ranges()
|
||||
for (let range of ranges) {
|
||||
goTo.position(range.start);
|
||||
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
|
||||
}
|
||||
17
tests/cases/fourslash/renameUMDModuleAlias1.ts
Normal file
17
tests/cases/fourslash/renameUMDModuleAlias1.ts
Normal file
@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: 0.d.ts
|
||||
//// export function doThing(): string;
|
||||
//// export function doTheOtherThing(): void;
|
||||
|
||||
//// export as namespace [|myLib|];
|
||||
|
||||
// @Filename: 1.ts
|
||||
//// /// <reference path="0.d.ts" />
|
||||
//// [|myLib|].doThing();
|
||||
|
||||
const ranges = test.ranges()
|
||||
for (const range of ranges) {
|
||||
goTo.position(range.start);
|
||||
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
|
||||
}
|
||||
14
tests/cases/fourslash/renameUMDModuleAlias2.ts
Normal file
14
tests/cases/fourslash/renameUMDModuleAlias2.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: 0.d.ts
|
||||
//// export function doThing(): string;
|
||||
//// export function doTheOtherThing(): void;
|
||||
|
||||
//// export as namespace /**/[|myLib|];
|
||||
|
||||
// @Filename: 1.ts
|
||||
//// /// <reference path="0.d.ts" />
|
||||
//// myLib.doThing();
|
||||
|
||||
goTo.marker();
|
||||
verify.renameInfoSucceeded("myLib");
|
||||
Loading…
x
Reference in New Issue
Block a user