Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port PR #10016 to Master #10100

Merged
merged 5 commits into from
Aug 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19673,7 +19673,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:
Expand All @@ -19691,6 +19691,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))) {

Expand Down
1 change: 1 addition & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4830,7 +4830,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 => {
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/umd-augmentation-1.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/umd-augmentation-1.types
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/umd-augmentation-2.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/umd-augmentation-2.types
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/umd-augmentation-3.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/umd-augmentation-3.types
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/umd-augmentation-4.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/umd-augmentation-4.types
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/umd1.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd1.types
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export interface Thing { n: typeof x }
>x : number

export as namespace Foo;
>Foo : any
>Foo : typeof Foo

1 change: 1 addition & 0 deletions tests/baselines/reference/umd3.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd3.types
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ export interface Thing { n: typeof x }
>x : number

export as namespace Foo;
>Foo : any
>Foo : typeof Foo

1 change: 1 addition & 0 deletions tests/baselines/reference/umd4.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd4.types
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ export interface Thing { n: typeof x }
>x : number

export as namespace Foo;
>Foo : any
>Foo : typeof Foo

1 change: 1 addition & 0 deletions tests/baselines/reference/umd6.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd6.types
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ export = Thing;
>Thing : typeof Thing

export as namespace Foo;
>Foo : any
>Foo : typeof Thing

1 change: 1 addition & 0 deletions tests/baselines/reference/umd7.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd7.types
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export = Thing;
>Thing : () => number

export as namespace Foo;
>Foo : any
>Foo : () => number

1 change: 1 addition & 0 deletions tests/baselines/reference/umd8.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))

2 changes: 1 addition & 1 deletion tests/baselines/reference/umd8.types
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export = Thing;
>Thing : Thing

export as namespace Foo;
>Foo : any
>Foo : typeof Thing

13 changes: 13 additions & 0 deletions tests/cases/fourslash/findAllRefsForUMDModuleAlias1.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions tests/cases/fourslash/quickInfoForUMDModuleAlias.ts
Original file line number Diff line number Diff line change
@@ -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");
8 changes: 4 additions & 4 deletions tests/cases/fourslash/renameAlias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 17 additions & 0 deletions tests/cases/fourslash/renameUMDModuleAlias1.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions tests/cases/fourslash/renameUMDModuleAlias2.ts
Original file line number Diff line number Diff line change
@@ -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");