[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:
Yui 2016-08-02 13:01:05 -07:00 committed by GitHub
parent 8ceeb4bdc4
commit 126c1eeb59
28 changed files with 96 additions and 16 deletions

View File

@ -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))) {

View File

@ -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:

View File

@ -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 => {

View File

@ -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))

View File

@ -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

View File

@ -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))

View File

@ -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

View File

@ -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))

View File

@ -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

View File

@ -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))

View File

@ -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

View File

@ -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))

View File

@ -31,5 +31,5 @@ export interface Thing { n: typeof x }
>x : number
export as namespace Foo;
>Foo : any
>Foo : typeof Foo

View File

@ -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))

View File

@ -33,5 +33,5 @@ export interface Thing { n: typeof x }
>x : number
export as namespace Foo;
>Foo : any
>Foo : typeof Foo

View File

@ -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))

View File

@ -33,5 +33,5 @@ export interface Thing { n: typeof x }
>x : number
export as namespace Foo;
>Foo : any
>Foo : typeof Foo

View File

@ -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))

View File

@ -19,5 +19,5 @@ export = Thing;
>Thing : typeof Thing
export as namespace Foo;
>Foo : any
>Foo : typeof Thing

View File

@ -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))

View File

@ -14,5 +14,5 @@ export = Thing;
>Thing : () => number
export as namespace Foo;
>Foo : any
>Foo : () => number

View File

@ -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))

View File

@ -23,5 +23,5 @@ export = Thing;
>Thing : Thing
export as namespace Foo;
>Foo : any
>Foo : typeof Thing

View 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();

View 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");

View File

@ -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);
}

View 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);
}

View 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");