mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Only error on non-ambient instantiated modules preceding clodules.
This commit is contained in:
parent
ca5d243ca7
commit
fac5201765
@ -9003,7 +9003,12 @@ module ts {
|
||||
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
|
||||
checkExportsOnMergedDeclarations(node);
|
||||
var symbol = getSymbolOfNode(node);
|
||||
if (symbol.flags & SymbolFlags.ValueModule && symbol.declarations.length > 1 && !isInAmbientContext(node)) {
|
||||
|
||||
// The following checks only apply on a non-ambient instantiated module declaration.
|
||||
if (symbol.flags & SymbolFlags.ValueModule
|
||||
&& symbol.declarations.length > 1
|
||||
&& !isInAmbientContext(node)
|
||||
&& isInstantiatedModule(node, compilerOptions.preserveConstEnums)) {
|
||||
var classOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
|
||||
if (classOrFunc) {
|
||||
if (getSourceFileOfNode(node) !== getSourceFileOfNode(classOrFunc)) {
|
||||
@ -9014,6 +9019,8 @@ module ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Checks for ambient external modules.
|
||||
if (node.name.kind === SyntaxKind.StringLiteral) {
|
||||
if (!isGlobalSourceFile(node.parent)) {
|
||||
error(node.name, Diagnostics.Ambient_external_modules_cannot_be_nested_in_other_modules);
|
||||
|
||||
@ -3680,8 +3680,8 @@ module ts {
|
||||
}
|
||||
|
||||
function emitModuleDeclaration(node: ModuleDeclaration) {
|
||||
var shouldEmit = getModuleInstanceState(node) === ModuleInstanceState.Instantiated ||
|
||||
(getModuleInstanceState(node) === ModuleInstanceState.ConstEnumOnly && compilerOptions.preserveConstEnums);
|
||||
// Emit only if this module is non-ambient.
|
||||
var shouldEmit = isInstantiatedModule(node, compilerOptions.preserveConstEnums);
|
||||
|
||||
if (!shouldEmit) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
|
||||
@ -525,6 +525,12 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) {
|
||||
var moduleState = getModuleInstanceState(node)
|
||||
return moduleState === ModuleInstanceState.Instantiated ||
|
||||
(preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly);
|
||||
}
|
||||
|
||||
export function isExternalModuleImportDeclaration(node: Node) {
|
||||
return node.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>node).moduleReference.kind === SyntaxKind.ExternalModuleReference;
|
||||
}
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts(2,8): error TS2434: A module declaration cannot be located prior to a class or function with which it is merged
|
||||
|
||||
|
||||
==== tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts (1 errors) ====
|
||||
// Ambient/uninstantiated module.
|
||||
module Moclodule {
|
||||
~~~~~~~~~
|
||||
!!! error TS2434: A module declaration cannot be located prior to a class or function with which it is merged
|
||||
export interface Someinterface {
|
||||
foo(): void;
|
||||
}
|
||||
}
|
||||
|
||||
class Moclodule {
|
||||
}
|
||||
|
||||
// Instantiated module.
|
||||
module Moclodule {
|
||||
export class Manager {
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
=== tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts ===
|
||||
// Ambient/uninstantiated module.
|
||||
module Moclodule {
|
||||
>Moclodule : typeof Moclodule
|
||||
|
||||
export interface Someinterface {
|
||||
>Someinterface : Someinterface
|
||||
|
||||
foo(): void;
|
||||
>foo : () => void
|
||||
}
|
||||
}
|
||||
|
||||
class Moclodule {
|
||||
>Moclodule : Moclodule
|
||||
}
|
||||
|
||||
// Instantiated module.
|
||||
module Moclodule {
|
||||
>Moclodule : typeof Moclodule
|
||||
|
||||
export class Manager {
|
||||
>Manager : Manager
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user