MCPcopy Create free account
hub / github.com/Snapchat/Valdi / isNonModuleWithAmbiantDeclarations

Function isNonModuleWithAmbiantDeclarations

compiler/companion/src/AST.ts:560–595  ·  view source on GitHub ↗
(sourceFile: ts.SourceFile)

Source from the content-addressed store, hash-verified

558
559function isFileAffectingGlobalScope(sourceFile: ts.SourceFile): boolean {
560 return (
561 containsGlobalScopeAugmentation(sourceFile) ||
562 (!isExternalOrCommonJsModule(sourceFile) &&
563 !isJsonSourceFile(sourceFile) &&
564 !containsOnlyAmbientModules(sourceFile))
565 );
566}
567
568export function isNonModuleWithAmbiantDeclarations(sourceFile: ts.SourceFile): boolean {
569 const statements = sourceFile.statements;
570
571 if (!statements.length) {
572 return false;
573 }
574
575 let hasAmbiantModuleDeclarations = false;
576 let hasImport = false;
577 let hasExports = false;
578
579 for (const statement of statements) {
580 const modifiers = ts.getCombinedModifierFlags(statement as unknown as ts.Declaration);
581 const isAmbiant = (modifiers & ts.ModifierFlags.Ambient) != 0;
582 const isExports = (modifiers & ts.ModifierFlags.Export) !== 0;
583
584 if (isAmbiant) {
585 if (ts.isModuleDeclaration(statement) && ts.isStringLiteral(statement.name)) {
586 hasAmbiantModuleDeclarations = true;
587 }
588 }
589 if (isExports) {
590 hasExports = true;
591 }
592
593 if (ts.isExportDeclaration(statement) || ts.isExportAssignment(statement)) {
594 hasExports = true;
595 }
596
597 if (ts.isImportDeclaration(statement) || ts.isImportEqualsDeclaration(statement)) {
598 hasImport = true;

Callers 2

AST.spec.tsFile · 0.90
doOpenFileMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected