Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit b78dde4

Browse files
committed
helper fn to raise error for multiple react comp
1 parent d837748 commit b78dde4

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

cli/reactjs_jsx_ppx.ml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,10 @@ module V4 = struct
15101510
let fullModuleName = String.concat "$" fullModuleName in
15111511
fullModuleName
15121512

1513+
let raiseErrorMultipleReactComponent ~loc =
1514+
Location.raise_errorf ~loc
1515+
"Each module should have one react component at most"
1516+
15131517
(*
15141518
AST node builders
15151519
These functions help us build AST nodes that are needed when transforming a [@react.component] into a
@@ -2018,8 +2022,7 @@ module V4 = struct
20182022
| [_] ->
20192023
(* If there is another @react.component, throw error *)
20202024
if config.hasReactComponent then
2021-
Location.raise_errorf ~loc:pstr_loc
2022-
"Each module should have one react component at most"
2025+
raiseErrorMultipleReactComponent ~loc:pstr_loc
20232026
else (
20242027
config.hasReactComponent <- true;
20252028
let rec getPropTypes types ({ptyp_loc; ptyp_desc} as fullType) =
@@ -2076,8 +2079,7 @@ module V4 = struct
20762079
let mapBinding binding =
20772080
if hasAttrOnBinding binding then
20782081
if config.hasReactComponent then
2079-
Location.raise_errorf ~loc:pstr_loc
2080-
"Each module should have one react component at most"
2082+
raiseErrorMultipleReactComponent ~loc:pstr_loc
20812083
else (
20822084
config.hasReactComponent <- true;
20832085
let bindingLoc = binding.pvb_loc in
@@ -2466,8 +2468,7 @@ module V4 = struct
24662468
| [_] ->
24672469
(* If there is another @react.component, throw error *)
24682470
if config.hasReactComponent then
2469-
Location.raise_errorf ~loc:psig_loc
2470-
"Each module should have one react component at most"
2471+
raiseErrorMultipleReactComponent ~loc:psig_loc
24712472
else config.hasReactComponent <- true;
24722473
let hasForwardRef = ref false in
24732474
let rec getPropTypes types ({ptyp_loc; ptyp_desc} as fullType) =

0 commit comments

Comments
 (0)