Skip to content

Commit 8d9530b

Browse files
committed
Ignore Class, Interface, Namespace for parser
1 parent e76fab1 commit 8d9530b

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

lib/buildtools/src/build/docs/__tests__/json.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,34 @@ describe(buildJson, () => {
115115
retType: 'number'
116116
});
117117
});
118+
119+
test('Classes, interfaces, and namespaces are ignored for JSON building', async ({ testBundle, project }) => {
120+
project.addChild(new td.DeclarationReflection(
121+
'TestClass',
122+
td.ReflectionKind.Class
123+
));
124+
project.addChild(new td.DeclarationReflection(
125+
'TestInterface',
126+
td.ReflectionKind.Interface
127+
));
128+
project.addChild(new td.DeclarationReflection(
129+
'TestNamespace',
130+
td.ReflectionKind.Namespace
131+
));
132+
133+
const result = await buildJson(testBundle, outDir, project);
134+
expectSuccess(result.severity);
135+
136+
expect(fs.writeFile).toHaveBeenCalledOnce();
137+
const { calls: [[path, data]] } = mockedWriteFile.mock;
138+
139+
expect(path).toEqual(pathlib.join(outDir, 'jsons', 'test0.json'));
140+
141+
const parsed = JSON.parse(data as string);
142+
expect(parsed).not.toHaveProperty('TestClass');
143+
expect(parsed).not.toHaveProperty('TestInterface');
144+
expect(parsed).not.toHaveProperty('TestNamespace');
145+
});
118146
});
119147

120148
describe('Test parsers', () => {

lib/buildtools/src/build/docs/json.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ function getInvalidExamples(parts: td.CommentTag[]): string[] {
6464
}
6565

6666
const typeToName = (type: td.SomeType) => type.stringify(td.TypeContext.none);
67+
const ignoredKinds = new Set<td.ReflectionKind>([
68+
td.ReflectionKind.Class,
69+
td.ReflectionKind.Interface,
70+
td.ReflectionKind.Namespace,
71+
td.ReflectionKind.TypeAlias
72+
]);
73+
6774
export const parsers: {
6875
[K in td.ReflectionKind]?: (obj: td.DeclarationReflection) => ParserResult
6976
} = {
@@ -156,8 +163,7 @@ export async function buildJson(bundle: ResolvedBundle, outDir: string, reflecti
156163
const [jsonData, warnings, errors] = reflection.children!.reduce<
157164
[Record<string, unknown>, string[], string[]]
158165
>(([res, warnings, errors], element) => {
159-
if (element.kind === td.ReflectionKind.TypeAlias) {
160-
// Ignore Type Aliases for JSON documentation
166+
if (ignoredKinds.has(element.kind)) {
161167
return [res, warnings, errors];
162168
}
163169

yarn.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17121,6 +17121,16 @@ __metadata:
1712117121
languageName: node
1712217122
linkType: hard
1712317123

17124+
"typescript@npm:^5.8.2":
17125+
version: 5.9.3
17126+
resolution: "typescript@npm:5.9.3"
17127+
bin:
17128+
tsc: bin/tsc
17129+
tsserver: bin/tsserver
17130+
checksum: 10c0/6bd7552ce39f97e711db5aa048f6f9995b53f1c52f7d8667c1abdc1700c68a76a308f579cd309ce6b53646deb4e9a1be7c813a93baaf0a28ccd536a30270e1c5
17131+
languageName: node
17132+
linkType: hard
17133+
1712417134
"typescript@npm:^6.0.2":
1712517135
version: 6.0.2
1712617136
resolution: "typescript@npm:6.0.2"
@@ -17161,6 +17171,16 @@ __metadata:
1716117171
languageName: node
1716217172
linkType: hard
1716317173

17174+
"typescript@patch:typescript@npm%3A^5.8.2#optional!builtin<compat/typescript>":
17175+
version: 5.9.3
17176+
resolution: "typescript@patch:typescript@npm%3A5.9.3#optional!builtin<compat/typescript>::version=5.9.3&hash=5786d5"
17177+
bin:
17178+
tsc: bin/tsc
17179+
tsserver: bin/tsserver
17180+
checksum: 10c0/ad09fdf7a756814dce65bc60c1657b40d44451346858eea230e10f2e95a289d9183b6e32e5c11e95acc0ccc214b4f36289dcad4bf1886b0adb84d711d336a430
17181+
languageName: node
17182+
linkType: hard
17183+
1716417184
"typescript@patch:typescript@npm%3A^6.0.2#optional!builtin<compat/typescript>":
1716517185
version: 6.0.2
1716617186
resolution: "typescript@patch:typescript@npm%3A6.0.2#optional!builtin<compat/typescript>::version=6.0.2&hash=5786d5"

0 commit comments

Comments
 (0)