Skip to content
This repository was archived by the owner on Nov 13, 2023. It is now read-only.

Commit 338a7e0

Browse files
committed
Fix missing conversion of optional arguments of components.
This was done for normal calls in ee6bda7, but not for components.
1 parent 71eca4a commit 338a7e0

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

examples/flow-react-example/src/components/ManyComponents.bs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/flow-react-example/src/components/ManyComponents.gen.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
/* eslint-disable */
77

8+
const $$toRE312434514 = {"Small": 0, "Medium": 1, "Large": 2};
9+
810
// $FlowExpectedError: Reason checked type sufficiently
911
import * as Curry from 'bs-platform/lib/es6/curry.js';
1012

@@ -14,6 +16,8 @@ import * as ManyComponentsBS from './ManyComponents.bs';
1416
// $FlowExpectedError: Reason checked type sufficiently
1517
import * as ReasonReact from 'reason-react/src/ReasonReact.js';
1618

19+
export type size = "Small" | "Medium" | "Large";
20+
1721
export type InnerComponent_Props = {| +children?: mixed |};
1822

1923
export const InnerComponent: React$ComponentType<InnerComponent_Props> = ReasonReact.wrapReasonForJs(
@@ -40,12 +44,12 @@ export const ManyProps: React$ComponentType<ManyProps_Props> = ReasonReact.wrapR
4044
return Curry.app(ManyComponentsBS.ManyProps[1], [jsProps.a, jsProps.b, jsProps.c, jsProps.d, jsProps.e, jsProps.f, jsProps.g, jsProps.h, jsProps.children]);
4145
}));
4246

43-
export type Props = {| +children?: mixed |};
47+
export type Props = {| +size?: size, +children?: mixed |};
4448

4549
export const component: React$ComponentType<Props> = ReasonReact.wrapReasonForJs(
4650
ManyComponentsBS.component,
4751
(function _(jsProps: Props) {
48-
return ManyComponentsBS.make(jsProps.children);
52+
return Curry._2(ManyComponentsBS.make, (jsProps.size == null ? undefined : $$toRE312434514[jsProps.size]), jsProps.children);
4953
}));
5054

5155
export default component;

examples/flow-react-example/src/components/ManyComponents.re

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@ module ManyProps = {
3131
};
3232
};
3333

34+
[@genType]
35+
type size =
36+
| Small
37+
| Medium
38+
| Large;
39+
3440
let component = ReasonReact.statelessComponent("ManyComponents");
3541

3642
[@genType]
37-
let make = _children => {
43+
let make = (~size as _=Small, _children) => {
3844
...component,
3945
render: _ =>
4046
<div> "Outer Component"->ReasonReact.string <InnerComponent /> </div>,

src/EmitJs.re

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,17 @@ let rec emitCodeItem =
509509
] =>
510510
(
511511
propConverters
512-
|> List.map(((s, _optional, argConverter)) =>
512+
|> List.map(((s, optional, argConverter)) =>
513513
jsPropsDot(s)
514514
|> Converter.toReason(
515515
~config,
516-
~converter=argConverter,
516+
~converter=
517+
optional == Optional
518+
&& !(
519+
argConverter
520+
|> Converter.converterIsIdentity(~toJS=false)
521+
) ?
522+
OptionC(argConverter) : argConverter,
517523
~indent,
518524
~nameGen,
519525
~useCreateBucklescriptBlock,

0 commit comments

Comments
 (0)