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
@@ -283,6 +279,7 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
283279 Ast_exp_handle_external. handle_raw_structure loc payload
284280 | Pstr_extension (({txt = (" bs.debugger.chrome" | " debugger.chrome" ) ;loc}, payload),_)
285281 ->
282+ Location. prerr_warning loc (Preprocessor " this extension can be safely removed" );
286283 Ast_structure. dummy_item loc
287284 | Pstr_type (
288285 _rf,
@@ -356,73 +353,31 @@ let unsafe_mapper : mapper =
356353 }
357354
358355
359- type action_table =
360- (Parsetree .expression option -> unit ) Map_string .t
361- (* * global configurations below *)
362- let common_actions_table :
363- (string * (Parsetree. expression option -> unit )) list =
364- [
365- ]
366356
367357
368- let structural_config_table : action_table =
369- Map_string. of_list
370- (( " no_export" ,
371- (fun x ->
372- no_export := (
373- match x with
374- | Some e -> Ast_payload. assert_bool_lit e
375- | None -> true )
376- ))
377- :: common_actions_table)
378358
379- let signature_config_table : action_table =
380- Map_string. of_list common_actions_table
381359
382360
383361let rewrite_signature (x : Parsetree.signature ) =
384362 Bs_ast_invariant. iter_warnings_on_sigi x;
385- let result =
386- match x with
387- | {psig_desc = Psig_attribute ({txt = " ocaml.ppx.context" },_)}
388- :: {psig_desc = Psig_attribute ({txt = " bs.config" ; loc}, payload); _} :: rest
389- | {psig_desc = Psig_attribute ({txt = " bs.config" ; loc}, payload); _} :: rest
390- ->
391- Ext_list. iter (Ast_payload. ident_or_record_as_config loc payload)
392- (Ast_payload. table_dispatch signature_config_table) ;
393- unsafe_mapper.signature unsafe_mapper rest
394- | _ ->
363+ Ast_config. iter_on_bs_config_sigi x;
364+ let result =
395365 unsafe_mapper.signature unsafe_mapper x in
396- reset () ;
397366 (* Keep this check, since the check is not inexpensive*)
398367 Bs_ast_invariant. emit_external_warnings_on_signature result;
399368 result
400369
370+
371+
372+
373+
374+
401375(* Note we also drop attributes like [@@@bs.deriving ] for convenience*)
402376let rewrite_implementation (x : Parsetree.structure ) =
403377 Bs_ast_invariant. iter_warnings_on_stru x ;
378+ Ast_config. iter_on_bs_config_stru x ;
404379 let result =
405- match x with
406- | {pstr_desc = Pstr_attribute ({txt = " ocaml.ppx.context" },_)}
407- :: {pstr_desc = Pstr_attribute ({txt = " bs.config" ; loc}, payload); _} :: rest
408- | {pstr_desc = Pstr_attribute ({txt = " bs.config" ; loc}, payload); _} :: rest
409- ->
410- begin
411- Ext_list. iter (Ast_payload. ident_or_record_as_config loc payload)
412- (Ast_payload. table_dispatch structural_config_table) ;
413- let rest = unsafe_mapper.structure unsafe_mapper rest in
414- if ! no_export then
415- Ast_helper. [Str. include_ ~loc
416- (Incl. mk ~loc
417- (Mod. constraint_ ~loc
418- (Mod. structure ~loc rest )
419- (Mty. signature ~loc [] )
420- ))]
421- else rest
422- end
423- | _ ->
424380 unsafe_mapper.structure unsafe_mapper x in
425- reset () ;
426381 (* Keep this check since it is not inexpensive*)
427382 Bs_ast_invariant. emit_external_warnings_on_structure result;
428383 result
0 commit comments