From 708818ce08272001d023a65d89cf98578ff85142 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli <913103+shulhi@users.noreply.github.com> Date: Tue, 10 Feb 2026 18:25:31 +0800 Subject: [PATCH] Fix module type --- src/scanner.c | 12 +++++++++ test/corpus/modules.txt | 60 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/src/scanner.c b/src/scanner.c index 98423cf..ba1cb28 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -256,6 +256,18 @@ bool tree_sitter_rescript_external_scanner_scan( } } } + } else if (lexer->lookahead == 'w') { + advance(lexer); + if (lexer->lookahead == 'i') { + advance(lexer); + if (lexer->lookahead == 't') { + advance(lexer); + if (lexer->lookahead == 'h') { + // Ignore new lines before `with` keyword (module type constraints) + in_multiline_statement = true; + } + } + } } if (in_multiline_statement) { diff --git a/test/corpus/modules.txt b/test/corpus/modules.txt index 9e7845a..1b530a9 100644 --- a/test/corpus/modules.txt +++ b/test/corpus/modules.txt @@ -747,6 +747,66 @@ module M = (Na: N, Nb: N): ( (type_identifier))))) body: (block))))) +================================================================================ +Module with type constraint +================================================================================ + +module LogResultDecoder: OnpingStdLib_PubSub.FromJSON + with type t = AlarmMixLogBatchTypes.batchResult = { + type t = AlarmMixLogBatchTypes.batchResult + let fromJSON = (json: JSON.t): result => { + AlarmMixLogBatchTypes.decodeBatchResult(json) + } +} + +-------------------------------------------------------------------------------- + +(source_file + (module_declaration + (module_binding + name: (module_identifier) + signature: (module_type_constraint + (module_identifier_path + (module_identifier) + (module_identifier)) + (constrain_type + (type_identifier) + (type_identifier_path + (module_identifier) + (type_identifier)))) + definition: (block + (type_declaration + (type_binding + name: (type_identifier) + (type_identifier_path + (module_identifier) + (type_identifier)))) + (let_declaration + (let_binding + pattern: (value_identifier) + body: (function + parameters: (formal_parameters + (parameter + (value_identifier) + (type_annotation + (type_identifier_path + (module_identifier) + (type_identifier))))) + return_type: (type_annotation + (generic_type + (type_identifier) + (type_arguments + (type_identifier) + (type_identifier)))) + body: (block + (expression_statement + (call_expression + function: (value_identifier_path + (module_identifier) + (value_identifier)) + arguments: (arguments + (value_identifier)))))))))))) + ================================================================================ Dynamic imports ================================================================================