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

Commit 74e71b1

Browse files
committed
fix alias props with default value
1 parent 6f69284 commit 74e71b1

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

cli/reactjs_jsx_v4.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,12 +1016,12 @@ let transformStructureItem ~config mapper item =
10161016
(argToType ~newtypes ~typeConstraints)
10171017
[] namedArgList
10181018
in
1019-
let vbMatch (name, default, {ppat_loc}, _, _, _) =
1019+
let vbMatch (name, default, _, alias, loc, _) =
10201020
let label = getLabel name in
10211021
match default with
10221022
| Some default ->
10231023
Vb.mk
1024-
(Pat.var (Location.mkloc label ppat_loc))
1024+
(Pat.var (Location.mkloc alias loc))
10251025
(Exp.match_
10261026
(Exp.ident
10271027
{txt = Ldot (Lident "props", label); loc = Location.none})
@@ -1037,7 +1037,7 @@ let transformStructureItem ~config mapper item =
10371037
])
10381038
| None ->
10391039
Vb.mk
1040-
(Pat.var (Location.mkloc label ppat_loc))
1040+
(Pat.var (Location.mkloc alias loc))
10411041
(Exp.ident @@ Location.mknoloc @@ Ldot (Lident "props", label))
10421042
in
10431043
let vbMatchList =

tests/ppx/react/aliasProps.res

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ module C1 = {
99
@react.component
1010
let make = (~priority as p, ~text="Test") => React.string(p ++ text)
1111
}
12+
13+
module C2 = {
14+
@react.component
15+
let make = (~foo as bar="") => <div />
16+
}

tests/ppx/react/expected/aliasProps.res.txt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module C0 = {
99
| Some(text) => text
1010
| None => "Test"
1111
}
12-
and priority = props.priority
12+
and _ = props.priority
1313

1414
React.string(text)
1515
}
@@ -29,7 +29,7 @@ module C1 = {
2929
| Some(text) => text
3030
| None => "Test"
3131
}
32-
and priority = props.priority
32+
and p = props.priority
3333

3434
React.string(p ++ text)
3535
}
@@ -39,3 +39,22 @@ module C1 = {
3939
\"AliasProps$C1"
4040
}
4141
}
42+
43+
module C2 = {
44+
type props<'foo> = {foo?: 'foo}
45+
46+
@react.component
47+
let make = (props: props<'foo>) => {
48+
let bar = switch props.foo {
49+
| Some(foo) => foo
50+
| None => ""
51+
}
52+
53+
ReactDOM.jsx("div", {})
54+
}
55+
let make = {
56+
let \"AliasProps$C2" = (props: props<_>) => make(props)
57+
58+
\"AliasProps$C2"
59+
}
60+
}

0 commit comments

Comments
 (0)