@@ -10,34 +10,6 @@ impl ESTree for bool {
1010 }
1111}
1212
13- /// [`ESTree`] implementation for `f32`.
14- impl ESTree for f32 {
15- fn serialize < S : Serializer > ( & self , mut serializer : S ) {
16- if self . is_finite ( ) {
17- // For f32, we need custom formatting to match ryu_js behavior
18- let s = if * self == f32:: MIN {
19- "-3.4028235e+38" . to_string ( )
20- } else if * self == f32:: MAX {
21- "3.4028235e+38" . to_string ( )
22- } else {
23- // For other finite values, standard formatting works
24- format ! ( "{self}" )
25- } ;
26- serializer. buffer_mut ( ) . print_str ( & s) ;
27- } else if self . is_nan ( ) {
28- // Serialize `NAN` as `null`
29- // TODO: Throw an error? Use a sentinel value?
30- serializer. buffer_mut ( ) . print_str ( "null" ) ;
31- } else if * self == f32:: INFINITY {
32- // Serialize `INFINITY` as `1e+400. `JSON.parse` deserializes this as `Infinity`.
33- serializer. buffer_mut ( ) . print_str ( "1e+400" ) ;
34- } else {
35- // Serialize `-INFINITY` as `-1e+400`. `JSON.parse` deserializes this as `-Infinity`.
36- serializer. buffer_mut ( ) . print_str ( "-1e+400" ) ;
37- }
38- }
39- }
40-
4113/// [`ESTree`] implementation for `f64`.
4214impl ESTree for f64 {
4315 fn serialize < S : Serializer > ( & self , mut serializer : S ) {
@@ -111,21 +83,6 @@ mod tests {
11183 run_test ( & [ ( true , "true" ) , ( false , "false" ) ] ) ;
11284 }
11385
114- #[ test]
115- fn serialize_f32 ( ) {
116- run_test ( & [
117- ( 0.0 , "0" ) ,
118- ( 1.0 , "1" ) ,
119- ( 123_456.0 , "123456" ) ,
120- ( 0.12345 , "0.12345" ) ,
121- ( 123.45 , "123.45" ) ,
122- ( f32:: MIN , "-3.4028235e+38" ) ,
123- ( f32:: MAX , "3.4028235e+38" ) ,
124- ( f32:: INFINITY , "1e+400" ) ,
125- ( -f32:: INFINITY , "-1e+400" ) ,
126- ] ) ;
127- }
128-
12986 #[ test]
13087 fn serialize_f64 ( ) {
13188 run_test ( & [
0 commit comments