Skip to content

Commit 911faff

Browse files
committed
Resolve aliased symbols before checking exclusion
Resolves #2937
1 parent 81c59bc commit 911faff

File tree

7 files changed

+27
-8
lines changed

7 files changed

+27
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ title: Changelog
88

99
- `@inline` now functions when referencing tuple types, #2932.
1010
- `@link` links to the current page are now rendered, #2934.
11+
- Aliased symbols (re-exports) are now resolved before checking if they are excluded/external, #2937.
1112

1213
## v0.28.2 (2025-04-07)
1314

src/lib/converter/context.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export class Context {
209209
this.addChild(reflection);
210210
}
211211

212-
if (symbol && this.converter.isExternal(symbol)) {
212+
if (symbol && this.converter.isExternal(symbol, this.checker)) {
213213
reflection.setFlag(ReflectionFlag.External);
214214
}
215215
if (exportSymbol) {
@@ -276,7 +276,7 @@ export class Context {
276276
}
277277

278278
shouldIgnore(symbol: ts.Symbol) {
279-
return this.converter.shouldIgnore(symbol);
279+
return this.converter.shouldIgnore(symbol, this.checker);
280280
}
281281

282282
/**

src/lib/converter/converter.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { SourcePlugin } from "./plugins/SourcePlugin.js";
6161
import { TypePlugin } from "./plugins/TypePlugin.js";
6262
import { IncludePlugin } from "./plugins/IncludePlugin.js";
6363
import { MergeModuleWithPlugin } from "./plugins/MergeModuleWithPlugin.js";
64+
import { resolveAliasedSymbol } from "./utils/symbols.js";
6465

6566
export interface ConverterEvents {
6667
begin: [Context];
@@ -330,7 +331,13 @@ export class Converter extends AbstractComponent<Application, ConverterEvents> {
330331
this.resolve(context);
331332

332333
this.trigger(Converter.EVENT_END, context);
333-
this._config = undefined;
334+
335+
// Delete caches of options so that test usage which changes options
336+
// doesn't have confusing behavior where tests run in isolation work
337+
// but break when run as a batch.
338+
delete this._config;
339+
delete this.excludeCache;
340+
delete this.externalPatternCache;
334341

335342
return project;
336343
}
@@ -613,12 +620,13 @@ export class Converter extends AbstractComponent<Application, ConverterEvents> {
613620
* information at this point since comment discovery hasn't happened.
614621
* @internal
615622
*/
616-
shouldIgnore(symbol: ts.Symbol) {
623+
shouldIgnore(symbol: ts.Symbol, checker: ts.TypeChecker) {
624+
symbol = resolveAliasedSymbol(symbol, checker);
617625
if (this.isExcluded(symbol)) {
618626
return true;
619627
}
620628

621-
return this.excludeExternals && this.isExternal(symbol);
629+
return this.excludeExternals && this.isExternal(symbol, checker);
622630
}
623631

624632
private isExcluded(symbol: ts.Symbol) {
@@ -631,11 +639,11 @@ export class Converter extends AbstractComponent<Application, ConverterEvents> {
631639
}
632640

633641
/** @internal */
634-
isExternal(symbol: ts.Symbol) {
642+
isExternal(symbol: ts.Symbol, checker: ts.TypeChecker) {
635643
this.externalPatternCache ??= new MinimatchSet(this.externalPattern);
636644
const cache = this.externalPatternCache;
637645

638-
const declarations = symbol.getDeclarations();
646+
const declarations = resolveAliasedSymbol(symbol, checker).getDeclarations();
639647

640648
// `undefined` has no declarations, if someone does `export default undefined`
641649
// the symbol ends up as having no declarations (the export symbol does, but

src/lib/converter/symbols.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import { convertJsDocAlias, convertJsDocCallback } from "./jsdoc.js";
2424
import { getHeritageTypes } from "./utils/nodes.js";
2525
import { removeUndefined } from "./utils/reflections.js";
26+
import { resolveAliasedSymbol } from "./utils/symbols.js";
2627

2728
const symbolConverters: {
2829
[K in ts.SymbolFlags]?: (
@@ -105,7 +106,7 @@ assert(
105106
);
106107

107108
function _convertSymbolNow(context: Context, symbol: ts.Symbol, exportSymbol: ts.Symbol | undefined) {
108-
if (context.shouldIgnore(symbol)) {
109+
if (context.shouldIgnore(resolveAliasedSymbol(symbol, context.checker))) {
109110
return;
110111
}
111112

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const excluded = true;
2+
export { notExcluded } from "./not-excluded.js";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const notExcluded = true;

src/test/issues.c2.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -2122,4 +2122,10 @@ describe("Issue Tests", () => {
21222122
const sig = querySig(project, "doStuff");
21232123
equal(sig.parameters?.[0].type?.toString(), "[start: number, end: number]");
21242124
});
2125+
2126+
it("#2937 resolves symbols before checking if they are excluded/external", () => {
2127+
app.options.setValue("exclude", ["!**/not-excluded.ts"]);
2128+
const project = convert();
2129+
equal(project.children?.map(c => c.name), ["notExcluded"]);
2130+
});
21252131
});

0 commit comments

Comments
 (0)