Skip to content

Commit 48289d6

Browse files
committed
tweak
1 parent d5aa5c4 commit 48289d6

File tree

4 files changed

+108
-99
lines changed

4 files changed

+108
-99
lines changed

jscomp/syntax/bs_builtin_ppx.ml

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,6 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
270270
)
271271
| _ -> default_mapper.signature_item self sigi
272272

273-
let local_module_name =
274-
let v = ref 0 in
275-
fun () ->
276-
incr v ;
277-
"local_" ^ (string_of_int !v)
278273

279274
let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
280275
match str.pstr_desc with
@@ -337,51 +332,59 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
337332
end
338333
| _ -> default_mapper.structure_item self str
339334

335+
let local_module_name =
336+
let v = ref 0 in
337+
fun () ->
338+
incr v ;
339+
"local_" ^ string_of_int !v
340+
341+
342+
let expand_local loc (stru : Ast_structure.t) (acc : Ast_structure.t) : Ast_structure.t =
343+
Ext_list.iter stru Typemod_hide.check;
344+
let local_module_name = local_module_name () in
345+
let open Ast_helper in
346+
Str.module_
347+
~loc
348+
{ pmb_name = {txt = local_module_name; loc};
349+
pmb_expr = {
350+
pmod_desc= Pmod_structure stru;
351+
pmod_loc = loc;
352+
pmod_attributes = [] };
353+
pmb_attributes = Typemod_hide.attrs; pmb_loc = loc} ::
354+
Str.open_ ~loc {
355+
popen_lid = {txt = Lident local_module_name; loc};
356+
popen_override = Override;
357+
popen_loc = loc;
358+
popen_attributes = []
359+
} :: acc
340360

341361
let rec
342362
structure_mapper (self : mapper) stru =
343363
match stru with
344364
| [] -> []
345365
| item::rest ->
346366
let new_x = self.structure_item self item in
367+
let rest = (structure_mapper self rest) in
347368
match new_x.pstr_desc with
348369
| Pstr_extension (({txt = ("bs.debugger.chrome" | "debugger.chrome") ;loc}, _),_)
349370
->
350371
Location.prerr_warning loc (Preprocessor "this extension can be safely removed");
351-
(structure_mapper self rest)
372+
rest
352373
| Pstr_extension ( ({txt = ("bs.raw"| "raw") ; loc}, payload), _attrs)
353374
->
354-
Ast_exp_handle_external.handle_raw_structure loc payload :: (structure_mapper self rest)
375+
Ast_exp_handle_external.handle_raw_structure loc payload :: rest
355376
| Pstr_extension (({txt = "local"; loc}, payload),_)
356377
->
357378
begin match payload with
358379
| PStr stru ->
359-
(* check no module, no type allowed *)
360-
(* let stru = self.structure self stru in *)
361-
Ext_list.iter stru Typemod_hide.check;
362-
let local_module_name = local_module_name () in
363-
let open Ast_helper in
364-
Str.module_
365-
~loc
366-
{ pmb_name = {txt = local_module_name; loc};
367-
pmb_expr = {
368-
pmod_desc= Pmod_structure stru;
369-
pmod_loc = loc;
370-
pmod_attributes = [] };
371-
pmb_attributes = Typemod_hide.attrs; pmb_loc = loc} ::
372-
Str.open_ ~loc {
373-
popen_lid = {txt = Lident local_module_name; loc};
374-
popen_override = Override;
375-
popen_loc = loc;
376-
popen_attributes = []
377-
} :: structure_mapper self rest
380+
expand_local loc stru rest
378381
| PSig _
379382
| PTyp _
380383
| PPat _ ->
381384
Location.raise_errorf ~loc "local extension is not support"
382385
end
383386
| _ ->
384-
new_x :: (structure_mapper self rest)
387+
new_x :: rest
385388

386389
let unsafe_mapper : mapper =
387390
{ default_mapper with

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -315455,11 +315455,6 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
315455315455
)
315456315456
| _ -> default_mapper.signature_item self sigi
315457315457

315458-
let local_module_name =
315459-
let v = ref 0 in
315460-
fun () ->
315461-
incr v ;
315462-
"local_" ^ (string_of_int !v)
315463315458

