Skip to content

Commit b62cec8

Browse files
silverwindMylesBorins
authored andcommitted
doc: linkify type[] syntax, support lowercase for primitives
PR-URL: #11167 Backport-PR-URL: #13054 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent dd1fb98 commit b62cec8

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

tools/doc/type-parser.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ const jsDocUrl = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/' +
55
const jsPrimitiveUrl = 'https://developer.mozilla.org/en-US/docs/Web/' +
66
'JavaScript/Data_structures';
77
const jsPrimitives = {
8-
'Integer': 'Number', // this is for extending
9-
'Number': 'Number',
10-
'String': 'String',
11-
'Boolean': 'Boolean',
12-
'Null': 'Null',
13-
'Symbol': 'Symbol'
8+
'integer': 'Number', // this is for extending
9+
'number': 'Number',
10+
'string': 'String',
11+
'boolean': 'Boolean',
12+
'null': 'Null',
13+
'symbol': 'Symbol'
1414
};
1515
const jsGlobalTypes = [
1616
'Error', 'Object', 'Function', 'Array', 'TypedArray', 'Uint8Array',
@@ -49,7 +49,16 @@ module.exports = {
4949
typeText = typeText.trim();
5050
if (typeText) {
5151
let typeUrl = null;
52-
const primitive = jsPrimitives[typeText];
52+
53+
// To support type[], we store the full string and use
54+
// the bracket-less version to lookup the type URL
55+
const typeTextFull = typeText;
56+
if (/\[]$/.test(typeText)) {
57+
typeText = typeText.slice(0, -2);
58+
}
59+
60+
const primitive = jsPrimitives[typeText.toLowerCase()];
61+
5362
if (primitive !== undefined) {
5463
typeUrl = `${jsPrimitiveUrl}#${primitive}_type`;
5564
} else if (jsGlobalTypes.indexOf(typeText) !== -1) {
@@ -60,9 +69,9 @@ module.exports = {
6069

6170
if (typeUrl) {
6271
typeLinks.push('<a href="' + typeUrl + '" class="type">&lt;' +
63-
typeText + '&gt;</a>');
72+
typeTextFull + '&gt;</a>');
6473
} else {
65-
typeLinks.push('<span class="type">&lt;' + typeText + '&gt;</span>');
74+
typeLinks.push('<span class="type">&lt;' + typeTextFull + '&gt;</span>');
6675
}
6776
}
6877
});

0 commit comments

Comments
 (0)