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

Commit cd86626

Browse files
authored
Printer: auto-pun record fields (#534)
* Printer: auto-pun record fields * Add test cases for single-element records
1 parent 3aec2c8 commit cd86626

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

src/res_printer.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4839,8 +4839,7 @@ and printRecordRow (lbl, expr) cmtTbl punningAllowed =
48394839
match expr.pexp_desc with
48404840
| Pexp_ident({txt = Lident key; loc = keyLoc}) when (
48414841
punningAllowed &&
4842-
Longident.last lbl.txt = key &&
4843-
lbl.loc.loc_start.pos_cnum == keyLoc.loc_start.pos_cnum
4842+
Longident.last lbl.txt = key
48444843
) ->
48454844
(* print punned field *)
48464845
printLidentPath lbl cmtTbl;

tests/conversion/reason/expected/bracedJsx.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ let make = () => {
9191
],
9292
),
9393
}
94-
| SetValue(input) => {...state, input: input}
94+
| SetValue(input) => {...state, input}
9595
}
9696
, {history: [], input: ""})
9797

tests/conversion/reason/expected/braces.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ let getDailyNewCases = x =>
2020
| Pair({prevRecord, record}) =>
2121
let confirmed = record.confirmed - prevRecord.confirmed
2222
let deaths = record.deaths - prevRecord.deaths
23-
{confirmed: confirmed, deaths: deaths}
23+
{confirmed, deaths}
2424
}

tests/printer/expr/expected/record.res.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ let user = {name: {(ceo.name: string)}}
4242

4343
// Punning
4444
let r = {a} // actually not a record, just an expression in braces
45+
let r = {a: a} // single-element record, not punned
46+
let r = {A.a: a} // single-element record, not punned
4547
let r = {a, b}
4648
let r = {a, b, c: 42}
4749
let r = {A.a, b}
48-
let r = {A.a: a, b}
49-
let r = {a: a, b}
50-
let r = {a, b: b}
50+
let r = {A.a, b}
51+
let r = {a, b}
52+
let r = {a, b}
5153

5254
// Punning + comments
5355
let r = {

tests/printer/expr/record.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ let user = {name: {(ceo.name: string)}}
3232

3333
// Punning
3434
let r = {a} // actually not a record, just an expression in braces
35+
let r = {a: a} // single-element record, not punned
36+
let r = {A.a: a} // single-element record, not punned
3537
let r = {a, b}
3638
let r = {a, b, c: 42}
3739
let r = {A.a, b}

0 commit comments

Comments
 (0)