@@ -32,15 +32,15 @@ let rec no_need_bound (exp : exp) =
32
32
| Pexp_constraint (e , _ ) -> no_need_bound e
33
33
| _ -> false
34
34
35
- let ocaml_obj_id = " __ocaml_internal_obj "
35
+ let tuple_obj_id = " __tuple_internal_obj "
36
36
37
37
let bound (e : exp ) (cb : exp -> _ ) =
38
38
if no_need_bound e then cb e
39
39
else
40
40
let loc = e.pexp_loc in
41
41
Exp. let_ ~loc Nonrecursive
42
- [Vb. mk ~loc (Pat. var ~loc {txt = ocaml_obj_id ; loc}) e]
43
- (cb (Exp. ident ~loc {txt = Lident ocaml_obj_id ; loc}))
42
+ [Vb. mk ~loc (Pat. var ~loc {txt = tuple_obj_id ; loc}) e]
43
+ (cb (Exp. ident ~loc {txt = Lident tuple_obj_id ; loc}))
44
44
45
45
let default_expr_mapper = Bs_ast_mapper. default_mapper.expr
46
46
@@ -71,8 +71,7 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option =
71
71
72
72
let infix_ops = [" |." ; " |.u" ; " #=" ; " ##" ]
73
73
74
- let app_exp_mapper (e : exp ) (self : Bs_ast_mapper.mapper ) (fn : exp )
75
- (args : Ast_compatible.args ) : exp =
74
+ let app_exp_mapper (e : exp ) (self : Bs_ast_mapper.mapper ) : exp =
76
75
match view_as_app e infix_ops with
77
76
| Some {op = ("|." | "|.u" ) as op ; args = [a_; f_]; loc} -> (
78
77
(*
@@ -82,6 +81,11 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
82
81
a |. `Variant
83
82
a |. (b |. f c [@bs])
84
83
*)
84
+ let add_uncurried_attr attrs =
85
+ if op = " |.u" && not (List. mem Ast_attributes. res_uapp attrs) then
86
+ Ast_attributes. res_uapp :: attrs
87
+ else attrs
88
+ in
85
89
let a = self.expr self a_ in
86
90
let f = self.expr self f_ in
87
91
match f.pexp_desc with
@@ -94,7 +98,8 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
94
98
{
95
99
pexp_desc = Pexp_apply (fn1, (Nolabel , a) :: args);
96
100
pexp_loc = e.pexp_loc;
97
- pexp_attributes = e.pexp_attributes @ f.pexp_attributes;
101
+ pexp_attributes =
102
+ add_uncurried_attr (e.pexp_attributes @ f.pexp_attributes);
98
103
}
99
104
| Pexp_tuple xs ->
100
105
bound a (fun bounded_obj_arg ->
@@ -114,22 +119,18 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
114
119
{
115
120
Parsetree. pexp_desc =
116
121
Pexp_apply (fn, (Nolabel , bounded_obj_arg) :: args);
117
- pexp_attributes = [] ;
122
+ pexp_attributes = add_uncurried_attr [] ;
118
123
pexp_loc = fn.pexp_loc;
119
124
}
120
125
| _ ->
121
- Ast_compatible. app1 ~loc: fn.pexp_loc fn bounded_obj_arg));
126
+ Ast_compatible. app1 ~loc: fn.pexp_loc
127
+ ~attrs: (add_uncurried_attr [] ) fn bounded_obj_arg));
122
128
pexp_attributes = f.pexp_attributes;
123
129
pexp_loc = f.pexp_loc;
124
130
})
125
131
| _ ->
126
- if op = " |.u" then
127
- (* a |.u f
128
- Uncurried unary application *)
129
- Ast_compatible. app1 ~loc
130
- ~attrs: (Ast_attributes. res_uapp :: e.pexp_attributes)
131
- f a
132
- else Ast_compatible. app1 ~loc ~attrs: e.pexp_attributes f a)
132
+ Ast_compatible. app1 ~loc ~attrs: (add_uncurried_attr e.pexp_attributes) f a
133
+ )
133
134
| Some {op = "##" ; loc; args = [obj; rest]} -> (
134
135
(* - obj##property
135
136
- obj#(method a b )
@@ -202,21 +203,4 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
202
203
Location. raise_errorf ~loc
203
204
" Js object ## expect syntax like obj##(paint (a,b)) "
204
205
| Some {op} -> Location. raise_errorf " invalid %s syntax" op
205
- | None -> (
206
- match Ext_list. exclude_with_val e.pexp_attributes Ast_attributes. is_bs with
207
- | Some pexp_attributes -> (
208
- (* syntax: {[f arg0 arg1 [@bs]]} only for legacy .ml files *)
209
- let fn = self.expr self fn in
210
- let args = Ext_list. map args (fun (lbl , e ) -> (lbl, self.expr self e)) in
211
- let js_internal = Ast_literal.Lid. js_internal in
212
- let loc = e.pexp_loc in
213
- match args with
214
- | [(Nolabel , {pexp_desc = Pexp_construct ({txt = Lident " ()" }, None )})] ->
215
- Exp. apply ~loc ~attrs: pexp_attributes
216
- (Exp. ident {txt = Ldot (js_internal, " run" ); loc})
217
- [(Nolabel , fn)]
218
- | _ ->
219
- Exp. apply ~loc
220
- ~attrs: (Ast_attributes. res_uapp :: pexp_attributes)
221
- fn args)
222
- | None -> default_expr_mapper self e)
206
+ | None -> default_expr_mapper self e
0 commit comments