Skip to content

Commit b50f638

Browse files
zweimachEmilios1995
authored andcommitted
feat: record type spread
1 parent b83d7eb commit b50f638

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

grammar.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ module.exports = grammar({
105105
[$._reserved_identifier, $.function],
106106
[$.exception_pattern, $.or_pattern],
107107
[$.type_binding, $._inline_type],
108-
[$._module_structure, $.parenthesized_module_expression]
108+
[$._module_structure, $.parenthesized_module_expression],
109+
[$.record_type_field, $.object_type_field],
109110
],
110111

111112
rules: {
@@ -382,11 +383,14 @@ module.exports = grammar({
382383
'}',
383384
),
384385

385-
record_type_field: $ => seq(
386-
optional('mutable'),
387-
alias($.value_identifier, $.property_identifier),
388-
optional('?'),
389-
$.type_annotation,
386+
record_type_field: $ => choice(
387+
seq('...', choice($.type_identifier, $.type_identifier_path)),
388+
seq(
389+
optional('mutable'),
390+
alias($.value_identifier, $.property_identifier),
391+
optional('?'),
392+
$.type_annotation,
393+
),
390394
),
391395

392396
object_type: $ => prec.left(seq(

test/corpus/type_declarations.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ type t = Mod.t = {a: int}
106106

107107
type t = {}
108108

109+
type t = {
110+
...a,
111+
...b,
112+
other: int,
113+
}
114+
109115
--------------------------------------------------------------------------------
110116

111117
(source_file
@@ -147,7 +153,19 @@ type t = {}
147153
(type_declaration
148154
(type_binding
149155
(type_identifier)
150-
(record_type))))
156+
(record_type)))
157+
(type_declaration
158+
(type_binding
159+
(type_identifier)
160+
(record_type
161+
(record_type_field
162+
(type_identifier))
163+
(record_type_field
164+
(type_identifier))
165+
(record_type_field
166+
(property_identifier)
167+
(type_annotation
168+
(type_identifier)))))))
151169

152170
================================================================================
153171
Extensible Variant

0 commit comments

Comments
 (0)