Merge pull request #13913 from Microsoft/allowExportDeclarationsInAmbientNamespaces
Allow export declarations in ambient namespaces
This commit is contained in:
commit
13cb66c555
8 changed files with 108 additions and 1 deletions
|
@ -19540,7 +19540,9 @@ namespace ts {
|
||||||
forEach(node.exportClause.elements, checkExportSpecifier);
|
forEach(node.exportClause.elements, checkExportSpecifier);
|
||||||
|
|
||||||
const inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && isAmbientModule(node.parent.parent);
|
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);
|
error(node, Diagnostics.Export_declarations_are_not_permitted_in_a_namespace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 () { });
|
|
@ -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))
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
//// [exportDeclarationsInAmbientNamespaces2.ts]
|
||||||
|
|
||||||
|
declare module "mod" {
|
||||||
|
export var x: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare namespace N {
|
||||||
|
export { x } from "mod"; // Error
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//// [exportDeclarationsInAmbientNamespaces2.js]
|
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
declare namespace Q {
|
||||||
|
function _try(method: Function, ...args: any[]): any;
|
||||||
|
export { _try as try };
|
||||||
|
}
|
||||||
|
|
||||||
|
Q.try(() => { });
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
declare module "mod" {
|
||||||
|
export var x: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare namespace N {
|
||||||
|
export { x } from "mod"; // Error
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue