Skip to content

Commit c6a757e

Browse files
committed
JS: More robust handling of cyclic aliases
1 parent 794a459 commit c6a757e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

javascript/extractor/lib/typescript/src/type_table.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,16 @@ export class TypeTable {
659659
*/
660660
public getSymbolId(symbol: AugmentedSymbol): number {
661661
if (symbol.flags & ts.SymbolFlags.Alias) {
662-
symbol = this.typeChecker.getAliasedSymbol(symbol);
662+
let aliasedSymbol: AugmentedSymbol = this.typeChecker.getAliasedSymbol(symbol);
663+
if (aliasedSymbol.$id !== -1) { // Check if aliased symbol is on-stack
664+
// Follow aliases eagerly, except in cases where this leads to cycles (for things like `import Foo = Foo.Bar`)
665+
symbol = aliasedSymbol;
666+
}
663667
}
664668
// We cache the symbol ID to avoid rebuilding long symbol strings.
665669
let id = symbol.$id;
666670
if (id != null) return id;
671+
symbol.$id = -1; // Mark as on-stack while we are computing the ID
667672
let content = this.getSymbolString(symbol);
668673
id = this.symbolIds.get(content);
669674
if (id != null) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| Success |

0 commit comments

Comments
 (0)