Skip to content

Remove jsx mode #7327

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 9 commits into from
Mar 11, 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 @@ -21,6 +21,7 @@
#### :boom: Breaking Change

- Replace ~date with ~day in Date.make\*. https://github.com/rescript-lang/rescript/pull/7324
- Remove `-bs-jsx-mode`. https://github.com/rescript-lang/rescript/pull/7327

#### :house: Internal

Expand Down
1 change: 0 additions & 1 deletion compiler/bsb/bsb_build_schemas.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ let react_jsx = "react-jsx"
let jsx = "jsx"
let jsx_version = "version"
let jsx_module = "module"
let jsx_mode = "mode"
let cut_generators = "cut-generators"
let generators = "generators"
let command = "command"
Expand Down
29 changes: 5 additions & 24 deletions compiler/bsb/bsb_jsx.ml
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
type version = Jsx_v4
type module_ = React | Generic of {moduleName: string}
type mode = Classic | Automatic
type dependencies = string list

type t = {version: version option; module_: module_ option; mode: mode option}
type t = {version: version option; module_: module_ option}

let encode_no_nl jsx =
(match jsx.version with
| None -> ""
| Some Jsx_v4 -> "4")
^ (match jsx.module_ with
| None -> ""
| Some React -> "React"
| Some (Generic {moduleName}) -> moduleName)
^
match jsx.mode with
match jsx.module_ with
| None -> ""
| Some Classic -> "Classic"
| Some Automatic -> "Automatic"
| Some React -> "React"
| Some (Generic {moduleName}) -> moduleName

let ( .?() ) = Map_string.find_opt
let ( |? ) m (key, cb) = m |> Ext_json.test key cb
Expand All @@ -33,7 +28,6 @@ let get_list_string s = get_list_string_acc s []
let from_map map =
let version : version option ref = ref None in
let module_ : module_ option ref = ref None in
let mode : mode option ref = ref None in
map
|? ( Bsb_build_schemas.jsx,
`Obj
Expand All @@ -59,18 +53,5 @@ let from_map map =
Bsb_exception.config_error x
"Unexpected input (jsx module name) for jsx module"
| None -> ()) )
|? ( Bsb_build_schemas.jsx,
`Obj
(fun m ->
match m.?(Bsb_build_schemas.jsx_mode) with
| Some (Str {loc; str}) -> (
match str with
| "classic" -> mode := Some Classic
| "automatic" -> mode := Some Automatic
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx mode %s" str)
| Some x ->
Bsb_exception.config_error x
"Unexpected input (expect classic or automatic) for jsx mode"
| None -> ()) )
|> ignore;
{version = !version; module_ = !module_; mode = !mode}
{version = !version; module_ = !module_}
4 changes: 0 additions & 4 deletions compiler/bsb/bsb_ninja_rule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config)
| Some React -> Ext_buffer.add_string buf " -bs-jsx-module react"
| Some (Generic {moduleName}) ->
Ext_buffer.add_string buf (" -bs-jsx-module " ^ moduleName));
(match jsx.mode with
| None -> ()
| Some Classic -> Ext_buffer.add_string buf " -bs-jsx-mode classic"
| Some Automatic -> Ext_buffer.add_string buf " -bs-jsx-mode automatic");

