1 | import * as tsm from 'ts-morph';
|
2 |
|
3 | export function isGlobalDeclaration({
|
4 | declaration,
|
5 | }: {
|
6 | declaration:
|
7 | | tsm.VariableDeclaration
|
8 | | tsm.FunctionDeclaration
|
9 | | tsm.ModuleDeclaration;
|
10 | }): boolean {
|
11 | const isGlobalVariable =
|
12 | tsm.Node.isVariableDeclaration(declaration) &&
|
13 | declaration.getVariableStatementOrThrow().isAmbient() &&
|
14 | !declaration.isExported();
|
15 |
|
16 | const isGlobalFunction =
|
17 | tsm.Node.isFunctionDeclaration(declaration) &&
|
18 | declaration.isAmbient() &&
|
19 | declaration.getName() !== undefined &&
|
20 | !declaration.isExported();
|
21 |
|
22 | const isGlobalNamespace =
|
23 | tsm.Node.isModuleDeclaration(declaration) &&
|
24 | declaration.isAmbient() &&
|
25 | !declaration.isExported() &&
|
26 | !declaration.hasModuleKeyword();
|
27 |
|
28 | return isGlobalVariable || isGlobalFunction || isGlobalNamespace;
|
29 | }
|