Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: Correct handling for intentionally broken references
  • Loading branch information
Gerrit0 committed May 1, 2021
1 parent ce6aac2 commit 5d581b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib/models/types/reference.ts
Expand Up @@ -3,6 +3,8 @@ import type { ProjectReflection } from "../reflections";
import { Reflection } from "../reflections/abstract";
import { Type } from "./abstract";

const BROKEN_REFERENCE_ID = -1;

/**
* Represents a type that refers to another reflection like a class, interface or enum.
*
Expand Down Expand Up @@ -66,7 +68,7 @@ export class ReferenceType extends Type {

/** @internal this is used for type parameters, which don't actually point to something */
static createBrokenReference(name: string, project: ProjectReflection) {
return new ReferenceType(name, -1, project);
return new ReferenceType(name, BROKEN_REFERENCE_ID, project);
}

/**
Expand All @@ -93,7 +95,14 @@ export class ReferenceType extends Type {

let matchesTarget;
if (!this.reflection) {
matchesTarget = this._target === other._target;
if (
this._target === BROKEN_REFERENCE_ID &&
other._target === BROKEN_REFERENCE_ID
) {
matchesTarget = this.name === other.name;
} else {
matchesTarget = this._target === other._target;
}
} else {
matchesTarget = this.reflection === other.reflection;
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/models/types/reference.test.ts
Expand Up @@ -66,5 +66,11 @@ describe("Reference Type", () => {

equal(type1.equals(type2), false);
});

it("intentionally broken reference types with different names are not equal", () => {
const type1 = ReferenceType.createBrokenReference("Type1", project);
const type2 = ReferenceType.createBrokenReference("Type2", project);
equal(type1.equals(type2), false);
});
});
});

0 comments on commit 5d581b0

Please sign in to comment.