Skip to content

Commit 45c6e5e

Browse files
feat: add support for raw generics in method strings
1 parent 8672044 commit 45c6e5e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/ParsedDocumentation.ts

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export declare type DocumentationBlock = {
5757
urlFragment?: string;
5858
};
5959
export declare type MethodDocumentationBlock = DocumentationBlock & {
60+
rawGenerics?: string;
6061
signature: string;
6162
parameters: MethodParameterDocumentation[];
6263
returns: TypeInformation | null;

src/block-parsers.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,25 @@ export const _headingToMethodBlock = (
8181
): MethodDocumentationBlock | null => {
8282
if (!heading) return null;
8383

84+
const methodStringWithGenericRegexp = /`(?:.+\.)?(.+?)(<.+>)(\(.*?\))`((?: _[^_]+?_)*)/g;
8485
const methodStringRegexp = /`(?:.+\.)?(.+?)(\(.*?\))`((?: _[^_]+?_)*)/g;
86+
const methodStringWithGenericMatch = methodStringWithGenericRegexp.exec(heading.heading);
8587
const methodStringMatch = methodStringRegexp.exec(heading.heading)!;
8688
methodStringRegexp.lastIndex = -1;
89+
methodStringWithGenericRegexp.lastIndex = -1;
8790
expect(heading.heading).to.match(
8891
methodStringRegexp,
8992
'each method should have a code blocked method name',
9093
);
91-
const [, methodString, methodSignature, headingTags] = methodStringMatch;
94+
let methodString: string;
95+
let methodGenerics = '';
96+
let methodSignature: string;
97+
let headingTags: string;
98+
if (methodStringWithGenericMatch) {
99+
[, methodString, methodGenerics, methodSignature, headingTags] = methodStringWithGenericMatch;
100+
} else {
101+
[, methodString, methodSignature, headingTags] = methodStringMatch;
102+
}
92103

93104
let parameters: MethodDocumentationBlock['parameters'] = [];
94105
if (methodSignature !== '()') {
@@ -128,6 +139,7 @@ export const _headingToMethodBlock = (
128139
name: methodString,
129140
signature: methodSignature,
130141
description: parsedDescription,
142+
rawGenerics: methodGenerics || undefined,
131143
parameters,
132144
returns: parsedReturnType,
133145
additionalTags: parseHeadingTags(headingTags),

0 commit comments

Comments
 (0)