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 60a577e15..b2f08ca65 100644 --- a/packages/@stylexjs/babel-plugin/__tests__/transform-value-normalization-test.js +++ b/packages/@stylexjs/babel-plugin/__tests__/transform-value-normalization-test.js @@ -174,6 +174,15 @@ describe('@stylexjs/babel-plugin', () => { `); }); + test('strip leading zeros from negative values', () => { + const code = transform(` + import stylex from 'stylex'; + const styles = stylex.create({ x: { marginTop: '-0.5px' } }); + `); + expect(code).toContain('margin-top:-.5px'); + expect(code).not.toContain('-0.5px'); + }); + test('use double quotes in empty strings', () => { expect( transform(` diff --git a/packages/@stylexjs/babel-plugin/src/shared/utils/normalizers/leading-zero.js b/packages/@stylexjs/babel-plugin/src/shared/utils/normalizers/leading-zero.js index 2c8866a19..00b1aad3b 100644 --- a/packages/@stylexjs/babel-plugin/src/shared/utils/normalizers/leading-zero.js +++ b/packages/@stylexjs/babel-plugin/src/shared/utils/normalizers/leading-zero.js @@ -27,7 +27,7 @@ export default function normalizeLeadingZero( return; } const dimension = parser.unit(node.value); - if (value < 1 && value >= 0) { + if (Math.abs(value) < 1) { node.value = value.toString().replace('0.', '.') + (dimension ? dimension.unit : ''); }