Skip to content

Commit b2fdf08

Browse files
authored
Merge pull request #17 from marcusolsson/refactor-src
Fix failing tests
2 parents 958f8c6 + 6465f89 commit b2fdf08

File tree

14 files changed

+323
-258
lines changed

14 files changed

+323
-258
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dts-docs",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"main": "dist/index.js",
55
"license": "MIT",
66
"scripts": {

src/printer/class.ts

Lines changed: 63 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,82 @@
1+
import { Printer } from ".";
12
import { ClassDocEntry } from "../parser/types";
23
import { escapeHTML } from "./utils";
34

4-
export const printClass = (c: ClassDocEntry): string => {
5-
const res: string[] = [];
5+
export class ClassPrinter implements Printer<ClassDocEntry> {
6+
print(c: ClassDocEntry): string {
7+
const res: string[] = [];
68

7-
res.push(`# ${c.name}`);
8-
res.push("");
9-
if (c.heritage.extends && c.heritage.extends.length > 0) {
10-
res.push("Extends `" + c.heritage.extends.join("`, `") + "`");
9+
res.push(`# ${c.name}`);
1110
res.push("");
12-
}
13-
if (c.heritage.implements && c.heritage.implements.length > 0) {
14-
res.push("Implements `" + c.heritage.implements.join("`, `") + "`");
15-
res.push("");
16-
}
17-
18-
if (c.documentation) {
19-
res.push(escapeHTML(c.documentation));
20-
res.push("");
21-
}
22-
23-
if (c.constructors.length > 0) {
24-
res.push("## Constructor");
25-
res.push("");
26-
27-
res.push("```ts");
28-
29-
c.constructors.forEach((constructor) => {
30-
res.push(
31-
`constructor(${constructor.parameters
32-
.map((p) => `${p.name}: ${p.type}`)
33-
.join(", ")});`
34-
);
35-
});
36-
res.push("```");
37-
res.push("");
38-
}
11+
if (c.heritage.extends && c.heritage.extends.length > 0) {
12+
res.push("Extends `" + c.heritage.extends.join("`, `") + "`");
13+
res.push("");
14+
}
15+
if (c.heritage.implements && c.heritage.implements.length > 0) {
16+
res.push("Implements `" + c.heritage.implements.join("`, `") + "`");
17+
res.push("");
18+
}
3919

40-
if (c.properties.length > 0) {
41-
res.push(`## Properties`);
42-
res.push("");
20+
if (c.documentation) {
21+
res.push(escapeHTML(c.documentation));
22+
res.push("");
23+
}
4324

44-
c.properties.forEach((m) => {
45-
res.push("### " + m.name);
25+
if (c.constructors.length > 0) {
26+
res.push("## Constructor");
4627
res.push("");
28+
4729
res.push("```ts");
48-
res.push(m.name + ": " + m.type);
30+
31+
c.constructors.forEach((constructor) => {
32+
res.push(
33+
`constructor(${constructor.parameters
34+
.map((p) => `${p.name}: ${p.type}`)
35+
.join(", ")});`
36+
);
37+
});
4938
res.push("```");
5039
res.push("");
40+
}
41+
42+
if (c.properties.length > 0) {
43+
res.push(`## Properties`);
44+
res.push("");
5145

52-
if (m.documentation) {
53-
res.push(escapeHTML(m.documentation));
46+
c.properties.forEach((m) => {
47+
res.push("### " + m.name);
48+
res.push("");
49+
res.push("```ts");
50+
res.push(m.name + ": " + m.type);
51+
res.push("```");
5452
res.push("");
55-
}
56-
});
57-
}
5853

59-
if (c.methods.length > 0) {
60-
res.push(`## Methods`);
61-
res.push("");
54+
if (m.documentation) {
55+
res.push(escapeHTML(m.documentation));
56+
res.push("");
57+
}
58+
});
59+
}
6260

63-
c.methods.forEach((m) => {
64-
res.push("### " + m.name);
65-
res.push("");
66-
res.push("```ts");
67-
res.push(m.raw);
68-
res.push("```");
61+
if (c.methods.length > 0) {
62+
res.push(`## Methods`);
6963
res.push("");
7064

71-
if (m.documentation) {
72-
res.push(escapeHTML(m.documentation));
65+
c.methods.forEach((m) => {
66+
res.push("### " + m.name);
7367
res.push("");
74-
}
75-
});
76-
}
68+
res.push("```ts");
69+
res.push(m.raw);
70+
res.push("```");
71+
res.push("");
72+
73+
if (m.documentation) {
74+
res.push(escapeHTML(m.documentation));
75+
res.push("");
76+
}
77+
});
78+
}
7779

78-
return res.join("\n");
79-
};
80+
return res.join("\n");
81+
}
82+
}

src/printer/enum.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1+
import { Printer } from ".";
12
import { DocEntry } from "../parser/types";
23
import { escapeHTML } from "./utils";
34

4-
export const printEnum = (e: DocEntry): string => {
5-
const res: string[] = [];
5+
export class EnumPrinter implements Printer<DocEntry> {
6+
print(e: DocEntry): string {
7+
const res: string[] = [];
68

7-
res.push(`# ${e.name}`);
8-
res.push("");
9-
res.push("```ts");
10-
res.push(e.raw);
11-
res.push("```");
12-
res.push("");
13-
14-
if (e.documentation) {
15-
res.push(escapeHTML(e.documentation));
9+
res.push(`# ${e.name}`);
10+
res.push("");
11+
res.push("```ts");
12+
res.push(e.raw);
13+
res.push("```");
1614
res.push("");
17-
}
1815

19-
return res.join("\n");
20-
};
16+
if (e.documentation) {
17+
res.push(escapeHTML(e.documentation));
18+
res.push("");
19+
}
20+
21+
return res.join("\n");
22+
}
23+
}

src/printer/function.ts

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
1+
import { Printer } from ".";
12
import { FunctionDocEntry } from "../parser/types";
23
import { escapeHTML } from "./utils";
34

4-
export const printFunction = (f: FunctionDocEntry): string => {
5-
const res: string[] = [];
5+
export class FunctionPrinter implements Printer<FunctionDocEntry> {
6+
print(f: FunctionDocEntry): string {
7+
const res: string[] = [];
68

7-
res.push("# " + f.name);
8-
res.push("");
9-
res.push("```ts");
10-
res.push(f.raw);
11-
res.push("```");
12-
res.push("");
13-
14-
if (f.documentation) {
15-
res.push(escapeHTML(f.documentation));
9+
res.push("# " + f.name);
1610
res.push("");
17-
}
18-
19-
if (f.parameters.length > 0) {
20-
res.push(`## Parameters`);
11+
res.push("```ts");
12+
res.push(f.raw);
13+
res.push("```");
2114
res.push("");
22-
res.push("| Parameter | Description |");
23-
res.push("|-----------|-------------|");
2415

25-
f.parameters.forEach((p) => {
26-
res.push(
27-
"| `" +
28-
p.name +
29-
"` | " +
30-
escapeHTML(p.documentation) +
31-
(p.documentation ? " " : "") +
32-
"|"
33-
);
34-
});
35-
res.push("");
36-
}
16+
if (f.documentation) {
17+
res.push(escapeHTML(f.documentation));
18+
res.push("");
19+
}
20+
21+
if (f.parameters.length > 0) {
22+
res.push(`## Parameters`);
23+
res.push("");
24+
res.push("| Parameter | Description |");
25+
res.push("|-----------|-------------|");
3726

38-
return res.join("\n");
39-
};
27+
f.parameters.forEach((p) => {
28+
res.push(
29+
"| `" +
30+
p.name +
31+
"` | " +
32+
escapeHTML(p.documentation) +
33+
(p.documentation ? " " : "") +
34+
"|"
35+
);
36+
});
37+
res.push("");
38+
}
39+
40+
return res.join("\n");
41+
}
42+
}

0 commit comments

Comments
 (0)