From 0c925f0f739911f98805d7a88714254d4268fb47 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 1 Sep 2024 18:51:18 +0200 Subject: [PATCH 1/2] Fix parse error on doc comment before "and" in type def --- jscomp/syntax/src/res_core.ml | 2 +- jscomp/syntax/tests/parsing/other/docComments.res | 6 +++++- .../syntax/tests/parsing/other/expected/docComments.res.txt | 6 +++++- jscomp/syntax/tests/printer/comments/docComments.res | 6 +++++- .../tests/printer/comments/expected/docComments.res.txt | 3 +++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/jscomp/syntax/src/res_core.ml b/jscomp/syntax/src/res_core.ml index 1ee182cba7..b0e68ae3ba 100644 --- a/jscomp/syntax/src/res_core.ml +++ b/jscomp/syntax/src/res_core.ml @@ -2511,7 +2511,7 @@ and parse_attributes_and_binding (p : Parser.t) = let comments = p.comments in match p.Parser.token with - | At -> ( + | At | DocComment (_, _) -> ( let attrs = parse_attributes p in match p.Parser.token with | And -> attrs diff --git a/jscomp/syntax/tests/parsing/other/docComments.res b/jscomp/syntax/tests/parsing/other/docComments.res index 2aec79b66c..793f5980d8 100644 --- a/jscomp/syntax/tests/parsing/other/docComments.res +++ b/jscomp/syntax/tests/parsing/other/docComments.res @@ -14,4 +14,8 @@ let q = 11 * is a multi-line multiline doc comment */ -type h = int \ No newline at end of file +type h = int + +type pathItem = {} +/** Issue 6844: doc comment before "and" */ +and operation = {} diff --git a/jscomp/syntax/tests/parsing/other/expected/docComments.res.txt b/jscomp/syntax/tests/parsing/other/expected/docComments.res.txt index f8427fb3ff..004126c18d 100644 --- a/jscomp/syntax/tests/parsing/other/expected/docComments.res.txt +++ b/jscomp/syntax/tests/parsing/other/expected/docComments.res.txt @@ -4,4 +4,8 @@ let z = 34[@@res.doc " This is a doc \226\156\133 comment "] [@@@res.doc {js|And this is a res.doc module annotation|js}] let q = 11[@@res.doc {js|And this is a res.doc ✅ annotation|js}] type nonrec h = int[@@res.doc - " This\n * is a multi-line\n multiline doc comment\n "] \ No newline at end of file + " This\n * is a multi-line\n multiline doc comment\n "] +type nonrec pathItem = { + } +and operation = { + }[@@res.doc " Issue 6844: doc comment before \"and\" "] \ No newline at end of file diff --git a/jscomp/syntax/tests/printer/comments/docComments.res b/jscomp/syntax/tests/printer/comments/docComments.res index e3e667adb3..731ca5d5cd 100644 --- a/jscomp/syntax/tests/printer/comments/docComments.res +++ b/jscomp/syntax/tests/printer/comments/docComments.res @@ -26,4 +26,8 @@ type h = int @foo @bar @baz let x = 10 /** doc comment and 0 attributes */ -let x = 10 \ No newline at end of file +let x = 10 + +type pathItem = {} +/** Issue 6844: doc comment before "and" */ +and operation = {} diff --git a/jscomp/syntax/tests/printer/comments/expected/docComments.res.txt b/jscomp/syntax/tests/printer/comments/expected/docComments.res.txt index 6a6a951e97..bae9ae907e 100644 --- a/jscomp/syntax/tests/printer/comments/expected/docComments.res.txt +++ b/jscomp/syntax/tests/printer/comments/expected/docComments.res.txt @@ -31,3 +31,6 @@ let x = 10 /** doc comment and 0 attributes */ let x = 10 + +type pathItem = {} +/** Issue 6844: doc comment before "and" */ and operation = {} From 2c449e20960d84f688e84aeb2d02d62a0b2b864e Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Mon, 2 Sep 2024 10:01:24 +0200 Subject: [PATCH 2/2] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4787fec7d3..9a50b0d335 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ - Fix incorrect printing of external with `@as` attribute and `_` placholder (fixed argument). https://github.com/rescript-lang/rescript-compiler/pull/6970 - Disallow spreading anything but regular variants inside of other variants. https://github.com/rescript-lang/rescript-compiler/pull/6980 - Fix comment removed when function signature has `type` keyword. https://github.com/rescript-lang/rescript-compiler/pull/6997 +- Fix parse error on doc comment before "and" in type def. https://github.com/rescript-lang/rescript-compiler/pull/7001 #### :house: Internal