Skip to content
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
4 changes: 3 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19372,7 +19372,9 @@ namespace ts {
forEach(node.exportClause.elements, checkExportSpecifier);

const inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && isAmbientModule(node.parent.parent);
if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) {
const inAmbientNamespaceDeclaration = !inAmbientExternalModule && node.parent.kind === SyntaxKind.ModuleBlock &&
!node.moduleSpecifier && isInAmbientContext(node);
if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule && !inAmbientNamespaceDeclaration) {
error(node, Diagnostics.Export_declarations_are_not_permitted_in_a_namespace);
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/baselines/reference/exportDeclarationsInAmbientNamespaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [exportDeclarationsInAmbientNamespaces.ts]

declare namespace Q {
function _try(method: Function, ...args: any[]): any;
export { _try as try };
}

Q.try(() => { });



//// [exportDeclarationsInAmbientNamespaces.js]
Q["try"](function () { });
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
=== tests/cases/compiler/exportDeclarationsInAmbientNamespaces.ts ===

declare namespace Q {
>Q : Symbol(Q, Decl(exportDeclarationsInAmbientNamespaces.ts, 0, 0))

function _try(method: Function, ...args: any[]): any;
>_try : Symbol(_try, Decl(exportDeclarationsInAmbientNamespaces.ts, 1, 21))
>method : Symbol(method, Decl(exportDeclarationsInAmbientNamespaces.ts, 2, 18))
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>args : Symbol(args, Decl(exportDeclarationsInAmbientNamespaces.ts, 2, 35))

export { _try as try };
>_try : Symbol(try, Decl(exportDeclarationsInAmbientNamespaces.ts, 3, 12))
>try : Symbol(try, Decl(exportDeclarationsInAmbientNamespaces.ts, 3, 12))
}

Q.try(() => { });
>Q.try : Symbol(Q.try, Decl(exportDeclarationsInAmbientNamespaces.ts, 3, 12))
>Q : Symbol(Q, Decl(exportDeclarationsInAmbientNamespaces.ts, 0, 0))
>try : Symbol(Q.try, Decl(exportDeclarationsInAmbientNamespaces.ts, 3, 12))


Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
=== tests/cases/compiler/exportDeclarationsInAmbientNamespaces.ts ===

declare namespace Q {
>Q : typeof Q

function _try(method: Function, ...args: any[]): any;
>_try : (method: Function, ...args: any[]) => any
>method : Function
>Function : Function
>args : any[]

export { _try as try };
>_try : (method: Function, ...args: any[]) => any
>try : (method: Function, ...args: any[]) => any
}

Q.try(() => { });
>Q.try(() => { }) : any
>Q.try : (method: Function, ...args: any[]) => any
>Q : typeof Q
>try : (method: Function, ...args: any[]) => any
>() => { } : () => void


Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tests/cases/compiler/exportDeclarationsInAmbientNamespaces2.ts(7,23): error TS1194: Export declarations are not permitted in a namespace.


==== tests/cases/compiler/exportDeclarationsInAmbientNamespaces2.ts (1 errors) ====

declare module "mod" {
export var x: number;
}

declare namespace N {
export { x } from "mod"; // Error
~~~~~
!!! error TS1194: Export declarations are not permitted in a namespace.
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [exportDeclarationsInAmbientNamespaces2.ts]

declare module "mod" {
export var x: number;
}

declare namespace N {
export { x } from "mod"; // Error
}



//// [exportDeclarationsInAmbientNamespaces2.js]
8 changes: 8 additions & 0 deletions tests/cases/compiler/exportDeclarationsInAmbientNamespaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

declare namespace Q {
function _try(method: Function, ...args: any[]): any;
export { _try as try };
}

Q.try(() => { });

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

declare module "mod" {
export var x: number;
}

declare namespace N {
export { x } from "mod"; // Error
}