@@ -44,8 +44,8 @@ let variance_ = function
|
44 | 44 | (* Main Transformation *)
|
45 | 45 | (*************************)
|
46 | 46 |
|
47 |
| -let layout_of_elt ~prefer_single_quotes ?(size = 5000) ?(with_comments = true) ~exact_by_default elt |
48 |
| -= |
| 47 | +let layout_of_elt |
| 48 | +~prefer_single_quotes ?(size = 5000) ?(with_comments = true) ~exact_by_default ~ts_syntax elt = |
49 | 49 | let size = ref size in
|
50 | 50 | let local_name_of_symbol symbol =
|
51 | 51 | let { sym_name = name; sym_provenance = provenance; _ } = symbol in
|
@@ -537,9 +537,12 @@ let layout_of_elt ~prefer_single_quotes ?(size = 5000) ?(with_comments = true) ~
|
537 | 537 | | _ -> type_ ~depth t
|
538 | 538 | and enum_decl s = fuse [Atom "enum"; space; identifier (local_name_of_symbol s)]
|
539 | 539 | and utility ~depth u =
|
540 |
| -let ctor = Ty.string_of_utility_ctor u in |
541 |
| -let ts = Ty.types_of_utility u in |
542 |
| -type_reference ~depth (identifier (Reason.OrdinaryName ctor)) ts |
| 540 | +match u with |
| 541 | +| ReadOnly (Tup _ as t) when ts_syntax -> fuse [Atom "readonly"; space; type_ ~depth t] |
| 542 | +| _ -> |
| 543 | +let ctor = Ty.string_of_utility_ctor u in |
| 544 | +let ts = Ty.types_of_utility u in |
| 545 | +type_reference ~depth (identifier (Reason.OrdinaryName ctor)) ts |
543 | 546 | and type_parameter ~depth params =
|
544 | 547 | list
|
545 | 548 | ~wrap:(Atom "<", Atom ">")
|
@@ -661,9 +664,16 @@ let layout_of_elt ~prefer_single_quotes ?(size = 5000) ?(with_comments = true) ~
|
661 | 664 | | Decl d -> decl ~depth:0 d
|
662 | 665 |
|
663 | 666 | let layout_of_type_at_pos_types
|
664 |
| -~prefer_single_quotes ?size ?with_comments ~exact_by_default (unevaluated, evaluated) = |
| 667 | +~prefer_single_quotes ?size ?with_comments ~exact_by_default ~ts_syntax (unevaluated, evaluated) |
| 668 | += |
665 | 669 | let layout_unevaluated =
|
666 |
| -layout_of_elt ~prefer_single_quotes ?size ?with_comments ~exact_by_default unevaluated |
| 670 | +layout_of_elt |
| 671 | +~prefer_single_quotes |
| 672 | +?size |
| 673 | +?with_comments |
| 674 | +~exact_by_default |
| 675 | +~ts_syntax |
| 676 | +unevaluated |
667 | 677 | in
|
668 | 678 | match (unevaluated, evaluated) with
|
669 | 679 | | (_, None) -> layout_unevaluated
|
@@ -676,7 +686,13 @@ let layout_of_type_at_pos_types
|
676 | 686 | | Decl (TypeAliasDecl { type_ = Some t; _ }) -> Type t
|
677 | 687 | | x -> x
|
678 | 688 | in
|
679 |
| -layout_of_elt ~prefer_single_quotes ?size ?with_comments ~exact_by_default evaluated |
| 689 | +layout_of_elt |
| 690 | +~prefer_single_quotes |
| 691 | +?size |
| 692 | +?with_comments |
| 693 | +~exact_by_default |
| 694 | +~ts_syntax |
| 695 | +evaluated |
680 | 696 | in
|
681 | 697 | fuse [layout_unevaluated; hardline; Atom "="; space; layout_evaluated]
|
682 | 698 |
|
@@ -702,31 +718,58 @@ let print_single_line ~source_maps node =
|
702 | 718 | let print_pretty ~source_maps node = Pretty_printer.print ~source_maps ~skip_endline:true node
|
703 | 719 |
|
704 | 720 | let string_of_elt
|
705 |
| -?(prefer_single_quotes = false) ?(with_comments = true) (elt : Ty.elt) ~exact_by_default : |
706 |
| - string = |
707 |
| -layout_of_elt ~prefer_single_quotes ~with_comments ~exact_by_default elt |
| 721 | +?(prefer_single_quotes = false) |
| 722 | +?(with_comments = true) |
| 723 | +~exact_by_default |
| 724 | +~ts_syntax |
| 725 | +(elt : Ty.elt) : string = |
| 726 | +layout_of_elt ~prefer_single_quotes ~with_comments ~exact_by_default ~ts_syntax elt |
708 | 727 | |> print_pretty ~source_maps:None
|
709 | 728 | |> Source.contents
|
710 | 729 |
|
711 | 730 | let string_of_elt_single_line
|
712 |
| -?(prefer_single_quotes = false) ?(with_comments = true) ?(exact_by_default = true) (elt : Ty.elt) |
713 |
| -= |
714 |
| -layout_of_elt ~prefer_single_quotes ~with_comments ~exact_by_default elt |
| 731 | +?(prefer_single_quotes = false) |
| 732 | +?(with_comments = true) |
| 733 | +?(exact_by_default = true) |
| 734 | +~ts_syntax |
| 735 | +(elt : Ty.elt) = |
| 736 | +layout_of_elt ~prefer_single_quotes ~with_comments ~exact_by_default ~ts_syntax elt |
715 | 737 | |> print_single_line ~source_maps:None
|
716 | 738 | |> Source.contents
|
717 | 739 |
|
718 | 740 | let string_of_t
|
719 |
| -?(prefer_single_quotes = false) ?(with_comments = true) ?(exact_by_default = true) (ty : Ty.t) = |
720 |
| -string_of_elt ~prefer_single_quotes ~with_comments ~exact_by_default (Ty.Type ty) |
| 741 | +?(prefer_single_quotes = false) |
| 742 | +?(with_comments = true) |
| 743 | +?(exact_by_default = true) |
| 744 | +~ts_syntax |
| 745 | +(ty : Ty.t) = |
| 746 | +string_of_elt ~prefer_single_quotes ~with_comments ~exact_by_default ~ts_syntax (Ty.Type ty) |
721 | 747 |
|
722 | 748 | let string_of_t_single_line
|
723 |
| -?(prefer_single_quotes = false) ?(with_comments = true) ?(exact_by_default = true) (ty : Ty.t) = |
724 |
| -string_of_elt_single_line ~prefer_single_quotes ~with_comments ~exact_by_default (Ty.Type ty) |
| 749 | +?(prefer_single_quotes = false) |
| 750 | +?(with_comments = true) |
| 751 | +?(exact_by_default = true) |
| 752 | +~ts_syntax |
| 753 | +(ty : Ty.t) = |
| 754 | +string_of_elt_single_line |
| 755 | +~prefer_single_quotes |
| 756 | +~with_comments |
| 757 | +~exact_by_default |
| 758 | +~ts_syntax |
| 759 | +(Ty.Type ty) |
725 | 760 |
|
726 | 761 | let string_of_decl_single_line
|
727 |
| -?(prefer_single_quotes = false) ?(with_comments = true) ?(exact_by_default = true) (d : Ty.decl) |
728 |
| -= |
729 |
| -string_of_elt_single_line ~prefer_single_quotes ~with_comments ~exact_by_default (Ty.Decl d) |
| 762 | +?(prefer_single_quotes = false) |
| 763 | +?(with_comments = true) |
| 764 | +?(exact_by_default = true) |
| 765 | +~ts_syntax |
| 766 | +(d : Ty.decl) = |
| 767 | +string_of_elt_single_line |
| 768 | +~prefer_single_quotes |
| 769 | +~with_comments |
| 770 | +~exact_by_default |
| 771 | +~ts_syntax |
| 772 | +(Ty.Decl d) |
730 | 773 |
|
731 | 774 | let string_of_symbol_set syms =
|
732 | 775 | LocSymbolSet.elements syms
|
@@ -745,10 +788,11 @@ let string_of_type_at_pos_result
|
745 | 788 | ?(prefer_single_quotes = false)
|
746 | 789 | ?(with_comments = true)
|
747 | 790 | ?(exact_by_default = true)
|
| 791 | +~ts_syntax |
748 | 792 | { Ty.unevaluated; evaluated; refs } =
|
749 | 793 | let type_str =
|
750 | 794 | (unevaluated, evaluated)
|
751 |
| -|> layout_of_type_at_pos_types ~prefer_single_quotes ~with_comments ~exact_by_default |
| 795 | +|> layout_of_type_at_pos_types ~prefer_single_quotes ~with_comments ~exact_by_default ~ts_syntax |
752 | 796 | |> print_pretty ~source_maps:None
|
753 | 797 | |> Source.contents
|
754 | 798 | in
|
|
0 commit comments