Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4c73ab4

Browse filesBrowse files
firedfoxMyles Borins
authored andcommitted
tools,doc: fix json for grouped optional params
Current tools/doc/json.js only supports one bracket style for optional params methodName(param0[,param1],param2). Add support to other styles such as methodName(param0,[param1,]param2) or methodName(param0[,param1,param2]) or methodName(param0[,param1[,param2]]). PR-URL: #5977 Fixes: #5976 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Robert Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
1 parent 3d4d577 commit 4c73ab4
Copy full SHA for 4c73ab4

File tree

Expand file treeCollapse file tree

1 file changed

+16
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-7
lines changed
Open diff view settings
Collapse file

‎tools/doc/json.js‎

Copy file name to clipboardExpand all lines: tools/doc/json.js
+16-7Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,21 +280,30 @@ function parseSignature(text, sig) {
280280
var params = text.match(paramExpr);
281281
if (!params) return;
282282
params = params[1];
283-
// the [ is irrelevant. ] indicates optionalness.
284-
params = params.replace(/\[/g, '');
285283
params = params.split(/,/);
284+
var optionalLevel = 0;
285+
var optionalCharDict = {'[': 1, ' ': 0, ']': -1};
286286
params.forEach(function(p, i, _) {
287287
p = p.trim();
288288
if (!p) return;
289289
var param = sig.params[i];
290290
var optional = false;
291291
var def;
292-
// [foo] -> optional
293-
if (p.charAt(p.length - 1) === ']') {
294-
optional = true;
295-
p = p.replace(/\]/g, '');
296-
p = p.trim();
292+
293+
// for grouped optional params such as someMethod(a[, b[, c]])
294+
var pos;
295+
for (pos = 0; pos < p.length; pos++) {
296+
if (optionalCharDict[p[pos]] === undefined) { break; }
297+
optionalLevel += optionalCharDict[p[pos]];
298+
}
299+
p = p.substring(pos);
300+
optional = (optionalLevel > 0);
301+
for (pos = p.length - 1; pos >= 0; pos--) {
302+
if (optionalCharDict[p[pos]] === undefined) { break; }
303+
optionalLevel += optionalCharDict[p[pos]];
297304
}
305+
p = p.substring(0, pos + 1);
306+
298307
var eq = p.indexOf('=');
299308
if (eq !== -1) {
300309
def = p.substr(eq + 1);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.