@@ -1406,6 +1406,49 @@ and print_record_declaration ~state (lds : Parsetree.label_declaration list)
14061406 Doc. rbrace;
14071407 ])
14081408
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+
14091452and print_constructor_declarations ~state ~private_flag
14101453 (cds : Parsetree.constructor_declaration list ) cmt_tbl =
14111454 let force_break =
@@ -4031,6 +4074,24 @@ and print_pexp_apply ~state expr cmt_tbl =
40314074 | [] -> doc
40324075 | attrs ->
40334076 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+ ]
40344095 | Pexp_apply
40354096 ( {pexp_desc = Pexp_ident {txt = Longident. Ldot (Lident " Array" , " get" )}},
40364097 [(Nolabel , parent_expr); (Nolabel , member_expr)] )
@@ -4541,7 +4602,7 @@ and print_jsx_name {txt = lident} =
45414602 Doc. join ~sep: Doc. dot segments
45424603
45434604and 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 .
45454606 * consumed comments need to be marked not-consumed and reprinted…
45464607 * Cheng's different comment algorithm will solve this. *)
45474608 let state = State. next_custom_layout state in
@@ -4624,7 +4685,7 @@ and print_arguments_with_callback_in_first_position ~state args cmt_tbl =
46244685 Doc. custom_layout [Lazy. force fits_on_one_line; Lazy. force break_all_args]
46254686
46264687and 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 .
46284689 * consumed comments need to be marked not-consumed and reprinted…
46294690 * Cheng's different comment algorithm will solve this. *)
46304691 let state = state |> State. next_custom_layout in
@@ -5822,7 +5883,7 @@ let print_pattern p = print_pattern ~state:(State.init ()) p
58225883let print_implementation ~width (s : Parsetree.structure ) ~comments =
58235884 let cmt_tbl = CommentTable. make () in
58245885 CommentTable. walk_structure s cmt_tbl comments;
5825- (* CommentTable.log cmtTbl ; *)
5886+ (* CommentTable.log cmt_tbl ; *)
58265887 let doc = print_structure ~state: (State. init () ) s cmt_tbl in
58275888 (* Doc.debug doc; *)
58285889 Doc. to_string ~width doc ^ " \n "
0 commit comments