diff --git a/build/document-extractor.js b/build/document-extractor.js index af852198f972..e290d7b5b3b6 100644 --- a/build/document-extractor.js +++ b/build/document-extractor.js @@ -441,6 +441,9 @@ function _addSingleSpecialSection($) { } } } + info.sort((a, b) => + _compareVersions(_getFirstVersion(b), _getFirstVersion(a)) + ); } } } @@ -460,6 +463,60 @@ function _addSingleSpecialSection($) { ]; } + /** + * @param {object} support - {bcd.SimpleSupportStatement} + * @returns {string} + */ + function _getFirstVersion(support) { + if (typeof support.version_added === "string") { + return support.version_added; + } else if (typeof support.version_removed === "string") { + return support.version_removed; + } else { + return "0"; + } + } + + /** + * @param {string} a + * @param {string} b + */ + function _compareVersions(a, b) { + const x = _splitVersion(a); + const y = _splitVersion(b); + + return _compareNumberArray(x, y); + } + + /** + * @param {number[]} a + * @param {number[]} b + * @return {number} + */ + function _compareNumberArray(a, b) { + while (a.length || b.length) { + const x = a.shift() || 0; + const y = b.shift() || 0; + if (x !== y) { + return x - y; + } + } + + return 0; + } + + /** + * @param {string} version + * @return {number[]} + */ + function _splitVersion(version) { + if (version.startsWith("≤")) { + version = version.slice(1); + } + + return version.split(".").map(Number); + } + function _buildSpecialSpecSection() { // Collect spec URLs from a BCD feature, a 'spec-urls' value, or both; // For a BCD feature, it can either be a string or an array of strings. diff --git a/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx b/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx index cdc11524d924..f0373f19612c 100644 --- a/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx +++ b/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx @@ -333,6 +333,8 @@ function getNotes( ) { if (support) { return asList(support) + .slice() + .reverse() .flatMap((item, i) => { const supportNotes = [ item.version_removed