Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools,doc: fix json result of grouped optional params #5977

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions tools/doc/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,30 @@ function parseSignature(text, sig) {
var params = text.match(paramExpr);
if (!params) return;
params = params[1];
// the [ is irrelevant. ] indicates optionalness.
params = params.replace(/\[/g, '');
params = params.split(/,/);
var optionalLevel = 0;
var optionalCharDict = {'[': 1, ' ': 0, ']': -1};
params.forEach(function(p, i, _) {
p = p.trim();
if (!p) return;
var param = sig.params[i];
var optional = false;
var def;
// [foo] -> optional
if (p.charAt(p.length - 1) === ']') {
optional = true;
p = p.replace(/\]/g, '');
p = p.trim();

// for grouped optional params such as someMethod(a[, b[, c]])
var pos;
for (pos = 0; pos < p.length; pos++) {
if (optionalCharDict[p[pos]] === undefined) { break; }
optionalLevel += optionalCharDict[p[pos]];
}
p = p.substring(pos);
optional = (optionalLevel > 0);
for (pos = p.length - 1; pos >= 0; pos--) {
if (optionalCharDict[p[pos]] === undefined) { break; }
optionalLevel += optionalCharDict[p[pos]];
}
p = p.substring(0, pos + 1);

var eq = p.indexOf('=');
if (eq !== -1) {
def = p.substr(eq + 1);
Expand Down