mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 21:06:50 -05:00
Only error on non-ambient instantiated modules preceding clodules.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user