()
| 84933 | } |
| 84934 | addLazyDiagnostic(checkModuleDeclarationDiagnostics); |
| 84935 | function checkModuleDeclarationDiagnostics() { |
| 84936 | // Grammar checking |
| 84937 | var isGlobalAugmentation = ts.isGlobalScopeAugmentation(node); |
| 84938 | var inAmbientContext = node.flags & 16777216 /* NodeFlags.Ambient */; |
| 84939 | if (isGlobalAugmentation && !inAmbientContext) { |
| 84940 | error(node.name, ts.Diagnostics.Augmentations_for_the_global_scope_should_have_declare_modifier_unless_they_appear_in_already_ambient_context); |
| 84941 | } |
| 84942 | var isAmbientExternalModule = ts.isAmbientModule(node); |
| 84943 | var contextErrorMessage = isAmbientExternalModule |
| 84944 | ? ts.Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file |
| 84945 | : ts.Diagnostics.A_namespace_declaration_is_only_allowed_at_the_top_level_of_a_namespace_or_module; |
| 84946 | if (checkGrammarModuleElementContext(node, contextErrorMessage)) { |
| 84947 | // If we hit a module declaration in an illegal context, just bail out to avoid cascading errors. |
| 84948 | return; |
| 84949 | } |
| 84950 | if (!checkGrammarDecoratorsAndModifiers(node)) { |
| 84951 | if (!inAmbientContext && node.name.kind === 10 /* SyntaxKind.StringLiteral */) { |
| 84952 | grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); |
| 84953 | } |
| 84954 | } |
| 84955 | if (ts.isIdentifier(node.name)) { |
| 84956 | checkCollisionsForDeclarationName(node, node.name); |
| 84957 | } |
| 84958 | checkExportsOnMergedDeclarations(node); |
| 84959 | var symbol = getSymbolOfNode(node); |
| 84960 | // The following checks only apply on a non-ambient instantiated module declaration. |
| 84961 | if (symbol.flags & 512 /* SymbolFlags.ValueModule */ |
| 84962 | && !inAmbientContext |
| 84963 | && symbol.declarations |
| 84964 | && symbol.declarations.length > 1 |
| 84965 | && isInstantiatedModule(node, ts.shouldPreserveConstEnums(compilerOptions))) { |
| 84966 | var firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); |
| 84967 | if (firstNonAmbientClassOrFunc) { |
| 84968 | if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(firstNonAmbientClassOrFunc)) { |
| 84969 | error(node.name, ts.Diagnostics.A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged); |
| 84970 | } |
| 84971 | else if (node.pos < firstNonAmbientClassOrFunc.pos) { |
| 84972 | error(node.name, ts.Diagnostics.A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged); |
| 84973 | } |
| 84974 | } |
| 84975 | // if the module merges with a class declaration in the same lexical scope, |
| 84976 | // we need to track this to ensure the correct emit. |
| 84977 | var mergedClass = ts.getDeclarationOfKind(symbol, 257 /* SyntaxKind.ClassDeclaration */); |
| 84978 | if (mergedClass && |
| 84979 | inSameLexicalScope(node, mergedClass)) { |
| 84980 | getNodeLinks(node).flags |= 32768 /* NodeCheckFlags.LexicalModuleMergesWithClass */; |
| 84981 | } |
| 84982 | } |
| 84983 | if (isAmbientExternalModule) { |
| 84984 | if (ts.isExternalModuleAugmentation(node)) { |
| 84985 | // body of the augmentation should be checked for consistency only if augmentation was applied to its target (either global scope or module) |
| 84986 | // otherwise we'll be swamped in cascading errors. |
| 84987 | // We can detect if augmentation was applied using following rules: |
| 84988 | // - augmentation for a global scope is always applied |
| 84989 | // - augmentation for some external module is applied if symbol for augmentation is merged (it was combined with target module). |
| 84990 | var checkBody = isGlobalAugmentation || (getSymbolOfNode(node).flags & 33554432 /* SymbolFlags.Transient */); |
| 84991 | if (checkBody && node.body) { |
| 84992 | for (var _i = 0, _a = node.body.statements; _i < _a.length; _i++) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…