summaryrefslogtreecommitdiff
path: root/tools/doc
diff options
context:
space:
mode:
authorVse Mozhet Byt <vsemozhetbyt@gmail.com>2018-04-14 12:45:06 +0300
committerVse Mozhet Byt <vsemozhetbyt@gmail.com>2018-04-22 18:09:37 +0300
commit7fcb52c7b2236cbd7db1dc63274a2670fcd2fb9d (patch)
tree5dbbbac1ffda42ea874e7f64d7000c7fe2341b97 /tools/doc
parent647954d0a045c72fc6b22afcfd89daa72d81bab3 (diff)
downloadandroid-node-v8-7fcb52c7b2236cbd7db1dc63274a2670fcd2fb9d.tar.gz
android-node-v8-7fcb52c7b2236cbd7db1dc63274a2670fcd2fb9d.tar.bz2
android-node-v8-7fcb52c7b2236cbd7db1dc63274a2670fcd2fb9d.zip
tools: improve heading type detection in json.js
PR-URL: https://github.com/nodejs/node/pull/20074 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'tools/doc')
-rw-r--r--tools/doc/json.js55
1 files changed, 47 insertions, 8 deletions
diff --git a/tools/doc/json.js b/tools/doc/json.js
index b1a04c6938..44b67e3e28 100644
--- a/tools/doc/json.js
+++ b/tools/doc/json.js
@@ -553,15 +553,54 @@ function cloneValue(src) {
}
-// These parse out the contents of an H# tag.
+// This section parse out the contents of an H# tag.
+
+// To reduse escape slashes in RegExp string components.
+const r = String.raw;
+
+const eventPrefix = '^Event: +';
+const classPrefix = '^[Cc]lass: +';
+const ctorPrefix = '^(?:[Cc]onstructor: +)?new +';
+const classMethodPrefix = '^Class Method: +';
+const maybeClassPropertyPrefix = '(?:Class Property: +)?';
+
+const maybeQuote = '[\'"]?';
+const notQuotes = '[^\'"]+';
+
+// To include constructs like `readable\[Symbol.asyncIterator\]()`
+// or `readable.\_read(size)` (with Markdown escapes).
+const simpleId = r`(?:(?:\\?_)+|\b)\w+\b`;
+const computedId = r`\\?\[[\w\.]+\\?\]`;
+const id = `(?:${simpleId}|${computedId})`;
+const classId = r`[A-Z]\w+`;
+
+const ancestors = r`(?:${id}\.?)+`;
+const maybeAncestors = r`(?:${id}\.?)*`;
+
+const callWithParams = r`\([^)]*\)`;
+
+const noCallOrProp = '(?![.[(])';
+
+const maybeExtends = `(?: +extends +${maybeAncestors}${classId})?`;
+
const headingExpressions = [
- { type: 'event', re: /^Event(?::|\s)+['"]?([^"']+).*$/i },
- { type: 'class', re: /^Class:\s*([^ ]+).*$/i },
- { type: 'property', re: /^[^.[]+(\[[^\]]+\])\s*$/ },
- { type: 'property', re: /^[^.]+\.([^ .()]+)\s*$/ },
- { type: 'classMethod', re: /^class\s*method\s*:?[^.]+\.([^ .()]+)\([^)]*\)\s*$/i },
- { type: 'method', re: /^(?:[^.]+\.)?([^ .()]+)\([^)]*\)\s*$/ },
- { type: 'ctor', re: /^new ([A-Z][a-zA-Z]+)\([^)]*\)\s*$/ },
+ { type: 'event', re: RegExp(
+ `${eventPrefix}${maybeQuote}(${notQuotes})${maybeQuote}$`, 'i') },
+
+ { type: 'class', re: RegExp(
+ `${classPrefix}(${maybeAncestors}${classId})${maybeExtends}$`, '') },
+
+ { type: 'ctor', re: RegExp(
+ `${ctorPrefix}(${maybeAncestors}${classId})${callWithParams}$`, '') },
+
+ { type: 'classMethod', re: RegExp(
+ `${classMethodPrefix}${maybeAncestors}(${id})${callWithParams}$`, 'i') },
+
+ { type: 'method', re: RegExp(
+ `^${maybeAncestors}(${id})${callWithParams}$`, 'i') },
+
+ { type: 'property', re: RegExp(
+ `^${maybeClassPropertyPrefix}${ancestors}(${id})${noCallOrProp}$`, 'i') },
];
function newSection({ text }) {