Skip to content

Commit

Permalink
latest syntax (#907)
Browse files Browse the repository at this point in the history
  • Loading branch information
zth committed Jan 30, 2024
1 parent 785f252 commit a83177c
Show file tree
Hide file tree
Showing 23 changed files with 553 additions and 778 deletions.
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
File renamed without changes.
Loading

0 comments on commit a83177c

Please sign in to comment.