From acaae6356dcb9aa87e9d566de50e3fbf3d3befb2 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 15 Feb 2024 12:16:22 +0100 Subject: [PATCH] Fix crash running `yarn flags --sort flag` --- scripts/flags/flags.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/flags/flags.js b/scripts/flags/flags.js index 8d1c903e14282..2b4fced638ff6 100644 --- a/scripts/flags/flags.js +++ b/scripts/flags/flags.js @@ -318,11 +318,15 @@ for (const flag of allFlagsUniqueFlags) { let sorted = table; if (isDiff || argv.sort) { const sortChannel = argToHeader(isDiff ? argv.diff[0] : argv.sort); - sorted = Object.fromEntries( - Object.entries(table).sort(([, rowA], [, rowB]) => - rowB[sortChannel].toString().localeCompare(rowA[sortChannel]) - ) - ); + const sortBy = + sortChannel === 'flag' + ? ([flagA], [flagB]) => { + return flagA.localeCompare(flagB); + } + : ([, rowA], [, rowB]) => { + return rowB[sortChannel].toString().localeCompare(rowA[sortChannel]); + }; + sorted = Object.fromEntries(Object.entries(table).sort(sortBy)); } if (argv.csv) {