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

Commit d12adba

Browse files
committed
Fix issue with formatting spread props.
1 parent d022a22 commit d12adba

File tree

7 files changed

+16
-3
lines changed

7 files changed

+16
-3
lines changed

cli/reactjs_jsx_v4.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ let recordFromProps ~loc ~removeKey callArguments =
188188
let props, propsToSpread =
189189
removeLastPositionUnitAux callArguments []
190190
|> List.rev
191-
|> List.partition (fun (label, _) -> label <> labelled "spreadProps")
191+
|> List.partition (fun (label, _) -> label <> labelled "_spreadProps")
192192
in
193193
let props =
194194
if removeKey then

src/res_core.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2635,7 +2635,7 @@ and parseJsxProp p =
26352635
{e with pexp_attributes = propLocAttr :: e.pexp_attributes}
26362636
in
26372637
(* using label "spreadProps" to distinguish from others *)
2638-
let label = Asttypes.Labelled "spreadProps" in
2638+
let label = Asttypes.Labelled "_spreadProps" in
26392639
match p.Parser.token with
26402640
| Rbrace ->
26412641
Parser.next p;

src/res_printer.ml

+3
Original file line numberDiff line numberDiff line change
@@ -4129,6 +4129,9 @@ and printJsxProp ~customLayout arg cmtTbl =
41294129
| Nolabel -> Doc.nil
41304130
| Labelled _lbl -> printIdentLike ident
41314131
| Optional _lbl -> Doc.concat [Doc.question; printIdentLike ident])
4132+
| Asttypes.Labelled "_spreadProps", expr ->
4133+
let doc = printExpressionWithComments ~customLayout expr cmtTbl in
4134+
Doc.concat [Doc.lbrace; Doc.dotdotdot; Doc.softLine; doc; Doc.rbrace]
41324135
| lbl, expr ->
41334136
let argLoc, expr =
41344137
match expr.pexp_attributes with

tests/parsing/grammar/expressions/expected/jsx.res.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -577,4 +577,8 @@ let _ =
577577
;;(([(((fun a -> 1))[@ns.braces ])])[@JSX ])
578578
;;(([((span ~children:[] ())[@JSX ])])[@JSX ])
579579
;;(([[|a|]])[@JSX ])
580-
;;(([(1, 2)])[@JSX ])
580+
;;(([(1, 2)])[@JSX ])
581+
let _ =
582+
((A.createElement ~x:(({js|y|js})[@ns.namedArgLoc ]) ~_spreadProps:((str)
583+
[@ns.namedArgLoc ]) ~children:[] ())
584+
[@JSX ])

tests/parsing/grammar/expressions/jsx.res

+2
Original file line numberDiff line numberDiff line change
@@ -513,3 +513,5 @@ let _ = <View style=styles["backgroundImageWrapper"]>
513513
<> ...<span /> </>
514514
<> ...[a] </>
515515
<> ...(1, 2) </>
516+
517+
let _ = <A x="y" {...str} />

tests/printer/expr/expected/jsx.res.txt

+2
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,5 @@ let v =
408408
}}
409409
</B>
410410
</A>
411+
412+
let x = <A x="y" {...str} />

tests/printer/expr/jsx.res

+2
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,5 @@ let v =
401401
}}
402402
</B>
403403
</A>
404+
405+
let x = <A x="y" {...str} />

0 commit comments

Comments
 (0)