Skip to content

Commit

Permalink
remove jsx v3
Browse files Browse the repository at this point in the history
  • Loading branch information
mununki committed Oct 4, 2024
1 parent 6d88e98 commit a1cd728
Show file tree
Hide file tree
Showing 69 changed files with 265 additions and 2,148 deletions.
19 changes: 1 addition & 18 deletions docs/docson/build-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,6 @@
},
"description": "path to gentype, path resolution is similar to ReScript"
},
"reason-specs": {
"type": "object",
"properties": {
"react-jsx": {
"$ref": "#/definitions/react-jsx-version",
"description": "Whether to apply the [RescriptReact](https://github.com/rescript-lang/rescript-react)-specific JSX PPX transformation."
}
}
},
"jsx-specs": {
"type": "object",
"properties": {
Expand All @@ -329,10 +320,6 @@
"type": "string",
"enum": ["classic", "automatic"],
"description": "JSX transformation mode"
},
"v3-dependencies": {
"$ref": "#/definitions/dependencies",
"description": "Build the given dependencies in JSX V3 compatibility mode."
}
},
"additionalProperties": false
Expand Down Expand Up @@ -422,10 +409,6 @@
"type": "boolean",
"description": "Configuration for the uncurried mode."
},
"reason": {
"$ref": "#/definitions/reason-specs",
"description": "ReScript comes with [Reason](http://reasonml.github.io/) by default. Specific configurations here."
},
"gentypeconfig": {
"$ref": "#/definitions/gentype-specs",
"description": "gentype config, see cristianoc/genType for more details"
Expand Down Expand Up @@ -458,7 +441,7 @@
},
"ppx-flags": {
"$ref": "#/definitions/ppx-specs",
"description": "PPX macros to pass to compiler. The syntax is package_name/binary, for example: `reason/reactjs_jsx_ppx_3.native`. Currenly searches in `node_modules`"
"description": "PPX macros to pass to compiler. The syntax is package_name/binary, for example: `rescript-relay/ppx`. Currenly searches in `node_modules`"
},
"pp-flags": {
"$ref": "#/definitions/pp-specs",
Expand Down
1 change: 0 additions & 1 deletion jscomp/bsb/bsb_build_schemas.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ let jsx = "jsx"
let jsx_version = "version"
let jsx_module = "module"
let jsx_mode = "mode"
let jsx_v3_dependencies = "v3-dependencies"
let cut_generators = "cut-generators"
let generators = "generators"
let command = "command"
Expand Down
31 changes: 0 additions & 31 deletions jscomp/bsb/bsb_config_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,6 @@ let extract_boolean (map : json_map) (field : string) (default : bool) : bool =
| Some config ->
Bsb_exception.config_error config (field ^ " expect a boolean")

let extract_reason_react_jsx (map : json_map) =
let default : Bsb_config_types.reason_react_jsx option ref = ref None in
map
|? ( Bsb_build_schemas.reason,
`Obj
(fun m ->
match m.?(Bsb_build_schemas.react_jsx) with
| Some (Flo { loc; flo }) -> (
match flo with
| "3" -> default := Some Jsx_v3
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx version %s" flo
)
| Some x ->
Bsb_exception.config_error x
"Unexpected input (expect a version number) for jsx, note \
boolean is no longer allowed"
| None -> ()) )
|> ignore;
!default

let extract_warning (map : json_map) =
match map.?(Bsb_build_schemas.warnings) with
| None -> Bsb_warning.use_default
Expand Down Expand Up @@ -262,7 +242,6 @@ let interpret_json
~desc:Bsb_build_schemas.pp_flags p)
.path)
in
let reason_react_jsx = extract_reason_react_jsx map in
let bs_dependencies =
extract_dependencies map per_proj_dir Bsb_build_schemas.bs_dependencies
in
Expand All @@ -287,15 +266,6 @@ let interpret_json
in
let bsc_flags = extract_string_list map Bsb_build_schemas.bsc_flags in
let jsx = Bsb_jsx.from_map map in
let jsx, bsc_flags =
match package_kind with
| Pinned_dependency x | Dependency x ->
if List.mem package_name x.jsx.v3_dependencies then
( { jsx with version = Some Jsx_v3 },
"-open ReactV3" :: bsc_flags )
else (x.jsx, bsc_flags)
| _ -> (jsx, bsc_flags)
in
{
pinned_dependencies;
gentype_config;
Expand Down Expand Up @@ -326,7 +296,6 @@ let interpret_json
| Pinned_dependency x | Dependency x -> x.package_specs);
file_groups = groups;
files_to_install = Queue.create ();
reason_react_jsx;
jsx;
generators = extract_generators map;
cut_generators;
Expand Down
3 changes: 0 additions & 3 deletions jscomp/bsb/bsb_config_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ type dependency = {
}

type dependencies = dependency list
type reason_react_jsx = Jsx_v3
(* string option *)

type gentype_config = bool
type command = string
Expand All @@ -56,7 +54,6 @@ type t = {
package_specs : Bsb_package_specs.t;
file_groups : Bsb_file_groups.t;
files_to_install : Bsb_db.module_info Queue.t;
reason_react_jsx : reason_react_jsx option;
jsx: Bsb_jsx.t;
(* whether apply PPX transform or not*)
generators : command Map_string.t;
Expand Down
17 changes: 1 addition & 16 deletions jscomp/bsb/bsb_jsx.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type version = Jsx_v3 | Jsx_v4
type version = Jsx_v4
type module_ = React | Generic of {moduleName: string}
type mode = Classic | Automatic
type dependencies = string list
Expand All @@ -7,13 +7,11 @@ type t = {
version : version option;
module_ : module_ option;
mode : mode option;
v3_dependencies : dependencies;
}

let encode_no_nl jsx =
(match jsx.version with
| None -> ""
| Some Jsx_v3 -> "3"
| Some Jsx_v4 -> "4")
^ (match jsx.module_ with None -> "" | Some React -> "React" | Some Generic {moduleName} -> moduleName)
^
Expand All @@ -35,15 +33,13 @@ 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
let v3_dependencies : dependencies ref = ref [] in
map
|? ( Bsb_build_schemas.jsx,
`Obj
(fun m ->
match m.?(Bsb_build_schemas.jsx_version) with
| Some (Flo { loc; flo }) -> (
match flo with
| "3" -> version := Some Jsx_v3
| "4" -> version := Some Jsx_v4
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx version %s" flo
)
Expand Down Expand Up @@ -76,20 +72,9 @@ let from_map map =
Bsb_exception.config_error x
"Unexpected input (expect classic or automatic) for jsx mode"
| None -> ()) )
|? ( Bsb_build_schemas.jsx,
`Obj
(fun m ->
match m.?(Bsb_build_schemas.jsx_v3_dependencies) with
| Some (Arr { content }) ->
v3_dependencies := get_list_string content
| Some x ->
Bsb_exception.config_error x
"Unexpected input for jsx v3-dependencies"
| None -> ()) )
|> ignore;
{
version = !version;
module_ = !module_;
mode = !mode;
v3_dependencies = !v3_dependencies;
}
5 changes: 2 additions & 3 deletions jscomp/bsb/bsb_ninja_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ let output_ninja_and_namespace_map ~per_proj_dir ~package_kind
package_specs;
file_groups = { files = bs_file_groups };
files_to_install;
reason_react_jsx;
jsx;
generators;
namespace;
Expand Down Expand Up @@ -195,8 +194,8 @@ let output_ninja_and_namespace_map ~per_proj_dir ~package_kind
in
let rules : Bsb_ninja_rule.builtin =
Bsb_ninja_rule.make_custom_rules ~gentype_config
~has_postbuild:js_post_build_cmd ~pp_file
~reason_react_jsx ~jsx ~package_specs ~namespace ~digest ~package_name
~has_postbuild:js_post_build_cmd ~pp_file ~jsx
~package_specs ~namespace ~digest ~package_name
~warnings ~ppx_files ~bsc_flags ~dpkg_incls (* dev dependencies *)
~lib_incls (* its own libs *)
~dev_incls (* its own devs *)
Expand Down
9 changes: 3 additions & 6 deletions jscomp/bsb/bsb_ninja_rule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ type builtin = {

let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config)
~(has_postbuild : string option) ~(pp_file : string option)
~(reason_react_jsx : Bsb_config_types.reason_react_jsx option)
~(jsx : Bsb_jsx.t) ~(digest : string) ~(package_specs : Bsb_package_specs.t)
~(namespace : string option) ~package_name ~warnings
~(ppx_files : Bsb_config_types.ppx list) ~bsc_flags ~(dpkg_incls : string)
Expand Down Expand Up @@ -156,11 +155,9 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config)
| None -> ()
| Some flag ->
Ext_buffer.add_char_string buf ' ' (Bsb_build_util.pp_flag flag));
(match (reason_react_jsx, jsx.version) with
| _, Some Jsx_v3 -> Ext_buffer.add_string buf " -bs-jsx 3"
| _, Some Jsx_v4 -> Ext_buffer.add_string buf " -bs-jsx 4"
| Some Jsx_v3, None -> Ext_buffer.add_string buf " -bs-jsx 3"
| None, None -> ());
(match (jsx.version) with
| Some Jsx_v4 -> Ext_buffer.add_string buf " -bs-jsx 4"
| None -> ());
(match jsx.module_ with
| None -> ()
| Some React -> Ext_buffer.add_string buf " -bs-jsx-module react"
Expand Down
1 change: 0 additions & 1 deletion jscomp/bsb/bsb_ninja_rule.mli
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ val make_custom_rules :
gentype_config:Bsb_config_types.gentype_config ->
has_postbuild:string option ->
pp_file:string option ->
reason_react_jsx:Bsb_config_types.reason_react_jsx option ->
jsx:Bsb_jsx.t ->
digest:string ->
package_specs:Bsb_package_specs.t ->
Expand Down
4 changes: 1 addition & 3 deletions jscomp/common/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

(** Browser is not set via command line only for internal use *)

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

Expand Down Expand Up @@ -59,7 +59,6 @@ let no_export = ref false
let as_ppx = ref false

let int_of_jsx_version = function
| Jsx_v3 -> 3
| Jsx_v4 -> 4

let string_of_jsx_module = function
Expand All @@ -71,7 +70,6 @@ let string_of_jsx_mode = function
| Automatic -> "automatic"

let jsx_version_of_int = function
| 3 -> Some Jsx_v3
| 4 -> Some Jsx_v4
| _ -> None

Expand Down
2 changes: 1 addition & 1 deletion jscomp/common/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

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

Expand Down
19 changes: 5 additions & 14 deletions jscomp/gentype/TranslateTypeExprFromTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
param_translation1.dependencies @ param_translation2.dependencies;
type_ = variant;
}
| ( (["React"; "callback"] | ["ReactV3"; "React"; "callback"]),
[from_translation; to_translation] ) ->
| ["React"; "callback"], [from_translation; to_translation] ->
{
dependencies = from_translation.dependencies @ to_translation.dependencies;
type_ =
Expand All @@ -163,8 +162,7 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
type_vars = [];
};
}
| ( (["React"; "componentLike"] | ["ReactV3"; "React"; "componentLike"]),
[props_translation; ret_translation] ) ->
| ["React"; "componentLike"], [props_translation; ret_translation] ->
{
dependencies =
props_translation.dependencies @ ret_translation.dependencies;
Expand All @@ -176,8 +174,7 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
type_vars = [];
};
}
| ( (["React"; "component"] | ["ReactV3"; "React"; "component"]),
[props_translation] ) ->
| ["React"; "component"], [props_translation] ->
{
dependencies = props_translation.dependencies;
type_ =
Expand All @@ -188,17 +185,12 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
type_vars = [];
};
}
| ( (["React"; "Context"; "t"] | ["ReactV3"; "React"; "Context"; "t"]),
[param_translation] ) ->
| ["React"; "Context"; "t"], [param_translation] ->
{
dependencies = param_translation.dependencies;
type_ = EmitType.type_react_context ~type_:param_translation.type_;
}
| ( ( ["React"; "Ref"; "t"]
| ["React"; "ref"]
| ["ReactV3"; "React"; "Ref"; "t"]
| ["ReactV3"; "React"; "ref"] ),
[param_translation] ) ->
| (["React"; "Ref"; "t"] | ["React"; "ref"]), [param_translation] ->
{
dependencies = param_translation.dependencies;
type_ = EmitType.type_react_ref ~type_:param_translation.type_;
Expand All @@ -214,7 +206,6 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
| ["ReactEvent"; "Mouse"; "t"], [] ->
{dependencies = []; type_ = EmitType.type_react_event_mouse_t}
| ( ( ["React"; "element"]
| ["ReactV3"; "React"; "element"]
| ["ReasonReact"; "reactElement"]
| ["Pervasives"; "Jsx"; "element"] ),
[] ) ->
Expand Down
16 changes: 2 additions & 14 deletions jscomp/syntax/src/jsx_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ let process_config_attribute attribute config =
if is_jsx_config_attr attribute then update_config config (snd attribute)

let get_mapper ~config =
let ( expr3,
module_binding3,
transform_signature_item3,
transform_structure_item3 ) =
Reactjs_jsx_v3.jsx_mapper ~config
in
let ( expr4,
module_binding4,
transform_signature_item4,
Expand All @@ -87,13 +81,11 @@ let get_mapper ~config =

let expr mapper e =
match config.version with
| 3 -> expr3 mapper e
| 4 -> expr4 mapper e
| _ -> default_mapper.expr mapper e
in
let module_binding mapper mb =
match config.version with
| 3 -> module_binding3 mapper mb
| 4 -> module_binding4 mapper mb
| _ -> default_mapper.module_binding mapper mb
in
Expand Down Expand Up @@ -122,9 +114,7 @@ let get_mapper ~config =
| Psig_attribute attr -> process_config_attribute attr config
| _ -> ());
let item = default_mapper.signature_item mapper item in
if config.version = 3 then transform_signature_item3 item
else if config.version = 4 then transform_signature_item4 item
else [item])
if config.version = 4 then transform_signature_item4 item else [item])
items
|> List.flatten
in
Expand All @@ -141,9 +131,7 @@ let get_mapper ~config =
| Pstr_attribute attr -> process_config_attribute attr config
| _ -> ());
let item = default_mapper.structure_item mapper item in
if config.version = 3 then transform_structure_item3 item
else if config.version = 4 then transform_structure_item4 item
else [item])
if config.version = 4 then transform_structure_item4 item else [item])
items
|> List.flatten
in
Expand Down
Loading

0 comments on commit a1cd728

Please sign in to comment.