Skip to content
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

Better error message extension (v10.1) #6057

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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#### :rocket: New Feature
- Add support for toplevel `await` https://github.com/rescript-lang/rescript-compiler/pull/6054

#### :nail_care: Polish

- Better error message for extension point https://github.com/rescript-lang/rescript-compiler/pull/6057

# 10.1.3

#### :rocket: New Feature
Expand Down
19 changes: 16 additions & 3 deletions jscomp/frontend/ast_exp_handle_external.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,23 @@ let handle_debugger loc (payload : Ast_payload.t) =
Ast_external_mk.local_external_apply loc ~pval_prim:[ "#debugger" ]
~pval_type:(Typ.arrow Nolabel (Typ.any ()) (Ast_literal.type_unit ()))
[ Ast_literal.val_unit ~loc () ]
| _ -> Location.raise_errorf ~loc "bs.debugger does not accept payload"
| _ ->
Location.raise_errorf ~loc "%%debugger extension doesn't accept arguments"

let handle_raw ~kind loc payload =
let is_function = ref false in
match Ast_payload.raw_as_string_exp_exn ~kind ~is_function payload with
| None -> Location.raise_errorf ~loc "bs.raw can only be applied to a string"
| None -> (
match kind with
| Raw_re ->
Location.raise_errorf ~loc
"%%re extension can only be applied to a string"
| Raw_exp ->
Location.raise_errorf ~loc
"%%raw extension can only be applied to a string"
| Raw_program ->
Location.raise_errorf ~loc
"%%%%raw extension can only be applied to a string")
| Some exp ->
{
exp with
Expand All @@ -99,4 +110,6 @@ let handle_raw_structure loc payload =
~pval_type:(Typ.arrow Nolabel (Typ.any ()) (Typ.any ()))
[ exp ];
}
| None -> Location.raise_errorf ~loc "bs.raw can only be applied to a string"
| None ->
Location.raise_errorf ~loc
"%%%%raw extension can only be applied to a string"