Skip to content

Commit

Permalink
fix: CommonJS export= with type exports
Browse files Browse the repository at this point in the history
Resolves #1476
  • Loading branch information
Gerrit0 committed Jan 23, 2021
1 parent 46371bf commit 4a539dd
Show file tree
Hide file tree
Showing 3 changed files with 550 additions and 448 deletions.
12 changes: 8 additions & 4 deletions src/lib/converter/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,21 @@ function getExports(
node: ts.SourceFile | ts.ModuleBlock,
symbol: ts.Symbol | undefined
): ts.Symbol[] {
const exports: ts.Symbol[] = [];

// The generated docs aren't great, but you really ought not be using
// this in the first place... so it's better than nothing.
const exportEq = symbol?.exports?.get("export=" as ts.__String);
if (exportEq) {
return [exportEq];
exports.push(exportEq);
}

if (symbol) {
return context.checker
.getExportsOfModule(symbol)
.filter((s) => !hasFlag(s.flags, ts.SymbolFlags.Prototype));
return exports.concat(
context.checker
.getExportsOfModule(symbol)
.filter((s) => !hasFlag(s.flags, ts.SymbolFlags.Prototype))
);
}

// Global file with no inferred top level symbol, get all symbols declared in this file.
Expand Down
6 changes: 6 additions & 0 deletions src/test/converter/js/export-eq-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @typedef {string} Foo */

/** @param {Foo} x */
const foo = (x) => x;

module.exports = foo;
Loading

0 comments on commit 4a539dd

Please sign in to comment.