Fix dealiaser throwing on TypeAlias nodes.
getAliasedSymbol only accepts Alias, not TypeAlias, so filter on that only.
PiperOrigin-RevId: 264161077
diff --git a/internal/tsetse/tests/ban_conformance_pattern/name_test.ts b/internal/tsetse/tests/ban_conformance_pattern/name_test.ts
index 6bb06ec..d3ffdd0 100644
--- a/internal/tsetse/tests/ban_conformance_pattern/name_test.ts
+++ b/internal/tsetse/tests/ban_conformance_pattern/name_test.ts
@@ -38,6 +38,30 @@
messageText: 'no blob url'
});
});
+
+ it('does not choke on type aliases', () => {
+ // This test case checks that we do not regress on the AbsoluteMatcher's
+ // handling of type aliases. In dealias, from utils/ast_tools.ts, the
+ // typechecker's getAliasedSymbol function should only be called with
+ // Symbols that verify ts.SymbolFlags.Alias, and ts.SymbolFlags.TypeAlias is
+ // not acceptable (the typechecker will throw).
+
+ const sources = [
+ `export type Foo = {bar: number, baz: (x:string)=>void}`,
+ `import {Foo} from './file_0';
+ export const c: Foo["baz"] = (x:string)=>{};`,
+ `import {c} from './file_1'; c(window.name);`
+ ];
+ const results = compileAndCheck(
+ new ConformancePatternRule({
+ errorMessage: 'should not trigger',
+ kind: PatternKind.BANNED_NAME,
+ values: ['whatever']
+ }),
+ ...sources);
+
+ expect(results.length).toBe(0);
+ });
});
beforeEach(() => {
diff --git a/internal/tsetse/util/ast_tools.ts b/internal/tsetse/util/ast_tools.ts
index cb0f0cb..024c008 100644
--- a/internal/tsetse/util/ast_tools.ts
+++ b/internal/tsetse/util/ast_tools.ts
@@ -100,7 +100,8 @@
if (!symbol) {
return undefined;
}
- if (symbol.getFlags() & (ts.SymbolFlags.Alias | ts.SymbolFlags.TypeAlias)) {
+ if (symbol.getFlags() & ts.SymbolFlags.Alias) {
+ // Note: something that has only TypeAlias is not acceptable here.
return dealias(tc.getAliasedSymbol(symbol), tc);
}
return symbol;