Fix double-negation of negative numbers in value parsers#1746
Open
durvesh1992 wants to merge 1 commit into
Open
Fix double-negation of negative numbers in value parsers#1746durvesh1992 wants to merge 1 commit into
durvesh1992 wants to merge 1 commit into
Conversation
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).
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With
@csstools/css-tokenizer3.x, a Number/Percentage token'svaluefield already includes the sign — e.g.-3tokenizes to{ value: -3, signCharacter: '-' }. Two parsers in@stylexjs/style-value-parseradditionally negated the value whensignCharacter === '-', double-negating negative inputs:numberOrPercentage(common-types.js) — used byScale,Scale3d,ScaleAxis. Soscale(-1)parsed toScale(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].valuedirectly, matching sibling parsers (e.g.Matrixintransform-function.js) that already use the signed token value as-is. Positive and+-signed values are unaffected.(Note:
flex.jsalso readssignCharacter, but there it's a legitimate guard against negativefrvalues, so it's left unchanged.)Test plan
Added regression tests for negative
scaleand negativealpha(both fail before, pass after):scale(-1)→Scale { sx: 1 };AlphaValue.parse('-0.5')→0.5.