Skip to content

Commit

Permalink
feat: Better detection for declaration files defining a module
Browse files Browse the repository at this point in the history
Might help with #1430
  • Loading branch information
Gerrit0 committed Dec 29, 2020
1 parent 02b915d commit 38d8edf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lib/converter/converter.ts
Expand Up @@ -427,9 +427,20 @@ function getExports(
// this isn't the best solution, it would be nice to have all globals given to a special
// "globals" file, but this is uncommon enough that I'm skipping it for now.
const sourceFile = node.getSourceFile();
return context.checker
const globalSymbols = context.checker
.getSymbolsInScope(node, ts.SymbolFlags.ModuleMember)
.filter((s) =>
s.getDeclarations()?.some((d) => d.getSourceFile() === sourceFile)
);

// Detect declaration files with declare module "foo" as their only export
// and lift that up one level
if (
globalSymbols.length === 1 &&
globalSymbols[0].getDeclarations()?.every(ts.isModuleDeclaration)
) {
return context.checker.getExportsOfModule(globalSymbols[0]);
}

return globalSymbols;
}

0 comments on commit 38d8edf

Please sign in to comment.