File tree Expand file tree Collapse file tree 5 files changed +57
-1
lines changed Expand file tree Collapse file tree 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 @@ -37960,6 +37960,20 @@ let transl_declaration env sdecl id =
37960
37960
| (_,_,loc)::_ ->
37961
37961
Location.prerr_warning loc Warnings.Constraint_on_gadt
37962
37962
end;
37963
+ let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
37964
+ let scstrs =
37965
+ Ext_list.map scstrs (fun ({pcd_args} as cstr) ->
37966
+ match pcd_args with
37967
+ | Pcstr_tuple _ -> cstr
37968
+ | Pcstr_record lds ->
37969
+ {cstr with pcd_args = Pcstr_record (Ext_list.map lds (fun ld ->
37970
+ if has_optional ld.pld_attributes then
37971
+ let typ = ld.pld_type in
37972
+ let typ = {typ with ptyp_desc = Ptyp_constr ({txt = Lident "option"; loc=typ.ptyp_loc}, [typ])} in
37973
+ {ld with pld_type = typ}
37974
+ else ld
37975
+ ))}
37976
+ ) in
37963
37977
let all_constrs = ref StringSet.empty in
37964
37978
List.iter
37965
37979
(fun {pcd_name = {txt = name}} ->
Original file line number Diff line number Diff line change @@ -37960,6 +37960,20 @@ let transl_declaration env sdecl id =
37960
37960
| (_,_,loc)::_ ->
37961
37961
Location.prerr_warning loc Warnings.Constraint_on_gadt
37962
37962
end;
37963
+ let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
37964
+ let scstrs =
37965
+ Ext_list.map scstrs (fun ({pcd_args} as cstr) ->
37966
+ match pcd_args with
37967
+ | Pcstr_tuple _ -> cstr
37968
+ | Pcstr_record lds ->
37969
+ {cstr with pcd_args = Pcstr_record (Ext_list.map lds (fun ld ->
37970
+ if has_optional ld.pld_attributes then
37971
+ let typ = ld.pld_type in
37972
+ let typ = {typ with ptyp_desc = Ptyp_constr ({txt = Lident "option"; loc=typ.ptyp_loc}, [typ])} in
37973
+ {ld with pld_type = typ}
37974
+ else ld
37975
+ ))}
37976
+ ) in
37963
37977
let all_constrs = ref StringSet.empty in
37964
37978
List.iter
37965
37979
(fun {pcd_name = {txt = name}} ->
Original file line number Diff line number Diff line change @@ -214132,6 +214132,20 @@ let transl_declaration env sdecl id =
214132
214132
| (_,_,loc)::_ ->
214133
214133
Location.prerr_warning loc Warnings.Constraint_on_gadt
214134
214134
end;
214135
+ let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
214136
+ let scstrs =
214137
+ Ext_list.map scstrs (fun ({pcd_args} as cstr) ->
214138
+ match pcd_args with
214139
+ | Pcstr_tuple _ -> cstr
214140
+ | Pcstr_record lds ->
214141
+ {cstr with pcd_args = Pcstr_record (Ext_list.map lds (fun ld ->
214142
+ if has_optional ld.pld_attributes then
214143
+ let typ = ld.pld_type in
214144
+ let typ = {typ with ptyp_desc = Ptyp_constr ({txt = Lident "option"; loc=typ.ptyp_loc}, [typ])} in
214145
+ {ld with pld_type = typ}
214146
+ else ld
214147
+ ))}
214148
+ ) in
214135
214149
let all_constrs = ref StringSet.empty in
214136
214150
List.iter
214137
214151
(fun {pcd_name = {txt = name}} ->
You can’t perform that action at this time.
0 commit comments