Skip to content

Commit

Permalink
Do not convert symbols which are unknown
Browse files Browse the repository at this point in the history
Resolves #3
  • Loading branch information
Gerrit0 committed Nov 6, 2021
1 parent b2f1e3e commit 59087f7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist
yarn-error.log

*.js.map
Expand Down
18 changes: 17 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ function onResolveBegin(

do {
for (const s of missing) {
internalContext.converter.convertSymbol(internalContext, s);
if (shouldConvertSymbol(s, context.checker)) {
internalContext.converter.convertSymbol(internalContext, s);
}
tried.add(s);
}

Expand Down Expand Up @@ -178,3 +180,17 @@ export function discoverMissingExports(root: Reflection): Set<ts.Symbol> {

return missing;
}

function shouldConvertSymbol(symbol: ts.Symbol, checker: ts.TypeChecker) {
while (symbol.flags & ts.SymbolFlags.Alias) {
symbol = checker.getAliasedSymbol(symbol);
}

// We're looking at an unknown symbol which is declared in some package without
// type declarations. We know nothing about it, so don't convert it.
if (symbol.name === "unknown" && symbol.flags & ts.SymbolFlags.Transient) {
return false;
}

return true;
}
19 changes: 19 additions & 0 deletions test/packages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@ test("Excluded non-exported", (t) => {
t.is(missing.size, 1);
});

test("Missing declaration", (t) => {
const entry: DocumentationEntryPoint = {
displayName: "decl",
program,
sourceFile: program.getSourceFile(
join(__dirname, "packages/missing-declaration/index.ts")
)!,
};

const project = app.converter.convert([entry]);
const internals = project.children?.find((x) => x.name === "<internal>");
t.truthy(internals, "No internals namespace created");

t.deepEqual(
internals?.children?.map((c) => c.name),
["Options"]
);
});

test.serial("Custom namespace name", (t) => {
const entry: DocumentationEntryPoint = {
displayName: "single",
Expand Down
10 changes: 10 additions & 0 deletions test/packages/missing-declaration/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-expect-error
import type { default as U } from "underscore";

type Options = {
u?: U | null | undefined;
};

export function f(o: Options): void {
o;
}

0 comments on commit 59087f7

Please sign in to comment.