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

Commit

Permalink
Fix issue with formatting spread props.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianoc committed Sep 20, 2022
1 parent 6cdc47b commit 6597a6b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cli/reactjs_jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ let recordFromProps ~loc ~removeKey callArguments =
let props, propsToSpread =
removeLastPositionUnitAux callArguments []
|> List.rev
|> List.partition (fun (label, _) -> label <> labelled "spreadProps")
|> List.partition (fun (label, _) -> label <> labelled "_spreadProps")
in
let props =
if removeKey then
Expand Down
2 changes: 1 addition & 1 deletion src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2635,7 +2635,7 @@ and parseJsxProp p =
{e with pexp_attributes = propLocAttr :: e.pexp_attributes}
in
(* using label "spreadProps" to distinguish from others *)
let label = Asttypes.Labelled "spreadProps" in
let label = Asttypes.Labelled "_spreadProps" in
match p.Parser.token with
| Rbrace ->
Parser.next p;
Expand Down
3 changes: 3 additions & 0 deletions src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4129,6 +4129,9 @@ and printJsxProp ~customLayout arg cmtTbl =
| Nolabel -> Doc.nil
| Labelled _lbl -> printIdentLike ident
| Optional _lbl -> Doc.concat [Doc.question; printIdentLike ident])
| Asttypes.Labelled "_spreadProps", expr ->
let doc = printExpressionWithComments ~customLayout expr cmtTbl in
Doc.concat [Doc.lbrace; Doc.dotdotdot; Doc.softLine; doc; Doc.rbrace]
| lbl, expr ->
let argLoc, expr =
match expr.pexp_attributes with
Expand Down
6 changes: 5 additions & 1 deletion tests/parsing/grammar/expressions/expected/jsx.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -577,4 +577,8 @@ let _ =
;;(([(((fun a -> 1))[@ns.braces ])])[@JSX ])
;;(([((span ~children:[] ())[@JSX ])])[@JSX ])
;;(([[|a|]])[@JSX ])
;;(([(1, 2)])[@JSX ])
;;(([(1, 2)])[@JSX ])
let _ =
((A.createElement ~x:(({js|y|js})[@ns.namedArgLoc ]) ~_spreadProps:((str)
[@ns.namedArgLoc ]) ~children:[] ())
[@JSX ])
2 changes: 2 additions & 0 deletions tests/parsing/grammar/expressions/jsx.res
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,5 @@ let _ = <View style=styles["backgroundImageWrapper"]>
<> ...<span /> </>
<> ...[a] </>
<> ...(1, 2) </>

let _ = <A x="y" {...str} />
2 changes: 2 additions & 0 deletions tests/printer/expr/expected/jsx.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,5 @@ let v =
}}
</B>
</A>

let x = <A x="y" {...str} />
2 changes: 2 additions & 0 deletions tests/printer/expr/jsx.res
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,5 @@ let v =
}}
</B>
</A>

let x = <A x="y" {...str} />

0 comments on commit 6597a6b

Please sign in to comment.