Skip to content

Commit 7f046e3

Browse files
author
Hongbo Zhang
committed
remove bs class type and auto uncurry for less magic
1 parent 6dae93f commit 7f046e3

22 files changed

+123
-109
lines changed

jscomp/syntax/ppx_entry.ml

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,14 @@ let record_as_js_object = ref false (* otherwise has an attribute *)
6464

6565
let obj_type_as_js_obj_type = ref false
6666
let uncurry_type = ref false
67-
let obj_type_auto_uncurry = ref false
67+
6868
let no_export = ref false
69-
let bs_class_type = ref false
69+
7070

7171
let reset () =
7272
record_as_js_object := false ;
7373
obj_type_as_js_obj_type := false ;
7474
uncurry_type := false ;
75-
obj_type_auto_uncurry := false ;
76-
bs_class_type := false;
7775
no_export := false
7876

7977

@@ -201,11 +199,7 @@ let handle_typ
201199
ptyp_loc = loc
202200
} ->
203201

204-
let check_auto_uncurry core_type =
205-
if !obj_type_auto_uncurry then
206-
Ext_ref.non_exn_protect uncurry_type true
207-
(fun _ -> self.typ self core_type )
208-
else self.typ self core_type in
202+
let check_auto_uncurry core_type = self.typ self core_type in
209203
let methods, ptyp_attributes =
210204
begin match Ext_list.exclude_with_fact
211205
(function
@@ -475,29 +469,39 @@ let rec unsafe_mapper : Ast_mapper.mapper =
475469
);
476470
typ = (fun self typ -> handle_typ Ast_mapper.default_mapper self typ);
477471
class_type =
478-
(fun self ({pcty_attributes} as ctd) ->
472+
(fun self ({pcty_attributes; pcty_loc} as ctd) ->
479473
match Ast_attributes.process_bs pcty_attributes with
480474
| `Nothing, _ ->
481475
Ast_mapper.default_mapper.class_type
482476
self ctd
483-
| `Has, pcty_attributes ->
484-
Ext_ref.non_exn_protect bs_class_type true begin fun _ ->
485-
Ast_mapper.default_mapper.class_type
486-
self {ctd with pcty_attributes}
487-
end
477+
| `Has, pcty_attributes ->
478+
begin match ctd.pcty_desc with
479+
| Pcty_signature ({pcsig_self; pcsig_fields })
480+
->
481+
let pcsig_self = self.typ self pcsig_self in
482+
{ctd with
483+
pcty_desc = Pcty_signature {
484+
pcsig_self ;
485+
pcsig_fields = List.fold_right (fun f acc ->
486+
handle_class_type_field acc self f
487+
) pcsig_fields []
488+
};
489+
pcty_attributes
490+
}
491+
492+
| Pcty_constr _
493+
| Pcty_extension _
494+
| Pcty_arrow _ ->
495+
Location.raise_errorf ~loc:pcty_loc "invalid or unused attribute `bs`"
496+
(* {[class x : int -> object
497+
end [@bs]
498+
]}
499+
Actually this is not going to happpen as below is an invalid syntax
500+
{[class type x = int -> object
501+
end[@bs]]}
502+
*)
503+
end
488504
);
489-
class_signature = begin fun self ({pcsig_self; pcsig_fields } as csg) ->
490-
if !bs_class_type then
491-
let pcsig_self = self.typ self pcsig_self in
492-
{
493-
pcsig_self ;
494-
pcsig_fields = List.fold_right (fun f acc ->
495-
handle_class_type_field acc self f
496-
) pcsig_fields []
497-
}
498-
else
499-
Ast_mapper.default_mapper.class_signature self csg
500-
end;
501505
signature_item = begin fun (self : Ast_mapper.mapper) (sigi : Parsetree.signature_item) ->
502506
match sigi.psig_desc with
503507
| Psig_type [{ptype_attributes} as tdcl] ->
@@ -607,18 +611,7 @@ let rec unsafe_mapper : Ast_mapper.mapper =
607611
(** global configurations below *)
608612
let common_actions_table :
609613
(string * (Parsetree.expression option -> unit)) list =
610-
[ "obj_type_auto_uncurry",
611-
(fun e ->
612-
obj_type_auto_uncurry :=
613-
(match e with Some e -> Ast_payload.assert_bool_lit e
614-
| None -> true)
615-
);
616-
"bs_class_type",
617-
(fun e ->
618-
bs_class_type :=
619-
(match e with Some e -> Ast_payload.assert_bool_lit e
620-
| None -> true)
621-
)
614+
[
622615
]
623616

624617

jscomp/test/.depend

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ mt.cmj : ../stdlib/list.cmi ../others/bs_node.cmi ../stdlib/array.cmi mt.cmi
405405
mt.cmx : ../stdlib/list.cmx ../others/bs_node.cmi ../stdlib/array.cmx mt.cmi
406406
mt_global.cmj : mt.cmi mt_global.cmi
407407
mt_global.cmx : mt.cmx mt_global.cmi
408+
mutable_obj_test.cmj : ../runtime/js.cmj
409+
mutable_obj_test.cmx : ../runtime/js.cmx
408410
mutual_non_recursive_type.cmj :
409411
mutual_non_recursive_type.cmx :
410412
nested_include.cmj :
@@ -1175,6 +1177,8 @@ mt.cmo : ../stdlib/list.cmi ../others/bs_node.cmi ../stdlib/array.cmi mt.cmi
11751177
mt.cmj : ../stdlib/list.cmj ../others/bs_node.cmi ../stdlib/array.cmj mt.cmi
11761178
mt_global.cmo : mt.cmi mt_global.cmi
11771179
mt_global.cmj : mt.cmj mt_global.cmi
1180+
mutable_obj_test.cmo : ../runtime/js.cmo
1181+
mutable_obj_test.cmj : ../runtime/js.cmj
11781182
mutual_non_recursive_type.cmo :
11791183
mutual_non_recursive_type.cmj :
11801184
nested_include.cmo :

jscomp/test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ OTHERS := literals a test_ari test_export2 test_internalOO test_obj_simple_ffi t
6060
bs_rest_test infer_type_test fs_test module_as_function\
6161
test_case_set test_mutliple string_bound_get_test inline_string_test\
6262
ppx_this_obj_test unsafe_obj_external gpr_627_test jsoo_485_test jsoo_400_test \
63-
test_require more_uncurry earger_curry_test poly_type bench
63+
test_require more_uncurry earger_curry_test poly_type bench mutable_obj_test
6464

6565

6666

jscomp/test/class_setter_getter.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11

2-
[@@@bs.config{bs_class_type}]
2+
33

44
class type _y = object
55
method height : int [@@bs.set {no_get}]
6-
end
6+
end [@bs]
77
type y = _y Js.t
88
class type _y0 = object
99
method height : int [@@bs.set] [@@bs.get {null}]
10-
end
10+
end [@bs]
1111
type y0 = _y0 Js.t
1212

1313
class type _y1 = object
1414
method height : int [@@bs.set] [@@bs.get {undefined}]
15-
end
15+
end[@bs]
1616
type y1 = _y1 Js.t
1717

1818
class type _y2 = object
1919
method height : int [@@bs.set] [@@bs.get {undefined; null}]
20-
end
20+
end [@bs]
2121
type y2 = _y2 Js.t
2222

2323
class type _y3 = object
2424
method height : int [@@bs.get {undefined ; null}]
25-
end
25+
end[@bs]
2626
type y3 = _y3 Js.t
2727

jscomp/test/class_type_ffi_test.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
[@@@bs.config{bs_class_type }]
1+
22
class type ['k,'v] arrayLike =
33
object
44
method case : 'k -> 'v Js.Null.t
55
method caseSet : 'k * 'v -> unit
66
method case_unsafe : 'k -> 'v
77
method length : int
8-
end
8+
end[@bs]
99

1010
class type floatArray = [int, float] arrayLike
11-
11+
(** here we can see [@bs] is really attached to `object end` instead of `class type` *)
1212
class type intArray = [int, int] arrayLike
1313

1414

jscomp/test/config1_test.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
;;[@@@bs.config{
3-
obj_type_auto_uncurry ;
3+
44
no_export ;
55
}]
66
;;

jscomp/test/config2_test.ml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
[@@@bs.config{
2-
obj_type_auto_uncurry ;
3-
bs_class_type
4-
(* no_export = true; *)
5-
}]
1+
62

73

84

95
class type v = object
106
method hey : int -> int -> int
11-
end
7+
end [@bs]
128

139
class type v2 = object
1410
method hey : int -> int -> int
15-
end
11+
end [@bs]
1612

1713
type vv =
1814
[%bs.obj: <
19-
hey : int -> int -> int
20-
> [@bs] ]
15+
hey : int -> int -> int [@bs]
16+
> ]
2117

2218
type vv2 =
2319
[%bs.obj: <
24-
hey : int -> int -> int
20+
hey : int -> int -> int [@bs]
2521
> ]
2622

2723

jscomp/test/config2_test.mli

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
[@@@bs.config {obj_type_auto_uncurry ; (* no_export = true *)
2-
bs_class_type
3-
} ]
41

52

63
class type v = object
74
method hey : int -> int -> int
8-
end
5+
end [@bs]
96

107
class type v2 = object
118
method hey : int -> int -> int
12-
end
9+
end [@bs]
1310

1411
type vv =
1512
[%bs.obj: <
16-
hey : int -> int -> int
17-
> [@bs]]
13+
hey : int -> int -> int [@bs]
14+
> ]
1815

1916
type vv2 =
2017
[%bs.obj: <
21-
hey : int -> int -> int
18+
hey : int -> int -> int [@bs]
2219
> ]
2320

2421

jscomp/test/demo_binding.ml

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,52 @@
1-
[@@@bs.config{bs_class_type }]
21

32
class type titlex =
43
object
54
method title : string [@@bs.set] [@@bs.get {null ; undefined}]
6-
end
5+
end[@bs]
76

87
class type widget =
98
object
109
method on : string -> (event -> unit [@bs]) -> unit
11-
end
10+
end[@bs]
1211
and event =
1312
object
1413
method source : widget
1514
method target : widget
16-
end
15+
end[@bs]
1716

1817

1918
class type title =
2019
object
2120
method title : string [@@bs.set]
22-
end
21+
end[@bs]
2322

2423
class type text =
2524
object
2625
method text : string [@@bs.set]
27-
end
26+
end[@bs]
2827

2928
class type measure =
3029
object
3130
method minHeight : int [@@bs.set]
3231
method minWidth : int [@@bs.set]
3332
method maxHeight : int [@@bs.set]
3433
method maxWidth : int [@@bs.set]
35-
end
34+
end[@bs]
3635

3736
class type layout =
3837
object
3938
method orientation : string [@@bs.set]
40-
end
39+
end[@bs]
4140

4241
class type applicationContext =
4342
object
4443
method exit : int -> unit
45-
end
44+
end[@bs]
4645
class type contentable =
4746
object
4847
method content : #widget Js.t [@@bs.set]
4948
method contentWidth : int [@@bs.set]
50-
end
49+
end[@bs]
5150

5251
class type hostedWindow =
5352
object
@@ -58,13 +57,13 @@ class type hostedWindow =
5857
method hide : unit -> unit
5958
method focus : unit -> unit
6059
method appContext : applicationContext [@@bs.set]
61-
end
60+
end[@bs]
6261

6362
class type hostedContent =
6463
object
6564
inherit widget
6665
inherit contentable
67-
end
66+
end[@bs]
6867

6968

7069
class type stackPanel =
@@ -75,7 +74,7 @@ class type stackPanel =
7574

7675
method addChild : #widget Js.t -> unit
7776

78-
end
77+
end[@bs]
7978

8079
class type grid =
8180
object
@@ -86,22 +85,22 @@ class type grid =
8685
[%bs.obj: <label : <text : string; .. > ; ..> ] array [@@bs.set]
8786
method dataSource :
8887
[%bs.obj: <label : <text : string; .. > ; ..> ] array array [@@bs.set]
89-
end
88+
end[@bs]
9089

9190

9291
class type button =
9392
object
9493
inherit widget
9594
inherit text
9695
inherit measure
97-
end
96+
end[@bs]
9897

9998
class type textArea =
10099
object
101100
inherit widget
102101
inherit measure
103102
inherit text
104-
end
103+
end[@bs]
105104

106105

107106
external set_interval : (unit -> unit [@bs]) -> float -> unit = "setInterval"

0 commit comments

Comments
 (0)