Skip to content

Commit 3a206b6

Browse files
committed
clean up extract jsx in bsb config
1 parent 2d90377 commit 3a206b6

File tree

2 files changed

+22
-46
lines changed

2 files changed

+22
-46
lines changed

jscomp/bsb/bsb_config_parse.ml

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -130,62 +130,52 @@ let extract_reason_react_jsx (map : json_map) =
130130
|> ignore;
131131
!default
132132

133-
let extract_jsx_version (map : json_map) =
134-
let default : Bsb_config_types.jsx_version option ref = ref None in
133+
let extract_jsx (map : json_map) =
134+
let version : Bsb_config_types.jsx_version option ref = ref None in
135+
let module_ : Bsb_config_types.jsx_module option ref = ref None in
136+
let mode : Bsb_config_types.jsx_mode option ref = ref None in
135137
map
136138
|? ( Bsb_build_schemas.jsx,
137139
`Obj
138140
(fun m ->
139141
match m.?(Bsb_build_schemas.jsx_version) with
140142
| Some (Flo { loc; flo }) -> (
141143
match flo with
142-
| "3" -> default := Some Jsx_v3
143-
| "4" -> default := Some Jsx_v4
144+
| "3" -> version := Some Jsx_v3
145+
| "4" -> version := Some Jsx_v4
144146
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-version %s" flo
145147
)
146148
| Some x ->
147149
Bsb_exception.config_error x
148150
"Unexpected input (expect a version number) for jsx-version"
149151
| None -> ()) )
150-
|> ignore;
151-
!default
152-
153-
let extract_jsx_module (map : json_map) =
154-
let default : Bsb_config_types.jsx_module option ref = ref None in
155-
map
156152
|? ( Bsb_build_schemas.jsx,
157153
`Obj
158154
(fun m ->
159155
match m.?(Bsb_build_schemas.jsx_module) with
160156
| Some (Str { loc; str }) -> (
161157
match str with
162-
| "react" -> default := Some React
158+
| "react" -> module_ := Some React
163159
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-module %s" str)
164160
| Some x ->
165161
Bsb_exception.config_error x
166162
"Unexpected input (jsx module name) for jsx-mode"
167163
| None -> ()) )
168-
|> ignore;
169-
!default
170-
171-
let extract_jsx_mode (map : json_map) =
172-
let default : Bsb_config_types.jsx_mode option ref = ref None in
173-
map
174164
|? ( Bsb_build_schemas.jsx,
175165
`Obj
176166
(fun m ->
177167
match m.?(Bsb_build_schemas.jsx_mode) with
178168
| Some (Str { loc; str }) -> (
179169
match str with
180-
| "classic" -> default := Some Classic
181-
| "automatic" -> default := Some Automatic
170+
| "classic" -> mode := Some Classic
171+
| "automatic" -> mode := Some Automatic
182172
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-mode %s" str)
183173
| Some x ->
184174
Bsb_exception.config_error x
185175
"Unexpected input (expect classic or automatic) for jsx-mode"
186176
| None -> ()) )
187177
|> ignore;
188-
!default
178+
(!version, !module_, !mode)
189179

190180
let extract_warning (map : json_map) =
191181
match map.?(Bsb_build_schemas.warnings) with
@@ -334,9 +324,7 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string)
334324
.path)
335325
in
336326
let reason_react_jsx = extract_reason_react_jsx map in
337-
let jsx_version = extract_jsx_version map in
338-
let jsx_module = extract_jsx_module map in
339-
let jsx_mode = extract_jsx_mode map in
327+
let jsx_version, jsx_module, jsx_mode = extract_jsx map in
340328
let bs_dependencies =
341329
extract_dependencies map per_proj_dir Bsb_build_schemas.bs_dependencies
342330
in

lib/4.06.1/rescript.ml

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10373,62 +10373,52 @@ let extract_reason_react_jsx (map : json_map) =
1037310373
|> ignore;
1037410374
!default
1037510375

10376-
let extract_jsx_version (map : json_map) =
10377-
let default : Bsb_config_types.jsx_version option ref = ref None in
10376+
let extract_jsx (map : json_map) =
10377+
let version : Bsb_config_types.jsx_version option ref = ref None in
10378+
let module_ : Bsb_config_types.jsx_module option ref = ref None in
10379+
let mode : Bsb_config_types.jsx_mode option ref = ref None in
1037810380
map
1037910381
|? ( Bsb_build_schemas.jsx,
1038010382
`Obj
1038110383
(fun m ->
1038210384
match m.?(Bsb_build_schemas.jsx_version) with
1038310385
| Some (Flo { loc; flo }) -> (
1038410386
match flo with
10385-
| "3" -> default := Some Jsx_v3
10386-
| "4" -> default := Some Jsx_v4
10387+
| "3" -> version := Some Jsx_v3
10388+
| "4" -> version := Some Jsx_v4
1038710389
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-version %s" flo
1038810390
)
1038910391
| Some x ->
1039010392
Bsb_exception.config_error x
1039110393
"Unexpected input (expect a version number) for jsx-version"
1039210394
| None -> ()) )
10393-
|> ignore;
10394-
!default
10395-
10396-
let extract_jsx_module (map : json_map) =
10397-
let default : Bsb_config_types.jsx_module option ref = ref None in
10398-
map
1039910395
|? ( Bsb_build_schemas.jsx,
1040010396
`Obj
1040110397
(fun m ->
1040210398
match m.?(Bsb_build_schemas.jsx_module) with
1040310399
| Some (Str { loc; str }) -> (
1040410400
match str with
10405-
| "react" -> default := Some React
10401+
| "react" -> module_ := Some React
1040610402
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-module %s" str)
1040710403
| Some x ->
1040810404
Bsb_exception.config_error x
1040910405
"Unexpected input (jsx module name) for jsx-mode"
1041010406
| None -> ()) )
10411-
|> ignore;
10412-
!default
10413-
10414-
let extract_jsx_mode (map : json_map) =
10415-
let default : Bsb_config_types.jsx_mode option ref = ref None in
10416-
map
1041710407
|? ( Bsb_build_schemas.jsx,
1041810408
`Obj
1041910409
(fun m ->
1042010410
match m.?(Bsb_build_schemas.jsx_mode) with
1042110411
| Some (Str { loc; str }) -> (
1042210412
match str with
10423-
| "classic" -> default := Some Classic
10424-
| "automatic" -> default := Some Automatic
10413+
| "classic" -> mode := Some Classic
10414+
| "automatic" -> mode := Some Automatic
1042510415
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx-mode %s" str)
1042610416
| Some x ->
1042710417
Bsb_exception.config_error x
1042810418
"Unexpected input (expect classic or automatic) for jsx-mode"
1042910419
| None -> ()) )
1043010420
|> ignore;
10431-
!default
10421+
(!version, !module_, !mode)
1043210422

1043310423
let extract_warning (map : json_map) =
1043410424
match map.?(Bsb_build_schemas.warnings) with
@@ -10577,9 +10567,7 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string)
1057710567
.path)
1057810568
in
1057910569
let reason_react_jsx = extract_reason_react_jsx map in
10580-
let jsx_version = extract_jsx_version map in
10581-
let jsx_module = extract_jsx_module map in
10582-
let jsx_mode = extract_jsx_mode map in
10570+
let jsx_version, jsx_module, jsx_mode = extract_jsx map in
1058310571
let bs_dependencies =
1058410572
extract_dependencies map per_proj_dir Bsb_build_schemas.bs_dependencies
1058510573
in

0 commit comments

Comments
 (0)