From b62cec8b02bfa2a29e36742d43b309ec7c98d4a9 Mon Sep 17 00:00:00 2001 From: Roman Reiss Date: Tue, 14 Feb 2017 21:38:19 +0100 Subject: [PATCH] doc: linkify type[] syntax, support lowercase for primitives PR-URL: https://github.com/nodejs/node/pull/11167 Backport-PR-URL: https://github.com/nodejs/node/pull/13054 Reviewed-By: Timothy Gu Reviewed-By: James M Snell Reviewed-By: Joyee Cheung --- tools/doc/type-parser.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tools/doc/type-parser.js b/tools/doc/type-parser.js index 38451b0e16b358..99ce2dfe7beebc 100644 --- a/tools/doc/type-parser.js +++ b/tools/doc/type-parser.js @@ -5,12 +5,12 @@ const jsDocUrl = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/' + const jsPrimitiveUrl = 'https://developer.mozilla.org/en-US/docs/Web/' + 'JavaScript/Data_structures'; const jsPrimitives = { - 'Integer': 'Number', // this is for extending - 'Number': 'Number', - 'String': 'String', - 'Boolean': 'Boolean', - 'Null': 'Null', - 'Symbol': 'Symbol' + 'integer': 'Number', // this is for extending + 'number': 'Number', + 'string': 'String', + 'boolean': 'Boolean', + 'null': 'Null', + 'symbol': 'Symbol' }; const jsGlobalTypes = [ 'Error', 'Object', 'Function', 'Array', 'TypedArray', 'Uint8Array', @@ -49,7 +49,16 @@ module.exports = { typeText = typeText.trim(); if (typeText) { let typeUrl = null; - const primitive = jsPrimitives[typeText]; + + // To support type[], 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); + } + + const primitive = jsPrimitives[typeText.toLowerCase()]; + if (primitive !== undefined) { typeUrl = `${jsPrimitiveUrl}#${primitive}_type`; } else if (jsGlobalTypes.indexOf(typeText) !== -1) { @@ -60,9 +69,9 @@ module.exports = { if (typeUrl) { typeLinks.push('<' + - typeText + '>'); + typeTextFull + '>'); } else { - typeLinks.push('<' + typeText + '>'); + typeLinks.push('<' + typeTextFull + '>'); } } });