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 {
1313 randomSeed : 1 ,
1414
1515 // 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 ,
1724 } )
1825
1926 // 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', () => {
173173 )
174174
175175 expect ( replaceCssCalc ( 'calc(1.25 / 0.875)' , ( node ) => evaluateExpression ( node . value ) ) ) . toBe (
176- '1.4286 ' ,
176+ '1.428571 ' ,
177177 )
178178
179179 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' )
180188} )
181189
182190test ( 'Inlining calc expressions using the design system' , ( ) => {
You can’t perform that action at this time.
0 commit comments