diff --git a/CHANGELOG.md b/CHANGELOG.md index 602c95d206..faedd3378d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ #### :nail_care: Polish - Update list of reserved JS keywords. https://github.com/rescript-lang/rescript-compiler/pull/6167 +- Add error message to `@@directive`. https://github.com/rescript-lang/rescript-compiler/pull/6174 # 11.0.0-alpha.3 diff --git a/jscomp/build_tests/super_errors/expected/directive_attr.res.expected b/jscomp/build_tests/super_errors/expected/directive_attr.res.expected new file mode 100644 index 0000000000..ee4b5d89e1 --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/directive_attr.res.expected @@ -0,0 +1,8 @@ + + We've found a bug for you! + /.../fixtures/directive_attr.res:1:1-11 + + 1 │ @@directive + 2 │ + + expect string literal \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/directive_attr.res b/jscomp/build_tests/super_errors/fixtures/directive_attr.res new file mode 100644 index 0000000000..ec80ff9c0d --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/directive_attr.res @@ -0,0 +1 @@ +@@directive diff --git a/jscomp/frontend/ast_config.ml b/jscomp/frontend/ast_config.ml index 8b0917292e..9f7eb7e311 100644 --- a/jscomp/frontend/ast_config.ml +++ b/jscomp/frontend/ast_config.ml @@ -46,17 +46,10 @@ let process_directives str = 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] + | Pstr_attribute ({txt = "directive"}, payload) -> ( + match Ast_payload.is_single_string payload with + | Some (d, _) -> Js_config.directives := !Js_config.directives @ [d] + | None -> Bs_syntaxerr.err item.pstr_loc Expect_string_literal) | Pstr_attribute ({txt = "uncurried"}, _) -> Config.uncurried := Uncurried | _ -> ())