Skip to content

Commit b0a1504

Browse files
committed
convert async component type
1 parent 6b69ccd commit b0a1504

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

jscomp/others/jsxPPXReactSupportC.res

+4
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ let createElementWithKey = (~key=?, component, props) =>
4848

4949
let createElementVariadicWithKey = (~key=?, component, props, elements) =>
5050
createElementVariadic(component, addKeyProp(~key?, props), elements)
51+
52+
external asyncComponent: ('props => promise<Jsx.element>) => Jsx.component<
53+
'props,
54+
> = "%identity"

jscomp/others/jsxPPXReactSupportU.res

+4
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ let createElementWithKey = (~key=?, component, props) =>
5050

5151
let createElementVariadicWithKey = (~key=?, component, props, elements) =>
5252
createElementVariadic(component, addKeyProp(~key?, props), elements)
53+
54+
external asyncComponent: ('props => promise<Jsx.element>) => Jsx.component<
55+
'props,
56+
> = "%identity"

jscomp/syntax/src/react_jsx_common.ml

+10
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,13 @@ let add_async_attribute ~async (body : Parsetree.expression) =
7676

7777
let is_async : Parsetree.attribute -> bool =
7878
fun ({txt}, _) -> txt = "async" || txt = "res.async"
79+
80+
let async_component expr =
81+
let open Ast_helper in
82+
Exp.apply
83+
(Exp.ident
84+
{
85+
loc = Location.none;
86+
txt = Ldot (Lident "JsxPPXReactSupport", "asyncComponent");
87+
})
88+
[(Nolabel, expr)]

jscomp/syntax/src/reactjs_jsx_v4.ml

+11
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,17 @@ let mapBinding ~config ~emptyLoc ~pstr_loc ~fileName ~recFlag binding =
969969
|> Ast_uncurried.uncurriedFun ~loc:fullExpression.pexp_loc ~arity:1
970970
else fullExpression
971971
in
972+
let fullExpression =
973+
if isAsync then
974+
Exp.apply
975+
(Exp.ident
976+
{
977+
loc = Location.none;
978+
txt = Ldot (Lident "JsxPPXReactSupport", "asyncComponent");
979+
})
980+
[(Nolabel, fullExpression)]
981+
else fullExpression
982+
in
972983
let fullExpression =
973984
match fullModuleName with
974985
| "" -> fullExpression

jscomp/syntax/tests/ppx/react/expected/asyncAwait.res.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let make = async ({a, _}: props<_>) => {
66
ReactDOM.jsx("div", {children: ?ReactDOM.someElement({React.int(a)})})
77
}
88
let make = {
9-
let \"AsyncAwait" = (props: props<_>) => make(props)
9+
let \"AsyncAwait" = JsxPPXReactSupport.asyncComponent((props: props<_>) => make(props))
1010

1111
\"AsyncAwait"
1212
}

0 commit comments

Comments
 (0)