Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2020-01-10 17:03:25 +0300
committerRich Trott <rtrott@gmail.com>2020-01-12 18:10:33 +0300
commitbe46a7257b36ce5519d56e50db12f91b82d194f4 (patch)
tree30dee439bdc2999476bd41f4103bbf66353ac7ea /tools
parentf9c16b87eff60858efa0b6977fa1d253be538589 (diff)
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: https://github.com/nodejs/node/issues/31290 PR-URL: https://github.com/nodejs/node/pull/31294 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/doc/json.js18
1 files changed, 11 insertions, 7 deletions
diff --git a/tools/doc/json.js b/tools/doc/json.js
index e07486265cf..94241d9903e 100644
--- a/tools/doc/json.js
+++ b/tools/doc/json.js
@@ -435,13 +435,15 @@ const r = String.raw;
const eventPrefix = '^Event: +';
const classPrefix = '^[Cc]lass: +';
-const ctorPrefix = '^(?:[Cc]onstructor: +)?new +';
+const ctorPrefix = '^(?:[Cc]onstructor: +)?`?new +';
const classMethodPrefix = '^Class Method: +';
const maybeClassPropertyPrefix = '(?:Class Property: +)?';
const maybeQuote = '[\'"]?';
const notQuotes = '[^\'"]+';
+const maybeBacktick = '`?';
+
// To include constructs like `readable\[Symbol.asyncIterator\]()`
// or `readable.\_read(size)` (with Markdown escapes).
const simpleId = r`(?:(?:\\?_)+|\b)\w+\b`;
@@ -458,25 +460,27 @@ const noCallOrProp = '(?![.[(])';
const maybeExtends = `(?: +extends +${maybeAncestors}${classId})?`;
+/* eslint-disable max-len */
const headingExpressions = [
{ type: 'event', re: RegExp(
- `${eventPrefix}${maybeQuote}(${notQuotes})${maybeQuote}$`, 'i') },
+ `${eventPrefix}${maybeBacktick}${maybeQuote}(${notQuotes})${maybeQuote}${maybeBacktick}$`, 'i') },
{ type: 'class', re: RegExp(
- `${classPrefix}(${maybeAncestors}${classId})${maybeExtends}$`, '') },
+ `${classPrefix}${maybeBacktick}(${maybeAncestors}${classId})${maybeExtends}${maybeBacktick}$`, '') },
{ type: 'ctor', re: RegExp(
- `${ctorPrefix}(${maybeAncestors}${classId})${callWithParams}$`, '') },
+ `${ctorPrefix}(${maybeAncestors}${classId})${callWithParams}${maybeBacktick}$`, '') },
{ type: 'classMethod', re: RegExp(
- `${classMethodPrefix}${maybeAncestors}(${id})${callWithParams}$`, 'i') },
+ `${classMethodPrefix}${maybeBacktick}${maybeAncestors}(${id})${callWithParams}${maybeBacktick}$`, 'i') },
{ type: 'method', re: RegExp(
- `^${maybeAncestors}(${id})${callWithParams}$`, 'i') },
+ `^${maybeBacktick}${maybeAncestors}(${id})${callWithParams}${maybeBacktick}$`, 'i') },
{ type: 'property', re: RegExp(
- `^${maybeClassPropertyPrefix}${ancestors}(${id})${noCallOrProp}$`, 'i') },
+ `^${maybeClassPropertyPrefix}${maybeBacktick}${ancestors}(${id})${maybeBacktick}${noCallOrProp}$`, 'i') },
];
+/* eslint-enable max-len */
function newSection(header, file) {
const text = textJoin(header.children, file);