Skip to content

Fix fatal error when JSX not configured in rescript.json #7661

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

Merged
merged 2 commits into from
Jul 17, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- Rewatch: Use root package suffix in clean log messages. https://github.com/rescript-lang/rescript/pull/7648
- Fix inside comment printing for empty dict. https://github.com/rescript-lang/rescript/pull/7654
- Fix I/O error message when trying to extract extra info from non-existing file. https://github.com/rescript-lang/rescript/pull/7656
- Fix fatal error when JSX expression used without configuring JSX in rescript.json. https://github.com/rescript-lang/rescript/pull/7656

# 12.0.0-beta.1

Expand Down
10 changes: 8 additions & 2 deletions compiler/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ type error =
| Field_not_optional of string * type_expr
| Type_params_not_supported of Longident.t
| Field_access_on_dict_type
| Jsx_not_enabled

exception Error of Location.t * Env.t * error
exception Error_forward of Location.error

Expand Down Expand Up @@ -184,7 +186,7 @@ let iter_expression f e =
| Pexp_pack me -> module_expr me
| Pexp_await _ -> assert false (* should be handled earlier *)
| Pexp_jsx_element _ ->
failwith "Pexp_jsx_element should be transformed at this point."
raise (Error (e.pexp_loc, Env.empty, Jsx_not_enabled))
and case {pc_lhs = _; pc_guard; pc_rhs} =
may expr pc_guard;
expr pc_rhs
Expand Down Expand Up @@ -3193,7 +3195,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
raise (Error_forward (Builtin_attributes.error_of_extension ext))
| Pexp_await _ -> (* should be handled earlier *) assert false
| Pexp_jsx_element _ ->
failwith "Pexp_jsx_element is expected to be transformed at this point"
raise (Error (sexp.pexp_loc, Env.empty, Jsx_not_enabled))

and type_function ?in_function ~arity ~async loc attrs env ty_expected_ l
caselist =
Expand Down Expand Up @@ -4608,6 +4610,10 @@ let report_error env loc ppf error =
| Field_access_on_dict_type ->
fprintf ppf
"Direct field access on a dict is not supported. Use Dict.get instead."
| Jsx_not_enabled ->
fprintf ppf
"Cannot compile JSX expression because JSX support is not enabled. Add \
\"jsx\" settings to rescript.json to enable JSX support."

let report_error env loc ppf err =
Printtyp.wrap_printing_env env (fun () -> report_error env loc ppf err)
Expand Down
2 changes: 2 additions & 0 deletions compiler/ml/typecore.mli
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ type error =
| Field_not_optional of string * type_expr
| Type_params_not_supported of Longident.t
| Field_access_on_dict_type
| Jsx_not_enabled

exception Error of Location.t * Env.t * error
exception Error_forward of Location.error

Expand Down