diff --git a/CHANGELOG.md b/CHANGELOG.md index e9d7639e04..79c368e4f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,10 @@ - Remove deprecated pipe last (`|>`) syntax. https://github.com/rescript-lang/rescript/pull/7512 - Improve error message for pipe (`->`) syntax. https://github.com/rescript-lang/rescript/pull/7520 - Improve a few error messages around various subtyping issues. https://github.com/rescript-lang/rescript/pull/7404 +- In module declarations, accept the invalid syntax `M = {...}` and format it to `M : {...}`. https://github.com/rescript-lang/rescript/pull/7527 + +#### :house: Internal + - Refactor the ast for record expressions and patterns. https://github.com/rescript-lang/rescript/pull/7528 # 12.0.0-alpha.13 diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index d6a8051623..aebd7bc62d 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -6541,10 +6541,15 @@ and parse_module_declaration_or_alias ~attrs p = | Colon -> Parser.next p; parse_module_type p - | Equal -> + | Equal -> ( Parser.next p; - let lident = parse_module_long_ident ~lowercase:false p in - Ast_helper.Mty.alias lident + match p.Parser.token with + | Lbrace -> + (* Parse `module M = {` as `module M : {` *) + parse_module_type p + | _ -> + let lident = parse_module_long_ident ~lowercase:false p in + Ast_helper.Mty.alias lident) | token -> Parser.err p (Diagnostics.unexpected token p.breadcrumbs); Recover.default_module_type () diff --git a/tests/syntax_tests/data/printer/signature/expected/module.resi.txt b/tests/syntax_tests/data/printer/signature/expected/module.resi.txt index 6ea923c4d6..80ffd77f95 100644 --- a/tests/syntax_tests/data/printer/signature/expected/module.resi.txt +++ b/tests/syntax_tests/data/printer/signature/expected/module.resi.txt @@ -23,3 +23,8 @@ module LongNaaaaame: MyModule @attr module LinkedList: module type of List + +// turn `=` into `:` +module M: { + let x: int +} diff --git a/tests/syntax_tests/data/printer/signature/module.resi b/tests/syntax_tests/data/printer/signature/module.resi index 453f3f85ab..5007d5fbed 100644 --- a/tests/syntax_tests/data/printer/signature/module.resi +++ b/tests/syntax_tests/data/printer/signature/module.resi @@ -24,3 +24,6 @@ module LongNaaaaame: MyModule @attr module LinkedList: module type of List + +// turn `=` into `:` +module M = { let x: int } \ No newline at end of file