From 6212ef2da436d56e7e1b85cedd1f5a97605cedbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=A1zquez=20Acosta?= Date: Tue, 5 May 2026 17:12:50 +0200 Subject: [PATCH] Fix module packs in unpack expressions Allow first-class module packs with module type annotations inside unpack expressions, e.g. `unpack(module(Cleanup): PipelineStep with type state = t)`. Fixes https://github.com/rescript-lang/tree-sitter-rescript/issues/288 --- grammar.js | 1 + src/grammar.json | 21 +++++++++++++++++++++ src/node-types.json | 4 ++++ src/parser.c | 4 ++-- test/corpus/modules.txt | 14 ++++++++++++++ 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/grammar.js b/grammar.js index a9b5ec2..a397989 100644 --- a/grammar.js +++ b/grammar.js @@ -218,6 +218,7 @@ export default grammar({ optional($.module_type_annotation), ), seq($.call_expression, optional($.module_type_annotation)), + seq($.module_pack, optional($.module_type_annotation)), $.extension_expression, ), ")", diff --git a/src/grammar.json b/src/grammar.json index 3bd9724..4ac3289 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -515,6 +515,27 @@ } ] }, + { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "module_pack" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "module_type_annotation" + }, + { + "type": "BLANK" + } + ] + } + ] + }, { "type": "SYMBOL", "name": "extension_expression" diff --git a/src/node-types.json b/src/node-types.json index a999e6b..749094b 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -2848,6 +2848,10 @@ "type": "member_expression", "named": true }, + { + "type": "module_pack", + "named": true + }, { "type": "module_type_annotation", "named": true diff --git a/src/parser.c b/src/parser.c index 494a5c3..a988f79 100644 --- a/src/parser.c +++ b/src/parser.c @@ -94034,7 +94034,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { [sym_try_expression] = STATE(1424), [sym_call_expression] = STATE(3465), [sym_pipe_expression] = STATE(1424), - [sym_module_pack] = STATE(1424), + [sym_module_pack] = STATE(3465), [sym__definition_signature] = STATE(4828), [sym_formal_parameters] = STATE(4448), [sym__jsx_element] = STATE(1424), @@ -94424,7 +94424,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { [sym_try_expression] = STATE(1424), [sym_call_expression] = STATE(3483), [sym_pipe_expression] = STATE(1424), - [sym_module_pack] = STATE(1424), + [sym_module_pack] = STATE(3483), [sym__definition_signature] = STATE(4828), [sym_formal_parameters] = STATE(4448), [sym__jsx_element] = STATE(1424), diff --git a/test/corpus/modules.txt b/test/corpus/modules.txt index ed7cb02..eec9f53 100644 --- a/test/corpus/modules.txt +++ b/test/corpus/modules.txt @@ -245,6 +245,8 @@ module( ) module(SomeFunctor(unpack(x))) +module M = unpack(module(Cleanup): PipelineStep with type state = t) + module T = unpack(foo: T) module S = unpack(foo: T with type t = a) @@ -288,6 +290,18 @@ module T3 = unpack(make(): T with type t = int) (arguments (module_unpack (value_identifier)))))) + (module_declaration + (module_binding + (module_identifier) + (module_unpack + (module_pack + (module_identifier)) + (module_type_annotation + (module_type_constraint + (module_identifier) + (constrain_type + (type_identifier) + (type_identifier))))))) (module_declaration (module_binding (module_identifier)