doc: support multidimensional arrays in type link

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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Vse Mozhet Byt 2017-10-15 01:40:17 +03:00 committed by James M Snell
parent 70896c7e3b
commit 89425817d0

View File

@ -58,6 +58,8 @@ const typeMap = {
'URLSearchParams': 'url.html#url_class_urlsearchparams'
};
const arrayPart = /(?:\[])+$/;
module.exports = {
toLink: function(typeInput) {
const typeLinks = [];
@ -69,12 +71,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()];