From 150ab4ace77e8609bd32de37c280a68609d54cfb Mon Sep 17 00:00:00 2001 From: kevin <5299031+kevin9327@users.noreply.github.com> Date: Fri, 30 Oct 2026 21:33:18 +0900 Subject: [PATCH] [babel-plugin] Keep the unit of an uppercase zero time, angle or fr value --- .../transform-value-normalization-test.js | 34 +++++++++++++++++++ .../utils/normalizers/zero-dimensions.js | 11 +++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/packages/@stylexjs/babel-plugin/__tests__/transform-value-normalization-test.js b/packages/@stylexjs/babel-plugin/__tests__/transform-value-normalization-test.js index 9ab0eb1d3..9f957a6e8 100644 --- a/packages/@stylexjs/babel-plugin/__tests__/transform-value-normalization-test.js +++ b/packages/@stylexjs/babel-plugin/__tests__/transform-value-normalization-test.js @@ -191,6 +191,40 @@ describe('@stylexjs/babel-plugin', () => { `); }); + test('0 dimensions keep their unit category whatever its case', () => { + expect( + transform(` + import stylex from 'stylex'; + const styles = stylex.create({ + x: { transitionDuration: '0MS' }, + y: { animationDelay: '0S' }, + z: { transform: '0DEG' }, + w: { gridTemplateColumns: '0FR 1fr' } + }); + `), + ).toMatchInlineSnapshot(` + "import _inject from "@stylexjs/stylex/lib/stylex-inject"; + var _inject2 = _inject; + import stylex from 'stylex'; + _inject2({ + ltr: ".x1mq3mr6{transition-duration:0s}", + priority: 3000 + }); + _inject2({ + ltr: ".x1uzojwf{animation-delay:0s}", + priority: 3000 + }); + _inject2({ + ltr: ".x1jpfit1{transform:0deg}", + priority: 3000 + }); + _inject2({ + ltr: ".xkxvfks{grid-template-columns:0fr 1fr}", + priority: 3000 + });" + `); + }); + test('calc() preserves spaces around "+" and "-"', () => { expect( transform(` diff --git a/packages/@stylexjs/babel-plugin/src/shared/utils/normalizers/zero-dimensions.js b/packages/@stylexjs/babel-plugin/src/shared/utils/normalizers/zero-dimensions.js index 639c7ad5d..ab45a383a 100644 --- a/packages/@stylexjs/babel-plugin/src/shared/utils/normalizers/zero-dimensions.js +++ b/packages/@stylexjs/babel-plugin/src/shared/utils/normalizers/zero-dimensions.js @@ -48,13 +48,16 @@ export default function normalizeZeroDimensions( if (!dimension || dimension.number !== '0') { return; } - if (angles.indexOf(dimension.unit) !== -1) { + // CSS units are ASCII case-insensitive: `0MS` is a time and `0FR` a flex + // value, and dropping their unit would change what the value means. + const unit = dimension.unit.toLowerCase(); + if (angles.indexOf(unit) !== -1) { node.value = '0deg'; - } else if (timings.indexOf(dimension.unit) !== -1) { + } else if (timings.indexOf(unit) !== -1) { node.value = '0s'; - } else if (dimension.unit === fraction) { + } else if (unit === fraction) { node.value = '0fr'; - } else if (dimension.unit === percentage) { + } else if (unit === percentage) { node.value = '0%'; } else if (!endFunction) { node.value = '0';