Skip to content

Commit 37e105f

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 4fdad9b commit 37e105f

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
1313
# 10.1.4
1414

15+
#### :bug: Bug Fix
16+
- Fix implementation of directives
17+
1518
# 10.1.3
1619

1720
#### :rocket: New Feature

jscomp/core/js_implementation.ml

Lines changed: 8 additions & 0 deletions
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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,6 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) :
475475
[ { pvb_pat; pvb_expr; pvb_attributes; pvb_loc } ] );
476476
})
477477
| Pstr_attribute ({ txt = "bs.config" | "config" }, _) -> str
478-
| Pstr_attribute ({ txt = "directive" },
479-
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
480-
Js_config.directives := d :: !Js_config.directives;
481-
str
482478
| _ -> default_mapper.structure_item self str
483479

484480
let local_module_name =

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273363,10 +273363,6 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) :
273363273363
[ { pvb_pat; pvb_expr; pvb_attributes; pvb_loc } ] );
273364273364
})
273365273365
| Pstr_attribute ({ txt = "bs.config" | "config" }, _) -> str
273366-
| Pstr_attribute ({ txt = "directive" },
273367-
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
273368-
Js_config.directives := d :: !Js_config.directives;
273369-
str
273370273366
| _ -> default_mapper.structure_item self str
273371273367

273372273368
let local_module_name =

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273363,10 +273363,6 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) :
273363273363
[ { pvb_pat; pvb_expr; pvb_attributes; pvb_loc } ] );
273364273364
})
273365273365
| Pstr_attribute ({ txt = "bs.config" | "config" }, _) -> str
273366-
| Pstr_attribute ({ txt = "directive" },
273367-
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
273368-
Js_config.directives := d :: !Js_config.directives;
273369-
str
273370273366
| _ -> default_mapper.structure_item self str
273371273367

273372273368
let local_module_name =

lib/4.06.1/whole_compiler.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283760,10 +283760,6 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) :
283760283760
[ { pvb_pat; pvb_expr; pvb_attributes; pvb_loc } ] );
283761283761
})
283762283762
| Pstr_attribute ({ txt = "bs.config" | "config" }, _) -> str
283763-
| Pstr_attribute ({ txt = "directive" },
283764-
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
283765-
Js_config.directives := d :: !Js_config.directives;
283766-
str
283767283763
| _ -> default_mapper.structure_item self str
283768283764

283769283765
let local_module_name =
@@ -294305,7 +294301,15 @@ let no_export (rest : Parsetree.structure) : Parsetree.structure =
294305294301
]
294306294302
| _ -> rest
294307294303

294304+
let process_attributes items =
294305+
items |> List.iter(fun (item : Parsetree.structure_item) -> match item.pstr_desc with
294306+
| Pstr_attribute ({ txt = "directive" },
294307+
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
294308+
Js_config.directives := !Js_config.directives @ [d]
294309+
| _ -> ())
294310+
294308294311
let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
294312+
process_attributes ast;
294309294313
if !Clflags.only_parse = false then (
294310294314
Js_config.all_module_aliases :=
294311294315
!Clflags.assume_no_mli = Mli_non_exists && all_module_alias ast;

0 commit comments

Comments
 (0)