Skip to content

Commit 535f3f3

Browse files
committed
Move depth to type.tsx, fix some bugs
Closes #1793
1 parent 96f6e3e commit 535f3f3

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
### Features
44

55
- Added support for specifying the tsconfig.json file in packages mode with `{ "typedoc": { "tsconfig": "tsconfig.lib.json" }}` in package.json, #2061.
6+
- Object types will now be pretty printed, #1793.
67
- Added support for specifying the base file url for links to source code, #2068.
78

89
### Bug Fixes
910

1011
- Private parameter properties will no longer be ignored, #2064.
1112

13+
### Thanks!
14+
15+
- @captainTorch
16+
1217
## v0.23.15 (2022-09-18)
1318

1419
### Features

src/lib/output/renderer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Reflection } from "../models";
2525
import type { JsxElement } from "../utils/jsx.elements";
2626
import type { DefaultThemeRenderContext } from "./themes/default/DefaultThemeRenderContext";
2727
import { clearSeenIconCache } from "./themes/default/partials/icon";
28+
import { validateStateIsClean } from "./themes/default/partials/type";
2829

2930
/**
3031
* Describes the hooks available to inject output in the default theme.
@@ -241,6 +242,7 @@ export class Renderer extends ChildableComponent<
241242
output.urls.forEach((mapping: UrlMapping) => {
242243
clearSeenIconCache();
243244
this.renderDocument(output.createPageEvent(mapping));
245+
validateStateIsClean(mapping.url);
244246
});
245247

246248
this.trigger(RendererEvent.END, output);

src/lib/output/themes/default/DefaultThemeRenderContext.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,13 @@ function bind<F, L extends any[], R>(fn: (f: F, ...a: L) => R, first: F) {
4646

4747
export class DefaultThemeRenderContext {
4848
options: Options;
49-
private currentDepth = 0;
5049

5150
constructor(private theme: DefaultTheme, options: Options) {
5251
this.options = options;
5352
}
5453

5554
icons = icons;
5655

57-
getCurrentDepth(): number {
58-
return this.currentDepth;
59-
}
60-
61-
incrementCurrentDepth(): void {
62-
this.currentDepth++;
63-
}
64-
65-
decrementCurrentDepth(): void {
66-
this.currentDepth--;
67-
}
68-
6956
hook = (name: keyof RendererHooks) =>
7057
this.theme.owner.hooks.emit(name, this);
7158

src/lib/output/themes/default/partials/type.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "../../../../models";
1313
import { JSX } from "../../../../utils";
1414
import { join, stringify } from "../../lib";
15+
import { ok } from "assert";
1516

1617
const EXPORTABLE: ReflectionKind =
1718
ReflectionKind.Class |
@@ -67,11 +68,16 @@ function renderUniquePath(context: DefaultThemeRenderContext, reflection: Reflec
6768
</a>
6869
));
6970
}
70-
function includeIndentation(context: DefaultThemeRenderContext): JSX.Element {
71-
return context.getCurrentDepth() > 0 ? (
72-
<span>{new Array(context.getCurrentDepth() * 4).fill("\u00A0").join("")}</span>
73-
) : (
74-
<></>
71+
72+
let indentationDepth = 0;
73+
function includeIndentation(): JSX.Element {
74+
return indentationDepth > 0 ? <span>{"\u00A0".repeat(indentationDepth * 4)}</span> : <></>;
75+
}
76+
77+
export function validateStateIsClean(page: string) {
78+
ok(
79+
indentationDepth === 0,
80+
`Rendering ${page}: Indentation depth increment/decrement not matched: ${indentationDepth}`
7581
);
7682
}
7783

@@ -287,7 +293,7 @@ const typeRenderers: {
287293
const members: JSX.Element[] = [];
288294
const children: DeclarationReflection[] = type.declaration.children || [];
289295

290-
if (children.length) context.incrementCurrentDepth();
296+
indentationDepth++;
291297

292298
for (const item of children) {
293299
if (item.getSignature && item.setSignature) {
@@ -353,6 +359,8 @@ const typeRenderers: {
353359
}
354360

355361
if (!members.length && type.declaration.signatures?.length === 1) {
362+
indentationDepth--;
363+
356364
return (
357365
<>
358366
<span class="tsd-signature-symbol">(</span>
@@ -371,27 +379,27 @@ const typeRenderers: {
371379

372380
if (members.length) {
373381
const membersWithSeparators = members.flatMap((m) => [
374-
includeIndentation(context),
382+
includeIndentation(),
375383
m,
376384
<span class="tsd-signature-symbol">; </span>,
377385
<br></br>,
378386
]);
379387
membersWithSeparators.pop();
380388

381-
context.decrementCurrentDepth();
382-
389+
indentationDepth--;
383390
return (
384391
<>
385392
<span class="tsd-signature-symbol">{"{"} </span>
386393
<br></br>
387394
{membersWithSeparators}
388395
<br></br>
389-
{includeIndentation(context)}
396+
{includeIndentation()}
390397
<span class="tsd-signature-symbol">{"}"}</span>
391398
</>
392399
);
393400
}
394401

402+
indentationDepth--;
395403
return <span class="tsd-signature-symbol">{"{}"}</span>;
396404
},
397405
rest(context, type) {

0 commit comments

Comments
 (0)