@@ -109,7 +109,7 @@ let exn_block_as_obj ~(stack : bool) (el : J.expression list) (ext : J.tag_info)
109109 | _ -> assert false
110110 in
111111 Object
112- (if stack then
112+ (None , if stack then
113113 Ext_list. mapi_append el
114114 (fun i e -> (Js_op. Lit (field_name i), e))
115115 [ (Js_op. Lit " Error" , E. new_ (E. js_global " Error" ) [] ) ]
@@ -725,9 +725,9 @@ and expression_desc cxt ~(level : int) f x : cxt =
725725 else E. runtime_call Js_runtime_modules. option " some" [ e ])
726726 | Caml_block (el , _ , _ , Blk_module fields ) ->
727727 expression_desc cxt ~level f
728- (Object
728+ (Object ( None ,
729729 (Ext_list. map_combine fields el (fun x ->
730- Js_op. Lit (Ext_ident. convert x))))
730+ Js_op. Lit (Ext_ident. convert x)))))
731731 (* name convention of Record is slight different from modules*)
732732 | Caml_block (el , mutable_flag , _ , Blk_record { fields; record_repr } ) -> (
733733 if
@@ -738,24 +738,24 @@ and expression_desc cxt ~(level : int) f x : cxt =
738738 match record_repr with
739739 | Record_regular ->
740740 expression_desc cxt ~level f
741- (Object (Ext_list. combine_array fields el (fun i -> Js_op. Lit i)))
741+ (Object (None , Ext_list. combine_array fields el (fun i -> Js_op. Lit i)))
742742 | Record_optional ->
743743 let fields =
744744 Ext_list. array_list_filter_map fields el (fun f x ->
745745 match x.expression_desc with
746746 | Undefined _ -> None
747747 | _ -> Some (Js_op. Lit f, x))
748748 in
749- expression_desc cxt ~level f (Object fields))
749+ expression_desc cxt ~level f (Object ( None , fields) ))
750750 | Caml_block (el , _ , _ , Blk_poly_var _ ) -> (
751751 match el with
752752 | [ tag; value ] ->
753753 expression_desc cxt ~level f
754- (Object
754+ (Object ( None ,
755755 [
756756 (Js_op. Lit Literals. polyvar_hash, tag);
757757 (Lit Literals. polyvar_value, value);
758- ])
758+ ]))
759759 | _ -> assert false )
760760 | Caml_block (el , _ , _ , ((Blk_extension | Blk_record_ext _ ) as ext )) ->
761761 expression_desc cxt ~level f (exn_block_as_obj ~stack: false el ext)
@@ -793,7 +793,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
793793 | Some t -> E. tag_type t )
794794 :: tails
795795 in
796- expression_desc cxt ~level f (Object objs)
796+ expression_desc cxt ~level f (Object ( None , objs) )
797797 | Caml_block (el , _ , tag , Blk_constructor p ) ->
798798 let not_is_cons = p.name <> Literals. cons in
799799 let tag_type = Ast_untagged_variants. process_tag_type p.attrs in
@@ -826,7 +826,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
826826 | [(_, e)] when untagged -> e.expression_desc
827827 | _ when untagged -> assert false (* should not happen *)
828828 (* TODO: put restriction on the variant definitions allowed, to make sure this never happens. *)
829- | _ -> J. Object objs in
829+ | _ -> J. Object ( None , objs) in
830830 expression_desc cxt ~level f exp
831831 | Caml_block
832832 ( _,
@@ -890,7 +890,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
890890 P. group f 1 (fun _ -> expression ~level: 3 cxt f e2)
891891 in
892892 if level > 2 then P. paren_vgroup f 1 action else action ()
893- | Object lst ->
893+ | Object ( dup , lst ) ->
894894 (* #1946 object literal is easy to be
895895 interpreted as block statement
896896 here we avoid parens in such case
@@ -899,11 +899,22 @@ and expression_desc cxt ~(level : int) f x : cxt =
899899 ]}
900900 *)
901901 P. cond_paren_group f (level > 1 ) (fun _ ->
902- if lst = [] then (
903- P. string f " {}" ;
904- cxt)
902+ let dup_expression e =
903+ expression ~level: 1 cxt f { e with expression_desc = J. Spread e }
904+ in
905+ if lst = [] then
906+ P. brace f (fun _ -> match dup with Some e -> dup_expression e | _ -> cxt)
905907 else
906- P. brace_vgroup f 1 (fun _ -> property_name_and_value_list cxt f lst))
908+ P. brace_vgroup f 1 (fun _ ->
909+ let cxt =
910+ match dup with
911+ | Some e ->
912+ let cxt = dup_expression e in
913+ comma_nl f;
914+ cxt
915+ | _ -> cxt
916+ in
917+ property_name_and_value_list cxt f lst))
907918 | Await e ->
908919 P. cond_paren_group f (level > 13 ) (fun _ ->
909920 P. string f " await " ;
0 commit comments