53
53
*)
54
54
55
55
56
- let record_as_js_object = ref false (* otherwise has an attribute *)
57
- let no_export = ref false
56
+
58
57
59
58
let () =
60
59
Ast_derive_projector. init () ;
61
60
Ast_derive_js_mapper. init ()
62
61
63
- let reset () =
64
- record_as_js_object := false ;
65
- no_export := false
66
62
67
63
68
64
@@ -74,7 +70,7 @@ let expr_mapper (self : mapper) (e : Parsetree.expression) =
74
70
match e.pexp_desc with
75
71
(* * Its output should not be rewritten anymore *)
76
72
| Pexp_extension extension ->
77
- Ast_exp_extension. handle_extension record_as_js_object e self extension
73
+ Ast_exp_extension. handle_extension Js_config. record_as_js_object e self extension
78
74
| Pexp_constant (
79
75
Pconst_string
80
76
(s, (Some delim)))
@@ -140,7 +136,7 @@ let expr_mapper (self : mapper) (e : Parsetree.expression) =
140
136
constraint 'b :> 'a
141
137
]}
142
138
*)
143
- if ! record_as_js_object then
139
+ if ! Js_config. record_as_js_object then
144
140
(match opt_exp with
145
141
| None ->
146
142
{ e with
@@ -180,7 +176,7 @@ let expr_mapper (self : mapper) (e : Parsetree.expression) =
180
176
181
177
182
178
let typ_mapper (self : mapper ) (typ : Parsetree.core_type ) =
183
- Ast_core_type_class_type. typ_mapper record_as_js_object self typ
179
+ Ast_core_type_class_type. typ_mapper Js_config. record_as_js_object self typ
184
180
185
181
let class_type_mapper (self : mapper ) ({pcty_attributes; pcty_loc} as ctd : Parsetree.class_type ) =
186
182
match Ast_attributes. process_bs pcty_attributes with
@@ -357,73 +353,31 @@ let unsafe_mapper : mapper =
357
353
}
358
354
359
355
360
- type action_table =
361
- (Parsetree .expression option -> unit ) Map_string .t
362
- (* * global configurations below *)
363
- let common_actions_table :
364
- (string * (Parsetree. expression option -> unit )) list =
365
- [
366
- ]
367
356
368
357
369
- let structural_config_table : action_table =
370
- Map_string. of_list
371
- (( " no_export" ,
372
- (fun x ->
373
- no_export := (
374
- match x with
375
- | Some e -> Ast_payload. assert_bool_lit e
376
- | None -> true )
377
- ))
378
- :: common_actions_table)
379
358
380
- let signature_config_table : action_table =
381
- Map_string. of_list common_actions_table
382
359
383
360
384
361
let rewrite_signature (x : Parsetree.signature ) =
385
362
Bs_ast_invariant. iter_warnings_on_sigi x;
386
- let result =
387
- match x with
388
- | {psig_desc = Psig_attribute ({txt = " ocaml.ppx.context" },_)}
389
- :: {psig_desc = Psig_attribute ({txt = " bs.config" ; loc}, payload); _} :: rest
390
- | {psig_desc = Psig_attribute ({txt = " bs.config" ; loc}, payload); _} :: rest
391
- ->
392
- Ext_list. iter (Ast_payload. ident_or_record_as_config loc payload)
393
- (Ast_payload. table_dispatch signature_config_table) ;
394
- unsafe_mapper.signature unsafe_mapper rest
395
- | _ ->
363
+ Ast_config. iter_on_bs_config_sigi x;
364
+ let result =
396
365
unsafe_mapper.signature unsafe_mapper x in
397
- reset () ;
398
366
(* Keep this check, since the check is not inexpensive*)
399
367
Bs_ast_invariant. emit_external_warnings_on_signature result;
400
368
result
401
369
370
+
371
+
372
+
373
+
374
+
402
375
(* Note we also drop attributes like [@@@bs.deriving ] for convenience*)
403
376
let rewrite_implementation (x : Parsetree.structure ) =
404
377
Bs_ast_invariant. iter_warnings_on_stru x ;
378
+ Ast_config. iter_on_bs_config_stru x ;
405
379
let result =
406
- match x with
407
- | {pstr_desc = Pstr_attribute ({txt = " ocaml.ppx.context" },_)}
408
- :: {pstr_desc = Pstr_attribute ({txt = " bs.config" ; loc}, payload); _} :: rest
409
- | {pstr_desc = Pstr_attribute ({txt = " bs.config" ; loc}, payload); _} :: rest
410
- ->
411
- begin
412
- Ext_list. iter (Ast_payload. ident_or_record_as_config loc payload)
413
- (Ast_payload. table_dispatch structural_config_table) ;
414
- let rest = unsafe_mapper.structure unsafe_mapper rest in
415
- if ! no_export then
416
- Ast_helper. [Str. include_ ~loc
417
- (Incl. mk ~loc
418
- (Mod. constraint_ ~loc
419
- (Mod. structure ~loc rest )
420
- (Mty. signature ~loc [] )
421
- ))]
422
- else rest
423
- end
424
- | _ ->
425
380
unsafe_mapper.structure unsafe_mapper x in
426
- reset () ;
427
381
(* Keep this check since it is not inexpensive*)
428
382
Bs_ast_invariant. emit_external_warnings_on_structure result;
429
383
result
0 commit comments