Skip to content

Commit

Permalink
doc: support multidimensional arrays in type link
Browse files Browse the repository at this point in the history
Currently, we have at least one multidimensional array
in type signature: see `records` parameter in
https://nodejs.org/api/dns.html#dns_dns_resolvetxt_hostname_callback

Our type parser does not linkify these signatures properly.
This PR tries to fix this.

PR-URL: #16207
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
  • Loading branch information
vsemozhetbyt authored and MylesBorins committed Nov 16, 2017
1 parent 0cc6bc9 commit dfac7eb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tools/doc/type-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const typeMap = {
'http.ServerResponse': 'http.html#http_class_http_serverresponse',
};

const arrayPart = /(?:\[])+$/;

module.exports = {
toLink: function(typeInput) {
const typeLinks = [];
Expand All @@ -51,12 +53,10 @@ module.exports = {
if (typeText) {
let typeUrl = null;

// To support type[], we store the full string and use
// the bracket-less version to lookup the type URL
// To support type[], type[][] etc., we store the full string
// and use the bracket-less version to lookup the type URL
const typeTextFull = typeText;
if (/\[]$/.test(typeText)) {
typeText = typeText.slice(0, -2);
}
typeText = typeText.replace(arrayPart, '');

const primitive = jsPrimitives[typeText.toLowerCase()];

Expand Down

0 comments on commit dfac7eb

Please sign in to comment.