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

Spread props #644

Merged
merged 2 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#### :bug: Bug Fix

- Fix issue in formatting JSX spread props https://github.com/rescript-lang/syntax/pull/644
- Fix pretty printer where it would print doc comments on the same line as other attributes https://github.com/rescript-lang/syntax/pull/642
- Fix location issue in error messages with JSX V4 where the body of the component is an application https://github.com/rescript-lang/syntax/pull/633
- Fix issue where the printer would omit attributes for `->` and `|>` https://github.com/rescript-lang/syntax/pull/629
Expand Down
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} />