File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
packages/tailwindcss-language-service/src/util/rewriting Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,14 @@ export function evaluateExpression(str: string): string | null {
13
13
randomSeed : 1 ,
14
14
15
15
// Limit precision to keep values environment independent
16
- precision : 4 ,
16
+ //
17
+ // This is mostly to limit displayed numbers to a reasonable length. Ideally
18
+ // we could perform any calcs with "infinite" precision and only then round
19
+ // numbers back for display purposes.
20
+ //
21
+ // This is short of the 7 digits that 32-bit floats provide. JS does store
22
+ // numbers as doubles so maybe this can be bumped to like 12–15?
23
+ precision : 6 ,
17
24
} )
18
25
19
26
// The result array is the same shape as the original so we're guaranteed to
Original file line number Diff line number Diff line change @@ -173,10 +173,18 @@ test('Evaluating CSS calc expressions', () => {
173
173
)
174
174
175
175
expect ( replaceCssCalc ( 'calc(1.25 / 0.875)' , ( node ) => evaluateExpression ( node . value ) ) ) . toBe (
176
- '1.4286 ' ,
176
+ '1.428571 ' ,
177
177
)
178
178
179
179
expect ( replaceCssCalc ( 'calc(1/4 * 100%)' , ( node ) => evaluateExpression ( node . value ) ) ) . toBe ( '25%' )
180
+
181
+ expect ( replaceCssCalc ( 'calc(0.12345rem * 0.5)' , ( node ) => evaluateExpression ( node . value ) ) ) . toBe (
182
+ '0.061725rem' ,
183
+ )
184
+
185
+ expect (
186
+ replaceCssCalc ( 'calc(0.12345789rem * 0.5)' , ( node ) => evaluateExpression ( node . value ) ) ,
187
+ ) . toBe ( '0.061729rem' )
180
188
} )
181
189
182
190
test ( 'Inlining calc expressions using the design system' , ( ) => {
You can’t perform that action at this time.
0 commit comments