@@ -136,7 +136,7 @@ type cxt = Ext_pp_scope.t
136
136
let semi f = P. string f L. semi
137
137
let comma f = P. string f L. comma
138
138
139
- let exn_block_as_obj (el : J.expression list ) (ext : J.tag_info ) : J.expression_desc =
139
+ let exn_block_as_obj ~ stack (el : J.expression list ) (ext : J.tag_info ) : J.expression_desc =
140
140
let field_name =
141
141
match ext with
142
142
| Blk_extension -> (fun i ->
@@ -152,9 +152,13 @@ let exn_block_as_obj (el : J.expression list) (ext : J.tag_info) : J.expression_
152
152
| i -> ss.(i-1 ))
153
153
| _ -> assert false in
154
154
Object (
155
- Ext_list. mapi el (fun i e -> field_name i, e)
155
+ if stack then
156
+ Ext_list. mapi_append el (fun i e -> field_name i, e)
157
+ [" Error" ,
158
+ E. new_ (E. js_global " Error" ) []
159
+ ]
160
+ else Ext_list. mapi el (fun i e -> field_name i, e)
156
161
)
157
- (* @ ["Error", {expression_desc = New ({expression_desc = Var (Id (Ext_ident .(create_js "Error")));comment = None},None); comment = None}] *)
158
162
159
163
let rec iter_lst cxt (f : P.t ) ls element inter =
160
164
match ls with
@@ -839,7 +843,7 @@ and expression_desc cxt ~(level:int) f x : cxt =
839
843
(* name convention of Record is slight different from modules
840
844
*)
841
845
| Caml_block (el ,_ , _ , (Blk_extension | Blk_record_ext _ as ext )) ->
842
- expression_desc cxt ~level f (exn_block_as_obj el ext)
846
+ expression_desc cxt ~level f (exn_block_as_obj ~stack: false el ext)
843
847
| Caml_block ( el, mutable_flag, tag, tag_info)
844
848
->
845
849
(* Note that, if we ignore more than tag [0] we loose some information
@@ -1292,6 +1296,10 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
1292
1296
P. newline f;
1293
1297
statement_list false cxt f def ))
1294
1298
| Throw e ->
1299
+ let e = match e.expression_desc with
1300
+ | Caml_block (el ,_ ,_ ,(Blk_extension | Blk_record_ext _ as ext )) ->
1301
+ {e with expression_desc = exn_block_as_obj ~stack: true el ext}
1302
+ | _ -> e in
1295
1303
P. string f L. throw;
1296
1304
P. space f ;
1297
1305
P. group f throw_indent (fun _ ->
0 commit comments