Skip to content

Commit 627dec7

Browse files
committed
Context.withScope is now used consistently
1 parent 4113ce1 commit 627dec7

File tree

7 files changed

+13
-36
lines changed

7 files changed

+13
-36
lines changed

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export {
6363
StructureDirRouter,
6464
StructureRouter,
6565
Theme,
66-
UrlMapping,
6766
} from "./lib/output/index.js";
6867
export type {
6968
Icons,

src/lib/converter/context.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ export class Context {
368368
}
369369

370370
public withScope(scope: Reflection): Context {
371-
// TODO: This will be important for #2862
372-
// assert(scope.parent === this.scope, "Incorrect context used for withScope");
371+
assert(scope.parent === this.scope || scope === this.scope, "Incorrect context used for withScope");
373372

374373
const context = new Context(
375374
this.converter,

src/lib/converter/factories/index-signature.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function convertIndexSignatures(context: Context, type: ts.Type) {
5151
ReflectionKind.IndexSignature,
5252
context.scope,
5353
);
54+
const ic = context.withScope(index);
5455
if (indexInfo.isReadonly) {
5556
index.setFlag(ReflectionFlag.Readonly);
5657
}
@@ -72,11 +73,11 @@ export function convertIndexSignatures(context: Context, type: ts.Type) {
7273
),
7374
];
7475
index.parameters[0].type = context.converter.convertType(
75-
context.withScope(index.parameters[0]),
76+
ic.withScope(index.parameters[0]),
7677
indexInfo.keyType,
7778
);
7879
index.type = context.converter.convertType(
79-
context.withScope(index),
80+
ic,
8081
indexInfo.type,
8182
);
8283

src/lib/converter/jsdoc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ function convertJsDocSignature(context: Context, node: ts.JSDocSignature) {
119119
ReflectionKind.TypeLiteral,
120120
context.scope,
121121
);
122+
const rc = context.withScope(reflection);
122123
context.registerReflection(reflection, symbol);
123124
context.converter.trigger(
124125
ConverterEvents.CREATE_DECLARATION,
@@ -136,7 +137,7 @@ function convertJsDocSignature(context: Context, node: ts.JSDocSignature) {
136137
createSymbolId(symbol, node),
137138
);
138139
context.registerReflection(signature, void 0);
139-
const signatureCtx = context.withScope(signature);
140+
const signatureCtx = rc.withScope(signature);
140141

141142
reflection.signatures = [signature];
142143
signature.type = context.converter.convertType(

src/lib/output/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
export { IndexEvent, MarkdownEvent, PageEvent, type PageHeading, RendererEvent } from "./events.js";
2-
export { UrlMapping } from "./models/UrlMapping.js";
3-
export type { RenderTemplate } from "./models/UrlMapping.js";
42
export { Renderer, type RendererEvents } from "./renderer.js";
53
export type { RendererHooks } from "./renderer.js";
64
export { Theme } from "./theme.js";
7-
export { DefaultTheme, type NavigationElement } from "./themes/default/DefaultTheme.js";
5+
export { DefaultTheme, type NavigationElement, type RenderTemplate } from "./themes/default/DefaultTheme.js";
86
export { DefaultThemeRenderContext } from "./themes/default/DefaultThemeRenderContext.js";
97
export type { Icons } from "./themes/default/partials/icon.js";
108
export { Slugger } from "./themes/default/Slugger.js";

src/lib/output/models/UrlMapping.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/lib/output/themes/default/DefaultTheme.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
ReflectionGroup,
1212
ReflectionKind,
1313
} from "../../../models/index.js";
14-
import { type RenderTemplate } from "../../models/UrlMapping.js";
1514
import type { PageEvent } from "../../events.js";
1615
import type { MarkedPlugin } from "../../plugins/index.js";
1716
import { DefaultThemeRenderContext } from "./DefaultThemeRenderContext.js";
@@ -29,6 +28,12 @@ export interface NavigationElement {
2928
children?: NavigationElement[];
3029
}
3130

31+
/**
32+
* @param data the reflection to render
33+
* @returns either a string to be written to the file, or an element to be serialized and then written.
34+
*/
35+
export type RenderTemplate<T> = (data: T) => JSX.Element | string;
36+
3237
export class DefaultTheme extends Theme {
3338
// Note: This will always contain lowercased names to avoid issues with
3439
// case-insensitive file systems.

0 commit comments

Comments
 (0)