@@ -150,6 +150,8 @@ let create_local_external loc
150150 pexp_loc = loc
151151 })
152152
153+ let record_as_js_object = ref None (* otherwise has an attribute *)
154+ let obj_type_as_js_obj_type = ref false
153155let handle_record_as_js_object
154156 loc
155157 attr
@@ -352,25 +354,48 @@ let handle_typ
352354 ptyp_attributes ;
353355 ptyp_loc = loc
354356 } ->
355- let methods = List. map (fun (label , ptyp_attrs , core_type ) ->
356- match find_uncurry_attrs_and_remove ptyp_attrs with
357- | None , _ -> label, ptyp_attrs , self.typ self core_type
358- | Some v , ptyp_attrs ->
359- label , ptyp_attrs, self.typ self
360- { core_type with ptyp_attributes = v :: core_type .ptyp_attributes}
361- ) methods in
362357 begin match Ext_list. exclude_with_fact (function
363358 | {Location. txt = "bs.obj" ; _} , _ -> true
364359 | _ -> false ) ptyp_attributes with
365- | None , _ ->
366- {ty with ptyp_desc = Ptyp_object (methods, closed_flag)}
367360 | Some _ , ptyp_attributes ->
361+ let methods =
362+ Ext_ref. protect obj_type_as_js_obj_type true begin fun _ ->
363+ List. map (fun (label , ptyp_attrs , core_type ) ->
364+ match find_uncurry_attrs_and_remove ptyp_attrs with
365+ | None , _ -> label, ptyp_attrs , self.typ self core_type
366+ | Some v , ptyp_attrs ->
367+ label , ptyp_attrs, self.typ self
368+ { core_type with ptyp_attributes = v :: core_type .ptyp_attributes}
369+ ) methods
370+ end
371+ in
372+
368373 {ptyp_desc =
369374 Ptyp_constr ({ txt = js_obj_type_id () ; loc},
370375 [{ ty with ptyp_desc = Ptyp_object (methods, closed_flag);
371376 ptyp_attributes }]);
372377 ptyp_attributes = [] ;
373378 ptyp_loc = loc }
379+ | None , _ ->
380+ let methods =
381+ List. map (fun (label , ptyp_attrs , core_type ) ->
382+ match find_uncurry_attrs_and_remove ptyp_attrs with
383+ | None , _ -> label, ptyp_attrs , self.typ self core_type
384+ | Some v , ptyp_attrs ->
385+ label , ptyp_attrs, self.typ self
386+ { core_type with ptyp_attributes = v :: core_type .ptyp_attributes}
387+ ) methods
388+ in
389+ if ! obj_type_as_js_obj_type then
390+ {ptyp_desc =
391+ Ptyp_constr ({ txt = js_obj_type_id () ; loc},
392+ [{ ty with ptyp_desc = Ptyp_object (methods, closed_flag);
393+ ptyp_attributes }]);
394+ ptyp_attributes = [] ;
395+ ptyp_loc = loc }
396+ else
397+ {ty with ptyp_desc = Ptyp_object (methods, closed_flag)}
398+
374399 end
375400 | _ -> super.typ self ty
376401
@@ -708,12 +733,22 @@ let rec unsafe_mapper : Ast_mapper.mapper =
708733 e.pexp_attributes
709734 with
710735 | Some attr , pexp_attributes ->
711- { e with
712- pexp_desc = handle_record_as_js_object e.pexp_loc attr label_exprs mapper;
713- pexp_attributes
714- }
736+ Ext_ref. protect record_as_js_object (Some attr) begin fun () ->
737+ { e with
738+ pexp_desc = handle_record_as_js_object e.pexp_loc attr label_exprs mapper;
739+ pexp_attributes
740+ }
741+ end
715742 | None , _ ->
716- Ast_mapper. default_mapper.expr mapper e
743+ begin match ! record_as_js_object with
744+ | Some attr
745+ ->
746+ { e with
747+ pexp_desc = handle_record_as_js_object e.pexp_loc attr label_exprs mapper;
748+ }
749+ | None ->
750+ Ast_mapper. default_mapper.expr mapper e
751+ end
717752 end
718753 | _ -> Ast_mapper. default_mapper.expr mapper e
719754 );
0 commit comments