Skip to content

Commit c6bc812

Browse files
authored
Merge pull request #3531 from rickyvetter/jsx_ppx_state
use predef option for interface externals
2 parents c6c20f5 + 07799b7 commit c6bc812

File tree

5 files changed

+136
-113
lines changed

5 files changed

+136
-113
lines changed

jscomp/syntax/reactjs_jsx_ppx.cppo.ml

+8-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,14 @@ let jsxMapper () =
670670
#else
671671
| Ptyp_arrow ("", _type, rest) ->
672672
#endif
673-
getPropTypes types rest
673+
getPropTypes types rest
674+
#if OCAML_VERSION >= (4,3,0)
675+
| Ptyp_arrow (name, ({ptyp_desc = Ptyp_constr ({txt=(Lident "option"); loc}, [type_])}), returnValue) when isLabelled name || isOptional name ->
676+
(returnValue, (name, returnValue.ptyp_loc, {
677+
type_ with
678+
ptyp_desc = Ptyp_constr ({loc; txt=optionIdent}, [type_]);
679+
})::types)
680+
#endif
674681
| Ptyp_arrow (name, type_, returnValue) when isLabelled name || isOptional name ->
675682
(returnValue, (name, returnValue.ptyp_loc, type_)::types)
676683
| _ -> (fullType, types))

lib/4.02.3/bsdep.ml

+32-28
Original file line numberDiff line numberDiff line change
@@ -41369,9 +41369,11 @@ let jsxMapper () =
4136941369

4137041370
# 671 "syntax/reactjs_jsx_ppx.cppo.ml"
4137141371
| Ptyp_arrow ("", _type, rest) ->
41372-
41372+
4137341373
# 673 "syntax/reactjs_jsx_ppx.cppo.ml"
41374-
getPropTypes types rest
41374+
getPropTypes types rest
41375+
41376+
# 681 "syntax/reactjs_jsx_ppx.cppo.ml"
4137541377
| Ptyp_arrow (name, type_, returnValue) when isLabelled name || isOptional name ->
4137641378
(returnValue, (name, returnValue.ptyp_loc, type_)::types)
4137741379
| _ -> (fullType, types))
@@ -41432,10 +41434,10 @@ let jsxMapper () =
4143241434
((fun expressionDesc -> {expression with pexp_desc = Pexp_let (recursive, vbs, wrapExpression expressionDesc)}), realReturnExpression)
4143341435
(* let make = React.forwardRef((~prop) => ...) *)
4143441436

41435-
# 736 "syntax/reactjs_jsx_ppx.cppo.ml"
41437+
# 743 "syntax/reactjs_jsx_ppx.cppo.ml"
4143641438
| { pexp_desc = Pexp_apply (wrapperExpression, [("", innerFunctionExpression)]) } ->
4143741439

