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..104f706e4 100644 --- a/packages/@stylexjs/babel-plugin/__tests__/transform-value-normalization-test.js +++ b/packages/@stylexjs/babel-plugin/__tests__/transform-value-normalization-test.js @@ -95,6 +95,16 @@ describe('@stylexjs/babel-plugin', () => { `); }); + test('preserves zero units inside a non-first function', () => { + const code = transform(` + import stylex from 'stylex'; + const styles = stylex.create({ x: { width: 'max(1px, 2px) calc(0px + 1%)' } }); + `); + // calc(0 + 1%) is invalid CSS — a unitless 0 cannot be added to a %. + expect(code).toContain('calc(0px + 1%)'); + expect(code).not.toContain('calc(0 + 1%)'); + }); + test('0 timings are all "0s"', () => { 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 4d355f2d8..2d6d84c1b 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 @@ -32,8 +32,8 @@ export default function normalizeZeroDimensions( let endFunction = 0; ast.walk((node) => { - if (node.type === 'function' && !endFunction) { - endFunction = node.sourceEndIndex ?? 0; + if (node.type === 'function') { + endFunction = Math.max(endFunction, node.sourceEndIndex ?? 0); } if (endFunction > 0 && node.sourceIndex > endFunction) { endFunction = 0;