Skip to content

Commit 2dd6f4a

Browse files
committed
Fix implementation of directives.
The compiler's ppx is only run when parsing the source file. For config settings such as directives, this is OK when `bsc` is invoked directly, but not when part of building a project. In the latter case, the ast is compiled separately, and the builtin ppx is not run again before emitting code.
1 parent d3848cf commit 2dd6f4a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ These are only breaking changes for unformatted code.
5151
- Parser: fix location of variable when function definition `{v => ...}` is enclosed in braces https://github.com/rescript-lang/rescript-compiler/pull/5949
5252
- Fix issue with error messages for uncurried functions where expected and given type were swapped https://github.com/rescript-lang/rescript-compiler/pull/5973
5353
- Fix issue with integer overflow check https://github.com/rescript-lang/rescript-compiler/pull/6028
54+
- Fix implementation of directives https://github.com/rescript-lang/rescript-compiler/pull/6052
5455

5556
#### :nail_care: Polish
5657

jscomp/core/js_implementation.ml

+8
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,15 @@ let no_export (rest : Parsetree.structure) : Parsetree.structure =
127127
]
128128
| _ -> rest
129129

130+
let process_attributes items =
131+
items |> List.iter(fun (item : Parsetree.structure_item) -> match item.pstr_desc with
132+
| Pstr_attribute ({ txt = "directive" },
133+
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
134+
Js_config.directives := !Js_config.directives @ [d]
135+
| _ -> ())
136+
130137
let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
138+
process_attributes ast;
131139
if !Clflags.only_parse = false then (
132140
Js_config.all_module_aliases :=
133141
!Clflags.assume_no_mli = Mli_non_exists && all_module_alias ast;

jscomp/frontend/bs_builtin_ppx.ml

-4
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,6 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) :
431431
[ { pvb_pat; pvb_expr; pvb_attributes; pvb_loc } ] );
432432
})
433433
| Pstr_attribute ({ txt = "bs.config" | "config" }, _) -> str
434-
| Pstr_attribute ({ txt = "directive" },
435-
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
436-
Js_config.directives := d :: !Js_config.directives;
437-
str
438434
| _ -> default_mapper.structure_item self str
439435

440436
let local_module_name =

0 commit comments

Comments
 (0)