Skip to content

Commit 20f857f

Browse files
Trottcodebytere
authored andcommitted
tools: update JSON header parsing for backticks
Methods, events, and so on in headers in our documentation may (and should) be set off with backticks in the raw markdown. When that happens, the headers is misinterpreted by tools/json.js as not being a method or event. Update the JSON tool generator to accommodate backticks in this situation and add a test for this situation. Fixes: #31290 PR-URL: #31294 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 597431b commit 20f857f

File tree

3 files changed

+92
-7
lines changed

3 files changed

+92
-7
lines changed

‎test/doctool/test-doctool-json.js‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,74 @@ const testData = [
157157
}
158158
]
159159
}
160+
},
161+
{
162+
file: fixtures.path('doc_with_backticks_in_headings.md'),
163+
json: {
164+
type: 'module',
165+
source: 'foo',
166+
modules: [
167+
{
168+
textRaw: 'Fhqwhgads',
169+
name: 'fhqwhgads',
170+
properties: [
171+
{
172+
name: 'fullName',
173+
textRaw: '`Fqhqwhgads.fullName`'
174+
}
175+
],
176+
classMethods: [
177+
{
178+
name: 'again',
179+
signatures: [
180+
{
181+
params: []
182+
}
183+
],
184+
textRaw: 'Class Method: `Fhqwhgads.again()`',
185+
type: 'classMethod'
186+
}
187+
],
188+
classes: [
189+
{
190+
textRaw: 'Class: `ComeOn`',
191+
type: 'class',
192+
name: 'ComeOn'
193+
}
194+
],
195+
ctors: [
196+
{
197+
name: 'Fhqwhgads',
198+
signatures: [
199+
{
200+
params: []
201+
}
202+
],
203+
textRaw: 'Constructor: `new Fhqwhgads()`',
204+
type: 'ctor'
205+
}
206+
],
207+
methods: [
208+
{
209+
textRaw: '`everybody.to(limit)`',
210+
type: 'method',
211+
name: 'to',
212+
signatures: [{params: []}]
213+
}
214+
],
215+
events: [
216+
{
217+
textRaw: "Event: `'FHQWHfest'`",
218+
type: 'event',
219+
name: 'FHQWHfest',
220+
params: []
221+
}
222+
],
223+
type: 'module',
224+
displayName: 'Fhqwhgads'
225+
}
226+
]
227+
}
160228
}
161229
];
162230

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Fhqwhgads
2+
3+
## Class: `ComeOn`
4+
5+
## `everybody.to(limit)`
6+
7+
## Event: `'FHQWHfest'`
8+
9+
## Constructor: `new Fhqwhgads()`
10+
11+
## Class Method: `Fhqwhgads.again()`
12+
13+
## `Fqhqwhgads.fullName`

‎tools/doc/json.js‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,15 @@ const r = String.raw;
435435

436436
consteventPrefix='^Event: +';
437437
constclassPrefix='^[Cc]lass: +';
438-
constctorPrefix='^(?:[Cc]onstructor: +)?new +';
438+
constctorPrefix='^(?:[Cc]onstructor: +)?`?new +';
439439
constclassMethodPrefix='^Class Method: +';
440440
constmaybeClassPropertyPrefix='(?:Class Property: +)?';
441441

442442
constmaybeQuote='[\'"]?';
443443
constnotQuotes='[^\'"]+';
444444

445+
constmaybeBacktick='`?';
446+
445447
// To include constructs like `readable\[Symbol.asyncIterator\]()`
446448
// or `readable.\_read(size)` (with Markdown escapes).
447449
constsimpleId=r`(?:(?:\\?_)+|\b)\w+\b`;
@@ -458,25 +460,27 @@ const noCallOrProp = '(?![.[(])'
458460

459461
constmaybeExtends=`(?: +extends +${maybeAncestors}${classId})?`;
460462

463+
/* eslint-disable max-len */
461464
constheadingExpressions=[
462465
{type: 'event',re: RegExp(
463-
`${eventPrefix}${maybeQuote}(${notQuotes})${maybeQuote}$`,'i')},
466+
`${eventPrefix}${maybeBacktick}${maybeQuote}(${notQuotes})${maybeQuote}${maybeBacktick}$`,'i')},
464467

465468
{type: 'class',re: RegExp(
466-
`${classPrefix}(${maybeAncestors}${classId})${maybeExtends}$`,'')},
469+
`${classPrefix}${maybeBacktick}(${maybeAncestors}${classId})${maybeExtends}${maybeBacktick}$`,'')},
467470

468471
{type: 'ctor',re: RegExp(
469-
`${ctorPrefix}(${maybeAncestors}${classId})${callWithParams}$`,'')},
472+
`${ctorPrefix}(${maybeAncestors}${classId})${callWithParams}${maybeBacktick}$`,'')},
470473

471474
{type: 'classMethod',re: RegExp(
472-
`${classMethodPrefix}${maybeAncestors}(${id})${callWithParams}$`,'i')},
475+
`${classMethodPrefix}${maybeBacktick}${maybeAncestors}(${id})${callWithParams}${maybeBacktick}$`,'i')},
473476

474477
{type: 'method',re: RegExp(
475-
`^${maybeAncestors}(${id})${callWithParams}$`,'i')},
478+
`^${maybeBacktick}${maybeAncestors}(${id})${callWithParams}${maybeBacktick}$`,'i')},
476479

477480
{type: 'property',re: RegExp(
478-
`^${maybeClassPropertyPrefix}${ancestors}(${id})${noCallOrProp}$`,'i')},
481+
`^${maybeClassPropertyPrefix}${maybeBacktick}${ancestors}(${id})${maybeBacktick}${noCallOrProp}$`,'i')},
479482
];
483+
/* eslint-enable max-len */
480484

481485
functionnewSection(header,file){
482486
consttext=textJoin(header.children,file);

0 commit comments

Comments
(0)