Skip to content

Commit 3159c94

Browse files
authored
Fix module type (#266)
1 parent 5938ae1 commit 3159c94

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

src/scanner.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,18 @@ bool tree_sitter_rescript_external_scanner_scan(
256256
}
257257
}
258258
}
259+
} else if (lexer->lookahead == 'w') {
260+
advance(lexer);
261+
if (lexer->lookahead == 'i') {
262+
advance(lexer);
263+
if (lexer->lookahead == 't') {
264+
advance(lexer);
265+
if (lexer->lookahead == 'h') {
266+
// Ignore new lines before `with` keyword (module type constraints)
267+
in_multiline_statement = true;
268+
}
269+
}
270+
}
259271
}
260272

261273
if (in_multiline_statement) {

test/corpus/modules.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,66 @@ module M = (Na: N, Nb: N): (
747747
(type_identifier)))))
748748
body: (block)))))
749749

750+
================================================================================
751+
Module with type constraint
752+
================================================================================
753+
754+
module LogResultDecoder: OnpingStdLib_PubSub.FromJSON
755+
with type t = AlarmMixLogBatchTypes.batchResult = {
756+
type t = AlarmMixLogBatchTypes.batchResult
757+
let fromJSON = (json: JSON.t): result<t, string> => {
758+
AlarmMixLogBatchTypes.decodeBatchResult(json)
759+
}
760+
}
761+
762+
--------------------------------------------------------------------------------
763+
764+
(source_file
765+
(module_declaration
766+
(module_binding
767+
name: (module_identifier)
768+
signature: (module_type_constraint
769+
(module_identifier_path
770+
(module_identifier)
771+
(module_identifier))
772+
(constrain_type
773+
(type_identifier)
774+
(type_identifier_path
775+
(module_identifier)
776+
(type_identifier))))
777+
definition: (block
778+
(type_declaration
779+
(type_binding
780+
name: (type_identifier)
781+
(type_identifier_path
782+
(module_identifier)
783+
(type_identifier))))
784+
(let_declaration
785+
(let_binding
786+
pattern: (value_identifier)
787+
body: (function
788+
parameters: (formal_parameters
789+
(parameter
790+
(value_identifier)
791+
(type_annotation
792+
(type_identifier_path
793+
(module_identifier)
794+
(type_identifier)))))
795+
return_type: (type_annotation
796+
(generic_type
797+
(type_identifier)
798+
(type_arguments
799+
(type_identifier)
800+
(type_identifier))))
801+
body: (block
802+
(expression_statement
803+
(call_expression
804+
function: (value_identifier_path
805+
(module_identifier)
806+
(value_identifier))
807+
arguments: (arguments
808+
(value_identifier))))))))))))
809+
750810
================================================================================
751811
Dynamic imports
752812
================================================================================

0 commit comments

Comments
 (0)