Skip to content

Commit 088a7de

Browse files
authored
Merge pull request #1 from Gerrit0/patch-1
fix: Allow including global symbols in module exports
2 parents 93ffb7a + 4220044 commit 088a7de

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/main.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ exports.load = function ({ application }: { application: Application }) {
6868
.getSymbolsInScope(node, TypeScript.SymbolFlags.ModuleMember)
6969
.filter(
7070
(symbol) =>
71-
symbol.getDeclarations()?.some((d) => d.parent === node) &&
71+
isInDocumentableScope(symbol, node) &&
7272
!exportedSymbols.includes(symbol)
7373
)
7474

@@ -83,3 +83,24 @@ exports.load = function ({ application }: { application: Application }) {
8383
}
8484
}
8585
}
86+
87+
function isInDocumentableScope(symbol: TypeScript.Symbol, node: TypeScript.Node) {
88+
for (const decl of symbol.getDeclarations() || []) {
89+
// Case 1: Included in this namespace/source file
90+
if (decl.parent === node) return true
91+
92+
// Case 2: Within `declare global {}`
93+
// We need to check isSourceFile here as well because otherwise it will be picked up
94+
// in the scope of namespaces while we should be picking it up only in the first case
95+
if (
96+
TypeScript.isSourceFile(node) &&
97+
TypeScript.isModuleBlock(decl.parent) &&
98+
decl.parent.parent.name.getText() === "global"
99+
) {
100+
return true
101+
}
102+
}
103+
104+
return false
105+
}
106+

0 commit comments

Comments
 (0)