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

Printer: auto-pun record fields #534

Merged
merged 2 commits into from
Jun 16, 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
3 changes: 1 addition & 2 deletions src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4826,8 +4826,7 @@ and printRecordRow (lbl, expr) cmtTbl punningAllowed =
match expr.pexp_desc with
| Pexp_ident({txt = Lident key; loc = keyLoc}) when (
punningAllowed &&
Longident.last lbl.txt = key &&
lbl.loc.loc_start.pos_cnum == keyLoc.loc_start.pos_cnum
Longident.last lbl.txt = key
) ->
(* print punned field *)
printLidentPath lbl cmtTbl;
Expand Down
2 changes: 1 addition & 1 deletion tests/conversion/reason/expected/bracedJsx.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ let make = () => {
],
),
}
| SetValue(input) => {...state, input: input}
| SetValue(input) => {...state, input}
}
, {history: [], input: ""})

Expand Down
2 changes: 1 addition & 1 deletion tests/conversion/reason/expected/braces.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ let getDailyNewCases = x =>
| Pair({prevRecord, record}) =>
let confirmed = record.confirmed - prevRecord.confirmed
let deaths = record.deaths - prevRecord.deaths
{confirmed: confirmed, deaths: deaths}
{confirmed, deaths}
}
8 changes: 5 additions & 3 deletions tests/printer/expr/expected/record.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ let user = {name: {(ceo.name: string)}}

// Punning
let r = {a} // actually not a record, just an expression in braces
let r = {a: a} // single-element record, not punned
let r = {A.a: a} // single-element record, not punned
let r = {a, b}
let r = {a, b, c: 42}
let r = {A.a, b}
let r = {A.a: a, b}
let r = {a: a, b}
let r = {a, b: b}
let r = {A.a, b}
let r = {a, b}
let r = {a, b}

// Punning + comments
let r = {
Expand Down
2 changes: 2 additions & 0 deletions tests/printer/expr/record.res
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ let user = {name: {(ceo.name: string)}}

// Punning
let r = {a} // actually not a record, just an expression in braces
let r = {a: a} // single-element record, not punned
let r = {A.a: a} // single-element record, not punned
let r = {a, b}
let r = {a, b, c: 42}
let r = {A.a, b}
Expand Down