Skip to content

Commit 1ce91fd

Browse files
committed
doc: linkify type[] syntax, support lowercase for primitives
1 parent 899a48b commit 1ce91fd

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

tools/doc/type-parser.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ const jsDocPrefix = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/';
44
const jsDocUrl = jsDocPrefix + 'Reference/Global_Objects/';
55
const jsPrimitiveUrl = jsDocPrefix + 'Data_structures';
66
const jsPrimitives = {
7-
'Integer': 'Number', // this is for extending
8-
'Number': 'Number',
9-
'String': 'String',
10-
'Boolean': 'Boolean',
11-
'Null': 'Null',
12-
'Symbol': 'Symbol'
7+
'integer': 'Number', // this is for extending
8+
'number': 'Number',
9+
'string': 'String',
10+
'boolean': 'Boolean',
11+
'null': 'Null',
12+
'symbol': 'Symbol'
1313
};
1414
const jsGlobalTypes = [
1515
'Error', 'Object', 'Function', 'Array', 'TypedArray', 'Uint8Array',
@@ -67,7 +67,16 @@ module.exports = {
6767
typeText = typeText.trim();
6868
if (typeText) {
6969
let typeUrl = null;
70-
const primitive = jsPrimitives[typeText];
70+
71+
// To support type[], we store the full string and use
72+
// the bracket-less version to lookup the type URL
73+
const typeTextFull = typeText;
74+
if (/\[]$/.test(typeText)) {
75+
typeText = typeText.slice(0, -2);
76+
}
77+
78+
const primitive = jsPrimitives[typeText.toLowerCase()];
79+
7180
if (primitive !== undefined) {
7281
typeUrl = `${jsPrimitiveUrl}#${primitive}_type`;
7382
} else if (jsGlobalTypes.indexOf(typeText) !== -1) {
@@ -78,9 +87,9 @@ module.exports = {
7887

7988
if (typeUrl) {
8089
typeLinks.push('<a href="' + typeUrl + '" class="type">&lt;' +
81-
typeText + '&gt;</a>');
90+
typeTextFull + '&gt;</a>');
8291
} else {
83-
typeLinks.push('<span class="type">&lt;' + typeText + '&gt;</span>');
92+
typeLinks.push('<span class="type">&lt;' + typeTextFull + '&gt;</span>');
8493
}
8594
}
8695
});

0 commit comments

Comments
 (0)