Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
tools: fix doc tool behavior for version arrays
Even though the doc tool supports version arrays in theory, it fails to
sort them properly causing the tool to crash.
  • Loading branch information
tniessen committed Sep 8, 2018
commit 2223cacd5b788c475b040090ebf08e45a71ac8f2
2 changes: 1 addition & 1 deletion tools/doc/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ function extractAndParseYAML(text) {
return meta;
}

module.exports = { isYAMLBlock, extractAndParseYAML };
module.exports = { arrify, isYAMLBlock, extractAndParseYAML };
14 changes: 11 additions & 3 deletions tools/doc/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ function parseYAML(text) {
.use(htmlStringify)
.processSync(change.description).toString();

result += `<tr><td>${change.version}</td>\n` +
const version = common.arrify(change.version).join(', ');

result += `<tr><td>${version}</td>\n` +
`<td>${description}</td></tr>\n`;
});

Expand All @@ -326,10 +328,16 @@ function parseYAML(text) {
return result;
}

function minVersion(a) {
if (!Array.isArray(a))
return a;
return a.reduce((min, e) => !min || versionSort(min, e) < 0 ? e : min);
}

const numberRe = /^\d*/;
function versionSort(a, b) {
a = a.trim();
b = b.trim();
a = minVersion(a).trim();
b = minVersion(b).trim();
let i = 0; // Common prefix length.
while (i < a.length && i < b.length && a[i] === b[i]) i++;
a = a.substr(i);
Expand Down