Skip to content

Commit a83177c

Browse files
authored
latest syntax (#907)
1 parent 785f252 commit a83177c

23 files changed

+553
-778
lines changed

analysis/vendor/res_syntax/react_jsx_common.ml renamed to analysis/vendor/res_syntax/jsx_common.ml

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ type jsxConfig = {
66
mutable module_: string;
77
mutable mode: string;
88
mutable nestedModules: string list;
9-
mutable hasReactComponent: bool;
9+
mutable hasComponent: bool;
1010
}
1111

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

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

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

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

40-
let raiseErrorMultipleReactComponent ~loc =
43+
let raiseErrorMultipleComponent ~loc =
4144
raiseError ~loc
4245
"Only one component definition is allowed for each module. Move to a \
4346
submodule or other file if necessary."

analysis/vendor/res_syntax/reactjs_jsx_ppx.ml renamed to analysis/vendor/res_syntax/jsx_ppx.ml

+12-12
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ let updateConfig config payload =
5050
let fields = getPayloadFields payload in
5151
(match getInt ~key:"version" fields with
5252
| None -> ()
53-
| Some i -> config.React_jsx_common.version <- i);
54-
(match getString ~key:"module" fields with
53+
| Some i -> config.Jsx_common.version <- i);
54+
(match getString ~key:"module_" fields with
5555
| None -> ()
5656
| Some s -> config.module_ <- s);
5757
match getString ~key:"mode" fields with
@@ -68,7 +68,7 @@ let getMapper ~config =
6868
Reactjs_jsx_v3.jsxMapper ~config
6969
in
7070
let expr4, module_binding4, transformSignatureItem4, transformStructureItem4 =
71-
Reactjs_jsx_v4.jsxMapper ~config
71+
Jsx_v4.jsxMapper ~config
7272
in
7373

7474
let expr mapper e =
@@ -89,18 +89,18 @@ let getMapper ~config =
8989
version = config.version;
9090
module_ = config.module_;
9191
mode = config.mode;
92-
hasReactComponent = config.hasReactComponent;
92+
hasComponent = config.hasComponent;
9393
}
9494
in
9595
let restoreConfig oldConfig =
96-
config.version <- oldConfig.React_jsx_common.version;
96+
config.version <- oldConfig.Jsx_common.version;
9797
config.module_ <- oldConfig.module_;
9898
config.mode <- oldConfig.mode;
99-
config.hasReactComponent <- oldConfig.hasReactComponent
99+
config.hasComponent <- oldConfig.hasComponent
100100
in
101101
let signature mapper items =
102102
let oldConfig = saveConfig () in
103-
config.hasReactComponent <- false;
103+
config.hasComponent <- false;
104104
let result =
105105
List.map
106106
(fun item ->
@@ -119,7 +119,7 @@ let getMapper ~config =
119119
in
120120
let structure mapper items =
121121
let oldConfig = saveConfig () in
122-
config.hasReactComponent <- false;
122+
config.hasComponent <- false;
123123
let result =
124124
List.map
125125
(fun item ->
@@ -143,11 +143,11 @@ let rewrite_implementation ~jsxVersion ~jsxModule ~jsxMode
143143
(code : Parsetree.structure) : Parsetree.structure =
144144
let config =
145145
{
146-
React_jsx_common.version = jsxVersion;
146+
Jsx_common.version = jsxVersion;
147147
module_ = jsxModule;
148148
mode = jsxMode;
149149
nestedModules = [];
150-
hasReactComponent = false;
150+
hasComponent = false;
151151
}
152152
in
153153
let mapper = getMapper ~config in
@@ -157,11 +157,11 @@ let rewrite_signature ~jsxVersion ~jsxModule ~jsxMode
157157
(code : Parsetree.signature) : Parsetree.signature =
158158
let config =
159159
{
160-
React_jsx_common.version = jsxVersion;
160+
Jsx_common.version = jsxVersion;
161161
module_ = jsxModule;
162162
mode = jsxMode;
163163
nestedModules = [];
164-
hasReactComponent = false;
164+
hasComponent = false;
165165
}
166166
in
167167
let mapper = getMapper ~config in

0 commit comments

Comments
 (0)