Skip to content

Commit 1ffc643

Browse files
JeanMechemmalerba
authored andcommitted
docs(docs-infra): fix @example in class members (angular#64249)
eg: ApplicationRef PR Close angular#64249
1 parent 9f5197a commit 1ffc643

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

adev/shared-docs/pipeline/api-gen/extraction/interpolate_code_examples.mts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {DocEntry} from '@angular/compiler-cli';
9+
import {DocEntry, ClassEntry, MethodEntry} from '@angular/compiler-cli';
1010
import {basename, dirname, resolve} from 'path';
1111
import fs from 'fs';
1212

@@ -48,6 +48,27 @@ export function interpolateCodeExamples(entries: DocEntry[]): void {
4848
for (const jsdocTag of entry.jsdocTags) {
4949
jsdocTag.comment = replaceExample(jsdocTag.comment);
5050
}
51+
52+
if ('members' in entry) {
53+
const members = (entry as ClassEntry).members ?? [];
54+
for (const member of members) {
55+
member.description = replaceExample(member.description);
56+
57+
for (const jsdocTag of member.jsdocTags) {
58+
jsdocTag.comment = replaceExample(jsdocTag.comment);
59+
}
60+
61+
const method = member as MethodEntry;
62+
if (method.implementation) {
63+
for (const functionSignature of [method.implementation, ...(method.signatures ?? [])]) {
64+
functionSignature.description = replaceExample(functionSignature.description);
65+
functionSignature.jsdocTags.forEach((jsdocTag) => {
66+
jsdocTag.comment = replaceExample(jsdocTag.comment);
67+
});
68+
}
69+
}
70+
}
71+
}
5172
}
5273
}
5374

adev/shared-docs/pipeline/api-gen/extraction/test/interpolate_code_examples.spec.mts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88

99
import fs from 'fs';
1010
import {interpolateCodeExamples} from '../interpolate_code_examples.mjs';
11-
import {DocEntry} from '@angular/compiler-cli';
11+
import {
12+
ClassEntry,
13+
DocEntry,
14+
EntryType,
15+
FunctionSignatureMetadata,
16+
MemberType,
17+
MethodEntry,
18+
} from '@angular/compiler-cli';
1219
import {mockReadFileSync} from './fake-examples.mjs';
1320

1421
const tsMdBlock = (code: string) => '```angular-ts\n' + code + '\n```';
@@ -156,4 +163,51 @@ class Baz {
156163

157164
expect(getComment(entries)).toMatch(/^\`\`\`/m);
158165
});
166+
167+
it('should interpolate an example on a method', () => {
168+
const entries: ClassEntry[] = [
169+
{
170+
description: '',
171+
rawComment: '',
172+
entryType: EntryType.UndecoratedClass,
173+
name: 'Test',
174+
jsdocTags: [],
175+
isAbstract: false,
176+
generics: [],
177+
implements: [],
178+
extends: undefined,
179+
members: [
180+
{
181+
name: 'test',
182+
jsdocTags: [],
183+
description: '',
184+
memberTags: [],
185+
memberType: MemberType.Method,
186+
signatures: [],
187+
entryType: EntryType.Function,
188+
rawComment: '',
189+
implementation: {
190+
name: 'test',
191+
entryType: EntryType.Function,
192+
rawComment: '',
193+
params: [],
194+
returnType: 'void',
195+
generics: [],
196+
isNewType: false,
197+
jsdocTags: [{name: '', comment: "{@example dummy/single.ts region='foo'}"}],
198+
description: `Example: {@example dummy/single.ts region='foo'}`,
199+
} as FunctionSignatureMetadata,
200+
} as MethodEntry,
201+
],
202+
},
203+
];
204+
205+
interpolateCodeExamples(entries as DocEntry[]);
206+
207+
const method = entries[0].members![0] as MethodEntry;
208+
expect(method.implementation!.description).toContain(tsMdBlock("foo('Hello world!');"));
209+
210+
const jsdocTag = method.implementation!.jsdocTags[0];
211+
expect(jsdocTag.comment).toEqual(tsMdBlock("foo('Hello world!');"));
212+
});
159213
});

0 commit comments

Comments
 (0)