Skip to content

Commit d267aca

Browse files
committed
Fix parsing of single record spread.
1 parent dd8e73c commit d267aca

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

jscomp/test/DotDotDot.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ type globalProps = {
2020
}
2121

2222
type anchorProps = {
23-
\"...": globalProps,
23+
...globalProps,
2424
download?: string,
2525
href?: string,
2626
target?: [#_self | #_blank | #_parent | #_top],
2727
}
2828

2929
// globalProps only case?
30-
type divProps = {\"...": globalProps}
30+
type divProps = {...globalProps}
3131

3232
type svgProps = {
3333
...globalProps,

res_syntax/src/res_core.ml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4975,15 +4975,20 @@ and parseRecordOrObjectDecl p =
49754975
(* start of object type spreading, e.g. `type u = {...a, "u": int}` *)
49764976
Parser.next p;
49774977
let typ = parseTypExpr p in
4978-
let () =
4979-
match p.token with
4980-
| Rbrace ->
4981-
(* {...x}, spread without extra fields *)
4982-
Parser.next p
4983-
| _ -> Parser.expect Comma p
4984-
in
49854978
match p.token with
4979+
| Rbrace ->
4980+
(* {...x}, spread without extra fields *)
4981+
Parser.next p;
4982+
let loc = mkLoc startPos p.prevEndPos in
4983+
let dotField =
4984+
Ast_helper.Type.field ~loc
4985+
{txt = "..."; loc = mkLoc dotdotdotStart dotdotdotEnd}
4986+
typ
4987+
in
4988+
let kind = Parsetree.Ptype_record [dotField] in
4989+
(None, Public, kind)
49864990
| _ ->
4991+
Parser.expect Comma p;
49874992
let loc = mkLoc startPos p.prevEndPos in
49884993
let dotField =
49894994
Ast_helper.Type.field ~loc

0 commit comments

Comments
 (0)