diff --git a/CHANGELOG.md b/CHANGELOG.md index 197d140d08..312a6d87c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,12 @@ These are only breaking changes for unformatted code. - New internal representation for uncurried functions using built-in type `function$` this avoids having to declare all the possible arities ahead of time https://github.com/rescript-lang/rescript-compiler/pull/5870 - Better error message for extension point https://github.com/rescript-lang/rescript-compiler/pull/5965 +# 10.1.4 + +#### :bug: Bug Fix + +- Fix implementation of directives https://github.com/rescript-lang/rescript-compiler/pull/6052 + # 10.1.3 #### :rocket: New Feature diff --git a/jscomp/core/js_implementation.ml b/jscomp/core/js_implementation.ml index 105a8033cf..e20cb021a3 100644 --- a/jscomp/core/js_implementation.ml +++ b/jscomp/core/js_implementation.ml @@ -46,7 +46,7 @@ let process_with_gentype cmt_file = let after_parsing_sig ppf outputprefix ast = if !Clflags.only_parse = false then ( - Ast_config.iter_on_bs_config_sigi ast; + Ast_config.process_sig ast; if !Js_config.modules then output_deps_set !Location.input_name (Ast_extract.read_parse_and_extract Mli ast); @@ -131,7 +131,7 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) = if !Clflags.only_parse = false then ( Js_config.all_module_aliases := !Clflags.assume_no_mli = Mli_non_exists && all_module_alias ast; - Ast_config.iter_on_bs_config_stru ast; + Ast_config.process_str ast; let ast = if !Js_config.no_export then no_export ast else ast in if !Js_config.modules then output_deps_set !Location.input_name diff --git a/jscomp/frontend/ast_config.ml b/jscomp/frontend/ast_config.ml index 8f5be7c66a..66d273c8c8 100644 --- a/jscomp/frontend/ast_config.ml +++ b/jscomp/frontend/ast_config.ml @@ -38,7 +38,15 @@ let signature_config_table : action_table ref = ref Map_string.empty let add_signature k v = signature_config_table := Map_string.add !signature_config_table k v -let rec iter_on_bs_config_stru (x : Parsetree.structure) = +let process_directives str = + Js_config.directives := []; (* Restt: multiple calls possible e.g. with bsc from the command-line *) + str |> List.iter(fun (item : Parsetree.structure_item) -> match item.pstr_desc with + | Pstr_attribute ({ txt = "directive" }, + PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) -> + Js_config.directives := !Js_config.directives @ [d] + | _ -> ()) + +let rec iter_on_bs_config_str (x : Parsetree.structure) = match x with | [] -> () | { @@ -51,10 +59,14 @@ let rec iter_on_bs_config_stru (x : Parsetree.structure) = Ext_list.iter (Ast_payload.ident_or_record_as_config loc payload) (Ast_payload.table_dispatch !structural_config_table) - | { pstr_desc = Pstr_attribute _ } :: rest -> iter_on_bs_config_stru rest + | { pstr_desc = Pstr_attribute _ } :: rest -> iter_on_bs_config_str rest | _ :: _ -> () -let rec iter_on_bs_config_sigi (x : Parsetree.signature) = +let process_str str = + iter_on_bs_config_str str; + process_directives str + +let rec iter_on_bs_config_sig (x : Parsetree.signature) = match x with | [] -> () | { @@ -67,5 +79,7 @@ let rec iter_on_bs_config_sigi (x : Parsetree.signature) = Ext_list.iter (Ast_payload.ident_or_record_as_config loc payload) (Ast_payload.table_dispatch !signature_config_table) - | { psig_desc = Psig_attribute _ } :: rest -> iter_on_bs_config_sigi rest + | { psig_desc = Psig_attribute _ } :: rest -> iter_on_bs_config_sig rest | _ :: _ -> () + +let process_sig s = iter_on_bs_config_sig s \ No newline at end of file diff --git a/jscomp/frontend/ast_config.mli b/jscomp/frontend/ast_config.mli index 311f0447dd..ab0e533722 100644 --- a/jscomp/frontend/ast_config.mli +++ b/jscomp/frontend/ast_config.mli @@ -26,6 +26,6 @@ val add_structure : string -> (Parsetree.expression option -> unit) -> unit val add_signature : string -> (Parsetree.expression option -> unit) -> unit -val iter_on_bs_config_stru : Parsetree.structure -> unit +val process_str : Parsetree.structure -> unit -val iter_on_bs_config_sigi : Parsetree.signature -> unit +val process_sig : Parsetree.signature -> unit diff --git a/jscomp/frontend/bs_builtin_ppx.ml b/jscomp/frontend/bs_builtin_ppx.ml index 0c2dc97501..17a23758e8 100644 --- a/jscomp/frontend/bs_builtin_ppx.ml +++ b/jscomp/frontend/bs_builtin_ppx.ml @@ -431,10 +431,6 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) : [ { pvb_pat; pvb_expr; pvb_attributes; pvb_loc } ] ); }) | Pstr_attribute ({ txt = "bs.config" | "config" }, _) -> str - | Pstr_attribute ({ txt = "directive" }, - PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) -> - Js_config.directives := d :: !Js_config.directives; - str | _ -> default_mapper.structure_item self str let local_module_name = diff --git a/jscomp/frontend/ppx_entry.ml b/jscomp/frontend/ppx_entry.ml index d98721c3c7..957a21467c 100644 --- a/jscomp/frontend/ppx_entry.ml +++ b/jscomp/frontend/ppx_entry.ml @@ -26,7 +26,7 @@ let unsafe_mapper = Bs_builtin_ppx.mapper let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature = Bs_ast_invariant.iter_warnings_on_sigi ast; - Ast_config.iter_on_bs_config_sigi ast; + Ast_config.process_sig ast; let ast = match !Js_config.jsx_version with | None -> ast @@ -46,7 +46,7 @@ let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature = let rewrite_implementation (ast : Parsetree.structure) : Parsetree.structure = Bs_ast_invariant.iter_warnings_on_stru ast; - Ast_config.iter_on_bs_config_stru ast; + Ast_config.process_str ast; let ast = match !Js_config.jsx_version with | None -> ast