File tree 5 files changed +57
-1
lines changed
5 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -358,6 +358,20 @@ let transl_declaration env sdecl id =
358
358
| (_ ,_ ,loc )::_ ->
359
359
Location. prerr_warning loc Warnings. Constraint_on_gadt
360
360
end ;
361
+ let has_optional attrs = Ext_list. exists attrs (fun ({txt } ,_ ) -> txt = " ns.optional" ) in
362
+ let scstrs =
363
+ Ext_list. map scstrs (fun ({pcd_args} as cstr ) ->
364
+ match pcd_args with
365
+ | Pcstr_tuple _ -> cstr
366
+ | Pcstr_record lds ->
367
+ {cstr with pcd_args = Pcstr_record (Ext_list. map lds (fun ld ->
368
+ if has_optional ld.pld_attributes then
369
+ let typ = ld.pld_type in
370
+ let typ = {typ with ptyp_desc = Ptyp_constr ({txt = Lident " option" ; loc= typ.ptyp_loc}, [typ])} in
371
+ {ld with pld_type = typ}
372
+ else ld
373
+ ))}
374
+ ) in
361
375
let all_constrs = ref StringSet. empty in
362
376
List. iter
363
377
(fun {pcd_name = {txt = name } } ->
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ var h10 = newrecord$3;
82
82
83
83
var foo = /* Foo */ {
84
84
name : "foo" ,
85
- age : undefined
85
+ age : 3
86
86
} ;
87
87
88
88
exports . f1 = f1 ;
Original file line number Diff line number Diff line change @@ -37956,6 +37956,20 @@ let transl_declaration env sdecl id =
37956
37956
| (_,_,loc)::_ ->
37957
37957
Location.prerr_warning loc Warnings.Constraint_on_gadt
37958
37958
end;
37959
+ let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
37960
+ let scstrs =
37961
+ Ext_list.map scstrs (fun ({pcd_args} as cstr) ->
37962
+ match pcd_args with
37963
+ | Pcstr_tuple _ -> cstr
37964
+ | Pcstr_record lds ->
37965
+ {cstr with pcd_args = Pcstr_record (Ext_list.map lds (fun ld ->
37966
+ if has_optional ld.pld_attributes then
37967
+ let typ = ld.pld_type in
37968
+ let typ = {typ with ptyp_desc = Ptyp_constr ({txt = Lident "option"; loc=typ.ptyp_loc}, [typ])} in
37969
+ {ld with pld_type = typ}
37970
+ else ld
37971
+ ))}
37972
+ ) in
37959
37973
let all_constrs = ref StringSet.empty in
37960
37974
List.iter
37961
37975
(fun {pcd_name = {txt = name}} ->
Original file line number Diff line number Diff line change @@ -37956,6 +37956,20 @@ let transl_declaration env sdecl id =
37956
37956
| (_,_,loc)::_ ->
37957
37957
Location.prerr_warning loc Warnings.Constraint_on_gadt
37958
37958
end;
37959
+ let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
37960
+ let scstrs =
37961
+ Ext_list.map scstrs (fun ({pcd_args} as cstr) ->
37962
+ match pcd_args with
37963
+ | Pcstr_tuple _ -> cstr
37964
+ | Pcstr_record lds ->
37965
+ {cstr with pcd_args = Pcstr_record (Ext_list.map lds (fun ld ->
37966
+ if has_optional ld.pld_attributes then
37967
+ let typ = ld.pld_type in
37968
+ let typ = {typ with ptyp_desc = Ptyp_constr ({txt = Lident "option"; loc=typ.ptyp_loc}, [typ])} in
37969
+ {ld with pld_type = typ}
37970
+ else ld
37971
+ ))}
37972
+ ) in
37959
37973
let all_constrs = ref StringSet.empty in
37960
37974
List.iter
37961
37975
(fun {pcd_name = {txt = name}} ->
Original file line number Diff line number Diff line change @@ -92954,6 +92954,20 @@ let transl_declaration env sdecl id =
92954
92954
| (_,_,loc)::_ ->
92955
92955
Location.prerr_warning loc Warnings.Constraint_on_gadt
92956
92956
end;
92957
+ let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
92958
+ let scstrs =
92959
+ Ext_list.map scstrs (fun ({pcd_args} as cstr) ->
92960
+ match pcd_args with
92961
+ | Pcstr_tuple _ -> cstr
92962
+ | Pcstr_record lds ->
92963
+ {cstr with pcd_args = Pcstr_record (Ext_list.map lds (fun ld ->
92964
+ if has_optional ld.pld_attributes then
92965
+ let typ = ld.pld_type in
92966
+ let typ = {typ with ptyp_desc = Ptyp_constr ({txt = Lident "option"; loc=typ.ptyp_loc}, [typ])} in
92967
+ {ld with pld_type = typ}
92968
+ else ld
92969
+ ))}
92970
+ ) in
92957
92971
let all_constrs = ref StringSet.empty in
92958
92972
List.iter
92959
92973
(fun {pcd_name = {txt = name}} ->
You can’t perform that action at this time.
0 commit comments