Skip to content

Commit

Permalink
Handle more skipLibCheck nonsense
Browse files Browse the repository at this point in the history
Resolves #2438
  • Loading branch information
Gerrit0 committed Nov 3, 2023
1 parent 5f24972 commit 2f8a83e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Unreleased

### Bug Fixes

- Fixed an infinite loop when `skipLibCheck` is used to ignore some compiler errors, #2438.
- `gitRevision` will now be replaced in `sourceLinkTemplate`, #2434.

### Thanks!

- @swarnpallav

## v0.25.3 (2023-10-29)

### Features
Expand Down
3 changes: 3 additions & 0 deletions src/lib/converter/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ function convertClassOrInterface(

// And finally, index signatures
convertIndexSignature(reflectionContext, symbol);

// Normally this shouldn't matter, unless someone did something with skipLibCheck off.
return ts.SymbolFlags.Alias;
}

function convertProperty(
Expand Down
5 changes: 5 additions & 0 deletions src/lib/converter/utils/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ export function resolveAliasedSymbol(
symbol: ts.Symbol,
checker: ts.TypeChecker,
): ts.Symbol {
const seen = new Set<ts.Symbol>();
while (ts.SymbolFlags.Alias & symbol.flags) {
symbol = checker.getAliasedSymbol(symbol);

// #2438, with declaration files, we might have an aliased symbol which eventually points to itself.
if (seen.has(symbol)) return symbol;
seen.add(symbol);
}
return symbol;
}
6 changes: 6 additions & 0 deletions src/test/converter2/issues/gh2438.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This only produces no errors because of skipLibCheck
export interface Bad {
badCode: true;
}

export type { Bad };
5 changes: 5 additions & 0 deletions src/test/issues.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1196,4 +1196,9 @@ describe("Issue Tests", () => {
"Index comment.",
);
});

it("Handles recursive aliases without looping infinitely #2438", () => {
const bad = query(convert(), "Bad");
equal(bad.kind, ReflectionKind.Interface);
});
});

0 comments on commit 2f8a83e

Please sign in to comment.