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

Commit 6975f8e

Browse files
committed
fix labelled arg alias
1 parent 783c967 commit 6975f8e

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

cli/reactjs_jsx_ppx.ml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,11 @@ module V4 = struct
23322332
]
23332333
(Exp.ident ~loc:emptyLoc {loc = emptyLoc; txt = Lident txt})
23342334
in
2335+
let stripConstraint pattern =
2336+
match pattern with
2337+
| {ppat_desc = Ppat_constraint (pattern, _)} -> pattern
2338+
| _ -> pattern
2339+
in
23352340
let rec returnedExpression patternsWithLabel patternsWithNolabel
23362341
({pexp_desc} as expr) =
23372342
match pexp_desc with
@@ -2348,14 +2353,19 @@ module V4 = struct
23482353
},
23492354
expr ) ->
23502355
(patternsWithLabel, patternsWithNolabel, expr)
2351-
| Pexp_fun (arg_label, _default, {ppat_loc; ppat_desc}, expr) -> (
2356+
| Pexp_fun
2357+
(arg_label, _default, ({ppat_loc; ppat_desc} as pattern), expr)
2358+
-> (
2359+
let pattern = stripConstraint pattern in
23522360
if isLabelled arg_label || isOptional arg_label then
23532361
returnedExpression
23542362
(( {loc = ppat_loc; txt = Lident (getLabel arg_label)},
2355-
Pat.var
2356-
~attrs:
2363+
{
2364+
pattern with
2365+
ppat_attributes =
23572366
(if isOptional arg_label then optionalAttr else [])
2358-
{txt = getLabel arg_label; loc = ppat_loc} )
2367+
@ pattern.ppat_attributes;
2368+
} )
23592369
:: patternsWithLabel)
23602370
patternsWithNolabel expr
23612371
else
@@ -2365,7 +2375,11 @@ module V4 = struct
23652375
| Ppat_var {txt} ->
23662376
returnedExpression patternsWithLabel
23672377
(( {loc = ppat_loc; txt = Lident txt},
2368-
Pat.var ~attrs:optionalAttr {txt; loc = ppat_loc} )
2378+
{
2379+
pattern with
2380+
ppat_attributes =
2381+
optionalAttr @ pattern.ppat_attributes;
2382+
} )
23692383
:: patternsWithNolabel)
23702384
expr
23712385
| _ ->

0 commit comments

Comments
 (0)