From 13682a88be9933369ba8b0725bc5b4a034464dc9 Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 17 Mar 2026 18:47:59 +0000 Subject: [PATCH] fix: Prevent reordering of `white-space` and `text-wrap` - `white-space` was missing as a shorthand, I added it to the list and included its shorthands from MDN. - the `withOverridesComparator` was not checking for this specific case where neither shorthand matched. --- src/core/main.mjs | 11 +++++++++++ src/core/main.test.mjs | 6 ++++++ src/core/shorthand-data.mjs | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/src/core/main.mjs b/src/core/main.mjs index a0eb71a..661aef9 100644 --- a/src/core/main.mjs +++ b/src/core/main.mjs @@ -123,6 +123,17 @@ function withOverridesComparator (shorthandData) { if (shorthandData[a] && shorthandData[a].includes(b)) return 0; if (shorthandData[b] && shorthandData[b].includes(a)) return 0; + // This is necessary when two shorthands have matching longhands + // without either shorthand being a longhand of the other. + // e.g. `text-wrap` and `white-space` both control `text-wrap-mode`. + if ( + shorthandData[a] && + shorthandData[b] && + shorthandData[a].some(prop => shorthandData[b].includes(prop)) + ) { + return 0; + } + return comparator(a, b); }; }; diff --git a/src/core/main.test.mjs b/src/core/main.test.mjs index 0a8e153..d482c20 100644 --- a/src/core/main.test.mjs +++ b/src/core/main.test.mjs @@ -244,6 +244,12 @@ const keepOverridesTests = [ expected: 'a{border-radius: 5px;border-end-end-radius: 0;border-end-start-radius: 0;}', options: { keepOverrides: true }, }, + { + message: 'Keep text-wrap and white-space in authored order.', + fixture: 'a{white-space: pre;text-wrap: wrap;}', + expected: 'a{white-space: pre;text-wrap: wrap;}', + options: { keepOverrides: true }, + }, ]; testCssFixtures('Should order declarations.', sortOrderTests); diff --git a/src/core/shorthand-data.mjs b/src/core/shorthand-data.mjs index 0295cc9..0d69461 100644 --- a/src/core/shorthand-data.mjs +++ b/src/core/shorthand-data.mjs @@ -470,6 +470,10 @@ export const shorthandData = { 'text-wrap-mode', 'text-wrap-style', ], + 'white-space': [ + 'white-space-collapse', + 'text-wrap-mode', + ], 'transition': [ 'transition-delay', 'transition-duration',