Skip to content

Fix implementation of directives. #6052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ These are only breaking changes for unformatted code.
- New internal representation for uncurried functions using built-in type `function$<fun_type, arity>` 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
Expand Down
4 changes: 2 additions & 2 deletions jscomp/core/js_implementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions jscomp/frontend/ast_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
| [] -> ()
| {
Expand All @@ -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
| [] -> ()
| {
Expand All @@ -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
4 changes: 2 additions & 2 deletions jscomp/frontend/ast_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions jscomp/frontend/bs_builtin_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions jscomp/frontend/ppx_entry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down