25
25
open Ast_helper
26
26
type 'a cxt = Ast_helper .loc -> Bs_ast_mapper .mapper -> 'a
27
27
type loc = Location .t
28
- type args = (string * Parsetree .expression ) list
28
+ type args = (Ast_compatible .arg_label * Parsetree .expression ) list
29
29
type label_exprs = (Longident .t Asttypes .loc * Parsetree .expression ) list
30
30
type uncurry_expression_gen =
31
31
(Parsetree .pattern ->
32
32
Parsetree .expression ->
33
33
Parsetree .expression_desc ) cxt
34
34
type uncurry_type_gen =
35
- (string ->
35
+ (Ast_compatible .arg_label ->
36
36
Parsetree .core_type ->
37
37
Parsetree .core_type ->
38
38
Parsetree .core_type ) cxt
@@ -48,9 +48,16 @@ let method_call_back_id =
48
48
49
49
let arity_lit = " Arity_"
50
50
51
- let mk_args loc n tys =
51
+ let mk_args loc ( n : int ) ( tys : Parsetree.core_type list ) : Parsetree.core_type =
52
52
Typ. variant ~loc
53
- [ Rtag (arity_lit ^ string_of_int n, [] , (n = 0 ), tys)] Closed None
53
+ [ Rtag (
54
+ #if OCAML_VERSION =~ " >4.03.0" then
55
+ {loc; txt = arity_lit ^ string_of_int n}
56
+ #else
57
+ arity_lit ^ string_of_int n
58
+ #end
59
+ ,
60
+ [] , (n = 0 ), tys)] Closed None
54
61
55
62
let generic_lift txt loc args result =
56
63
let xs =
@@ -89,13 +96,19 @@ let lift_js_method_callback loc
89
96
let arrow = Ast_compatible. arrow
90
97
91
98
92
- let js_property loc obj name =
99
+ let js_property loc obj ( name : string ) =
93
100
Parsetree. Pexp_send
94
101
((Ast_compatible. app1 ~loc
95
102
(Exp. ident ~loc
96
103
{loc;
97
104
txt = Ldot (Ast_literal.Lid. js_unsafe, Literals. unsafe_downgrade)})
98
- obj), name)
105
+ obj),
106
+ #if OCAML_VERSION =~ " >4.03.0" then
107
+ {loc; txt = name}
108
+ #else
109
+ name
110
+ #end
111
+ )
99
112
100
113
(* TODO:
101
114
have a final checking for property arities
@@ -110,7 +123,7 @@ let generic_apply kind loc
110
123
let obj = self.expr self obj in
111
124
let args =
112
125
Ext_list. map (fun (label ,e ) ->
113
- if label <> " " then
126
+ if not ( Ast_compatible. is_arg_label_simple label) then
114
127
Bs_syntaxerr. err loc Label_in_uncurried_bs_attribute ;
115
128
self.expr self e
116
129
) args in
@@ -133,7 +146,7 @@ let generic_apply kind loc
133
146
Longident. Ldot (Ast_literal.Lid. js_unsafe,
134
147
Literals. method_run ^ string_of_int arity
135
148
) in
136
- Parsetree. Pexp_apply (Exp. ident {txt ; loc}, (" " ,fn) :: Ext_list. map (fun x -> " " ,x) args)
149
+ Parsetree. Pexp_apply (Exp. ident {txt ; loc}, (Ast_compatible. no_label ,fn) :: Ext_list. map (fun x -> Ast_compatible. no_label ,x) args)
137
150
else
138
151
let fn_type, args_type, result_type = Ast_comb. tuple_type_pair ~loc `Run arity in
139
152
let string_arity = string_of_int arity in
@@ -164,7 +177,7 @@ let method_apply loc self obj name args =
164
177
let generic_to_uncurry_type kind loc (mapper : Bs_ast_mapper.mapper ) label
165
178
(first_arg : Parsetree.core_type )
166
179
(typ : Parsetree.core_type ) =
167
- if label <> " " then
180
+ if not ( Ast_compatible. is_arg_label_simple label) then
168
181
Bs_syntaxerr. err loc Label_in_uncurried_bs_attribute ;
169
182
170
183
let rec aux acc (typ : Parsetree.core_type ) =
@@ -178,7 +191,7 @@ let generic_to_uncurry_type kind loc (mapper : Bs_ast_mapper.mapper) label
178
191
begin match typ.ptyp_desc with
179
192
| Ptyp_arrow (label, arg, body)
180
193
->
181
- if label <> " " then
194
+ if not ( Ast_compatible. is_arg_label_simple label) then
182
195
Bs_syntaxerr. err typ.ptyp_loc Label_in_uncurried_bs_attribute ;
183
196
aux (mapper.typ mapper arg :: acc) body
184
197
| _ -> mapper.typ mapper typ, acc
@@ -261,7 +274,7 @@ let generic_to_uncurry_exp kind loc (self : Bs_ast_mapper.mapper) pat body
261
274
Longident. Ldot ( Ast_literal.Lid. js_unsafe, Literals. fn_mk ^ string_of_int arity)
262
275
| `Method_callback ->
263
276
Longident. Ldot (Ast_literal.Lid. js_unsafe, Literals. fn_method ^ string_of_int arity) in
264
- Parsetree. Pexp_apply (Exp. ident {txt;loc} , [" " , body])
277
+ Parsetree. Pexp_apply (Exp. ident {txt;loc} , [ Ast_compatible. no_label, body])
265
278
266
279
else
267
280
let pval_prim =
@@ -291,7 +304,7 @@ let handle_debugger loc (payload : Ast_payload.t) =
291
304
| PStr [] ->
292
305
Parsetree. Pexp_apply
293
306
(Exp. ident {txt = Ldot (Ast_literal.Lid. js_unsafe, Literals. debugger ); loc},
294
- [" " , Ast_literal. val_unit ~loc () ])
307
+ [ Ast_compatible. no_label , Ast_literal. val_unit ~loc () ])
295
308
| _ ->
296
309
Location. raise_errorf ~loc " bs.debugger does not accept payload"
297
310
@@ -310,7 +323,7 @@ let handle_raw ~check_js_regex loc payload =
310
323
txt =
311
324
Ldot (Ast_literal.Lid. js_unsafe,
312
325
Literals. raw_expr)},
313
- [" " ,exp]
326
+ [Ast_compatible. no_label ,exp]
314
327
)
315
328
in
316
329
{ exp with pexp_desc }
@@ -352,7 +365,7 @@ let handle_raw_structure loc payload =
352
365
let pexp_desc =
353
366
Parsetree. Pexp_apply (
354
367
Exp. ident {txt = Ldot (Ast_literal.Lid. js_unsafe, Literals. raw_stmt); loc},
355
- [" " ,exp]) in
368
+ [ Ast_compatible. no_label ,exp]) in
356
369
Ast_helper.Str. eval
357
370
{ exp with pexp_desc }
358
371
@@ -393,7 +406,7 @@ let ocaml_obj_as_js_object
393
406
((val_name , [] , result ) ::
394
407
(if is_mutable then
395
408
[val_name ^ Literals. setter_suffix,[],
396
- to_method_type loc mapper " " result (Ast_literal. type_unit ~loc () ) ]
409
+ to_method_type loc mapper Ast_compatible. no_label result (Ast_literal. type_unit ~loc () ) ]
397
410
else
398
411
[] ) )
399
412
in
@@ -406,7 +419,7 @@ let ocaml_obj_as_js_object
406
419
method_name arity : Ast_core_type.t =
407
420
let result = Typ. var ~loc method_name in
408
421
if arity = 0 then
409
- to_method_type loc mapper " " (Ast_literal. type_unit ~loc () ) result
422
+ to_method_type loc mapper Ast_compatible. no_label (Ast_literal. type_unit ~loc () ) result
410
423
411
424
else
412
425
let tyvars =
@@ -417,7 +430,7 @@ let ocaml_obj_as_js_object
417
430
let method_rest =
418
431
Ext_list. fold_right (fun v acc -> Ast_compatible. arrow ~loc v acc)
419
432
rest result in
420
- to_method_type loc mapper " " x method_rest
433
+ to_method_type loc mapper Ast_compatible. no_label x method_rest
421
434
| _ -> assert false
422
435
end in
423
436
@@ -434,7 +447,7 @@ let ocaml_obj_as_js_object
434
447
| Some ty -> Typ. alias ~loc ty self_type_lit
435
448
in
436
449
if arity = 0 then
437
- to_method_callback_type loc mapper " " self_type result
450
+ to_method_callback_type loc mapper Ast_compatible. no_label self_type result
438
451
else
439
452
let tyvars =
440
453
Ext_list. init arity (fun i -> Typ. var ~loc (method_name ^ string_of_int i))
@@ -444,7 +457,7 @@ let ocaml_obj_as_js_object
444
457
let method_rest =
445
458
Ext_list. fold_right (fun v acc -> Ast_compatible. arrow ~loc v acc)
446
459
rest result in
447
- (to_method_callback_type loc mapper " " self_type
460
+ (to_method_callback_type loc mapper Ast_compatible. no_label self_type
448
461
(Ast_compatible. arrow ~loc x method_rest))
449
462
| _ -> assert false
450
463
end in
0 commit comments