Skip to content

Commit a108643

Browse files
avivkellerGerrit0
andauthored
feat(router): move anchor creation to seperate function (#3092)
* feat(router): move anchor creation to seperate function * fixup! Modifier * Restore protected visibility fully --------- Co-authored-by: Gerrit Birkeland <gerrit@gerritbirkeland.com>
1 parent d743a1c commit a108643

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

src/lib/output/router.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,27 @@ export abstract class BaseRouter implements Router {
356356
}
357357
}
358358

359+
protected createAnchor(
360+
target: Reflection,
361+
pageTarget: RouterTarget,
362+
): string {
363+
const parts = [target.name];
364+
while (target.parent && target.parent !== pageTarget) {
365+
target = target.parent;
366+
// Avoid duplicate names for signatures and useless __type in anchors
367+
if (
368+
!target.kindOf(
369+
ReflectionKind.TypeLiteral |
370+
ReflectionKind.FunctionOrMethod,
371+
)
372+
) {
373+
parts.unshift(target.name);
374+
}
375+
}
376+
377+
return this.getSlugger(pageTarget).slug(parts.join("."));
378+
}
379+
359380
protected buildAnchors(
360381
target: RouterTarget,
361382
pageTarget: RouterTarget,
@@ -387,24 +408,7 @@ export abstract class BaseRouter implements Router {
387408
}
388409

389410
if (!target.kindOf(ReflectionKind.TypeLiteral)) {
390-
let refl: Reflection | undefined = target;
391-
const parts = [refl.name];
392-
while (refl.parent && refl.parent !== pageTarget) {
393-
refl = refl.parent;
394-
// Avoid duplicate names for signatures and useless __type in anchors
395-
if (
396-
!refl.kindOf(
397-
ReflectionKind.TypeLiteral |
398-
ReflectionKind.FunctionOrMethod,
399-
)
400-
) {
401-
parts.unshift(refl.name);
402-
}
403-
}
404-
405-
const anchor = this.getSlugger(pageTarget).slug(
406-
parts.join("."),
407-
);
411+
const anchor = this.createAnchor(target, pageTarget);
408412

409413
this.fullUrls.set(
410414
target,

0 commit comments

Comments
 (0)