From c1ebf14f8e5bea3c8af31dfedf06880b53b70d38 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 15 Dec 2024 09:57:18 -0700 Subject: [PATCH] Slightly smarter router --- src/lib/output/router.ts | 3 +++ src/test/output/router.test.ts | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/lib/output/router.ts b/src/lib/output/router.ts index 8c56934ca..cc6560a2e 100644 --- a/src/lib/output/router.ts +++ b/src/lib/output/router.ts @@ -187,6 +187,9 @@ export class DefaultRouter implements Router { relativeUrl(from: Reflection, to: Reflection): string { let slashes = 0; + while (!this.hasOwnDocument(from)) { + from = from.parent!; + } const fromUrl = this.getFullUrl(from); const toUrl = this.getFullUrl(to); let equal = true; diff --git a/src/test/output/router.test.ts b/src/test/output/router.test.ts index 6882834da..2bd17ecf9 100644 --- a/src/test/output/router.test.ts +++ b/src/test/output/router.test.ts @@ -112,6 +112,7 @@ describe("DefaultRouter", () => { const Foo = query(project, "Foo"); const codeGen = query(project, "Foo.codeGeneration"); + const iterator = query(project, "Foo.iterator"); const abc = query(project, "abc"); const Obj = query(project, "Obj"); const ObjArray = query(project, "ObjArray"); @@ -125,6 +126,7 @@ describe("DefaultRouter", () => { equal(router.relativeUrl(Obj, ObjArray), "ObjArray.html"); equal(router.relativeUrl(Foo, codeGen), "#codegeneration"); + equal(router.relativeUrl(iterator, codeGen), "#codegeneration"); }); it("Can get a URL to an asset relative to the base", () => {