Skip to content

Fix double-negation of negative numbers in value parsers#1746

Open
durvesh1992 wants to merge 1 commit into
facebook:mainfrom
durvesh1992:fix/parser-negative-number-double-negation
Open

Fix double-negation of negative numbers in value parsers#1746
durvesh1992 wants to merge 1 commit into
facebook:mainfrom
durvesh1992:fix/parser-negative-number-double-negation

Conversation

@durvesh1992

Copy link
Copy Markdown

Summary

With @csstools/css-tokenizer 3.x, a Number/Percentage token's value field already includes the sign — e.g. -3 tokenizes to { value: -3, signCharacter: '-' }. Two parsers in @stylexjs/style-value-parser additionally negated the value when signCharacter === '-', double-negating negative inputs:

  • numberOrPercentage (common-types.js) — used by Scale, Scale3d, ScaleAxis. So scale(-1) parsed to Scale(1), turning a mirror/flip into a positive scale.
  • AlphaValue.parser (alpha-value.js) — negative alpha values lost their sign.

The fix reads v[4].value directly, matching sibling parsers (e.g. Matrix in transform-function.js) that already use the signed token value as-is. Positive and +-signed values are unaffected.

(Note: flex.js also reads signCharacter, but there it's a legitimate guard against negative fr values, so it's left unchanged.)

Test plan

Added regression tests for negative scale and negative alpha (both fail before, pass after):

yarn --cwd packages/style-value-parser jest
# Tests: 325 passed
  • Before: scale(-1)Scale { sx: 1 }; AlphaValue.parse('-0.5')0.5.
  • After: signs preserved.

With @csstools/css-tokenizer 3.x, a Number/Percentage token's `value`
already includes the sign (e.g. '-3' tokenizes to {value: -3,
signCharacter: '-'}). numberOrPercentage (common-types.js) and
AlphaValue.parser (alpha-value.js) additionally negated the value when
signCharacter was '-', so negatives were flipped to positive:
scale(-1) parsed to Scale(1), and negative alpha values lost their sign.

Use the token value directly, matching sibling parsers like Matrix that
already read v[4].value raw. Adds regression tests for negative scale
and negative alpha (both fail before, pass after).
@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
stylex Skipped Skipped Jun 27, 2026 9:48pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant