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

Commit bf6561b

Browse files
author
Iwan
committed
Improve formatting of poly variant typexprs with attributes
1 parent 7cc70c9 commit bf6561b

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

src/res_printer.ml

+13-9
Original file line numberDiff line numberDiff line change
@@ -1652,10 +1652,12 @@ and printTypExpr (typExpr : Parsetree.core_type) cmtTbl =
16521652
| Ptyp_variant (rowFields, closedFlag, labelsOpt) ->
16531653
let printRowField = function
16541654
| Parsetree.Rtag ({txt}, attrs, true, []) ->
1655-
Doc.concat [
1656-
printAttributes attrs cmtTbl;
1657-
Doc.concat [Doc.text "#"; printIdentLike ~allowUident:true txt]
1658-
]
1655+
Doc.group (
1656+
Doc.concat [
1657+
printAttributes attrs cmtTbl;
1658+
Doc.concat [Doc.text "#"; printIdentLike ~allowUident:true txt]
1659+
]
1660+
)
16591661
| Rtag ({txt}, attrs, truth, types) ->
16601662
let doType t = match t.Parsetree.ptyp_desc with
16611663
| Ptyp_tuple _ -> printTypExpr t cmtTbl
@@ -1664,11 +1666,13 @@ and printTypExpr (typExpr : Parsetree.core_type) cmtTbl =
16641666
let printedTypes = List.map doType types in
16651667
let cases = Doc.join ~sep:(Doc.concat [Doc.line; Doc.text "& "]) printedTypes in
16661668
let cases = if truth then Doc.concat [Doc.line; Doc.text "& "; cases] else cases in
1667-
Doc.group (Doc.concat [
1668-
printAttributes attrs cmtTbl;
1669-
Doc.concat [Doc.text "#"; printIdentLike ~allowUident:true txt];
1670-
cases
1671-
])
1669+
Doc.group (
1670+
Doc.concat [
1671+
printAttributes attrs cmtTbl;
1672+
Doc.concat [Doc.text "#"; printIdentLike ~allowUident:true txt];
1673+
cases
1674+
]
1675+
)
16721676
| Rinherit coreType ->
16731677
printTypExpr coreType cmtTbl
16741678
in

tests/printer/expr/__snapshots__/render.spec.js.snap

+18
Original file line numberDiff line numberDiff line change
@@ -3191,6 +3191,24 @@ let r = #lident
31913191
let r = #lident(a, b)
31923192
let r = #\\\\\\"exotic lident\\"
31933193
let r = #\\\\\\"exotic lident\\"(a, b)
3194+
3195+
external openSync: (
3196+
path,
3197+
@bs.string
3198+
[
3199+
| @bs.as(\\"r\\") #Read
3200+
| @bs.as(\\"r+\\") #Read_write
3201+
| @bs.as(\\"rs+\\") #Read_write_sync
3202+
| @bs.as(\\"w\\") #Write
3203+
| @bs.as(\\"wx\\") #Write_fail_if_exists
3204+
| @bs.as(\\"w+\\") #Write_read
3205+
| @bs.as(\\"wx+\\") #Write_read_fail_if_exists
3206+
| @bs.as(\\"a\\") #Append
3207+
| @bs.as(\\"ax\\") #Append_fail_if_exists
3208+
| @bs.as(\\"a+\\") #Append_read
3209+
| @bs.as(\\"ax+\\") #Append_read_fail_if_exists
3210+
],
3211+
) => unit = \\"openSync\\"
31943212
"
31953213
`;
31963214

tests/printer/expr/polyvariant.js

+17
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,20 @@ let r = #lident
103103
let r = #lident(a, b)
104104
let r = #\"exotic lident"
105105
let r = #\"exotic lident"(a, b)
106+
107+
external openSync: (
108+
path,
109+
@bs.string [
110+
| @bs.as("r") #Read
111+
| @bs.as("r+") #Read_write
112+
| @bs.as("rs+") #Read_write_sync
113+
| @bs.as("w") #Write
114+
| @bs.as("wx") #Write_fail_if_exists
115+
| @bs.as("w+") #Write_read
116+
| @bs.as("wx+") #Write_read_fail_if_exists
117+
| @bs.as("a") #Append
118+
| @bs.as("ax") #Append_fail_if_exists
119+
| @bs.as("a+") #Append_read
120+
| @bs.as("ax+") #Append_read_fail_if_exists
121+
],
122+
) => unit = "openSync"

0 commit comments

Comments
 (0)