Repository navigation
Conversation
`resolveValue` now resolves the argument of a `-` or `+` sign recursively,
so a sign applies to any value that resolves: a literal, a `const`, an
import, or a member of a namespace import, like `${-gap}` or
`${-theme.spacing}`. The sign converts the value to a number like JS does,
so `-'5'` is `-5`. A value that is not a number, like a class name, which
would be `NaN`, or a namespace, which would throw, does not resolve.
Warnings name a signed reference with its sign, like "-gap".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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.
Signs resolve their argument
resolveValueonly accepted a sign (-or+) on a number literal, like${-5}. It now resolves the argument recursively, like any other expression it supports. So a sign applies to any value that resolves:const, like${-gap}${-spacing}or${-theme.spacing}${-negativeOffset}whenconst negativeOffset = -5A signed value is returned as a promise only when its argument is one, so local values stay synchronous.
Conversion
Numbers are resolved as strings, so a sign converts the value with
Number(), like JS does:-'5'is-5, and+'0.50'is0.5. A number literal round-trips through its string, so${-5}and${-0.25}give the same CSS as before.A sign on a value that is not a number doesn't resolve, so the block is skipped with a warning:
NaNat runtimeOther unary operators (
~,!,typeof, and so on) still don't resolve.Warnings
referenceNameOfnow names a signed reference with its sign. So${-gap}, whengapdoesn't resolve, warnsUNRESOLVED_INTERPOLATIONwithcould not resolve "-gap", like${gap}does. Before, it warnedCOMPLEX_INTERPOLATION. A sign on a complex expression, like${-Math.random()}, still warnsCOMPLEX_INTERPOLATION.Tests
negatedConstClass, which was skipped, with:signedValueClass, which resolves a signedconst, a double sign through aconst, a signed import, and a signed numeric stringsignedStringClass, a sign on a non-numeric string, which is skippedbitwiseNotClass, with~, which is skippedCoverage is the same as on main: line 260 (now 285) is the only uncovered line, and the 15 uncovered branches are the same ones.
I didn't benchmark: only signed interpolations take the new path.
Docs
The README example shows signs on a literal and on an import, and its list of skipped interpolations adds signed values that are not numbers. AGENTS.md's
transformentry says the values can be signed.Left out
The recursion now covers every expression that
resolveValuesupports. These wrappers around such expressions still don't resolve, and each would be a one-line recursive case:${-(gap)}, which the parser keeps asParenthesizedExpressionas,satisfies, and!, like${gap as number}🤖 Generated with Claude Code