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

Use {} for empty record. #632

Merged
merged 3 commits into from
Sep 13, 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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
- Add surface syntax for `async`/`await` https://github.com/rescript-lang/syntax/pull/600

- Initial support for JSX V4, still work in progress.

- :boom: when V4 is activated, at most one component is allowed for each module.

- Add support for empty record literal `{}` for records with only optional fields, and type definition of empty record (e.g. `type empty = {}`) https://github.com/rescript-lang/syntax/pull/632

#### :bug: Bug Fix

- Fix issue where the printer would omit attributes for `->` and `|>` https://github.com/rescript-lang/syntax/pull/629
Expand Down
13 changes: 1 addition & 12 deletions src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2691,13 +2691,9 @@ and parseBracedOrRecordExpr p =
Parser.expect Lbrace p;
match p.Parser.token with
| Rbrace ->
Parser.err p (Diagnostics.unexpected Rbrace p.breadcrumbs);
Parser.next p;
let loc = mkLoc startPos p.prevEndPos in
let braces = makeBracesAttr loc in
Ast_helper.Exp.construct ~attrs:[braces] ~loc
(Location.mkloc (Longident.Lident "()") loc)
None
Ast_helper.Exp.record ~loc [] None
| DotDotDot ->
(* beginning of record spread, parse record *)
Parser.next p;
Expand Down Expand Up @@ -4913,13 +4909,6 @@ and parseRecordOrObjectDecl p =
:: parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations
~closing:Rbrace ~f:parseFieldDeclarationRegion p
in
let () =
match fields with
| [] ->
Parser.err ~startPos p
(Diagnostics.message "A record needs at least one field")
| _ -> ()
in
Parser.expect Rbrace p;
Parser.eatBreadcrumb p;
(None, Asttypes.Public, Parsetree.Ptype_record fields))
Expand Down
25 changes: 2 additions & 23 deletions tests/parsing/errors/expressions/expected/emptyBlock.res.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@

Syntax error!
tests/parsing/errors/expressions/emptyBlock.res:1:10

1 │ let x = {}
2 │
3 │ let f = (a, b) => {}

This let-binding misses an expression


Syntax error!
tests/parsing/errors/expressions/emptyBlock.res:3:20

1 │ let x = {}
2 │
3 │ let f = (a, b) => {}
4 │

Missing expression

let x = ((())[@ns.braces ])
let f a b = ((())[@ns.braces ])
let x = { }
let f a b = { }
9 changes: 0 additions & 9 deletions tests/parsing/errors/typeDef/expected/emptyRecord.res.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@

Syntax error!
tests/parsing/errors/typeDef/emptyRecord.res:1:15-16

1 │ type record = {}
2 │

A record needs at least one field

type nonrec record = {
}
25 changes: 2 additions & 23 deletions tests/parsing/recovery/expression/expected/emptyBlock.res.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@

Syntax error!
tests/parsing/recovery/expression/emptyBlock.res:1:10

1 │ let x = {}
2 │
3 │ let f = (a, b) => {}

This let-binding misses an expression


Syntax error!
tests/parsing/recovery/expression/emptyBlock.res:3:20

1 │ let x = {}
2 │
3 │ let f = (a, b) => {}
4 │

Missing expression

let x = ((())[@ns.braces ])
let f a b = ((())[@ns.braces ])
let x = { }
let f a b = { }