Skip to content

Commit fac5201

Browse files
Only error on non-ambient instantiated modules preceding clodules.
1 parent ca5d243 commit fac5201

File tree

5 files changed

+41
-24
lines changed

5 files changed

+41
-24
lines changed

src/compiler/checker.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -9003,7 +9003,12 @@ module ts {
90039003
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
90049004
checkExportsOnMergedDeclarations(node);
90059005
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)) {
90079012
var classOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
90089013
if (classOrFunc) {
90099014
if (getSourceFileOfNode(node) !== getSourceFileOfNode(classOrFunc)) {
@@ -9014,6 +9019,8 @@ module ts {
90149019
}
90159020
}
90169021
}
9022+
9023+
// Checks for ambient external modules.
90179024
if (node.name.kind === SyntaxKind.StringLiteral) {
90189025
if (!isGlobalSourceFile(node.parent)) {
90199026
error(node.name, Diagnostics.Ambient_external_modules_cannot_be_nested_in_other_modules);

src/compiler/emitter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3680,8 +3680,8 @@ module ts {
36803680
}
36813681

36823682
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);
36853685

36863686
if (!shouldEmit) {
36873687
return emitPinnedOrTripleSlashComments(node);

src/compiler/utilities.ts

+6
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,12 @@ module ts {
525525
return false;
526526
}
527527

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+
528534
export function isExternalModuleImportDeclaration(node: Node) {
529535
return node.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>node).moduleReference.kind === SyntaxKind.ExternalModuleReference;
530536
}

tests/baselines/reference/cloduleWithPriorUninstantiatedModule.errors.txt

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

0 commit comments

Comments
 (0)