Skip to content

Commit e896491

Browse files
committed
fix polymorphic type inference
1 parent a0402ae commit e896491

File tree

5 files changed

+47
-20
lines changed

5 files changed

+47
-20
lines changed

jscomp/others/jsxPPXReactSupportC.res

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,4 @@ let createElementWithKey = (~key=?, component, props) =>
4949
let createElementVariadicWithKey = (~key=?, component, props, elements) =>
5050
createElementVariadic(component, addKeyProp(~key?, props), elements)
5151

52-
external asyncComponent: ('props => promise<Jsx.element>) => Jsx.component<
53-
'props,
54-
> = "%identity"
52+
external asyncComponent: promise<Jsx.element> => Jsx.element = "%identity"

jscomp/others/jsxPPXReactSupportU.res

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,4 @@ let createElementWithKey = (~key=?, component, props) =>
5151
let createElementVariadicWithKey = (~key=?, component, props, elements) =>
5252
createElementVariadic(component, addKeyProp(~key?, props), elements)
5353

54-
external asyncComponent: ('props => promise<Jsx.element>) => Jsx.component<
55-
'props,
56-
> = "%identity"
54+
external asyncComponent: promise<Jsx.element> => Jsx.element = "%identity"

jscomp/syntax/src/reactjs_jsx_v4.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,9 @@ let mapBinding ~config ~emptyLoc ~pstr_loc ~fileName ~recFlag binding =
947947
(Pat.var @@ Location.mknoloc "props")
948948
(Typ.constr (Location.mknoloc @@ Lident "props") [Typ.any ()])
949949
in
950+
let innerExpression =
951+
React_jsx_common.async_component ~async:isAsync innerExpression
952+
in
950953
let fullExpression =
951954
(* React component name should start with uppercase letter *)
952955
(* let make = { let \"App" = props => make(props); \"App" } *)
@@ -969,9 +972,6 @@ let mapBinding ~config ~emptyLoc ~pstr_loc ~fileName ~recFlag binding =
969972
|> Ast_uncurried.uncurriedFun ~loc:fullExpression.pexp_loc ~arity:1
970973
else fullExpression
971974
in
972-
let fullExpression =
973-
React_jsx_common.async_component ~async:isAsync fullExpression
974-
in
975975
let fullExpression =
976976
match fullModuleName with
977977
| "" -> fullExpression
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
let f = a => Js.Promise.resolve(a + a)
22

3-
@react.component
4-
let make = async (~a) => {
5-
let a = await f(a)
6-
<div> {React.int(a)} </div>
3+
module C0 = {
4+
@react.component
5+
let make = async (~a) => {
6+
let a = await f(a)
7+
<div> {React.int(a)} </div>
8+
}
79
}
10+
11+
module C1 = {
12+
@react.component
13+
let make = async (~status) => {
14+
switch status {
15+
| #on => React.string("on")
16+
| #off => React.string("off")
17+
}
18+
}
19+
}
Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
let f = a => Js.Promise.resolve(a + a)
2-
type props<'a> = {a: 'a}
32

4-
let make = async ({a, _}: props<_>) => {
5-
let a = await f(a)
6-
ReactDOM.jsx("div", {children: ?ReactDOM.someElement({React.int(a)})})
3+
module C0 = {
4+
type props<'a> = {a: 'a}
5+
6+
let make = async ({a, _}: props<_>) => {
7+
let a = await f(a)
8+
ReactDOM.jsx("div", {children: ?ReactDOM.someElement({React.int(a)})})
9+
}
10+
let make = {
11+
let \"AsyncAwait$C0" = (props: props<_>) => JsxPPXReactSupport.asyncComponent(make(props))
12+
13+
\"AsyncAwait$C0"
14+
}
715
}
8-
let make = {
9-
let \"AsyncAwait" = JsxPPXReactSupport.asyncComponent((props: props<_>) => make(props))
1016

11-
\"AsyncAwait"
17+
module C1 = {
18+
type props<'status> = {status: 'status}
19+
20+
let make = async ({status, _}: props<_>) => {
21+
switch status {
22+
| #on => React.string("on")
23+
| #off => React.string("off")
24+
}
25+
}
26+
let make = {
27+
let \"AsyncAwait$C1" = (props: props<_>) => JsxPPXReactSupport.asyncComponent(make(props))
28+
29+
\"AsyncAwait$C1"
30+
}
1231
}

0 commit comments

Comments
 (0)