Skip to content

Commit 0555147

Browse files
committed
Clean up difference between v10 and v11 ppx so files are identical.
1 parent 168445a commit 0555147

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

res_syntax/src/react_jsx_common.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,25 @@ let raiseErrorMultipleReactComponent ~loc =
4141
raiseError ~loc
4242
"Only one component definition is allowed for each module. Move to a \
4343
submodule or other file if necessary."
44+
45+
let optionalAttr = ({txt = "res.optional"; loc = Location.none}, PStr [])
46+
47+
let extractUncurried typ =
48+
if Ast_uncurried.typeIsUncurriedFun typ then
49+
let _arity, t = Ast_uncurried.typeExtractUncurriedFun typ in
50+
t
51+
else typ
52+
53+
let removeArity binding =
54+
let rec removeArityRecord expr =
55+
match expr.pexp_desc with
56+
| _ when Ast_uncurried.exprIsUncurriedFun expr ->
57+
Ast_uncurried.exprExtractUncurriedFun expr
58+
| Pexp_apply (forwardRef, [(label, e)]) ->
59+
{
60+
expr with
61+
pexp_desc = Pexp_apply (forwardRef, [(label, removeArityRecord e)]);
62+
}
63+
| _ -> expr
64+
in
65+
{binding with pvb_expr = removeArityRecord binding.pvb_expr}

res_syntax/src/reactjs_jsx_v4.ml

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ let getLabel str =
2727
| Optional str | Labelled str -> str
2828
| Nolabel -> ""
2929

30-
let optionalAttr = ({txt = "res.optional"; loc = Location.none}, PStr [])
31-
let optionalAttrs = [optionalAttr]
30+
let optionalAttrs = [React_jsx_common.optionalAttr]
3231

3332
let constantString ~loc str =
3433
Ast_helper.Exp.constant ~loc (Pconst_string (str, None))
@@ -740,12 +739,7 @@ let transformStructureItem ~config item =
740739
config.hasReactComponent <- true;
741740
check_string_int_attribute_iter.structure_item
742741
check_string_int_attribute_iter item;
743-
let pval_type =
744-
if Ast_uncurried.typeIsUncurriedFun pval_type then
745-
let _arity, t = Ast_uncurried.typeExtractUncurriedFun pval_type in
746-
t
747-
else pval_type
748-
in
742+
let pval_type = React_jsx_common.extractUncurried pval_type in
749743
let coreTypeOfAttr = React_jsx_common.coreTypeOfAttrs pval_attributes in
750744
let typVarsOfCoreType =
751745
coreTypeOfAttr
@@ -816,21 +810,7 @@ let transformStructureItem ~config item =
816810
React_jsx_common.raiseErrorMultipleReactComponent ~loc:pstr_loc
817811
else (
818812
config.hasReactComponent <- true;
819-
let rec removeArityRecord expr =
820-
match expr.pexp_desc with
821-
| _ when Ast_uncurried.exprIsUncurriedFun expr ->
822-
Ast_uncurried.exprExtractUncurriedFun expr
823-
| Pexp_apply (forwardRef, [(label, e)]) ->
824-
{
825-
expr with
826-
pexp_desc =
827-
Pexp_apply (forwardRef, [(label, removeArityRecord e)]);
828-
}
829-
| _ -> expr
830-
in
831-
let binding =
832-
{binding with pvb_expr = removeArityRecord binding.pvb_expr}
833-
in
813+
let binding = React_jsx_common.removeArity binding in
834814
let coreTypeOfAttr =
835815
React_jsx_common.coreTypeOfAttrs binding.pvb_attributes
836816
in
@@ -1274,12 +1254,7 @@ let transformSignatureItem ~config _mapper item =
12741254
if config.React_jsx_common.hasReactComponent then
12751255
React_jsx_common.raiseErrorMultipleReactComponent ~loc:psig_loc
12761256
else config.hasReactComponent <- true;
1277-
let pval_type =
1278-
if Ast_uncurried.typeIsUncurriedFun pval_type then
1279-
let _arity, t = Ast_uncurried.typeExtractUncurriedFun pval_type in
1280-
t
1281-
else pval_type
1282-
in
1257+
let pval_type = React_jsx_common.extractUncurried pval_type in
12831258
check_string_int_attribute_iter.signature_item
12841259
check_string_int_attribute_iter item;
12851260
let hasForwardRef = ref false in

0 commit comments

Comments
 (0)