Skip to content

Commit 4a539dd

Browse files
committed
fix: CommonJS export= with type exports
Resolves #1476
1 parent 46371bf commit 4a539dd

File tree

3 files changed

+550
-448
lines changed

3 files changed

+550
-448
lines changed

src/lib/converter/converter.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,17 +449,21 @@ function getExports(
449449
node: ts.SourceFile | ts.ModuleBlock,
450450
symbol: ts.Symbol | undefined
451451
): ts.Symbol[] {
452+
const exports: ts.Symbol[] = [];
453+
452454
// The generated docs aren't great, but you really ought not be using
453455
// this in the first place... so it's better than nothing.
454456
const exportEq = symbol?.exports?.get("export=" as ts.__String);
455457
if (exportEq) {
456-
return [exportEq];
458+
exports.push(exportEq);
457459
}
458460

459461
if (symbol) {
460-
return context.checker
461-
.getExportsOfModule(symbol)
462-
.filter((s) => !hasFlag(s.flags, ts.SymbolFlags.Prototype));
462+
return exports.concat(
463+
context.checker
464+
.getExportsOfModule(symbol)
465+
.filter((s) => !hasFlag(s.flags, ts.SymbolFlags.Prototype))
466+
);
463467
}
464468

465469
// Global file with no inferred top level symbol, get all symbols declared in this file.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @typedef {string} Foo */
2+
3+
/** @param {Foo} x */
4+
const foo = (x) => x;
5+
6+
module.exports = foo;

0 commit comments

Comments
 (0)