Ext_buffer.add_char_string buf ' ' bsc_flags;
Ext_buffer.add_string buf " -absname -bs-ast -o $out $i";
Expand Down
11 changes: 3 additions & 8 deletions compiler/bsc/rescript_compiler_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,11 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
| _ -> true
in
Js_config.jsx_module := Js_config.jsx_module_of_string i;
if is_generic then (
Js_config.jsx_mode := Automatic;
Js_config.jsx_version := Some Jsx_v4)),
if is_generic then Js_config.jsx_version := Some Jsx_v4),
"*internal* Set jsx module" );
( "-bs-jsx-mode",
string_call (fun i ->
if i <> "classic" && i <> "automatic" then
Bsc_args.bad_arg (" Not supported jsx-mode : " ^ i);
Js_config.jsx_mode := Js_config.jsx_mode_of_string i),
"*internal* Set jsx mode" );
string_call ignore,
"*internal* Set jsx mode, this is no longer used and is a no-op." );
( "-bs-package-output",
string_call Js_packages_state.update_npm_package_path,
"*internal* Set npm-output-path: [opt_module]:path, for example: \
Expand Down
11 changes: 0 additions & 11 deletions compiler/common/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

type jsx_version = Jsx_v4
type jsx_module = React | Generic of {module_name: string}
type jsx_mode = Classic | Automatic

let no_version_header = ref false

Expand All @@ -51,7 +50,6 @@ let force_cmi = ref false
let force_cmj = ref false
let jsx_version = ref None
let jsx_module = ref React
let jsx_mode = ref Automatic
let js_stdout = ref true
let all_module_aliases = ref false
let no_stdlib = ref false
Expand All @@ -63,10 +61,6 @@ let string_of_jsx_module = function
| React -> "react"
| Generic {module_name} -> module_name

let string_of_jsx_mode = function
| Classic -> "classic"
| Automatic -> "automatic"

let jsx_version_of_int = function
| 4 -> Some Jsx_v4
| _ -> None
Expand All @@ -75,11 +69,6 @@ let jsx_module_of_string = function
| "react" -> React
| module_name -> Generic {module_name}

let jsx_mode_of_string = function
| "classic" -> Classic
| "automatic" -> Automatic
| _ -> Classic

(* option to config `@rescript/std`*)
let customize_runtime : string option ref = ref None
let as_pp = ref false
Expand Down
7 changes: 0 additions & 7 deletions compiler/common/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

type jsx_version = Jsx_v4
type jsx_module = React | Generic of {module_name: string}
type jsx_mode = Classic | Automatic

(* val get_packages_info :
unit -> Js_packages_info.t *)
Expand Down Expand Up @@ -81,8 +80,6 @@ val jsx_version : jsx_version option ref

val jsx_module : jsx_module ref

val jsx_mode : jsx_mode ref

val js_stdout : bool ref

val all_module_aliases : bool ref
Expand All @@ -95,14 +92,10 @@ val int_of_jsx_version : jsx_version -> int

val string_of_jsx_module : jsx_module -> string

val string_of_jsx_mode : jsx_mode -> string

val jsx_version_of_int : int -> jsx_version option

val jsx_module_of_string : string -> jsx_module

val jsx_mode_of_string : string -> jsx_mode

val customize_runtime : string option ref

val as_pp : bool ref
Expand Down
6 changes: 2 additions & 4 deletions compiler/frontend/ppx_entry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature =
let open Js_config in
let jsx_version = int_of_jsx_version jsx_version_ in
let jsx_module = string_of_jsx_module !jsx_module in
let jsx_mode = string_of_jsx_mode !jsx_mode in
Jsx_ppx.rewrite_signature ~jsx_version ~jsx_module ~jsx_mode ast
Jsx_ppx.rewrite_signature ~jsx_version ~jsx_module ast
in
if !Js_config.no_builtin_ppx then ast
else
Expand All @@ -54,8 +53,7 @@ let rewrite_implementation (ast : Parsetree.structure) : Parsetree.structure =
let open Js_config in
let jsx_version = int_of_jsx_version jsx_version_ in
let jsx_module = string_of_jsx_module !jsx_module in
let jsx_mode = string_of_jsx_mode !jsx_mode in
Jsx_ppx.rewrite_implementation ~jsx_version ~jsx_module ~jsx_mode ast
Jsx_ppx.rewrite_implementation ~jsx_version ~jsx_module ast
in
if !Js_config.no_builtin_ppx then ast
else
Expand Down
2 changes: 0 additions & 2 deletions compiler/jsoo/jsoo_playground_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,6 @@ module Compile = struct
let types_signature = ref [] in
Js_config.jsx_version := Some Js_config.Jsx_v4;
(* default *)
Js_config.jsx_mode := Js_config.Automatic;
(* default *)
let ast = impl str in
let ast = Ppx_entry.rewrite_implementation ast in
let typed_tree =
Expand Down
16 changes: 5 additions & 11 deletions compiler/syntax/cli/res_cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ module ResClflags : sig
val interface : bool ref
val jsx_version : int ref
val jsx_module : string ref
val jsx_mode : string ref
val typechecker : bool ref
val test_ast_conversion : bool ref

Expand All @@ -176,7 +175,6 @@ end = struct
let interface = ref false
let jsx_version = ref (-1)
let jsx_module = ref "react"
let jsx_mode = ref "automatic"
let file = ref ""
let typechecker = ref false
let test_ast_conversion = ref false
Expand Down Expand Up @@ -210,9 +208,6 @@ end = struct
( "-jsx-module",
Arg.String (fun txt -> jsx_module := txt),
"Specify the jsx module. Default: react" );
( "-jsx-mode",
Arg.String (fun txt -> jsx_mode := txt),
"Specify the jsx mode, classic or automatic. Default: automatic" );
( "-typechecker",
Arg.Unit (fun () -> typechecker := true),
"Parses the ast as it would be passed to the typechecker and not the \
Expand All @@ -230,7 +225,7 @@ module CliArgProcessor = struct
[@@unboxed]

let process_file ~is_interface ~width ~recover ~target ~jsx_version
~jsx_module ~jsx_mode ~typechecker ~test_ast_conversion filename =
~jsx_module ~typechecker ~test_ast_conversion filename =
let len = String.length filename in
let process_interface =
is_interface
Expand Down Expand Up @@ -282,7 +277,7 @@ module CliArgProcessor = struct
Ast_mapper_from0.default_mapper tree0
in
let parsetree =
Jsx_ppx.rewrite_signature ~jsx_version ~jsx_module ~jsx_mode parsetree
Jsx_ppx.rewrite_signature ~jsx_version ~jsx_module parsetree
in
print_engine.print_interface ~width ~filename
~comments:parse_result.comments parsetree
Expand All @@ -307,8 +302,7 @@ module CliArgProcessor = struct
Ast_mapper_from0.default_mapper tree0
in
let parsetree =
Jsx_ppx.rewrite_implementation ~jsx_version ~jsx_module ~jsx_mode
parsetree
Jsx_ppx.rewrite_implementation ~jsx_version ~jsx_module parsetree
in
print_engine.print_implementation ~width ~filename
~comments:parse_result.comments parsetree
Expand All @@ -321,7 +315,7 @@ let () =
CliArgProcessor.process_file ~is_interface:!ResClflags.interface
~width:!ResClflags.width ~recover:!ResClflags.recover
~target:!ResClflags.print ~jsx_version:!ResClflags.jsx_version
~jsx_module:!ResClflags.jsx_module ~jsx_mode:!ResClflags.jsx_mode
~typechecker:!ResClflags.typechecker !ResClflags.file
~jsx_module:!ResClflags.jsx_module ~typechecker:!ResClflags.typechecker
!ResClflags.file
~test_ast_conversion:!ResClflags.test_ast_conversion)
[@@raises exit]
1 change: 0 additions & 1 deletion compiler/syntax/src/jsx_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ open Parsetree
type jsx_config = {
mutable version: int;
mutable module_: string;
mutable mode: string;
mutable nested_modules: string list;
mutable has_component: bool;
}
Expand Down
20 changes: 6 additions & 14 deletions compiler/syntax/src/jsx_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,9 @@ let update_config config payload =
| true, _ -> config.Jsx_common.version <- 4
| false, Some i -> config.Jsx_common.version <- i
| _ -> ());
(match module_raw with
match module_raw with
| None -> ()
| Some s -> config.module_ <- s);
match (is_generic, get_string ~key:"mode" fields) with
| true, _ -> config.mode <- "automatic"
| false, Some s -> config.mode <- s
| _ -> ()
| Some s -> config.module_ <- s

