Skip to content

Commit 9a5c876

Browse files
Shulhi Saplishulhi
Shulhi Sapli
authored andcommitted
WIP
1 parent 4ab9a5f commit 9a5c876

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

jscomp/syntax/src/res_parsetree_viewer.ml

+25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
open Parsetree
22

3+
let attrs_string attrs =
4+
List.map (fun (attr, _) -> print_endline attr.Asttypes.txt) attrs
5+
6+
let ident_string ident =
7+
match ident with
8+
| Longident.Lident v -> v
9+
| Longident.Ldot (_, v) -> v
10+
| Longident.Lapply _ -> "Lapply"
11+
12+
let print_ct ct =
13+
match ct with
14+
| {ptyp_desc = Ptyp_constr (ident, _); ptyp_attributes = attrs} ->
15+
let _ =
16+
print_endline
17+
("Ptyp_constr: " ^ ident_string ident.txt ^ " attrs: "
18+
^ string_of_int (List.length attrs))
19+
in
20+
let _ = attrs_string attrs in
21+
()
22+
| {ptyp_desc = Ptyp_arrow _; ptyp_attributes = attrs} ->
23+
print_endline
24+
("Ptyp_arrow: " ^ " attrs: " ^ string_of_int (List.length attrs))
25+
| {ptyp_desc = Ptyp_variant _} -> print_endline "Ptyp_variant"
26+
| _ -> print_endline "Something else"
27+
328
let arrow_type ?(arity = max_int) ct =
429
let has_as_attr attrs =
530
Ext_list.exists attrs (fun (x, _) -> x.Asttypes.txt = "as")

jscomp/syntax/src/res_parsetree_viewer.mli

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ val arrow_type :
88
* (Parsetree.attributes * Asttypes.arg_label * Parsetree.core_type) list
99
* Parsetree.core_type
1010

11+
val print_ct : Parsetree.core_type -> unit
12+
1113
val functor_type :
1214
Parsetree.module_type ->
1315
(Parsetree.attributes * string Asttypes.loc * Parsetree.module_type option)

jscomp/syntax/src/res_printer.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,7 @@ and print_label_declaration ~state (ld : Parsetree.label_declaration) cmt_tbl =
15911591
])
15921592

15931593
and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
1594+
let parent_has_attrs = Ast_uncurried.core_type_is_uncurried_fun typ_expr && not (typ_expr.ptyp_attributes = []) in
15941595
let print_arrow ?(arity = max_int) typ_expr =
15951596
let attrs_before, args, return_type =
15961597
ParsetreeViewer.arrow_type ~arity typ_expr
@@ -1626,7 +1627,7 @@ and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
16261627
[
16271628
Doc.group attrs;
16281629
Doc.group
1629-
(if has_attrs_before then
1630+
(if has_attrs_before || parent_has_attrs then
16301631
Doc.concat
16311632
[
16321633
Doc.lparen;

0 commit comments

Comments
 (0)