Skip to content

Commit d2fca1b

Browse files
authored
Merge pull request github#13926 from asgerf/js/fix-cyclic-alias-extraction
JS: fix crash in case of cyclic alias
2 parents 08d44c1 + b8fc84e commit d2fca1b

File tree

6 files changed

+21
-1
lines changed

6 files changed

+21
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: fix
3+
---
4+
* Fixed an extractor crash that would occur in rare cases when a TypeScript file contains a self-referential namespace alias.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Foo = Foo.Bar;
2+
3+
declare namespace Foo {
4+
var Bar: {};
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| Success |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Just check that extraction succeeds
2+
select "Success"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"include": ["."]
3+
}

0 commit comments

Comments
 (0)