Skip to content

Commit

Permalink
Fix issue where an inline record with attributes did not parse.
Browse files Browse the repository at this point in the history
This did not parse without a `,` after the field:

```res
type inlineWithAttrs = | A({@as("VALUE") value: string})
```

Fixes #6497
  • Loading branch information
cristianoc committed Nov 29, 2023
1 parent c1b9701 commit 0cee83f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
11 changes: 7 additions & 4 deletions jscomp/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4675,12 +4675,15 @@ and parseConstrDeclArgs p =
let attrs =
if optional then optionalAttr :: attrs else attrs
in
Parser.expect Comma p;
{field with Parsetree.pld_attributes = attrs}
in
first
:: parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations
~closing:Rbrace ~f:parseFieldDeclarationRegion p
if p.token = Rbrace then [first]
else (
Parser.expect Comma p;
first
:: parseCommaDelimitedRegion
~grammar:Grammar.FieldDeclarations ~closing:Rbrace
~f:parseFieldDeclarationRegion p)
in
Parser.expect Rbrace p;
Parser.optional p Comma |> ignore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ type nonrec multipleWithAttrs = {
x: int ;
y: string [@res.optional ][@attr ]}
type nonrec singleWithAttrs = {
y: string [@res.optional ][@attr ]}
y: string [@res.optional ][@attr ]}
type nonrec inlineWithAttrs =
| A of {
value: string [@as {js|VALUE|js}]}
4 changes: 3 additions & 1 deletion jscomp/syntax/tests/parsing/grammar/expressions/record.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ type ttt = {x:int, y?: string}

type multipleWithAttrs = {x:int, @attr y?: string}

type singleWithAttrs = {@attr y?: string}
type singleWithAttrs = {@attr y?: string}

type inlineWithAttrs = | A({@as("VALUE") value: string})

0 comments on commit 0cee83f

Please sign in to comment.