Skip to content

Commit c6c8962

Browse files
authored
Add error message to @@directive (#6174)
* initial tests * fix typo * refactor * add test * update tests * update CHANGELOG.md
1 parent d920fb9 commit c6c8962

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#### :nail_care: Polish
3131

3232
- Update list of reserved JS keywords. https://github.com/rescript-lang/rescript-compiler/pull/6167
33+
- Add error message to `@@directive`. https://github.com/rescript-lang/rescript-compiler/pull/6174
3334

3435
# 11.0.0-alpha.3
3536

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/directive_attr.res:1:1-11
4+
5+
1 │ @@directive
6+
2 │
7+
8+
expect string literal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@@directive

jscomp/frontend/ast_config.ml

+4-11
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,10 @@ let process_directives str =
4646
str
4747
|> List.iter (fun (item : Parsetree.structure_item) ->
4848
match item.pstr_desc with
49-
| Pstr_attribute
50-
( {txt = "directive"},
51-
PStr
52-
[
53-
{
54-
pstr_desc =
55-
Pstr_eval
56-
({pexp_desc = Pexp_constant (Pconst_string (d, _))}, _);
57-
};
58-
] ) ->
59-
Js_config.directives := !Js_config.directives @ [d]
49+
| Pstr_attribute ({txt = "directive"}, payload) -> (
50+
match Ast_payload.is_single_string payload with
51+
| Some (d, _) -> Js_config.directives := !Js_config.directives @ [d]
52+
| None -> Bs_syntaxerr.err item.pstr_loc Expect_string_literal)
6053
| Pstr_attribute ({txt = "uncurried"}, _) ->
6154
Config.uncurried := Uncurried
6255
| _ -> ())

0 commit comments

Comments
 (0)