Skip to content

Commit 797d9a8

Browse files
Trottevanlucas
authored andcommitted
tools: refactor json.js
* Simplify regular expressions (see below) * Remove unneeded `parseYAML()` wrapper * Remove unused callback argument Regular expression simplifications include: * Changing trailing `*?$/` to `*$/` because non-greedy matching to the end of a line will not change behavior * Change regexp beginnings like `/^(?:property:?\s*)?[^.\[]+` to the equivalent `/[^.\]]+` * For regular expressions changed per the above, remove case-insensitivity if it no longer affects the regexp PR-URL: #10442 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Italo A. Casas <[email protected]>
1 parent 04d82a5 commit 797d9a8

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

tools/doc/json.js

+8-14
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function doJSON(input, filename, cb) {
102102
current.list.push(tok);
103103
current.list.level = 1;
104104
} else if (type === 'html' && common.isYAMLBlock(tok.text)) {
105-
current.meta = parseYAML(tok.text);
105+
current.meta = common.extractAndParseYAML(tok.text);
106106
} else {
107107
current.desc = current.desc || [];
108108
if (!Array.isArray(current.desc)) {
@@ -302,10 +302,6 @@ function processList(section) {
302302
delete section.list;
303303
}
304304

305-
function parseYAML(text) {
306-
return common.extractAndParseYAML(text);
307-
}
308-
309305
// textRaw = "someobject.someMethod(a[, b=100][, c])"
310306
function parseSignature(text, sig) {
311307
var params = text.match(paramExpr);
@@ -314,7 +310,7 @@ function parseSignature(text, sig) {
314310
params = params.split(/,/);
315311
var optionalLevel = 0;
316312
var optionalCharDict = {'[': 1, ' ': 0, ']': -1};
317-
params.forEach(function(p, i, _) {
313+
params.forEach(function(p, i) {
318314
p = p.trim();
319315
if (!p) return;
320316
var param = sig.params[i];
@@ -544,14 +540,12 @@ function deepCopy_(src) {
544540

545541
// these parse out the contents of an H# tag
546542
var eventExpr = /^Event(?::|\s)+['"]?([^"']+).*$/i;
547-
var classExpr = /^Class:\s*([^ ]+).*?$/i;
548-
var propExpr = /^(?:property:?\s*)?[^.]+\.([^ .()]+)\s*?$/i;
549-
var braceExpr = /^(?:property:?\s*)?[^.\[]+(\[[^\]]+\])\s*?$/i;
550-
var classMethExpr =
551-
/^class\s*method\s*:?[^.]+\.([^ .()]+)\([^)]*\)\s*?$/i;
552-
var methExpr =
553-
/^(?:method:?\s*)?(?:[^.]+\.)?([^ .()]+)\([^)]*\)\s*?$/i;
554-
var newExpr = /^new ([A-Z][a-zA-Z]+)\([^)]*\)\s*?$/;
543+
var classExpr = /^Class:\s*([^ ]+).*$/i;
544+
var propExpr = /^[^.]+\.([^ .()]+)\s*$/;
545+
var braceExpr = /^[^.[]+(\[[^\]]+\])\s*$/;
546+
var classMethExpr = /^class\s*method\s*:?[^.]+\.([^ .()]+)\([^)]*\)\s*$/i;
547+
var methExpr = /^(?:[^.]+\.)?([^ .()]+)\([^)]*\)\s*$/;
548+
var newExpr = /^new ([A-Z][a-zA-Z]+)\([^)]*\)\s*$/;
555549
var paramExpr = /\((.*)\);?$/;
556550

557551
function newSection(tok) {

0 commit comments

Comments
 (0)