315464315459
let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
315465315460
match str.pstr_desc with
@@ -315522,6 +315517,31 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
315522315517
end
315523315518
| _ -> default_mapper.structure_item self str
315524315519

315520+
let local_module_name =
315521+
let v = ref 0 in
315522+
fun () ->
315523+
incr v ;
315524+
"local_" ^ string_of_int !v
315525+
315526+
315527+
let expand_local loc (stru : Ast_structure.t) (acc : Ast_structure.t) : Ast_structure.t =
315528+
Ext_list.iter stru Typemod_hide.check;
315529+
let local_module_name = local_module_name () in
315530+
let open Ast_helper in
315531+
Str.module_
315532+
~loc
315533+
{ pmb_name = {txt = local_module_name; loc};
315534+
pmb_expr = {
315535+
pmod_desc= Pmod_structure stru;
315536+
pmod_loc = loc;
315537+
pmod_attributes = [] };
315538+
pmb_attributes = Typemod_hide.attrs; pmb_loc = loc} ::
315539+
Str.open_ ~loc {
315540+
popen_lid = {txt = Lident local_module_name; loc};
315541+
popen_override = Override;
315542+
popen_loc = loc;
315543+
popen_attributes = []
315544+
} :: acc
315525315545

315526315546
let rec
315527315547
structure_mapper (self : mapper) stru =
@@ -315541,25 +315561,7 @@ let rec
315541315561
->
315542315562
begin match payload with
315543315563
| PStr stru ->
315544-
(* check no module, no type allowed *)
315545-
(* let stru = self.structure self stru in *)
315546-
Ext_list.iter stru Typemod_hide.check;
315547-
let local_module_name = local_module_name () in
315548-
let open Ast_helper in
315549-
Str.module_
315550-
~loc
315551-
{ pmb_name = {txt = local_module_name; loc};
315552-
pmb_expr = {
315553-
pmod_desc= Pmod_structure stru;
315554-
pmod_loc = loc;
315555-
pmod_attributes = [] };
315556-
pmb_attributes = Typemod_hide.attrs; pmb_loc = loc} ::
315557-
Str.open_ ~loc {
315558-
popen_lid = {txt = Lident local_module_name; loc};
315559-
popen_override = Override;
315560-
popen_loc = loc;
315561-
popen_attributes = []
315562-
} :: structure_mapper self rest
315564+
expand_local loc stru (structure_mapper self rest)
315563315565
| PSig _
315564315566
| PTyp _
315565315567
| PPat _ ->

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -315455,11 +315455,6 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
315455315455
)
315456315456
| _ -> default_mapper.signature_item self sigi
315457315457

315458-
let local_module_name =
315459-
let v = ref 0 in
315460-
fun () ->
315461-
incr v ;
315462-
"local_" ^ (string_of_int !v)
315463315458

315464315459
let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
315465315460
match str.pstr_desc with
@@ -315522,6 +315517,31 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
315522315517
end
315523315518
| _ -> default_mapper.structure_item self str
315524315519

315520+
let local_module_name =
315521+
let v = ref 0 in
315522+
fun () ->
315523+
incr v ;
315524+
"local_" ^ string_of_int !v
315525+
315526+
315527+
let expand_local loc (stru : Ast_structure.t) (acc : Ast_structure.t) : Ast_structure.t =
315528+
Ext_list.iter stru Typemod_hide.check;
315529+
let local_module_name = local_module_name () in
315530+
let open Ast_helper in
315531+
Str.module_
315532+
~loc
315533+
{ pmb_name = {txt = local_module_name; loc};
315534+
pmb_expr = {
315535+
pmod_desc= Pmod_structure stru;
315536+
pmod_loc = loc;
315537+
pmod_attributes = [] };
315538+
pmb_attributes = Typemod_hide.attrs; pmb_loc = loc} ::
315539+
Str.open_ ~loc {
315540+
popen_lid = {txt = Lident local_module_name; loc};
315541+
popen_override = Override;
315542+
popen_loc = loc;
315543+
popen_attributes = []
315544+
} :: acc
315525315545

