diff --git a/CHANGELOG.md b/CHANGELOG.md index b0212b19fa..00bf3af9f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Generic JSX transform: Rename expected module name for lowercase JSX to `Elements` from `DOM`. https://github.com/rescript-lang/rescript-compiler/pull/6606 - Generic JSX transform: Set default config params for `jsxConfig`. https://github.com/rescript-lang/rescript-compiler/pull/6606 - Generic JSX transform: Handle namespaced names. https://github.com/rescript-lang/rescript-compiler/pull/6606 +- Fix issue with doc comment in recursive module. https://github.com/rescript-lang/rescript-compiler/pull/6613 #### :house: Internal diff --git a/jscomp/syntax/src/res_core.ml b/jscomp/syntax/src/res_core.ml index fb90d8a20c..dca3a15bb2 100644 --- a/jscomp/syntax/src/res_core.ml +++ b/jscomp/syntax/src/res_core.ml @@ -6028,7 +6028,14 @@ and parseModuleBindingBody p = and parseModuleBindings ~attrs ~startPos p = let rec loop p acc = let startPos = p.Parser.startPos in - let attrs = parseAttributesAndBinding p in + let docAttr : Parsetree.attributes = + match p.Parser.token with + | DocComment (loc, s) -> + Parser.next p; + [docCommentToAttribute loc s] + | _ -> [] + in + let attrs = docAttr @ parseAttributesAndBinding p in match p.Parser.token with | And -> Parser.next p; diff --git a/jscomp/syntax/tests/printer/expr/DocComments.res b/jscomp/syntax/tests/printer/expr/DocComments.res index c2188c7b77..d07b49116f 100644 --- a/jscomp/syntax/tests/printer/expr/DocComments.res +++ b/jscomp/syntax/tests/printer/expr/DocComments.res @@ -11,3 +11,18 @@ module M : { @val external ex : (/** ddd */ ~x: int, /** eee */ n) => int = "ex" + +/** A */ +module rec A : { type t } = { + type t +} + +/** B */ +and B : { type t } = { + type t +} + +@res.doc(" C ") +and C : { type t} = { + type t +} diff --git a/jscomp/syntax/tests/printer/expr/expected/DocComments.res.txt b/jscomp/syntax/tests/printer/expr/expected/DocComments.res.txt index 70c276d364..1ec6c528d7 100644 --- a/jscomp/syntax/tests/printer/expr/expected/DocComments.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/DocComments.res.txt @@ -11,3 +11,24 @@ module M: { @val external ex: (/** ddd */ ~x: int, /** eee */ n) => int = "ex" + +/** A */ +module rec A: { + type t +} = { + type t +} + +/** B */ +and B: { + type t +} = { + type t +} + +/** C */ +and C: { + type t +} = { + type t +}