@@ -1406,6 +1406,49 @@ and print_record_declaration ~state (lds : Parsetree.label_declaration list)
1406
1406
Doc. rbrace;
1407
1407
])
1408
1408
1409
+ and print_literal_dict_expr ~state (e : Parsetree.expression ) cmt_tbl =
1410
+ let force_break =
1411
+ e.pexp_loc.loc_start.pos_lnum < e.pexp_loc.loc_end.pos_lnum
1412
+ in
1413
+ let tuple_to_row (e : Parsetree.expression ) =
1414
+ match e with
1415
+ | {
1416
+ pexp_desc =
1417
+ Pexp_tuple
1418
+ [
1419
+ {pexp_desc = Pexp_constant (Pconst_string (name, _)); pexp_loc}; value;
1420
+ ];
1421
+ } ->
1422
+ Some ((Location. mkloc (Longident. Lident name) pexp_loc, value), e)
1423
+ | _ -> None
1424
+ in
1425
+ let rows =
1426
+ match e with
1427
+ | {pexp_desc = Pexp_array expressions } ->
1428
+ List. filter_map tuple_to_row expressions
1429
+ | _ -> []
1430
+ in
1431
+ Doc. breakable_group ~force_break
1432
+ (Doc. concat
1433
+ [
1434
+ Doc. indent
1435
+ (Doc. concat
1436
+ [
1437
+ Doc. soft_line;
1438
+ Doc. join
1439
+ ~sep: (Doc. concat [Doc. text " ," ; Doc. line])
1440
+ (List. map
1441
+ (fun ((row , e ) :
1442
+ (Longident. t Location. loc * Parsetree. expression )
1443
+ * Parsetree. expression ) ->
1444
+ let doc = print_bs_object_row ~state row cmt_tbl in
1445
+ print_comments doc cmt_tbl e.pexp_loc)
1446
+ rows);
1447
+ ]);
1448
+ Doc. trailing_comma;
1449
+ Doc. soft_line;
1450
+ ])
1451
+
1409
1452
and print_constructor_declarations ~state ~private_flag
1410
1453
(cds : Parsetree.constructor_declaration list ) cmt_tbl =
1411
1454
let force_break =
@@ -4031,6 +4074,24 @@ and print_pexp_apply ~state expr cmt_tbl =
4031
4074
| [] -> doc
4032
4075
| attrs ->
4033
4076
Doc. group (Doc. concat [print_attributes ~state attrs cmt_tbl; doc]))
4077
+ | Pexp_apply
4078
+ ( {
4079
+ pexp_desc =
4080
+ Pexp_ident
4081
+ {
4082
+ txt =
4083
+ Longident. Ldot
4084
+ (Longident. Ldot (Lident " Js" , " Dict" ), " fromArray" );
4085
+ };
4086
+ },
4087
+ [(Nolabel , key_values)] )
4088
+ when Res_parsetree_viewer. is_tuple_array key_values ->
4089
+ Doc. concat
4090
+ [
4091
+ Doc. text " dict{" ;
4092
+ print_literal_dict_expr ~state key_values cmt_tbl;
4093
+ Doc. rbrace;
4094
+ ]
4034
4095
| Pexp_apply
4035
4096
( {pexp_desc = Pexp_ident {txt = Longident. Ldot (Lident " Array" , " get" )}},
4036
4097
[(Nolabel , parent_expr); (Nolabel , member_expr)] )
@@ -4541,7 +4602,7 @@ and print_jsx_name {txt = lident} =
4541
4602
Doc. join ~sep: Doc. dot segments
4542
4603
4543
4604
and print_arguments_with_callback_in_first_position ~state args cmt_tbl =
4544
- (* Because the same subtree gets printed twice, we need to copy the cmtTbl .
4605
+ (* Because the same subtree gets printed twice, we need to copy the cmt_tbl .
4545
4606
* consumed comments need to be marked not-consumed and reprinted…
4546
4607
* Cheng's different comment algorithm will solve this. *)
4547
4608
let state = State. next_custom_layout state in
@@ -4624,7 +4685,7 @@ and print_arguments_with_callback_in_first_position ~state args cmt_tbl =
4624
4685
Doc. custom_layout [Lazy. force fits_on_one_line; Lazy. force break_all_args]
4625
4686
4626
4687
and print_arguments_with_callback_in_last_position ~state args cmt_tbl =
4627
- (* Because the same subtree gets printed twice, we need to copy the cmtTbl .
4688
+ (* Because the same subtree gets printed twice, we need to copy the cmt_tbl .
4628
4689
* consumed comments need to be marked not-consumed and reprinted…
4629
4690
* Cheng's different comment algorithm will solve this. *)
4630
4691
let state = state |> State. next_custom_layout in
@@ -5822,7 +5883,7 @@ let print_pattern p = print_pattern ~state:(State.init ()) p
5822
5883
let print_implementation ~width (s : Parsetree.structure ) ~comments =
5823
5884
let cmt_tbl = CommentTable. make () in
5824
5885
CommentTable. walk_structure s cmt_tbl comments;
5825
- (* CommentTable.log cmtTbl ; *)
5886
+ (* CommentTable.log cmt_tbl ; *)
5826
5887
let doc = print_structure ~state: (State. init () ) s cmt_tbl in
5827
5888
(* Doc.debug doc; *)
5828
5889
Doc. to_string ~width doc ^ " \n "
0 commit comments