let is_jsx_config_attr ((loc, _) : attribute) = loc.txt = "jsxConfig"

Expand Down Expand Up @@ -94,14 +90,12 @@ let get_mapper ~config =
config with
version = config.version;
module_ = config.module_;
mode = config.mode;
has_component = config.has_component;
}
in
let restore_config old_config =
config.version <- old_config.Jsx_common.version;
config.module_ <- old_config.module_;
config.mode <- old_config.mode;
config.has_component <- old_config.has_component
in
let signature mapper items =
Expand Down Expand Up @@ -141,27 +135,25 @@ let get_mapper ~config =

{default_mapper with expr; module_binding; signature; structure}

let rewrite_implementation ~jsx_version ~jsx_module ~jsx_mode
(code : Parsetree.structure) : Parsetree.structure =
let rewrite_implementation ~jsx_version ~jsx_module (code : Parsetree.structure)
: Parsetree.structure =
let config =
{
Jsx_common.version = jsx_version;
module_ = jsx_module;
mode = jsx_mode;
nested_modules = [];
has_component = false;
}
in
let mapper = get_mapper ~config in
mapper.structure mapper code

let rewrite_signature ~jsx_version ~jsx_module ~jsx_mode
(code : Parsetree.signature) : Parsetree.signature =
let rewrite_signature ~jsx_version ~jsx_module (code : Parsetree.signature) :
Parsetree.signature =
let config =
{
Jsx_common.version = jsx_version;
module_ = jsx_module;
mode = jsx_mode;
nested_modules = [];
has_component = false;
}
Expand Down
2 changes: 0 additions & 2 deletions compiler/syntax/src/jsx_ppx.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
val rewrite_implementation :
jsx_version:int ->
jsx_module:string ->
jsx_mode:string ->
Parsetree.structure ->
Parsetree.structure

val rewrite_signature :
jsx_version:int ->
jsx_module:string ->
jsx_mode:string ->
Parsetree.signature ->
Parsetree.signature
Loading