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 <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent dd1fb98 commit b62cec8

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

‎tools/doc/type-parser.js‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ const jsDocUrl = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/' +
55
constjsPrimitiveUrl='https://developer.mozilla.org/en-US/docs/Web/'+
66
'JavaScript/Data_structures';
77
constjsPrimitives={
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
constjsGlobalTypes=[
1616
'Error','Object','Function','Array','TypedArray','Uint8Array',
@@ -49,7 +49,16 @@ module.exports = {
4949
typeText=typeText.trim();
5050
if(typeText){
5151
lettypeUrl=null;
52-
constprimitive=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+
consttypeTextFull=typeText;
56+
if(/\[]$/.test(typeText)){
57+
typeText=typeText.slice(0,-2);
58+
}
59+
60+
constprimitive=jsPrimitives[typeText.toLowerCase()];
61+
5362
if(primitive!==undefined){
5463
typeUrl=`${jsPrimitiveUrl}#${primitive}_type`;
5564
}elseif(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)