Skip to content

Commit 858ae31

Browse files
committed
fix format for multi-line record updates
1 parent a2213c3 commit 858ae31

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/Common/Format/Render/Box.elm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2398,7 +2398,13 @@ formatExpression importInfo (A.At region aexpr) =
23982398

23992399
fields_ : List (Src.C2Eol (Src.Pair Name Src.Expr))
24002400
fields_ =
2401-
List.map (Src.c2EolMap (\( ( nameComments, A.At _ name_ ), expr ) -> Src.Pair ( nameComments, name_ ) expr multiline)) fields
2401+
List.map
2402+
(Src.c2EolMap
2403+
(\( ( nameComments, A.At _ name_ ), ( _, A.At exprRegion _ ) as expr ) ->
2404+
Src.Pair ( nameComments, name_ ) expr (Src.ForceMultiline (A.isMultiline exprRegion))
2405+
)
2406+
)
2407+
fields
24022408
in
24032409
( SyntaxSeparated
24042410
, formatRecordLike

src/Common/Format/Render/ElmStructure.elm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ forceableSpaceSepOrStack forceMultiline first rest =
5454

5555
forceableRowOrStack : Bool -> Box -> List Box -> Box
5656
forceableRowOrStack forceMultiline first rest =
57-
case
58-
( forceMultiline, first, Box.allSingles rest )
59-
of
57+
case ( forceMultiline, first, Box.allSingles rest ) of
6058
( False, Box.SingleLine first_, Ok rest_ ) ->
6159
Box.line <| Box.row (first_ :: rest_)
6260

tests/format.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ const examples = [
277277
}
278278
},
279279
{ title: "multi-line record", filename: "MultiLineRecordDeclarations", module: { ...defaultModule, declarations: [`recordFn =\n { age = 23\n , name =\n "John"\n }`] } },
280+
{ title: "multi-line update record", filename: "MultiLineUpdateRecordDeclarations", module: { ...defaultModule, declarations: [`updateRecordFn =\n { record | age = 23\n , name = "John"\n }`] } },
280281
]],
281282
// UNION DECLARATIONS
282283
["Union", [
@@ -366,11 +367,6 @@ describe("format", () => {
366367
});
367368

368369
const generateModule = ({ header, docs, imports, infixes, declarations }) => {
369-
// console.log(`${header}
370-
// ${docs}
371-
// ${imports.join("\n")}
372-
// ${infixes.join("\n")}
373-
// ${declarations.join("\n")}`);
374370
return `${header}
375371
${docs}
376372
${imports.join("\n")}

0 commit comments

Comments
 (0)