Skip to content

Commit 5d581b0

Browse files
committed
fix: Correct handling for intentionally broken references
1 parent ce6aac2 commit 5d581b0

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/lib/models/types/reference.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { ProjectReflection } from "../reflections";
33
import { Reflection } from "../reflections/abstract";
44
import { Type } from "./abstract";
55

6+
const BROKEN_REFERENCE_ID = -1;
7+
68
/**
79
* Represents a type that refers to another reflection like a class, interface or enum.
810
*
@@ -66,7 +68,7 @@ export class ReferenceType extends Type {
6668

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

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

9496
let matchesTarget;
9597
if (!this.reflection) {
96-
matchesTarget = this._target === other._target;
98+
if (
99+
this._target === BROKEN_REFERENCE_ID &&
100+
other._target === BROKEN_REFERENCE_ID
101+
) {
102+
matchesTarget = this.name === other.name;
103+
} else {
104+
matchesTarget = this._target === other._target;
105+
}
97106
} else {
98107
matchesTarget = this.reflection === other.reflection;
99108
}

src/test/models/types/reference.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,11 @@ describe("Reference Type", () => {
6666

6767
equal(type1.equals(type2), false);
6868
});
69+
70+
it("intentionally broken reference types with different names are not equal", () => {
71+
const type1 = ReferenceType.createBrokenReference("Type1", project);
72+
const type2 = ReferenceType.createBrokenReference("Type2", project);
73+
equal(type1.equals(type2), false);
74+
});
6975
});
7076
});

0 commit comments

Comments
 (0)