1- import {
2- SourceFile ,
3- type FunctionDeclaration ,
4- type ModuleDeclaration ,
5- type VariableDeclaration ,
6- } from "ts-morph" ;
1+ import { SourceFile } from "ts-morph" ;
72import { isGlobal } from "./is-global.ts" ;
83import { isHidden } from "./is-hidden.ts" ;
9-
10- export type GlobalAmbientDeclarationsReturn = {
11- containerName : string ;
12- exportName : string ;
13- declaration : VariableDeclaration | FunctionDeclaration | ModuleDeclaration ;
14- } [ ] ;
4+ import type { FoundDeclaration } from "./types.ts" ;
155
166export function globalAmbientDeclarations (
177 containerName : string ,
188 container : SourceFile ,
19- ) : GlobalAmbientDeclarationsReturn {
9+ ) : FoundDeclaration [ ] {
2010 // See https://www.typescriptlang.org/docs/handbook/declaration-files/by-example.html#global-variables.
2111 const globalCandidates = [
2212 ...container . getVariableDeclarations ( ) ,
@@ -25,15 +15,12 @@ export function globalAmbientDeclarations(
2515 ] ;
2616 const globalAmbientDeclarations = [ ] ;
2717 for ( const declaration of globalCandidates ) {
28- if ( isHidden ( declaration ) || ! isGlobal ( declaration ) ) {
29- continue ;
30- }
31- globalAmbientDeclarations . push ( {
32- containerName,
33- // Global ambient functions must have a name.
34- exportName : declaration . getName ( ) ! ,
35- declaration,
36- } ) ;
18+ if ( ! isGlobal ( declaration ) ) continue ;
19+ if ( isHidden ( declaration ) ) continue ;
20+
21+ // Global ambient functions must have a name.
22+ const exportName = declaration . getName ( ) ! ;
23+ globalAmbientDeclarations . push ( { containerName, exportName, declaration } ) ;
3724 }
3825 return globalAmbientDeclarations ;
3926}
0 commit comments