Skip to content

Commit

Permalink
doc: linkify type[] syntax, support lowercase for primitives
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
silverwind authored and gibfahn committed May 16, 2017
1 parent 99ebb9a commit 0a1dbcb
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions tools/doc/type-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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) {
Expand All @@ -60,9 +69,9 @@ module.exports = {

if (typeUrl) {
typeLinks.push('<a href="' + typeUrl + '" class="type">&lt;' +
typeText + '&gt;</a>');
typeTextFull + '&gt;</a>');
} else {
typeLinks.push('<span class="type">&lt;' + typeText + '&gt;</span>');
typeLinks.push('<span class="type">&lt;' + typeTextFull + '&gt;</span>');
}
}
});
Expand Down

0 comments on commit 0a1dbcb

Please sign in to comment.