@@ -128,6 +128,10 @@ type sugared_list_item =
128128 | Regular (Parsetree . expression)
129129 | Spread (Parsetree . expression);
130130
131+ type record_item =
132+ | Field ((Location . loc(Identifier . t), Parsetree . expression))
133+ | RecordSpread (Parsetree . expression);
134+
131135type sugared_pattern_item =
132136 | RegularPattern (Parsetree . pattern)
133137 | SpreadPattern (Parsetree . pattern);
@@ -1627,53 +1631,81 @@ and print_ident = (ident: Identifier.t) => {
16271631
16281632and print_record =
16291633 (
1634+ ~base: option (Parsetree . expression ),
16301635 ~fields: list ((Location . loc (Identifier . t ), Parsetree . expression )),
16311636 ~original_source: array (string ),
16321637 ~comments: list (Parsetree . comment ),
16331638 recloc: Location . t ,
16341639 ) => {
1635- let get_loc = (field: (Location . loc (Identifier . t ), Parsetree . expression )) => {
1636- let (_ , expr ) = field;
1637- expr. pexp_loc;
1640+ let get_loc = item => {
1641+ switch (item) {
1642+ | Field ((_ , expr )) => expr. pexp_loc
1643+ | RecordSpread (base ) => base. pexp_loc
1644+ };
16381645 };
16391646
1640- let print_item =
1641- (~comments, field: (Location . loc (Identifier . t ), Parsetree . expression )) => {
1642- let (locidentifier , expr ) = field;
1643- let ident = locidentifier. txt;
1644- let printed_ident = print_ident(ident);
1645- let printed_expr =
1646- print_expression(
1647- ~expression_parent= GenericExpression ,
1648- ~original_source,
1649- ~comments,
1650- expr,
1651- );
1652- let punned_expr = check_for_pun(expr);
1647+ let print_item = (~comments, item) => {
1648+ switch (item) {
1649+ | Field (field ) =>
1650+ let (locidentifier , expr ) = field;
1651+ let ident = locidentifier. txt;
1652+ let printed_ident = print_ident(ident);
1653+ let printed_expr =
1654+ print_expression(
1655+ ~expression_parent= GenericExpression ,
1656+ ~original_source,
1657+ ~comments,
1658+ expr,
1659+ );
1660+ let punned_expr = check_for_pun(expr);
16531661
1654- let pun =
1655- switch (printed_ident, punned_expr: Doc . t ) {
1656- | (Text (i ), Text (e )) => i == e
1657- | _ => false
1658- };
1662+ let pun =
1663+ switch (printed_ident, punned_expr: Doc . t ) {
1664+ | (Text (i ), Text (e )) => i == e
1665+ | _ => false
1666+ };
16591667
1660- if (! pun) {
1661- Doc . group(
1662- Doc . concat([ printed_ident, Doc . text(":" ), Doc . space, printed_expr] ),
1663- );
1664- } else {
1665- Doc . group(printed_ident);
1668+ if (! pun) {
1669+ Doc . group(
1670+ Doc . concat([
1671+ printed_ident,
1672+ Doc . text(":" ),
1673+ Doc . space,
1674+ printed_expr,
1675+ ] ),
1676+ );
1677+ } else {
1678+ Doc . group(printed_ident);
1679+ };
1680+ | RecordSpread (base ) =>
1681+ Doc . concat([
1682+ Doc . text("..." ),
1683+ print_expression(
1684+ ~expression_parent= GenericExpression ,
1685+ ~original_source,
1686+ ~comments,
1687+ base,
1688+ ),
1689+ ] )
16661690 };
16671691 };
16681692
1693+ let items =
1694+ Option . to_list(Option . map(x => RecordSpread (x), base))
1695+ @ List . map(x => Field (x), fields);
1696+
16691697 let after_brace_comments =
1670- switch (fields) {
1671- | [ field , ... _ ] =>
1672- let (ident , expr ) = field;
1698+ switch (items) {
1699+ | [ item , ... _ ] =>
1700+ let loc =
1701+ switch (item) {
1702+ | Field ((ident , _ )) => ident. loc
1703+ | RecordSpread (exp ) => exp. pexp_loc
1704+ };
16731705
16741706 Comment_utils . get_after_brace_comments(
16751707 ~loc= recloc,
1676- ~first= ident . loc,
1708+ ~first= loc,
16771709 comments,
16781710 );
16791711
@@ -1689,7 +1721,7 @@ and print_record =
16891721 ~print_item,
16901722 ~comments= cleaned_comments,
16911723 ~iterated_item= IteratedRecord ,
1692- fields ,
1724+ items ,
16931725 );
16941726 let printed_fields = Doc . join(~sep= Doc . line, items);
16951727
@@ -1707,7 +1739,7 @@ and print_record =
17071739 printed_fields_after_brace,
17081740 Doc . ifBreaks(
17091741 Doc . nil,
1710- switch (fields ) {
1742+ switch (items ) {
17111743 | [ _one ] =>
17121744 // TODO: not needed once we annotate with ::
17131745 Doc . comma // append a comma as single argument record look like block {data:val}
@@ -2787,8 +2819,14 @@ and print_expression_inner =
27872819 ] ),
27882820 )
27892821
2790- | PExpRecord (record ) =>
2791- print_record(~fields= record, ~original_source, ~comments, expr. pexp_loc)
2822+ | PExpRecord (base , record ) =>
2823+ print_record(
2824+ ~base,
2825+ ~fields= record,
2826+ ~original_source,
2827+ ~comments,
2828+ expr. pexp_loc,
2829+ )
27922830 | PExpRecordGet (expression , {txt, _ }) =>
27932831 Doc . concat([
27942832 print_expression(
0 commit comments