From ba62b0e48ab2f335067d419a61b2b76a28d7198d Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 15 Oct 2017 01:40:17 +0300 Subject: [PATCH] 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 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto --- tools/doc/type-parser.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/doc/type-parser.js b/tools/doc/type-parser.js index 3f1ea9597c4fbe..c2bca80641152e 100644 --- a/tools/doc/type-parser.js +++ b/tools/doc/type-parser.js @@ -40,6 +40,8 @@ const typeMap = { 'http.ServerResponse': 'http.html#http_class_http_serverresponse', }; +const arrayPart = /(?:\[])+$/; + module.exports = { toLink: function(typeInput) { const typeLinks = []; @@ -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()];