From d0d45b4ea1b07bf47ec40e3cfab5643f1b7bcc44 Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Mon, 21 Sep 2026 19:51:37 -0400 Subject: [PATCH] fix: preserve color migration slot pairing --- scripts/check-token-parity.mjs | 15 ++++++++------- scripts/check-token-parity.test.mjs | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/scripts/check-token-parity.mjs b/scripts/check-token-parity.mjs index 9363daecf6..cda2e4ffd1 100644 --- a/scripts/check-token-parity.mjs +++ b/scripts/check-token-parity.mjs @@ -125,7 +125,7 @@ function classSlots(line) { const result = []; const classes = [ ...line.matchAll( - /([\w:-]+)-(white|black)(?:\/(\d+(?:\.\d+)?))?\b|([\w:-]+)-\[(var\([^)]*\))\]/g, + /([\w:-]+)-(white|black)(?:\/(\d+(?:\.\d+)?))?\b|([\w:-]+)-\[((?:var|rgba?|hsla?)\([^)]*\)|#[\da-f]{3,8})\]/g, ), ]; for (const match of classes) { @@ -135,10 +135,11 @@ function classSlots(line) { return result; } function slots(line) { - const classes = classSlots(line); - if (classes.length) return classes; - const properties = propertySlots(line); - return properties.length ? properties : [{ key: "line", value: line }]; + const properties = propertySlots(line).filter( + (slot) => !["class", "className"].includes(slot.key), + ); + const result = [...properties, ...classSlots(line)]; + return result.length ? result : [{ key: "line", value: line }]; } function matchReplacement(slot, oldSlots, values) { @@ -151,8 +152,8 @@ function matchReplacement(slot, oldSlots, values) { ); if (!candidates.length) return undefined; const expanded = canonical(expandTokens(slot.value, values)); - const exact = candidates.find((old) => canonical(old.value) === expanded); - return { before: exact ?? candidates[0], equal: Boolean(exact), names }; + const before = candidates[0]; + return { before, equal: canonical(before.value) === expanded, names }; } function compareSlot(file, line, slot, oldSlots, values, allowlist) { const match = matchReplacement(slot, oldSlots, values); diff --git a/scripts/check-token-parity.test.mjs b/scripts/check-token-parity.test.mjs index b1c7b88a0a..bf186489ae 100644 --- a/scripts/check-token-parity.test.mjs +++ b/scripts/check-token-parity.test.mjs @@ -82,3 +82,23 @@ test("duplicate additions cannot hide a second wrong replacement", () => { '--- a/packages/a.ts\n+++ b/packages/a.ts\n@@ -1,2 +1,2 @@\n-color: "#fff"\n-color: "#000"\n+color: "var(--x)"\n+color: "var(--x)"'; assert.equal(findTokenParityIssues(change, "--x: #f00;").length, 2); }); + +test("arbitrary Tailwind literals are colour migrations", () => { + assert.equal( + findTokenParityIssues(diff('className="bg-[#fff]"', 'className="bg-[var(--x)]"'), "--x: #000;") + .length, + 1, + ); +}); + +test("class utilities do not hide inline colour slots", () => { + const old = '
'; + const next = '
'; + assert.equal(findTokenParityIssues(diff(old, next), "--x: #000;").length, 1); +}); + +test("swapping opposite token values between declarations fails", () => { + const change = + "--- a/packages/a.css\n+++ b/packages/a.css\n@@ -1,2 +1,2 @@\n-.a { color: #fff; }\n-.b { color: #000; }\n+.a { color: var(--black); }\n+.b { color: var(--white); }"; + assert.equal(findTokenParityIssues(change, "--black: #000; --white: #fff;").length, 2); +});