@@ -109,7 +109,7 @@ let exn_block_as_obj ~(stack : bool) (el : J.expression list) (ext : J.tag_info)
109
109
| _ -> assert false
110
110
in
111
111
Object
112
- (if stack then
112
+ (None , if stack then
113
113
Ext_list. mapi_append el
114
114
(fun i e -> (Js_op. Lit (field_name i), e))
115
115
[ (Js_op. Lit " Error" , E. new_ (E. js_global " Error" ) [] ) ]
@@ -725,9 +725,9 @@ and expression_desc cxt ~(level : int) f x : cxt =
725
725
else E. runtime_call Js_runtime_modules. option " some" [ e ])
726
726
| Caml_block (el , _ , _ , Blk_module fields ) ->
727
727
expression_desc cxt ~level f
728
- (Object
728
+ (Object ( None ,
729
729
(Ext_list. map_combine fields el (fun x ->
730
- Js_op. Lit (Ext_ident. convert x))))
730
+ Js_op. Lit (Ext_ident. convert x)))))
731
731
(* name convention of Record is slight different from modules*)
732
732
| Caml_block (el , mutable_flag , _ , Blk_record { fields; record_repr } ) -> (
733
733
if
@@ -738,24 +738,24 @@ and expression_desc cxt ~(level : int) f x : cxt =
738
738
match record_repr with
739
739
| Record_regular ->
740
740
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)))
742
742
| Record_optional ->
743
743
let fields =
744
744
Ext_list. array_list_filter_map fields el (fun f x ->
745
745
match x.expression_desc with
746
746
| Undefined _ -> None
747
747
| _ -> Some (Js_op. Lit f, x))
748
748
in
749
- expression_desc cxt ~level f (Object fields))
749
+ expression_desc cxt ~level f (Object ( None , fields) ))
750
750
| Caml_block (el , _ , _ , Blk_poly_var _ ) -> (
751
751
match el with
752
752
| [ tag; value ] ->
753
753
expression_desc cxt ~level f
754
- (Object
754
+ (Object ( None ,
755
755
[
756
756
(Js_op. Lit Literals. polyvar_hash, tag);
757
757
(Lit Literals. polyvar_value, value);
758
- ])
758
+ ]))
759
759
| _ -> assert false )
760
760
| Caml_block (el , _ , _ , ((Blk_extension | Blk_record_ext _ ) as ext )) ->
761
761
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 =
793
793
| Some t -> E. tag_type t )
794
794
:: tails
795
795
in
796
- expression_desc cxt ~level f (Object objs)
796
+ expression_desc cxt ~level f (Object ( None , objs) )
797
797
| Caml_block (el , _ , tag , Blk_constructor p ) ->
798
798
let not_is_cons = p.name <> Literals. cons in
799
799
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 =
826
826
| [(_, e)] when untagged -> e.expression_desc
827
827
| _ when untagged -> assert false (* should not happen *)
828
828
(* 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
830
830
expression_desc cxt ~level f exp
831
831
| Caml_block
832
832
( _,
@@ -890,7 +890,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
890
890
P. group f 1 (fun _ -> expression ~level: 3 cxt f e2)
891
891
in
892
892
if level > 2 then P. paren_vgroup f 1 action else action ()
893
- | Object lst ->
893
+ | Object ( dup , lst ) ->
894
894
(* #1946 object literal is easy to be
895
895
interpreted as block statement
896
896
here we avoid parens in such case
@@ -899,11 +899,22 @@ and expression_desc cxt ~(level : int) f x : cxt =
899
899
]}
900
900
*)
901
901
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)
905
907
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))
907
918
| Await e ->
908
919
P. cond_paren_group f (level > 13 ) (fun _ ->
909
920
P. string f " await " ;
0 commit comments