Skip to content

Latest syntax #907

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 1 commit into from
Jan 30, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ type jsxConfig = {
mutable module_: string;
mutable mode: string;
mutable nestedModules: string list;
mutable hasReactComponent: bool;
mutable hasComponent: bool;
}

(* Helper method to look up the [@react.component] attribute *)
let hasAttr (loc, _) = loc.txt = "react.component"
let hasAttr (loc, _) =
match loc.txt with
| "react.component" | "jsx.component" -> true
| _ -> false

(* Iterate over the attributes and try to find the [@react.component] attribute *)
let hasAttrOnBinding {pvb_attributes} =
Expand All @@ -20,7 +23,7 @@ let coreTypeOfAttrs attributes =
List.find_map
(fun ({txt}, payload) ->
match (txt, payload) with
| "react.component", PTyp coreType -> Some coreType
| ("react.component" | "jsx.component"), PTyp coreType -> Some coreType
| _ -> None)
attributes

Expand All @@ -37,7 +40,7 @@ let typVarsOfCoreType {ptyp_desc} =

let raiseError ~loc msg = Location.raise_errorf ~loc msg

let raiseErrorMultipleReactComponent ~loc =
let raiseErrorMultipleComponent ~loc =
raiseError ~loc
"Only one component definition is allowed for each module. Move to a \
submodule or other file if necessary."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ let updateConfig config payload =
let fields = getPayloadFields payload in
(match getInt ~key:"version" fields with
| None -> ()
| Some i -> config.React_jsx_common.version <- i);
(match getString ~key:"module" fields with
| Some i -> config.Jsx_common.version <- i);
(match getString ~key:"module_" fields with
| None -> ()
| Some s -> config.module_ <- s);
match getString ~key:"mode" fields with
Expand All @@ -68,7 +68,7 @@ let getMapper ~config =
Reactjs_jsx_v3.jsxMapper ~config
in
let expr4, module_binding4, transformSignatureItem4, transformStructureItem4 =
Reactjs_jsx_v4.jsxMapper ~config
Jsx_v4.jsxMapper ~config
in

let expr mapper e =
Expand All @@ -89,18 +89,18 @@ let getMapper ~config =
version = config.version;
module_ = config.module_;
mode = config.mode;
hasReactComponent = config.hasReactComponent;
hasComponent = config.hasComponent;
}
in
let restoreConfig oldConfig =
config.version <- oldConfig.React_jsx_common.version;
config.version <- oldConfig.Jsx_common.version;
config.module_ <- oldConfig.module_;
config.mode <- oldConfig.mode;
config.hasReactComponent <- oldConfig.hasReactComponent
config.hasComponent <- oldConfig.hasComponent
in
let signature mapper items =
let oldConfig = saveConfig () in
config.hasReactComponent <- false;
config.hasComponent <- false;
let result =
List.map
(fun item ->
Expand All @@ -119,7 +119,7 @@ let getMapper ~config =
in
let structure mapper items =
let oldConfig = saveConfig () in
config.hasReactComponent <- false;
config.hasComponent <- false;
let result =
List.map
(fun item ->
Expand All @@ -143,11 +143,11 @@ let rewrite_implementation ~jsxVersion ~jsxModule ~jsxMode
(code : Parsetree.structure) : Parsetree.structure =
let config =
{
React_jsx_common.version = jsxVersion;
Jsx_common.version = jsxVersion;
module_ = jsxModule;
mode = jsxMode;
nestedModules = [];
hasReactComponent = false;
hasComponent = false;
}
in
let mapper = getMapper ~config in
Expand All @@ -157,11 +157,11 @@ let rewrite_signature ~jsxVersion ~jsxModule ~jsxMode
(code : Parsetree.signature) : Parsetree.signature =
let config =
{
React_jsx_common.version = jsxVersion;
Jsx_common.version = jsxVersion;
module_ = jsxModule;
mode = jsxMode;
nestedModules = [];
hasReactComponent = false;
hasComponent = false;
}
in
let mapper = getMapper ~config in
Expand Down
Loading