5353*)
5454
5555
56- let record_as_js_object = ref false (* otherwise has an attribute *)
57- let no_export = ref false
56+
5857
5958let () =
6059 Ast_derive_projector. init () ;
6160 Ast_derive_js_mapper. init ()
6261
63- let reset () =
64- record_as_js_object := false ;
65- no_export := false
6662
6763
6864
@@ -74,7 +70,7 @@ let expr_mapper (self : mapper) (e : Parsetree.expression) =
7470 match e.pexp_desc with
7571 (* * Its output should not be rewritten anymore *)
7672 | 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
7874 | Pexp_constant (
7975 Pconst_string
8076 (s, (Some delim)))
@@ -140,7 +136,7 @@ let expr_mapper (self : mapper) (e : Parsetree.expression) =
140136 constraint 'b :> 'a
141137 ]}
142138 *)
143- if ! record_as_js_object then
139+ if ! Js_config. record_as_js_object then
144140 (match opt_exp with
145141 | None ->
146142 { e with
@@ -180,7 +176,7 @@ let expr_mapper (self : mapper) (e : Parsetree.expression) =
180176
181177
182178let 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
184180
185181let class_type_mapper (self : mapper ) ({pcty_attributes; pcty_loc} as ctd : Parsetree.class_type ) =
186182 match Ast_attributes. process_bs pcty_attributes with
@@ -357,73 +353,31 @@ let unsafe_mapper : mapper =
357353 }
358354
359355
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- ]
367356
368357
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)
379358
380- let signature_config_table : action_table =
381- Map_string. of_list common_actions_table
382359
383360
384361let rewrite_signature (x : Parsetree.signature ) =
385362 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 =
396365 unsafe_mapper.signature unsafe_mapper x in
397- reset () ;
398366 (* Keep this check, since the check is not inexpensive*)
399367 Bs_ast_invariant. emit_external_warnings_on_signature result;
400368 result
401369
370+
371+
372+
373+
374+
402375(* Note we also drop attributes like [@@@bs.deriving ] for convenience*)
403376let rewrite_implementation (x : Parsetree.structure ) =
404377 Bs_ast_invariant. iter_warnings_on_stru x ;
378+ Ast_config. iter_on_bs_config_stru x ;
405379 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- | _ ->
425380 unsafe_mapper.structure unsafe_mapper x in
426- reset () ;
427381 (* Keep this check since it is not inexpensive*)
428382 Bs_ast_invariant. emit_external_warnings_on_structure result;
429383 result
0 commit comments