41438-
# 738 "syntax/reactjs_jsx_ppx.cppo.ml"
41440+
# 745 "syntax/reactjs_jsx_ppx.cppo.ml"
4143941441
let (wrapExpression, realReturnExpression) = spelunkForFunExpression innerFunctionExpression in
4144041442
((fun expressionDesc -> {
4144141443
expression with pexp_desc =
@@ -41578,10 +41580,10 @@ let jsxMapper () =
4157841580
| Ptyp_arrow (name, type_, ({ptyp_desc = Ptyp_arrow _} as rest)) when isOptional name || isLabelled name ->
4157941581
getPropTypes ((name, ptyp_loc, type_)::types) rest
4158041582

41581-
# 882 "syntax/reactjs_jsx_ppx.cppo.ml"
41583+
# 889 "syntax/reactjs_jsx_ppx.cppo.ml"
4158241584
| Ptyp_arrow ("", _type, rest) ->
4158341585

41584-
# 884 "syntax/reactjs_jsx_ppx.cppo.ml"
41586+
# 891 "syntax/reactjs_jsx_ppx.cppo.ml"
4158541587
getPropTypes types rest
4158641588
| Ptyp_arrow (name, type_, returnValue) when isOptional name || isLabelled name ->
4158741589
(returnValue, (name, returnValue.ptyp_loc, type_)::types)
@@ -41629,11 +41631,11 @@ let jsxMapper () =
4162941631
| {loc; txt = Ldot (modulePath, ("createElement" | "make"))} ->
4163041632
(match !jsxVersion with
4163141633

41632-
# 931 "syntax/reactjs_jsx_ppx.cppo.ml"
41634+
# 938 "syntax/reactjs_jsx_ppx.cppo.ml"
4163341635
| None
4163441636
| Some 2 -> transformUppercaseCall modulePath mapper loc attrs callExpression callArguments
4163541637

41636-
# 937 "syntax/reactjs_jsx_ppx.cppo.ml"
41638+
# 944 "syntax/reactjs_jsx_ppx.cppo.ml"
4163741639
| Some 3 -> transformUppercaseCall3 modulePath mapper loc attrs callExpression callArguments
4163841640
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
4163941641

@@ -41643,11 +41645,11 @@ let jsxMapper () =
4164341645
| {loc; txt = Lident id} ->
4164441646
(match !jsxVersion with
4164541647

41646-
# 946 "syntax/reactjs_jsx_ppx.cppo.ml"
41648+
# 953 "syntax/reactjs_jsx_ppx.cppo.ml"
4164741649
| None
4164841650
| Some 2 -> transformLowercaseCall mapper loc attrs callArguments id
4164941651

41650-
# 952 "syntax/reactjs_jsx_ppx.cppo.ml"
41652+
# 959 "syntax/reactjs_jsx_ppx.cppo.ml"
4165141653
| Some 3 -> transformLowercaseCall3 mapper loc attrs callArguments id
4165241654
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
4165341655

@@ -41704,17 +41706,17 @@ let jsxMapper () =
4170441706
| ([], _) -> default_mapper.structure mapper structure
4170541707
(* {jsx: 2} *)
4170641708

41707-
# 1010 "syntax/reactjs_jsx_ppx.cppo.ml"
41709+
# 1017 "syntax/reactjs_jsx_ppx.cppo.ml"
4170841710
| ((_, {pexp_desc = Pexp_constant (Const_int version)})::_rest, recordFieldsWithoutJsx) -> begin
4170941711

41710-
# 1012 "syntax/reactjs_jsx_ppx.cppo.ml"
41712+
# 1019 "syntax/reactjs_jsx_ppx.cppo.ml"
4171141713
(match version with
4171241714

41713-
# 1017 "syntax/reactjs_jsx_ppx.cppo.ml"
41715+
# 1024 "syntax/reactjs_jsx_ppx.cppo.ml"
4171441716
| 2 -> jsxVersion := Some 2
4171541717
| 3 -> jsxVersion := Some 3
4171641718

41717-
# 1020 "syntax/reactjs_jsx_ppx.cppo.ml"
41719+
# 1027 "syntax/reactjs_jsx_ppx.cppo.ml"
4171841720
| _ -> raise (Invalid_argument "JSX: the file-level bs.config's jsx version must be 2 or 3"));
4171941721
match recordFieldsWithoutJsx with
4172041722
(* record empty now, remove the whole bs.config attribute *)
@@ -42428,9 +42430,11 @@ let jsxMapper () =
4242842430

4242942431
# 671 "syntax/reactjs_jsx_ppx.cppo.ml"
4243042432
| Ptyp_arrow ("", _type, rest) ->
42431-
42433+
4243242434
# 673 "syntax/reactjs_jsx_ppx.cppo.ml"
42433-
getPropTypes types rest
42435+
getPropTypes types rest
42436+
42437+
# 681 "syntax/reactjs_jsx_ppx.cppo.ml"
4243442438
| Ptyp_arrow (name, type_, returnValue) when isLabelled name || isOptional name ->
4243542439
(returnValue, (name, returnValue.ptyp_loc, type_)::types)
4243642440
| _ -> (fullType, types))
@@ -42491,10 +42495,10 @@ let jsxMapper () =
4249142495
((fun expressionDesc -> {expression with pexp_desc = Pexp_let (recursive, vbs, wrapExpression expressionDesc)}), realReturnExpression)
4249242496
(* let make = React.forwardRef((~prop) => ...) *)
4249342497

42494-
# 736 "syntax/reactjs_jsx_ppx.cppo.ml"
42498+
# 743 "syntax/reactjs_jsx_ppx.cppo.ml"
4249542499
| { pexp_desc = Pexp_apply (wrapperExpression, [("", innerFunctionExpression)]) } ->
4249642500

42497-
# 738 "syntax/reactjs_jsx_ppx.cppo.ml"
42501+
# 745 "syntax/reactjs_jsx_ppx.cppo.ml"
4249842502
let (wrapExpression, realReturnExpression) = spelunkForFunExpression innerFunctionExpression in
4249942503
((fun expressionDesc -> {
4250042504
expression with pexp_desc =
@@ -42637,10 +42641,10 @@ let jsxMapper () =
4263742641
| Ptyp_arrow (name, type_, ({ptyp_desc = Ptyp_arrow _} as rest)) when isOptional name || isLabelled name ->
4263842642
getPropTypes ((name, ptyp_loc, type_)::types) rest
4263942643

42640-
# 882 "syntax/reactjs_jsx_ppx.cppo.ml"
42644+
# 889 "syntax/reactjs_jsx_ppx.cppo.ml"
4264142645
| Ptyp_arrow ("", _type, rest) ->
4264242646

42643-
# 884 "syntax/reactjs_jsx_ppx.cppo.ml"
42647+
# 891 "syntax/reactjs_jsx_ppx.cppo.ml"
4264442648
getPropTypes types rest
4264542649
| Ptyp_arrow (name, type_, returnValue) when isOptional name || isLabelled name ->
4264642650
(returnValue, (name, returnValue.ptyp_loc, type_)::types)
@@ -42688,11 +42692,11 @@ let jsxMapper () =
4268842692
| {loc; txt = Ldot (modulePath, ("createElement" | "make"))} ->
4268942693
(match !jsxVersion with
4269042694

42691-
# 934 "syntax/reactjs_jsx_ppx.cppo.ml"
42695+
# 941 "syntax/reactjs_jsx_ppx.cppo.ml"
4269242696
| Some 2 -> transformUppercaseCall modulePath mapper loc attrs callExpression callArguments
4269342697
| None
4269442698

42695-
# 937 "syntax/reactjs_jsx_ppx.cppo.ml"
42699+
# 944 "syntax/reactjs_jsx_ppx.cppo.ml"
4269642700
| Some 3 -> transformUppercaseCall3 modulePath mapper loc attrs callExpression callArguments
4269742701
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
4269842702

@@ -42702,11 +42706,11 @@ let jsxMapper () =
4270242706
| {loc; txt = Lident id} ->
4270342707
(match !jsxVersion with
4270442708

42705-
# 949 "syntax/reactjs_jsx_ppx.cppo.ml"
42709+
# 956 "syntax/reactjs_jsx_ppx.cppo.ml"
4270642710
| Some 2 -> transformLowercaseCall mapper loc attrs callArguments id
4270742711
| None
4270842712

42709-
# 952 "syntax/reactjs_jsx_ppx.cppo.ml"
42713+
# 959 "syntax/reactjs_jsx_ppx.cppo.ml"
4271042714
| Some 3 -> transformLowercaseCall3 mapper loc attrs callArguments id
4271142715
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
4271242716

@@ -42763,17 +42767,17 @@ let jsxMapper () =
4276342767
| ([], _) -> default_mapper.structure mapper structure
4276442768
(* {jsx: 2} *)
4276542769

42766-
# 1010 "syntax/reactjs_jsx_ppx.cppo.ml"
42770+
# 1017 "syntax/reactjs_jsx_ppx.cppo.ml"
4276742771
| ((_, {pexp_desc = Pexp_constant (Const_int version)})::_rest, recordFieldsWithoutJsx) -> begin
4276842772

42769-
# 1012 "syntax/reactjs_jsx_ppx.cppo.ml"
42773+
# 1019 "syntax/reactjs_jsx_ppx.cppo.ml"
4277042774
(match version with
4277142775

42772-
# 1017 "syntax/reactjs_jsx_ppx.cppo.ml"
42776+
# 1024 "syntax/reactjs_jsx_ppx.cppo.ml"
4277342777
| 2 -> jsxVersion := Some 2
4277442778
| 3 -> jsxVersion := Some 3
4277542779

42776-
# 1020 "syntax/reactjs_jsx_ppx.cppo.ml"
42780+
# 1027 "syntax/reactjs_jsx_ppx.cppo.ml"
4277742781
| _ -> raise (Invalid_argument "JSX: the file-level bs.config's jsx version must be 2 or 3"));
4277842782
match recordFieldsWithoutJsx with
4277942783
(* record empty now, remove the whole bs.config attribute *)

lib/4.02.3/bsppx.ml

+32-28
Original file line numberDiff line numberDiff line change
@@ -24591,9 +24591,11 @@ let jsxMapper () =
2459124591

2459224592
# 671 "syntax/reactjs_jsx_ppx.cppo.ml"
2459324593
| Ptyp_arrow ("", _type, rest) ->
24594-
24594+
2459524595
# 673 "syntax/reactjs_jsx_ppx.cppo.ml"
24596-
getPropTypes types rest
24596+
getPropTypes types rest
24597+
24598+
# 681 "syntax/reactjs_jsx_ppx.cppo.ml"
2459724599
| Ptyp_arrow (name, type_, returnValue) when isLabelled name || isOptional name ->
2459824600
(returnValue, (name, returnValue.ptyp_loc, type_)::types)
2459924601
| _ -> (fullType, types))
@@ -24654,10 +24656,10 @@ let jsxMapper () =
2465424656
((fun expressionDesc -> {expression with pexp_desc = Pexp_let (recursive, vbs, wrapExpression expressionDesc)}), realReturnExpression)
2465524657
(* let make = React.forwardRef((~prop) => ...) *)
2465624658

24657-
# 736 "syntax/reactjs_jsx_ppx.cppo.ml"
24659+
# 743 "syntax/reactjs_jsx_ppx.cppo.ml"
2465824660
| { pexp_desc = Pexp_apply (wrapperExpression, [("", innerFunctionExpression)]) } ->
2465924661

24660-
# 738 "syntax/reactjs_jsx_ppx.cppo.ml"
24662+
# 745 "syntax/reactjs_jsx_ppx.cppo.ml"
2466124663
let (wrapExpression, realReturnExpression) = spelunkForFunExpression innerFunctionExpression in
2466224664
((fun expressionDesc -> {
2466324665
expression with pexp_desc =
@@ -24800,10 +24802,10 @@ let jsxMapper () =
2480024802
| Ptyp_arrow (name, type_, ({ptyp_desc = Ptyp_arrow _} as rest)) when isOptional name || isLabelled name ->
2480124803
getPropTypes ((name, ptyp_loc, type_)::types) rest
2480224804

24803-
# 882 "syntax/reactjs_jsx_ppx.cppo.ml"
24805+
# 889 "syntax/reactjs_jsx_ppx.cppo.ml"
2480424806
| Ptyp_arrow ("", _type, rest) ->
2480524807

24806-
# 884 "syntax/reactjs_jsx_ppx.cppo.ml"
24808+
# 891 "syntax/reactjs_jsx_ppx.cppo.ml"
2480724809
getPropTypes types rest
2480824810
| Ptyp_arrow (name, type_, returnValue) when isOptional name || isLabelled name ->
2480924811
(returnValue, (name, returnValue.ptyp_loc, type_)::types)
@@ -24851,11 +24853,11 @@ let jsxMapper () =
2485124853
| {loc; txt = Ldot (modulePath, ("createElement" | "make"))} ->
2485224854
(match !jsxVersion with
2485324855

24854-
# 931 "syntax/reactjs_jsx_ppx.cppo.ml"
24856+
# 938 "syntax/reactjs_jsx_ppx.cppo.ml"
2485524857
| None
2485624858
| Some 2 -> transformUppercaseCall modulePath mapper loc attrs callExpression callArguments
2485724859

24858-
# 937 "syntax/reactjs_jsx_ppx.cppo.ml"
24860+
# 944 "syntax/reactjs_jsx_ppx.cppo.ml"
2485924861
| Some 3 -> transformUppercaseCall3 modulePath mapper loc attrs callExpression callArguments
2486024862
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
2486124863

@@ -24865,11 +24867,11 @@ let jsxMapper () =
2486524867
| {loc; txt = Lident id} ->
2486624868
(match !jsxVersion with
2486724869

24868-
# 946 "syntax/reactjs_jsx_ppx.cppo.ml"
24870+
# 953 "syntax/reactjs_jsx_ppx.cppo.ml"
2486924871
| None
2487024872
| Some 2 -> transformLowercaseCall mapper loc attrs callArguments id
2487124873

24872-
# 952 "syntax/reactjs_jsx_ppx.cppo.ml"
24874+
# 959 "syntax/reactjs_jsx_ppx.cppo.ml"
2487324875
| Some 3 -> transformLowercaseCall3 mapper loc attrs callArguments id
2487424876
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
2487524877

@@ -24926,17 +24928,17 @@ let jsxMapper () =
2492624928
| ([], _) -> default_mapper.structure mapper structure
2492724929
(* {jsx: 2} *)
2492824930

24929-
# 1010 "syntax/reactjs_jsx_ppx.cppo.ml"
24931+
# 1017 "syntax/reactjs_jsx_ppx.cppo.ml"
2493024932
| ((_, {pexp_desc = Pexp_constant (Const_int version)})::_rest, recordFieldsWithoutJsx) -> begin
2493124933

24932-
# 1012 "syntax/reactjs_jsx_ppx.cppo.ml"
24934+
# 1019 "syntax/reactjs_jsx_ppx.cppo.ml"
2493324935
(match version with
2493424936

24935-
# 1017 "syntax/reactjs_jsx_ppx.cppo.ml"
24937+
# 1024 "syntax/reactjs_jsx_ppx.cppo.ml"
2493624938
| 2 -> jsxVersion := Some 2
2493724939
| 3 -> jsxVersion := Some 3
2493824940

24939-
# 1020 "syntax/reactjs_jsx_ppx.cppo.ml"
24941+
# 1027 "syntax/reactjs_jsx_ppx.cppo.ml"
2494024942
| _ -> raise (Invalid_argument "JSX: the file-level bs.config's jsx version must be 2 or 3"));
2494124943
match recordFieldsWithoutJsx with
2494224944
(* record empty now, remove the whole bs.config attribute *)
@@ -25650,9 +25652,11 @@ let jsxMapper () =
2565025652

2565125653
# 671 "syntax/reactjs_jsx_ppx.cppo.ml"
2565225654
| Ptyp_arrow ("", _type, rest) ->
25653-
25655+
2565425656
# 673 "syntax/reactjs_jsx_ppx.cppo.ml"
25655-
getPropTypes types rest
25657+
getPropTypes types rest
25658+
25659+
# 681 "syntax/reactjs_jsx_ppx.cppo.ml"
2565625660
| Ptyp_arrow (name, type_, returnValue) when isLabelled name || isOptional name ->
2565725661
(returnValue, (name, returnValue.ptyp_loc, type_)::types)
2565825662
| _ -> (fullType, types))
@@ -25713,10 +25717,10 @@ let jsxMapper () =
2571325717
((fun expressionDesc -> {expression with pexp_desc = Pexp_let (recursive, vbs, wrapExpression expressionDesc)}), realReturnExpression)
2571425718
(* let make = React.forwardRef((~prop) => ...) *)
2571525719

25716-
# 736 "syntax/reactjs_jsx_ppx.cppo.ml"
25720+
# 743 "syntax/reactjs_jsx_ppx.cppo.ml"
2571725721
| { pexp_desc = Pexp_apply (wrapperExpression, [("", innerFunctionExpression)]) } ->
2571825722

25719-
# 738 "syntax/reactjs_jsx_ppx.cppo.ml"
25723+
# 745 "syntax/reactjs_jsx_ppx.cppo.ml"
2572025724
let (wrapExpression, realReturnExpression) = spelunkForFunExpression innerFunctionExpression in
2572125725
((fun expressionDesc -> {
2572225726
expression with pexp_desc =
@@ -25859,10 +25863,10 @@ let jsxMapper () =
2585925863
| Ptyp_arrow (name, type_, ({ptyp_desc = Ptyp_arrow _} as rest)) when isOptional name || isLabelled name ->
2586025864
getPropTypes ((name, ptyp_loc, type_)::types) rest
2586125865

25862-
# 882 "syntax/reactjs_jsx_ppx.cppo.ml"
25866+
# 889 "syntax/reactjs_jsx_ppx.cppo.ml"
2586325867
| Ptyp_arrow ("", _type, rest) ->
2586425868

25865-
# 884 "syntax/reactjs_jsx_ppx.cppo.ml"
25869+
# 891 "syntax/reactjs_jsx_ppx.cppo.ml"
2586625870
getPropTypes types rest
2586725871
| Ptyp_arrow (name, type_, returnValue) when isOptional name || isLabelled name ->
2586825872
(returnValue, (name, returnValue.ptyp_loc, type_)::types)
@@ -25910,11 +25914,11 @@ let jsxMapper () =
2591025914
| {loc; txt = Ldot (modulePath, ("createElement" | "make"))} ->
2591125915
(match !jsxVersion with
2591225916

25913-
# 934 "syntax/reactjs_jsx_ppx.cppo.ml"
25917+
# 941 "syntax/reactjs_jsx_ppx.cppo.ml"
2591425918
| Some 2 -> transformUppercaseCall modulePath mapper loc attrs callExpression callArguments
2591525919
| None
2591625920

25917-
# 937 "syntax/reactjs_jsx_ppx.cppo.ml"
25921+
# 944 "syntax/reactjs_jsx_ppx.cppo.ml"
2591825922
| Some 3 -> transformUppercaseCall3 modulePath mapper loc attrs callExpression callArguments
2591925923
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
2592025924

@@ -25924,11 +25928,11 @@ let jsxMapper () =
2592425928
| {loc; txt = Lident id} ->
2592525929
(match !jsxVersion with
2592625930

25927-
# 949 "syntax/reactjs_jsx_ppx.cppo.ml"
25931+
# 956 "syntax/reactjs_jsx_ppx.cppo.ml"
2592825932
| Some 2 -> transformLowercaseCall mapper loc attrs callArguments id
2592925933
| None
2593025934

25931-
# 952 "syntax/reactjs_jsx_ppx.cppo.ml"
25935+
# 959 "syntax/reactjs_jsx_ppx.cppo.ml"
2593225936
| Some 3 -> transformLowercaseCall3 mapper loc attrs callArguments id
2593325937
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 2 or 3"))
2593425938

@@ -25985,17 +25989,17 @@ let jsxMapper () =
2598525989
| ([], _) -> default_mapper.structure mapper structure
2598625990
(* {jsx: 2} *)
2598725991

25988-
# 1010 "syntax/reactjs_jsx_ppx.cppo.ml"
25992+
# 1017 "syntax/reactjs_jsx_ppx.cppo.ml"
2598925993
| ((_, {pexp_desc = Pexp_constant (Const_int version)})::_rest, recordFieldsWithoutJsx) -> begin
2599025994

25991-
# 1012 "syntax/reactjs_jsx_ppx.cppo.ml"
25995+
# 1019 "syntax/reactjs_jsx_ppx.cppo.ml"
2599225996
(match version with
2599325997

25994-
# 1017 "syntax/reactjs_jsx_ppx.cppo.ml"
25998+
# 1024 "syntax/reactjs_jsx_ppx.cppo.ml"
2599525999
| 2 -> jsxVersion := Some 2
2599626000
| 3 -> jsxVersion := Some 3
2599726001

25998-
# 1020 "syntax/reactjs_jsx_ppx.cppo.ml"
26002+
# 1027 "syntax/reactjs_jsx_ppx.cppo.ml"
2599926003
| _ -> raise (Invalid_argument "JSX: the file-level bs.config's jsx version must be 2 or 3"));
2600026004
match recordFieldsWithoutJsx with
2600126005
(* record empty now, remove the whole bs.config attribute *)

0 commit comments

Comments
 (0)