From 913aa08c9dc2041ea9b487a84de6b67296d8f5fc Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Tue, 7 Feb 2023 01:56:12 +0900 Subject: [PATCH 1/5] add test --- tests/ppx/react/expected/v4.res.txt | 17 +++++++++++++++++ tests/ppx/react/v4.res | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/tests/ppx/react/expected/v4.res.txt b/tests/ppx/react/expected/v4.res.txt index b15c2592..f4d2b1fd 100644 --- a/tests/ppx/react/expected/v4.res.txt +++ b/tests/ppx/react/expected/v4.res.txt @@ -16,3 +16,20 @@ module AnotherName = { \"V4$AnotherName$anotherName" } } + +module Rec = { + type props = {} + + let rec make = { + @merlin.focus + let rec \"make$Internal" = (_: props) => { + make(({}: props)) + } + and make = { + let \"V4$Rec" = props => make(props) + + \"V4$Rec" + } + make + } +} diff --git a/tests/ppx/react/v4.res b/tests/ppx/react/v4.res index 27c6a6c6..e61fff38 100644 --- a/tests/ppx/react/v4.res +++ b/tests/ppx/react/v4.res @@ -7,3 +7,10 @@ module AnotherName = { @react.component let anotherName = (~x) => React.string(x) } + +module Rec = { + @react.component + let rec make = () => { + make({}:props) + } +} \ No newline at end of file From 410ee434525e76a50bece3e0cbe9cd0abad738bf Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Tue, 7 Feb 2023 04:24:33 +0900 Subject: [PATCH 2/5] fix support for recursive components in JSX4 --- cli/reactjs_jsx_v4.ml | 7 ++++++- tests/ppx/react/expected/v4.res.txt | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/reactjs_jsx_v4.ml b/cli/reactjs_jsx_v4.ml index 68fa27c1..42589dc1 100644 --- a/cli/reactjs_jsx_v4.ml +++ b/cli/reactjs_jsx_v4.ml @@ -1043,7 +1043,12 @@ let transformStructureItem ~config mapper item = in let innerExpression = Exp.apply - (Exp.ident (Location.mknoloc @@ Lident fnName)) + (Exp.ident + (Location.mknoloc + @@ Lident + (match recFlag with + | Recursive -> internalFnName + | Nonrecursive -> fnName))) ([(Nolabel, Exp.ident (Location.mknoloc @@ Lident "props"))] @ match hasForwardRef with diff --git a/tests/ppx/react/expected/v4.res.txt b/tests/ppx/react/expected/v4.res.txt index f4d2b1fd..664395f9 100644 --- a/tests/ppx/react/expected/v4.res.txt +++ b/tests/ppx/react/expected/v4.res.txt @@ -26,7 +26,7 @@ module Rec = { make(({}: props)) } and make = { - let \"V4$Rec" = props => make(props) + let \"V4$Rec" = props => \"make$Internal"(props) \"V4$Rec" } From 9220ef9717666b30e489a2292bcb253b7bd36d9e Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Tue, 7 Feb 2023 04:25:01 +0900 Subject: [PATCH 3/5] add more tests --- tests/ppx/react/expected/v4.res.txt | 35 +++++++++++++++++++++++++++++ tests/ppx/react/v4.res | 17 +++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/tests/ppx/react/expected/v4.res.txt b/tests/ppx/react/expected/v4.res.txt index 664395f9..4aec3b81 100644 --- a/tests/ppx/react/expected/v4.res.txt +++ b/tests/ppx/react/expected/v4.res.txt @@ -33,3 +33,38 @@ module Rec = { make } } + +module Rec1 = { + type props = {} + + let rec make = { + @merlin.focus + let rec \"make$Internal" = (_: props) => { + React.null + } + and make = { + let \"V4$Rec1" = props => \"make$Internal"(props) + + \"V4$Rec1" + } + make + } +} + +module Rec2 = { + type props = {} + + let rec make = { + @merlin.focus + let rec \"make$Internal" = (_: props) => { + mm(({}: props)) + } + and make = { + let \"V4$Rec2" = props => \"make$Internal"(props) + + \"V4$Rec2" + } + make + } + and mm = x => make(x) +} diff --git a/tests/ppx/react/v4.res b/tests/ppx/react/v4.res index e61fff38..3b128108 100644 --- a/tests/ppx/react/v4.res +++ b/tests/ppx/react/v4.res @@ -13,4 +13,19 @@ module Rec = { let rec make = () => { make({}:props) } -} \ No newline at end of file +} + +module Rec1 = { + @react.component + let rec make = () => { + React.null + } +} + +module Rec2 = { + @react.component + let rec make = () => { + mm(({}: props)) + } + and mm = (x) => make(x) +} From 92a77360dd5f1996d7b07f0652b93d74da62bcc8 Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Tue, 7 Feb 2023 04:55:15 +0900 Subject: [PATCH 4/5] remove unused rec flag warning --- cli/reactjs_jsx_v4.ml | 17 +++++++++-------- tests/ppx/react/expected/v4.res.txt | 12 ++++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/cli/reactjs_jsx_v4.ml b/cli/reactjs_jsx_v4.ml index 42589dc1..b4c9ed61 100644 --- a/cli/reactjs_jsx_v4.ml +++ b/cli/reactjs_jsx_v4.ml @@ -1190,14 +1190,15 @@ let transformStructureItem ~config mapper item = | Recursive -> ( [ bindingWrapper - (Exp.let_ ~loc:emptyLoc Recursive - [ - makeNewBinding binding expression internalFnName; - Vb.mk - (Pat.var {loc = emptyLoc; txt = fnName}) - fullExpression; - ] - (Exp.ident {loc = emptyLoc; txt = Lident fnName})); + (Exp.let_ ~loc:emptyLoc Nonrecursive + [makeNewBinding binding expression internalFnName] + (Exp.let_ ~loc:emptyLoc Nonrecursive + [ + Vb.mk + (Pat.var {loc = emptyLoc; txt = fnName}) + fullExpression; + ] + (Exp.ident {loc = emptyLoc; txt = Lident fnName}))); ], None ) | Nonrecursive -> diff --git a/tests/ppx/react/expected/v4.res.txt b/tests/ppx/react/expected/v4.res.txt index 4aec3b81..9e709259 100644 --- a/tests/ppx/react/expected/v4.res.txt +++ b/tests/ppx/react/expected/v4.res.txt @@ -22,10 +22,10 @@ module Rec = { let rec make = { @merlin.focus - let rec \"make$Internal" = (_: props) => { + let \"make$Internal" = (_: props) => { make(({}: props)) } - and make = { + let make = { let \"V4$Rec" = props => \"make$Internal"(props) \"V4$Rec" @@ -39,10 +39,10 @@ module Rec1 = { let rec make = { @merlin.focus - let rec \"make$Internal" = (_: props) => { + let \"make$Internal" = (_: props) => { React.null } - and make = { + let make = { let \"V4$Rec1" = props => \"make$Internal"(props) \"V4$Rec1" @@ -56,10 +56,10 @@ module Rec2 = { let rec make = { @merlin.focus - let rec \"make$Internal" = (_: props) => { + let \"make$Internal" = (_: props) => { mm(({}: props)) } - and make = { + let make = { let \"V4$Rec2" = props => \"make$Internal"(props) \"V4$Rec2" From 56bc9428f5a1a327213981c976141bdc4ab70318 Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Tue, 7 Feb 2023 04:59:54 +0900 Subject: [PATCH 5/5] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91c51a7e..2717505f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ - Fix issue where error messages related to non-existent props were displayed without location information https://github.com/rescript-lang/syntax/pull/730 - Fix issue where uncurried functions were incorrectly converting the type of a prop given as a default value to curried https://github.com/rescript-lang/syntax/pull/731 - Fix issue with printing async functions with locally abstract types https://github.com/rescript-lang/syntax/pull/732 +- Fix support for recursive components in JSX V4 https://github.com/rescript-lang/syntax/pull/733 #### :eyeglasses: Spec Compliance