File tree 4 files changed +22
-15
lines changed
4 files changed +22
-15
lines changed Original file line number Diff line number Diff line change 2
2
3
3
4
4
function Alias_default_value_test$C0 ( props ) {
5
- var b = props . b ;
6
- var b$1 = b !== undefined ? b : 2 ;
7
5
var a = props . a ;
8
6
var a$1 = a !== undefined ? a : 2 ;
7
+ var b = props . b ;
8
+ var b$1 = b !== undefined ? b : ( a$1 << 1 ) ;
9
9
return a$1 + b$1 | 0 ;
10
10
}
11
11
Original file line number Diff line number Diff line change @@ -1064,9 +1064,15 @@ let transformStructureItem ~config mapper item =
1064
1064
(Exp. ident {txt = Lident " props" ; loc = Location. none})
1065
1065
(Location. mknoloc @@ Lident label))
1066
1066
in
1067
- let vbMatchList =
1068
- if hasDefaultValue namedArgList then List. map vbMatch namedArgList
1069
- else []
1067
+ let vbMatchExpr namedArgList expr =
1068
+ let rec aux namedArgList =
1069
+ match namedArgList with
1070
+ | [] -> expr
1071
+ | [namedArg] -> Exp. let_ Nonrecursive [vbMatch namedArg] expr
1072
+ | namedArg :: rest ->
1073
+ Exp. let_ Nonrecursive [vbMatch namedArg] (aux rest)
1074
+ in
1075
+ aux (List. rev namedArgList)
1070
1076
in
1071
1077
(* type props = { ... } *)
1072
1078
let propsRecordType =
@@ -1186,8 +1192,9 @@ let transformStructureItem ~config mapper item =
1186
1192
in
1187
1193
(* add pattern matching for optional prop value *)
1188
1194
let expression =
1189
- if List. length vbMatchList = 0 then expression
1190
- else Exp. let_ Nonrecursive vbMatchList expression
1195
+ if hasDefaultValue namedArgList then
1196
+ vbMatchExpr namedArgList expression
1197
+ else expression
1191
1198
in
1192
1199
(* (ref) => expr *)
1193
1200
let expression =
Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ module C0 = {
5
5
6
6
@react.component
7
7
let make = (props: props<'priority, 'text>) => {
8
+ let _ = props.priority
8
9
let text = switch props.text {
9
10
| Some(text) => text
10
11
| None => "Test"
11
12
}
12
- and _ = props.priority
13
13
14
14
React.string(text)
15
15
}
@@ -25,11 +25,11 @@ module C1 = {
25
25
26
26
@react.component
27
27
let make = (props: props<'priority, 'text>) => {
28
+ let p = props.priority
28
29
let text = switch props.text {
29
30
| Some(text) => text
30
31
| None => "Test"
31
32
}
32
- and p = props.priority
33
33
34
34
React.string(p ++ text)
35
35
}
Original file line number Diff line number Diff line change @@ -4,14 +4,14 @@ module C0 = {
4
4
5
5
@react.component
6
6
let make = (props: props<'a, 'b>) => {
7
+ let a = switch props.a {
8
+ | Some(a) => a
9
+ | None => 2
10
+ }
7
11
let b = switch props.b {
8
12
| Some(b) => b
9
13
| None => a * 2
10
14
}
11
- and a = switch props.a {
12
- | Some(a) => a
13
- | None => 2
14
- }
15
15
16
16
React.int(a + b)
17
17
}
@@ -27,11 +27,11 @@ module C1 = {
27
27
28
28
@react.component
29
29
let make = (props: props<'a, 'b>) => {
30
- let b = props.b
31
- and a = switch props.a {
30
+ let a = switch props.a {
32
31
| Some(a) => a
33
32
| None => 2
34
33
}
34
+ let b = props.b
35
35
36
36
React.int(a + b)
37
37
}
You can’t perform that action at this time.
0 commit comments