315526315546
let rec
315527315547
structure_mapper (self : mapper) stru =
@@ -315541,25 +315561,7 @@ let rec
315541315561
->
315542315562
begin match payload with
315543315563
| PStr stru ->
315544-
(* check no module, no type allowed *)
315545-
(* let stru = self.structure self stru in *)
315546-
Ext_list.iter stru Typemod_hide.check;
315547-
let local_module_name = local_module_name () in
315548-
let open Ast_helper in
315549-
Str.module_
315550-
~loc
315551-
{ pmb_name = {txt = local_module_name; loc};
315552-
pmb_expr = {
315553-
pmod_desc= Pmod_structure stru;
315554-
pmod_loc = loc;
315555-
pmod_attributes = [] };
315556-
pmb_attributes = Typemod_hide.attrs; pmb_loc = loc} ::
315557-
Str.open_ ~loc {
315558-
popen_lid = {txt = Lident local_module_name; loc};
315559-
popen_override = Override;
315560-
popen_loc = loc;
315561-
popen_attributes = []
315562-
} :: structure_mapper self rest
315564+
expand_local loc stru (structure_mapper self rest)
315563315565
| PSig _
315564315566
| PTyp _
315565315567
| PPat _ ->

lib/4.06.1/whole_compiler.ml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -413158,11 +413158,6 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
413158413158
)
413159413159
| _ -> default_mapper.signature_item self sigi
413160413160

413161-
let local_module_name =
413162-
let v = ref 0 in
413163-
fun () ->
413164-
incr v ;
413165-
"local_" ^ (string_of_int !v)
413166413161

413167413162
let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
413168413163
match str.pstr_desc with
@@ -413225,6 +413220,31 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
413225413220
end
413226413221
| _ -> default_mapper.structure_item self str
413227413222

413223+
let local_module_name =
413224+
let v = ref 0 in
413225+
fun () ->
413226+
incr v ;
413227+
"local_" ^ string_of_int !v
413228+
413229+
413230+
let expand_local loc (stru : Ast_structure.t) (acc : Ast_structure.t) : Ast_structure.t =
413231+
Ext_list.iter stru Typemod_hide.check;
413232+
let local_module_name = local_module_name () in
413233+
let open Ast_helper in
413234+
Str.module_
413235+
~loc
413236+
{ pmb_name = {txt = local_module_name; loc};
413237+
pmb_expr = {
413238+
pmod_desc= Pmod_structure stru;
413239+
pmod_loc = loc;
413240+
pmod_attributes = [] };
413241+
pmb_attributes = Typemod_hide.attrs; pmb_loc = loc} ::
413242+
Str.open_ ~loc {
413243+
popen_lid = {txt = Lident local_module_name; loc};
413244+
popen_override = Override;
413245+
popen_loc = loc;
413246+
popen_attributes = []
413247+
} :: acc
413228413248

413229413249
let rec
413230413250
structure_mapper (self : mapper) stru =
@@ -413244,25 +413264,7 @@ let rec
413244413264
->
413245413265
begin match payload with
413246413266
| PStr stru ->
413247-
(* check no module, no type allowed *)
413248-
(* let stru = self.structure self stru in *)
413249-
Ext_list.iter stru Typemod_hide.check;
413250-
let local_module_name = local_module_name () in
413251-
let open Ast_helper in
413252-
Str.module_
413253-
~loc
413254-
{ pmb_name = {txt = local_module_name; loc};
413255-
pmb_expr = {
413256-
pmod_desc= Pmod_structure stru;
413257-
pmod_loc = loc;
413258-
pmod_attributes = [] };
413259-
pmb_attributes = Typemod_hide.attrs; pmb_loc = loc} ::
413260-
Str.open_ ~loc {
413261-
popen_lid = {txt = Lident local_module_name; loc};
413262-
popen_override = Override;
413263-
popen_loc = loc;
413264-
popen_attributes = []
413265-
} :: structure_mapper self rest
413267+
expand_local loc stru (structure_mapper self rest)
413266413268
| PSig _
413267413269
| PTyp _
413268413270
| PPat _ ->

0 commit comments

Comments
 (0)