Skip to content

Commit 95bf235

Browse files
author
Hongbo Zhang
committed
remove magic when bs attribute applied on object
1 parent 7f046e3 commit 95bf235

File tree

2 files changed

+36
-68
lines changed

2 files changed

+36
-68
lines changed

jscomp/syntax/ppx_entry.ml

Lines changed: 29 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,14 @@ let record_as_js_object = ref false (* otherwise has an attribute *)
6363

6464

6565
let obj_type_as_js_obj_type = ref false
66-
let uncurry_type = ref false
66+
6767

6868
let no_export = ref false
6969

7070

7171
let reset () =
7272
record_as_js_object := false ;
7373
obj_type_as_js_obj_type := false ;
74-
uncurry_type := false ;
7574
no_export := false
7675

7776

@@ -188,78 +187,46 @@ let handle_typ
188187
| `Method, ptyp_attributes ->
189188
Ast_util.to_method_type loc self label args body
190189
| `Nothing , _ ->
191-
if !uncurry_type then
192-
Ast_util.to_uncurry_type loc self label args body
193-
else
194190
Ast_mapper.default_mapper.typ self ty
195191
end
196192
| {
197193
ptyp_desc = Ptyp_object ( methods, closed_flag) ;
198-
ptyp_attributes ;
199194
ptyp_loc = loc
200195
} ->
201196

202197
let check_auto_uncurry core_type = self.typ self core_type in
203-
let methods, ptyp_attributes =
204-
begin match Ext_list.exclude_with_fact
205-
(function
206-
| {Location.txt = "bs"; _}, _ -> true
207-
| _ -> false)
208-
ptyp_attributes with
209-
| None, _ ->
210-
List.map (fun (label, ptyp_attrs, core_type ) ->
211-
match Ast_attributes.process_attributes_rev ptyp_attrs with
212-
| `Nothing, _ ->
213-
label, ptyp_attrs , check_auto_uncurry core_type
214-
| `Uncurry, _ ->
215-
label , ptyp_attrs,
216-
check_auto_uncurry
217-
{ core_type with
218-
ptyp_attributes =
219-
Ast_attributes.bs :: core_type.ptyp_attributes}
220-
| `Method, ptyp_attrs
221-
->
222-
label , ptyp_attrs,
223-
check_auto_uncurry
224-
{ core_type with
225-
ptyp_attributes =
226-
Ast_attributes.bs_method :: core_type.ptyp_attributes}
227-
| `Meth_callback, ptyp_attrs
228-
->
229-
label , ptyp_attrs,
230-
check_auto_uncurry
231-
{ core_type with
232-
ptyp_attributes =
233-
Ast_attributes.bs_this :: core_type.ptyp_attributes}
234-
) methods , ptyp_attributes
235-
| Some _ , ptyp_attributes ->
236-
Ext_ref.non_exn_protect uncurry_type true begin fun _ ->
237-
List.map (fun (label, ptyp_attrs, core_type ) ->
238-
match Ast_attributes.process_attributes_rev ptyp_attrs with
239-
| `Nothing, _ -> label, ptyp_attrs , self.typ self core_type
240-
| `Uncurry, ptyp_attrs ->
241-
label , ptyp_attrs, self.typ self
242-
{ core_type with
243-
ptyp_attributes =
244-
Ast_attributes.bs :: core_type.ptyp_attributes}
245-
| `Method, ptyp_attrs ->
246-
label , ptyp_attrs, self.typ self
247-
{ core_type with
248-
ptyp_attributes =
249-
Ast_attributes.bs_method :: core_type.ptyp_attributes}
250-
| `Meth_callback, ptyp_attrs ->
251-
label , ptyp_attrs, self.typ self
252-
{ core_type with
253-
ptyp_attributes =
254-
Ast_attributes.bs_this :: core_type.ptyp_attributes}
255-
) methods
256-
end, ptyp_attributes
257-
end
198+
let methods =
199+
List.map (fun (label, ptyp_attrs, core_type ) ->
200+
match Ast_attributes.process_attributes_rev ptyp_attrs with
201+
| `Nothing, _ ->
202+
label, ptyp_attrs , check_auto_uncurry core_type
203+
| `Uncurry, _ ->
204+
label , ptyp_attrs,
205+
check_auto_uncurry
206+
{ core_type with
207+
ptyp_attributes =
208+
Ast_attributes.bs :: core_type.ptyp_attributes}
209+
| `Method, ptyp_attrs
210+
->
211+
label , ptyp_attrs,
212+
check_auto_uncurry
213+
{ core_type with
214+
ptyp_attributes =
215+
Ast_attributes.bs_method :: core_type.ptyp_attributes}
216+
| `Meth_callback, ptyp_attrs
217+
->
218+
label , ptyp_attrs,
219+
check_auto_uncurry
220+
{ core_type with
221+
ptyp_attributes =
222+
Ast_attributes.bs_this :: core_type.ptyp_attributes}
223+
) methods
224+
258225
in
259226
let inner_type =
260227
{ ty
261228
with ptyp_desc = Ptyp_object(methods, closed_flag);
262-
ptyp_attributes } in
229+
} in
263230
if !obj_type_as_js_obj_type then
264231
Ast_comb.to_js_type loc inner_type
265232
else inner_type

jscomp/test/test_index.ml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@ let ff (x : int case Js.t)
2323

2424

2525
type 'a return = int -> 'a [@bs]
26+
2627
let h (x :
27-
[%bs.obj:< cse : (int -> 'a return ); .. > [@bs] ]) =
28+
[%bs.obj:< cse : int -> 'a return [@bs] ; .. > ]) =
2829
(x#@cse 3) 2 [@bs]
2930

3031

3132

3233
type x_obj =
3334
[%bs.obj: <
34-
cse : int -> int ;
35-
cse_st : int -> int -> unit ;
36-
> [@bs] ]
35+
cse : int -> int [@bs] ;
36+
cse_st : int -> int -> unit [@bs];
37+
> ]
3738

3839
let f_ext
3940
(x : x_obj)
@@ -44,8 +45,8 @@ let f_ext
4445

4546
type 'a h_obj =
4647
[%bs.obj: <
47-
cse : int -> 'a return
48-
> [@bs] ]
48+
cse : int -> 'a return [@bs]
49+
> ]
4950

5051
let h_ext (x : 'a h_obj) =
5152
(x #@cse 3) 2 [@bs]

0 commit comments

Comments
 (0)