Skip to content

Commit 66ce487

Browse files
committed
Fix fatal error when JSX not configured in rescript.json
1 parent 7883fe2 commit 66ce487

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler/ml/typecore.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ type error =
8484
| Field_not_optional of string * type_expr
8585
| Type_params_not_supported of Longident.t
8686
| Field_access_on_dict_type
87+
| Jsx_not_enabled
88+
8789
exception Error of Location.t * Env.t * error
8890
exception Error_forward of Location.error
8991

@@ -184,7 +186,7 @@ let iter_expression f e =
184186
| Pexp_pack me -> module_expr me
185187
| Pexp_await _ -> assert false (* should be handled earlier *)
186188
| Pexp_jsx_element _ ->
187-
failwith "Pexp_jsx_element should be transformed at this point."
189+
raise (Error (e.pexp_loc, Env.empty, Jsx_not_enabled))
188190
and case {pc_lhs = _; pc_guard; pc_rhs} =
189191
may expr pc_guard;
190192
expr pc_rhs
@@ -3193,7 +3195,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
31933195
raise (Error_forward (Builtin_attributes.error_of_extension ext))
31943196
| Pexp_await _ -> (* should be handled earlier *) assert false
31953197
| Pexp_jsx_element _ ->
3196-
failwith "Pexp_jsx_element is expected to be transformed at this point"
3198+
raise (Error (sexp.pexp_loc, Env.empty, Jsx_not_enabled))
31973199
31983200
and type_function ?in_function ~arity ~async loc attrs env ty_expected_ l
31993201
caselist =
@@ -4608,6 +4610,10 @@ let report_error env loc ppf error =
46084610
| Field_access_on_dict_type ->
46094611
fprintf ppf
46104612
"Direct field access on a dict is not supported. Use Dict.get instead."
4613+
| Jsx_not_enabled ->
4614+
fprintf ppf
4615+
"Cannot compile JSX expression because JSX support is not enabled. Add \
4616+
\"jsx\" settings to rescript.json to enable JSX support."
46114617
46124618
let report_error env loc ppf err =
46134619
Printtyp.wrap_printing_env env (fun () -> report_error env loc ppf err)

compiler/ml/typecore.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ type error =
116116
| Field_not_optional of string * type_expr
117117
| Type_params_not_supported of Longident.t
118118
| Field_access_on_dict_type
119+
| Jsx_not_enabled
120+
119121
exception Error of Location.t * Env.t * error
120122
exception Error_forward of Location.error
121123

0 commit comments

Comments
 (0)