@@ -166,7 +166,7 @@ module.exports = grammar({
166166 'module' ,
167167 optional ( 'rec' ) ,
168168 optional ( 'type' ) ,
169- field ( 'name' , $ . module_identifier ) ,
169+ field ( 'name' , choice ( $ . module_identifier , $ . _type_identifier ) ) ,
170170 optional ( seq (
171171 ':' ,
172172 field ( 'signature' , choice ( $ . block , $ . module_expression , $ . functor ) ) ,
@@ -182,8 +182,11 @@ module.exports = grammar({
182182 $ . module_expression ,
183183 $ . functor ,
184184 $ . extension_expression ,
185+ $ . module_unpack ,
185186 ) ,
186187
188+ module_unpack : $ => seq ( 'unpack' , $ . call_arguments ) ,
189+
187190 functor : $ => seq (
188191 field ( 'parameters' , $ . functor_parameters ) ,
189192 optional ( field ( 'return_module_type' , $ . module_type_annotation ) ) ,
@@ -276,6 +279,17 @@ module.exports = grammar({
276279 $ . object_type ,
277280 $ . generic_type ,
278281 $ . unit_type ,
282+ $ . module_type ,
283+ ) ,
284+
285+ module_type : $ => seq (
286+ 'module' ,
287+ '(' ,
288+ choice ( $ . module_identifier , $ . _type_identifier ) ,
289+ optional (
290+ seq ( 'with' , sep1 ( 'and' , seq ( 'type' , $ . _type_identifier , '=' , $ . _type_identifier ) ) )
291+ ) ,
292+ ')'
279293 ) ,
280294
281295 tuple_type : $ => prec . dynamic ( - 1 , seq (
@@ -428,6 +442,7 @@ module.exports = grammar({
428442 $ . record_pattern ,
429443 $ . array_pattern ,
430444 $ . list_pattern ,
445+ $ . module_unpack_pattern ,
431446 $ . unit
432447 ) ,
433448
@@ -474,7 +489,7 @@ module.exports = grammar({
474489 $ . pipe_expression ,
475490 $ . subscript_expression ,
476491 $ . member_expression ,
477- $ . module_destructuring_expression ,
492+ $ . module_pack_expression ,
478493 $ . extension_expression ,
479494 ) ,
480495
@@ -700,8 +715,17 @@ module.exports = grammar({
700715 ) ,
701716 ) ) ,
702717
703- module_destructuring_expression : $ => seq (
704- 'module' , '(' , choice ( $ . module_identifier , $ . module_identifier_path ) , ')'
718+ module_pack_expression : $ => seq (
719+ 'module' , '(' ,
720+ choice (
721+ seq (
722+ field ( 'name' , choice ( $ . module_identifier , $ . module_identifier_path ) ) ,
723+ optional ( field ( 'signature' , seq ( ':' , $ . module_identifier ) ) ) ,
724+ optional ( field ( 'definition' , seq ( '(' , $ . module_unpack , ')' ) ) )
725+ ) ,
726+ seq ( field ( 'definition' , $ . block ) , ':' , field ( 'signature' , $ . module_identifier ) )
727+ ) ,
728+ ')'
705729 ) ,
706730
707731 call_arguments : $ => seq (
@@ -770,7 +794,7 @@ module.exports = grammar({
770794
771795 type_parameter : $ => seq (
772796 'type' ,
773- $ . type_identifier ,
797+ repeat ( $ . type_identifier ) ,
774798 ) ,
775799
776800 _labeled_parameter_default_value : $ => seq (
@@ -884,6 +908,10 @@ module.exports = grammar({
884908 choice ( $ . value_identifier , $ . list_pattern , $ . array_pattern ) ,
885909 ) ,
886910
911+ module_unpack_pattern : $ => seq (
912+ 'module' , '(' , $ . module_identifier , ')' ,
913+ ) ,
914+
887915 _jsx_element : $ => choice ( $ . jsx_element , $ . jsx_self_closing_element ) ,
888916
889917 jsx_element : $ => seq (
0 commit comments