MCPcopy Index your code
hub / github.com/nodejs/node / checkModuleDeclaration

Function checkModuleDeclaration

test/fixtures/snapshot/typescript.js:84927–85018  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

84925 }
84926 }
84927 function checkModuleDeclaration(node) {
84928 if (node.body) {
84929 checkSourceElement(node.body);
84930 if (!ts.isGlobalScopeAugmentation(node)) {
84931 registerForUnusedIdentifiersCheck(node);
84932 }
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)) {

Callers 1

checkSourceElementWorkerFunction · 0.85

Calls 3

checkSourceElementFunction · 0.85
addLazyDiagnosticFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…