Skip to content

Commit 3c87ea2

Browse files
committed
fix: add fallback for reexported symbols and correct barrel pagination
When hasExportedCol is false (older databases), reexported symbols now use the same findCrossFileCallTargets fallback as direct exports instead of silently returning an empty array. _pagination.hasMore now accounts for reexportedSymbols in barrel-only files where direct results are empty, preventing API consumers from truncating results without knowing more pages exist. Impact: 2 functions changed, 1 affected
1 parent 7b588fe commit 3c87ea2

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

src/domain/analysis/exports.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ export function exportsData(file, customDbPath, opts = {}) {
6868
if (opts.limit != null) {
6969
const off = opts.offset || 0;
7070
paginated.reexportedSymbols = paginated.reexportedSymbols.slice(off, off + opts.limit);
71+
// Update _pagination.hasMore to account for reexportedSymbols (barrel-only files
72+
// have empty results[], so hasMore would always be false without this)
73+
if (paginated._pagination) {
74+
const reexTotal = opts.unused ? base.totalReexportedUnused : base.totalReexported;
75+
const resultsHasMore = paginated._pagination.hasMore;
76+
const reexHasMore = off + opts.limit < reexTotal;
77+
paginated._pagination.hasMore = resultsHasMore || reexHasMore;
78+
}
7179
}
7280
return paginated;
7381
} finally {
@@ -151,13 +159,19 @@ function exportsFileImpl(db, target, noTests, getFileLines, unused, displayOpts)
151159

152160
const reexportedSymbols = [];
153161
for (const target of reexportTargets) {
154-
const targetExported = hasExportedCol
155-
? db
156-
.prepare(
157-
"SELECT * FROM nodes WHERE file = ? AND kind != 'file' AND exported = 1 ORDER BY line",
158-
)
159-
.all(target.file)
160-
: [];
162+
let targetExported;
163+
if (hasExportedCol) {
164+
targetExported = db
165+
.prepare(
166+
"SELECT * FROM nodes WHERE file = ? AND kind != 'file' AND exported = 1 ORDER BY line",
167+
)
168+
.all(target.file);
169+
} else {
170+
// Fallback: same heuristic as direct exports — symbols called from other files
171+
const targetSymbols = findNodesByFile(db, target.file);
172+
const exportedIds = findCrossFileCallTargets(db, target.file);
173+
targetExported = targetSymbols.filter((s) => exportedIds.has(s.id));
174+
}
161175
for (const s of targetExported) {
162176
const fileLines = getFileLines(target.file);
163177
reexportedSymbols.push({

0 commit comments

Comments
 (0)