Skip to content

Commit

Permalink
Resolve alias of alias
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin committed Nov 2, 2023
1 parent 043ab92 commit 87864a2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/compiler/src/core/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2344,12 +2344,19 @@ export function createChecker(program: Program): Checker {
mapper: TypeMapper | undefined,
options: SymbolResolutionOptions
): Sym | undefined {
const node = aliasSymbol.declarations[0];
const targetNode = node.kind === SyntaxKind.AliasStatement ? node.value : node;
const sym = resolveTypeReferenceSymInternal(targetNode as any, mapper, options);
if (sym === undefined) {
return undefined;
let current = aliasSymbol;
while (current.flags & SymbolFlags.Alias) {
const node = current.declarations[0];
const targetNode = node.kind === SyntaxKind.AliasStatement ? node.value : node;
const sym = resolveTypeReferenceSymInternal(targetNode as any, mapper, options);
if (sym === undefined) {
return undefined;
}
current = sym;
}
const sym = current;
const node = aliasSymbol.declarations[0];

const resolvedTargetNode = sym.declarations[0];
if (!options.checkTemplateTypes || !isTemplatedNode(resolvedTargetNode)) {
return sym;
Expand Down
24 changes: 24 additions & 0 deletions packages/compiler/test/checker/references.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ describe("compiler: references", () => {
ref: "MyModel.x",
}));

describe("member of alias of alias of model", () =>
itCanReference({
code: `
model MyModel {
@test("target") x: string;
}
alias Alias1 = MyModel;
alias MyModelAlias = Alias1;
`,
ref: "MyModelAlias.x",
}));

describe("spread property from model defined before", () =>
itCanReference({
code: `
Expand Down Expand Up @@ -421,6 +433,18 @@ describe("compiler: references", () => {
ref: "MyInterfaceAlias.operation",
}));

describe("member of alias of alias of interface", () =>
itCanReference({
code: `
interface MyInterface {
@test("target") operation(): void;
}
alias MyInterfaceAlias1 = MyInterface;
alias MyInterfaceAlias = MyInterfaceAlias1;
`,
ref: "MyInterfaceAlias.operation",
}));

describe("member of templated interface instance", () =>
itCanReference({
code: `
Expand Down

0 comments on commit 87864a2

Please sign in to comment.