diff --git a/CHANGELOG.md b/CHANGELOG.md index cbaf93af..d885d754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/res_core.ml b/src/res_core.ml index 1eea0a64..ba0e4d4d 100644 --- a/src/res_core.ml +++ b/src/res_core.ml @@ -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; @@ -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)) diff --git a/tests/parsing/errors/expressions/expected/emptyBlock.res.txt b/tests/parsing/errors/expressions/expected/emptyBlock.res.txt index c64b2e3a..36cfe2e4 100644 --- a/tests/parsing/errors/expressions/expected/emptyBlock.res.txt +++ b/tests/parsing/errors/expressions/expected/emptyBlock.res.txt @@ -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 ]) \ No newline at end of file +let x = { } +let f a b = { } \ No newline at end of file diff --git a/tests/parsing/errors/typeDef/expected/emptyRecord.res.txt b/tests/parsing/errors/typeDef/expected/emptyRecord.res.txt index ab8bf28c..a6f4d8f4 100644 --- a/tests/parsing/errors/typeDef/expected/emptyRecord.res.txt +++ b/tests/parsing/errors/typeDef/expected/emptyRecord.res.txt @@ -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 = { } \ No newline at end of file diff --git a/tests/parsing/recovery/expression/expected/emptyBlock.res.txt b/tests/parsing/recovery/expression/expected/emptyBlock.res.txt index 44309238..36cfe2e4 100644 --- a/tests/parsing/recovery/expression/expected/emptyBlock.res.txt +++ b/tests/parsing/recovery/expression/expected/emptyBlock.res.txt @@ -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 ]) \ No newline at end of file +let x = { } +let f a b = { } \ No newline at end of file