Skip to content

Commit b77be05

Browse files
committed
Fix implementation of directives.
1 parent 37e105f commit b77be05

File tree

8 files changed

+90
-37
lines changed

8 files changed

+90
-37
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# 10.1.4
1414

1515
#### :bug: Bug Fix
16-
- Fix implementation of directives
16+
- Fix implementation of directives https://github.com/rescript-lang/rescript-compiler/pull/6052
1717

1818
# 10.1.3
1919

jscomp/core/js_implementation.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let process_with_gentype cmt_file =
4646

4747
let after_parsing_sig ppf outputprefix ast =
4848
if !Clflags.only_parse = false then (
49-
Ast_config.iter_on_bs_config_sigi ast;
49+
Ast_config.process_sig ast;
5050
if !Js_config.modules then
5151
output_deps_set !Location.input_name
5252
(Ast_extract.read_parse_and_extract Mli ast);
@@ -139,7 +139,7 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
139139
if !Clflags.only_parse = false then (
140140
Js_config.all_module_aliases :=
141141
!Clflags.assume_no_mli = Mli_non_exists && all_module_alias ast;
142-
Ast_config.iter_on_bs_config_stru ast;
142+
Ast_config.process_str ast;
143143
let ast = if !Js_config.no_export then no_export ast else ast in
144144
if !Js_config.modules then
145145
output_deps_set !Location.input_name

jscomp/frontend/ast_config.ml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ let signature_config_table : action_table ref = ref Map_string.empty
3838
let add_signature k v =
3939
signature_config_table := Map_string.add !signature_config_table k v
4040

41-
let rec iter_on_bs_config_stru (x : Parsetree.structure) =
41+
let process_directives str =
42+
Js_config.directives := []; (* Restt: multiple calls possible e.g. with bsc from the command-line *)
43+
str |> List.iter(fun (item : Parsetree.structure_item) -> match item.pstr_desc with
44+
| Pstr_attribute ({ txt = "directive" },
45+
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
46+
Js_config.directives := !Js_config.directives @ [d]
47+
| _ -> ())
48+
49+
let rec iter_on_bs_config_str (x : Parsetree.structure) =
4250
match x with
4351
| [] -> ()
4452
| {
@@ -51,10 +59,14 @@ let rec iter_on_bs_config_stru (x : Parsetree.structure) =
5159
Ext_list.iter
5260
(Ast_payload.ident_or_record_as_config loc payload)
5361
(Ast_payload.table_dispatch !structural_config_table)
54-
| { pstr_desc = Pstr_attribute _ } :: rest -> iter_on_bs_config_stru rest
62+
| { pstr_desc = Pstr_attribute _ } :: rest -> iter_on_bs_config_str rest
5563
| _ :: _ -> ()
5664

57-
let rec iter_on_bs_config_sigi (x : Parsetree.signature) =
65+
let process_str str =
66+
iter_on_bs_config_str str;
67+
process_directives str
68+
69+
let rec iter_on_bs_config_sig (x : Parsetree.signature) =
5870
match x with
5971
| [] -> ()
6072
| {
@@ -67,5 +79,7 @@ let rec iter_on_bs_config_sigi (x : Parsetree.signature) =
6779
Ext_list.iter
6880
(Ast_payload.ident_or_record_as_config loc payload)
6981
(Ast_payload.table_dispatch !signature_config_table)
70-
| { psig_desc = Psig_attribute _ } :: rest -> iter_on_bs_config_sigi rest
82+
| { psig_desc = Psig_attribute _ } :: rest -> iter_on_bs_config_sig rest
7183
| _ :: _ -> ()
84+
85+
let process_sig s = iter_on_bs_config_sig s

jscomp/frontend/ast_config.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ val add_structure : string -> (Parsetree.expression option -> unit) -> unit
2626

2727
val add_signature : string -> (Parsetree.expression option -> unit) -> unit
2828

29-
val iter_on_bs_config_stru : Parsetree.structure -> unit
29+
val process_str : Parsetree.structure -> unit
3030

31-
val iter_on_bs_config_sigi : Parsetree.signature -> unit
31+
val process_sig : Parsetree.signature -> unit

jscomp/frontend/ppx_entry.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let unsafe_mapper = Bs_builtin_ppx.mapper
2626

2727
let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature =
2828
Bs_ast_invariant.iter_warnings_on_sigi ast;
29-
Ast_config.iter_on_bs_config_sigi ast;
29+
Ast_config.process_sig ast;
3030
let ast =
3131
match !Js_config.jsx_version with
3232
| None -> ast
@@ -46,7 +46,7 @@ let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature =
4646

4747
let rewrite_implementation (ast : Parsetree.structure) : Parsetree.structure =
4848
Bs_ast_invariant.iter_warnings_on_stru ast;
49-
Ast_config.iter_on_bs_config_stru ast;
49+
Ast_config.process_str ast;
5050
let ast =
5151
match !Js_config.jsx_version with
5252
| None -> ast

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265869,9 +265869,9 @@ val add_structure : string -> (Parsetree.expression option -> unit) -> unit
265869265869

265870265870
val add_signature : string -> (Parsetree.expression option -> unit) -> unit
265871265871

265872-
val iter_on_bs_config_stru : Parsetree.structure -> unit
265872+
val process_str : Parsetree.structure -> unit
265873265873

265874-
val iter_on_bs_config_sigi : Parsetree.signature -> unit
265874+
val process_sig : Parsetree.signature -> unit
265875265875

265876265876
end = struct
265877265877
#1 "ast_config.ml"
@@ -265915,7 +265915,15 @@ let signature_config_table : action_table ref = ref Map_string.empty
265915265915
let add_signature k v =
265916265916
signature_config_table := Map_string.add !signature_config_table k v
265917265917

265918-
let rec iter_on_bs_config_stru (x : Parsetree.structure) =
265918+
let process_directives str =
265919+
Js_config.directives := []; (* Restt: multiple calls possible e.g. with bsc from the command-line *)
265920+
str |> List.iter(fun (item : Parsetree.structure_item) -> match item.pstr_desc with
265921+
| Pstr_attribute ({ txt = "directive" },
265922+
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
265923+
Js_config.directives := !Js_config.directives @ [d]
265924+
| _ -> ())
265925+
265926+
let rec iter_on_bs_config_str (x : Parsetree.structure) =
265919265927
match x with
265920265928
| [] -> ()
265921265929
| {
@@ -265928,10 +265936,14 @@ let rec iter_on_bs_config_stru (x : Parsetree.structure) =
265928265936
Ext_list.iter
265929265937
(Ast_payload.ident_or_record_as_config loc payload)
265930265938
(Ast_payload.table_dispatch !structural_config_table)
265931-
| { pstr_desc = Pstr_attribute _ } :: rest -> iter_on_bs_config_stru rest
265939+
| { pstr_desc = Pstr_attribute _ } :: rest -> iter_on_bs_config_str rest
265932265940
| _ :: _ -> ()
265933265941

265934-
let rec iter_on_bs_config_sigi (x : Parsetree.signature) =
265942+
let process_str str =
265943+
iter_on_bs_config_str str;
265944+
process_directives str
265945+
265946+
let rec iter_on_bs_config_sig (x : Parsetree.signature) =
265935265947
match x with
265936265948
| [] -> ()
265937265949
| {
@@ -265944,9 +265956,10 @@ let rec iter_on_bs_config_sigi (x : Parsetree.signature) =
265944265956
Ext_list.iter
265945265957
(Ast_payload.ident_or_record_as_config loc payload)
265946265958
(Ast_payload.table_dispatch !signature_config_table)
265947-
| { psig_desc = Psig_attribute _ } :: rest -> iter_on_bs_config_sigi rest
265959+
| { psig_desc = Psig_attribute _ } :: rest -> iter_on_bs_config_sig rest
265948265960
| _ :: _ -> ()
265949265961

265962+
let process_sig s = iter_on_bs_config_sig s
265950265963
end
265951265964
module Ast_async
265952265965
= struct
@@ -276354,7 +276367,7 @@ let unsafe_mapper = Bs_builtin_ppx.mapper
276354276367

276355276368
let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature =
276356276369
Bs_ast_invariant.iter_warnings_on_sigi ast;
276357-
Ast_config.iter_on_bs_config_sigi ast;
276370+
Ast_config.process_sig ast;
276358276371
let ast =
276359276372
match !Js_config.jsx_version with
276360276373
| None -> ast
@@ -276374,7 +276387,7 @@ let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature =
276374276387

276375276388
let rewrite_implementation (ast : Parsetree.structure) : Parsetree.structure =
276376276389
Bs_ast_invariant.iter_warnings_on_stru ast;
276377-
Ast_config.iter_on_bs_config_stru ast;
276390+
Ast_config.process_str ast;
276378276391
let ast =
276379276392
match !Js_config.jsx_version with
276380276393
| None -> ast

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265869,9 +265869,9 @@ val add_structure : string -> (Parsetree.expression option -> unit) -> unit
265869265869

265870265870
val add_signature : string -> (Parsetree.expression option -> unit) -> unit
265871265871

265872-
val iter_on_bs_config_stru : Parsetree.structure -> unit
265872+
val process_str : Parsetree.structure -> unit
265873265873

265874-
val iter_on_bs_config_sigi : Parsetree.signature -> unit
265874+
val process_sig : Parsetree.signature -> unit
265875265875

265876265876
end = struct
265877265877
#1 "ast_config.ml"
@@ -265915,7 +265915,15 @@ let signature_config_table : action_table ref = ref Map_string.empty
265915265915
let add_signature k v =
265916265916
signature_config_table := Map_string.add !signature_config_table k v
265917265917

265918-
let rec iter_on_bs_config_stru (x : Parsetree.structure) =
265918+
let process_directives str =
265919+
Js_config.directives := []; (* Restt: multiple calls possible e.g. with bsc from the command-line *)
265920+
str |> List.iter(fun (item : Parsetree.structure_item) -> match item.pstr_desc with
265921+
| Pstr_attribute ({ txt = "directive" },
265922+
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
265923+
Js_config.directives := !Js_config.directives @ [d]
265924+
| _ -> ())
265925+
265926+
let rec iter_on_bs_config_str (x : Parsetree.structure) =
265919265927
match x with
265920265928
| [] -> ()
265921265929
| {
@@ -265928,10 +265936,14 @@ let rec iter_on_bs_config_stru (x : Parsetree.structure) =
265928265936
Ext_list.iter
265929265937
(Ast_payload.ident_or_record_as_config loc payload)
265930265938
(Ast_payload.table_dispatch !structural_config_table)
265931-
| { pstr_desc = Pstr_attribute _ } :: rest -> iter_on_bs_config_stru rest
265939+
| { pstr_desc = Pstr_attribute _ } :: rest -> iter_on_bs_config_str rest
265932265940
| _ :: _ -> ()
265933265941

265934-
let rec iter_on_bs_config_sigi (x : Parsetree.signature) =
265942+
let process_str str =
265943+
iter_on_bs_config_str str;
265944+
process_directives str
265945+
265946+
let rec iter_on_bs_config_sig (x : Parsetree.signature) =
265935265947
match x with
265936265948
| [] -> ()
265937265949
| {
@@ -265944,9 +265956,10 @@ let rec iter_on_bs_config_sigi (x : Parsetree.signature) =
265944265956
Ext_list.iter
265945265957
(Ast_payload.ident_or_record_as_config loc payload)
265946265958
(Ast_payload.table_dispatch !signature_config_table)
265947-
| { psig_desc = Psig_attribute _ } :: rest -> iter_on_bs_config_sigi rest
265959+
| { psig_desc = Psig_attribute _ } :: rest -> iter_on_bs_config_sig rest
265948265960
| _ :: _ -> ()
265949265961

265962+
let process_sig s = iter_on_bs_config_sig s
265950265963
end
265951265964
module Ast_async
265952265965
= struct
@@ -276354,7 +276367,7 @@ let unsafe_mapper = Bs_builtin_ppx.mapper
276354276367

276355276368
let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature =
276356276369
Bs_ast_invariant.iter_warnings_on_sigi ast;
276357-
Ast_config.iter_on_bs_config_sigi ast;
276370+
Ast_config.process_sig ast;
276358276371
let ast =
276359276372
match !Js_config.jsx_version with
276360276373
| None -> ast
@@ -276374,7 +276387,7 @@ let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature =
276374276387

276375276388
let rewrite_implementation (ast : Parsetree.structure) : Parsetree.structure =
276376276389
Bs_ast_invariant.iter_warnings_on_stru ast;
276377-
Ast_config.iter_on_bs_config_stru ast;
276390+
Ast_config.process_str ast;
276378276391
let ast =
276379276392
match !Js_config.jsx_version with
276380276393
| None -> ast

lib/4.06.1/whole_compiler.ml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180556,9 +180556,9 @@ val add_structure : string -> (Parsetree.expression option -> unit) -> unit
180556180556

180557180557
val add_signature : string -> (Parsetree.expression option -> unit) -> unit
180558180558

180559-
val iter_on_bs_config_stru : Parsetree.structure -> unit
180559+
val process_str : Parsetree.structure -> unit
180560180560

180561-
val iter_on_bs_config_sigi : Parsetree.signature -> unit
180561+
val process_sig : Parsetree.signature -> unit
180562180562

180563180563
end = struct
180564180564
#1 "ast_config.ml"
@@ -180602,7 +180602,15 @@ let signature_config_table : action_table ref = ref Map_string.empty
180602180602
let add_signature k v =
180603180603
signature_config_table := Map_string.add !signature_config_table k v
180604180604

180605-
let rec iter_on_bs_config_stru (x : Parsetree.structure) =
180605+
let process_directives str =
180606+
Js_config.directives := []; (* Restt: multiple calls possible e.g. with bsc from the command-line *)
180607+
str |> List.iter(fun (item : Parsetree.structure_item) -> match item.pstr_desc with
180608+
| Pstr_attribute ({ txt = "directive" },
180609+
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
180610+
Js_config.directives := !Js_config.directives @ [d]
180611+
| _ -> ())
180612+
180613+
let rec iter_on_bs_config_str (x : Parsetree.structure) =
180606180614
match x with
180607180615
| [] -> ()
180608180616
| {
@@ -180615,10 +180623,14 @@ let rec iter_on_bs_config_stru (x : Parsetree.structure) =
180615180623
Ext_list.iter
180616180624
(Ast_payload.ident_or_record_as_config loc payload)
180617180625
(Ast_payload.table_dispatch !structural_config_table)
180618-
| { pstr_desc = Pstr_attribute _ } :: rest -> iter_on_bs_config_stru rest
180626+
| { pstr_desc = Pstr_attribute _ } :: rest -> iter_on_bs_config_str rest
180619180627
| _ :: _ -> ()
180620180628

180621-
let rec iter_on_bs_config_sigi (x : Parsetree.signature) =
180629+
let process_str str =
180630+
iter_on_bs_config_str str;
180631+
process_directives str
180632+
180633+
let rec iter_on_bs_config_sig (x : Parsetree.signature) =
180622180634
match x with
180623180635
| [] -> ()
180624180636
| {
@@ -180631,9 +180643,10 @@ let rec iter_on_bs_config_sigi (x : Parsetree.signature) =
180631180643
Ext_list.iter
180632180644
(Ast_payload.ident_or_record_as_config loc payload)
180633180645
(Ast_payload.table_dispatch !signature_config_table)
180634-
| { psig_desc = Psig_attribute _ } :: rest -> iter_on_bs_config_sigi rest
180646+
| { psig_desc = Psig_attribute _ } :: rest -> iter_on_bs_config_sig rest
180635180647
| _ :: _ -> ()
180636180648

180649+
let process_sig s = iter_on_bs_config_sig s
180637180650
end
180638180651
module Ccomp : sig
180639180652
#1 "ccomp.mli"
@@ -286751,7 +286764,7 @@ let unsafe_mapper = Bs_builtin_ppx.mapper
286751286764

286752286765
let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature =
286753286766
Bs_ast_invariant.iter_warnings_on_sigi ast;
286754-
Ast_config.iter_on_bs_config_sigi ast;
286767+
Ast_config.process_sig ast;
286755286768
let ast =
286756286769
match !Js_config.jsx_version with
286757286770
| None -> ast
@@ -286771,7 +286784,7 @@ let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature =
286771286784

286772286785
let rewrite_implementation (ast : Parsetree.structure) : Parsetree.structure =
286773286786
Bs_ast_invariant.iter_warnings_on_stru ast;
286774-
Ast_config.iter_on_bs_config_stru ast;
286787+
Ast_config.process_str ast;
286775286788
let ast =
286776286789
match !Js_config.jsx_version with
286777286790
| None -> ast
@@ -294220,7 +294233,7 @@ let process_with_gentype cmt_file =
294220294233

294221294234
let after_parsing_sig ppf outputprefix ast =
294222294235
if !Clflags.only_parse = false then (
294223-
Ast_config.iter_on_bs_config_sigi ast;
294236+
Ast_config.process_sig ast;
294224294237
if !Js_config.modules then
294225294238
output_deps_set !Location.input_name
294226294239
(Ast_extract.read_parse_and_extract Mli ast);
@@ -294313,7 +294326,7 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
294313294326
if !Clflags.only_parse = false then (
294314294327
Js_config.all_module_aliases :=
294315294328
!Clflags.assume_no_mli = Mli_non_exists && all_module_alias ast;
294316-
Ast_config.iter_on_bs_config_stru ast;
294329+
Ast_config.process_str ast;
294317294330
let ast = if !Js_config.no_export then no_export ast else ast in
294318294331
if !Js_config.modules then
294319294332
output_deps_set !Location.input_name

0 commit comments

Comments
 (0)