Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: The exclude option will now remove symbols re-exported from exc…
…luded files

Resolves #1578.
  • Loading branch information
Gerrit0 committed May 1, 2021
1 parent dc8416a commit bb5a5ae
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/lib/converter/converter.ts
Expand Up @@ -40,6 +40,7 @@ export class Converter extends ChildableComponent<
@BindOption("externalPattern")
externalPattern!: string[];
private externalPatternCache?: IMinimatch[];
private excludeCache?: IMinimatch[];

@BindOption("excludeExternals")
excludeExternals!: boolean;
Expand Down Expand Up @@ -384,13 +385,33 @@ export class Converter extends ChildableComponent<
return true;
}

if (this.isExcluded(symbol)) {
return true;
}

if (!this.excludeExternals) {
return false;
}

return this.isExternal(symbol);
}

private isExcluded(symbol: ts.Symbol) {
this.excludeCache ??= createMinimatch(this.application.exclude);

for (const node of symbol.getDeclarations() ?? []) {
if (
this.excludeCache.some((p) =>
p.match(node.getSourceFile().fileName)
)
) {
return true;
}
}

return false;
}

/** @internal */
isExternal(symbol: ts.Symbol) {
this.externalPatternCache ??= createMinimatch(this.externalPattern);
Expand Down
10 changes: 9 additions & 1 deletion src/test/converter2.test.ts
Expand Up @@ -186,6 +186,14 @@ const issueTests: Record<string, (project: ProjectReflection) => void> = {
equal(query(project, "emptyObj").defaultValue, "{}");
equal(query(project, "nonEmptyObj").defaultValue, "...");
},

gh1578(project) {
ok(query(project, "notIgnored"));
ok(
!project.findReflectionByName("ignored"),
"Symbol re-exported from ignored file is ignored."
);
},
};

describe("Converter2", () => {
Expand Down Expand Up @@ -221,7 +229,7 @@ describe("Converter2", () => {
join(base, "issues", `${entry}.d.ts`),
join(base, "issues", `${entry}.tsx`),
join(base, "issues", `${entry}.js`),
join(base, "issues", entry),
join(base, "issues", entry, "index.ts"),
].find(existsSync);

ok(entryPoint, `No entry point found for ${entry}`);
Expand Down
1 change: 1 addition & 0 deletions src/test/converter2/issues/gh1578/ignored.ts
@@ -0,0 +1 @@
export const ignored = true;
2 changes: 2 additions & 0 deletions src/test/converter2/issues/gh1578/index.ts
@@ -0,0 +1,2 @@
export { ignored } from "./ignored";
export const notIgnored = true;
3 changes: 3 additions & 0 deletions src/test/converter2/tsconfig.json
Expand Up @@ -8,5 +8,8 @@

// See #1524. We might force this to false eventually.
"skipLibCheck": true
},
"typedocOptions": {
"exclude": ["**/ignored.ts"]
}
}

0 comments on commit bb5a5ae

Please sign in to comment.