Skip to content

Commit 81dcb36

Browse files
author
Rahul Kumar
committed
review comments
1 parent e69fbe3 commit 81dcb36

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

jscomp/tools/ppx_class.ml

+21-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1717
*)
1818

19-
(* Author: Hongbo Zhang *)
19+
(* Author: Rahul Kumar *)
2020
open Ast_mapper
2121
open Ast_helper
2222
open Asttypes
@@ -34,7 +34,8 @@ type indication =
3434
let compare_indication : indication -> indication -> int = compare
3535

3636
(* Given an attribute string, determine the indications *)
37-
let classify_indication name = match name with
37+
let classify_indication name =
38+
match name with
3839
| "r" -> [Indication_read]
3940
| "w" -> [Indication_write]
4041
| "rw" -> [Indication_read;Indication_write]
@@ -44,7 +45,7 @@ let classify_indication name = match name with
4445
(* Get unique indications from an attribute list *)
4546
let indications_of_attr attrlst =
4647
List.sort_uniq compare_indication (List.concat
47-
(List.map (fun ({txt=x;_},_) -> classify_indication x) attrlst))
48+
(List.map (fun ({txt=x;_},_) -> classify_indication x) attrlst))
4849

4950
(* Define the methods generated by this ppx extension *)
5051
type methods =
@@ -97,7 +98,8 @@ let filter_attributes attrlst = List.filter
9798
let strip_attr t = {t with ptyp_attributes=filter_attributes t.ptyp_attributes}
9899

99100
(* Count the arity of a core_type *)
100-
let rec count_arity z = match z with
101+
let rec count_arity z =
102+
match z with
101103
| {ptyp_desc = Ptyp_arrow (_,_,y);_} -> 1 + (count_arity y)
102104
| _ -> 0
103105

@@ -106,18 +108,23 @@ let is_non_nullary_fn z = (count_arity z) > 0
106108

107109
(* Produce a new core_type from the given core_type, removing 'opt/option/def'
108110
from the return type*)
109-
let rec optless typ loc prefix = match typ with
110-
| {ptyp_desc = Ptyp_constr ({txt=(Lident ("opt"|"def"|"option")) |
111-
(Ldot (Lident "Js",("opt"|"def"|"option")));_},[x]);_} -> x
111+
let rec optless typ loc prefix =
112+
match typ with
113+
| {ptyp_desc =
114+
Ptyp_constr ({txt=
115+
(Lident ("opt"|"def"|"opt_def")) |
116+
(Ldot (Lident "Js",
117+
("opt"|"def"|"opt_def")));_},[x]);_} -> x
112118
| {ptyp_desc = Ptyp_arrow (tag,t1,t2);_} as t_ ->
113-
{t_ with ptyp_desc = Ptyp_arrow (tag,t1,optless t2 loc prefix)}
119+
{t_ with ptyp_desc = Ptyp_arrow (tag,t1,optless t2 loc prefix)}
114120
| _ -> begin
115121
pwarn loc true (prefix^"indication provided for non-option type.");
116122
typ
117123
end
118124

119125
(* Generate method signature with appropriate warnings/checks *)
120-
let gen_method loc original abs vis name attr typ meth = match meth with
126+
let gen_method loc original abs vis name attr typ meth =
127+
match meth with
121128
| Method_read -> begin
122129
let () = pwarn loc (is_non_nullary_fn typ)
123130
"Read indication provided for non-property."
@@ -184,7 +191,8 @@ let new_methods m =
184191
| _ -> [m]
185192

186193
(* Map class_type_declaration for FFI *)
187-
let new_ctd mapper ctd = match ctd with
194+
let new_ctd mapper ctd =
195+
match ctd with
188196
| { pci_name=name;
189197
pci_expr =
190198
{ pcty_desc = Pcty_signature (
@@ -193,9 +201,9 @@ let new_ctd mapper ctd = match ctd with
193201
pci_attributes = attrlst
194202
} as c ->
195203
{ c with pci_expr =
196-
{ expr with pcty_desc = Pcty_signature
197-
{ flds with pcsig_fields =
198-
(List.concat (List.map new_methods methodlst)) } };
204+
{ expr with pcty_desc = Pcty_signature
205+
{ flds with pcsig_fields =
206+
(List.concat (List.map new_methods methodlst)) } };
199207
}
200208
| _ -> default_mapper.class_type_declaration mapper ctd
201209

0 commit comments

Comments
 (0)