Skip to content

Commit 49e702f

Browse files
committed
Fix parse error on doc comment before "and" in type def (#7001)
* Fix parse error on doc comment before "and" in type def * CHANGELOG # Conflicts: # jscomp/syntax/src/res_core.ml
1 parent 0148456 commit 49e702f

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Fix incorrect incorrect printing of module binding with signature. https://github.com/rescript-lang/rescript-compiler/pull/6963
1818
- Disallow spreading anything but regular variants inside of other variants. https://github.com/rescript-lang/rescript-compiler/pull/6980
1919
- Fix comment removed when function signature has `type` keyword. https://github.com/rescript-lang/rescript-compiler/pull/6997
20+
- Fix parse error on doc comment before "and" in type def. https://github.com/rescript-lang/rescript-compiler/pull/7001
2021

2122
# 11.1.3
2223

jscomp/syntax/src/res_core.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2525,7 +2525,7 @@ and parseAttributesAndBinding (p : Parser.t) =
25252525
let comments = p.comments in
25262526

25272527
match p.Parser.token with
2528-
| At -> (
2528+
| At | DocComment (_, _) -> (
25292529
let attrs = parseAttributes p in
25302530
match p.Parser.token with
25312531
| And -> attrs

jscomp/syntax/tests/parsing/other/docComments.res

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ let q = 11
1414
* is a multi-line
1515
multiline doc comment
1616
*/
17-
type h = int
17+
type h = int
18+
19+
type pathItem = {}
20+
/** Issue 6844: doc comment before "and" */
21+
and operation = {}

jscomp/syntax/tests/parsing/other/expected/docComments.res.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ let z = 34[@@res.doc " This is a doc \226\156\133 comment "]
44
[@@@res.doc {js|And this is a res.doc module annotation|js}]
55
let q = 11[@@res.doc {js|And this is a res.doc ✅ annotation|js}]
66
type nonrec h = int[@@res.doc
7-
" This\n * is a multi-line\n multiline doc comment\n "]
7+
" This\n * is a multi-line\n multiline doc comment\n "]
8+
type nonrec pathItem = {
9+
}
10+
and operation = {
11+
}[@@res.doc " Issue 6844: doc comment before \"and\" "]

jscomp/syntax/tests/printer/comments/docComments.res

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ type h = int
2626
@foo @bar @baz let x = 10
2727

2828
/** doc comment and 0 attributes */
29-
let x = 10
29+
let x = 10
30+
31+
type pathItem = {}
32+
/** Issue 6844: doc comment before "and" */
33+
and operation = {}

jscomp/syntax/tests/printer/comments/expected/docComments.res.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ let x = 10
3131

3232
/** doc comment and 0 attributes */
3333
let x = 10
34+
35+
type pathItem = {}
36+
/** Issue 6844: doc comment before "and" */ and operation = {}

0 commit comments

Comments
 (0)