File tree 5 files changed +41
-24
lines changed
tests/baselines/reference
5 files changed +41
-24
lines changed Original file line number Diff line number Diff line change @@ -9003,7 +9003,12 @@ module ts {
9003
9003
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
9004
9004
checkExportsOnMergedDeclarations(node);
9005
9005
var symbol = getSymbolOfNode(node);
9006
- if (symbol.flags & SymbolFlags.ValueModule && symbol.declarations.length > 1 && !isInAmbientContext(node)) {
9006
+
9007
+ // The following checks only apply on a non-ambient instantiated module declaration.
9008
+ if (symbol.flags & SymbolFlags.ValueModule
9009
+ && symbol.declarations.length > 1
9010
+ && !isInAmbientContext(node)
9011
+ && isInstantiatedModule(node, compilerOptions.preserveConstEnums)) {
9007
9012
var classOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
9008
9013
if (classOrFunc) {
9009
9014
if (getSourceFileOfNode(node) !== getSourceFileOfNode(classOrFunc)) {
@@ -9014,6 +9019,8 @@ module ts {
9014
9019
}
9015
9020
}
9016
9021
}
9022
+
9023
+ // Checks for ambient external modules.
9017
9024
if (node.name.kind === SyntaxKind.StringLiteral) {
9018
9025
if (!isGlobalSourceFile(node.parent)) {
9019
9026
error(node.name, Diagnostics.Ambient_external_modules_cannot_be_nested_in_other_modules);
Original file line number Diff line number Diff line change @@ -3680,8 +3680,8 @@ module ts {
3680
3680
}
3681
3681
3682
3682
function emitModuleDeclaration ( node : ModuleDeclaration ) {
3683
- var shouldEmit = getModuleInstanceState ( node ) === ModuleInstanceState . Instantiated ||
3684
- ( getModuleInstanceState ( node ) === ModuleInstanceState . ConstEnumOnly && compilerOptions . preserveConstEnums ) ;
3683
+ // Emit only if this module is non-ambient.
3684
+ var shouldEmit = isInstantiatedModule ( node , compilerOptions . preserveConstEnums ) ;
3685
3685
3686
3686
if ( ! shouldEmit ) {
3687
3687
return emitPinnedOrTripleSlashComments ( node ) ;
Original file line number Diff line number Diff line change @@ -525,6 +525,12 @@ module ts {
525
525
return false ;
526
526
}
527
527
528
+ export function isInstantiatedModule ( node : ModuleDeclaration , preserveConstEnums : boolean ) {
529
+ var moduleState = getModuleInstanceState ( node )
530
+ return moduleState === ModuleInstanceState . Instantiated ||
531
+ ( preserveConstEnums && moduleState === ModuleInstanceState . ConstEnumOnly ) ;
532
+ }
533
+
528
534
export function isExternalModuleImportDeclaration ( node : Node ) {
529
535
return node . kind === SyntaxKind . ImportDeclaration && ( < ImportDeclaration > node ) . moduleReference . kind === SyntaxKind . ExternalModuleReference ;
530
536
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ === tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts ===
2
+ // Ambient/uninstantiated module.
3
+ module Moclodule {
4
+ >Moclodule : typeof Moclodule
5
+
6
+ export interface Someinterface {
7
+ >Someinterface : Someinterface
8
+
9
+ foo(): void;
10
+ >foo : () => void
11
+ }
12
+ }
13
+
14
+ class Moclodule {
15
+ >Moclodule : Moclodule
16
+ }
17
+
18
+ // Instantiated module.
19
+ module Moclodule {
20
+ >Moclodule : typeof Moclodule
21
+
22
+ export class Manager {
23
+ >Manager : Manager
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments