Skip to content

Commit 39720a2

Browse files
authored
Merge pull request rescript-lang#169 from aspeddro/fix-object-as-aliasing
support as-aliasing-type
2 parents b0c8d4a + 1c16789 commit 39720a2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

grammar.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ module.exports = grammar({
359359
optional('|'),
360360
barSep1($.polyvar_declaration),
361361
']',
362-
optional(seq('as', $.type_identifier))
362+
optional($.as_aliasing_type)
363363
)),
364364

365365
polyvar_declaration: $ => prec.right(
@@ -393,15 +393,16 @@ module.exports = grammar({
393393
$.type_annotation,
394394
),
395395

396-
object_type: $ => seq(
396+
object_type: $ => prec.left(seq(
397397
'{',
398398
choice(
399399
commaSep1t($._object_type_field),
400400
seq('.', commaSept($._object_type_field)),
401401
seq('..', commaSept($._object_type_field)),
402402
),
403403
'}',
404-
),
404+
optional($.as_aliasing_type)
405+
)),
405406

406407
_object_type_field: $ => alias($.object_type_field, $.field),
407408

@@ -732,6 +733,8 @@ module.exports = grammar({
732733
optional($.type_annotation)
733734
)),
734735

736+
as_aliasing_type: $ => seq('as', $.type_identifier),
737+
735738
assert_expression: $ => prec.left(seq('assert', $.expression)),
736739

737740
call_expression: $ => prec('call', seq(

test/corpus/type_declarations.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ type foo<'a> = [> #Blue | #DeepBlue | #LightBlue ] as 'a
243243
(polyvar_declaration (polyvar_identifier))
244244
(polyvar_declaration (polyvar_identifier))
245245
(polyvar_declaration (polyvar_identifier))
246-
(type_identifier))))
246+
(as_aliasing_type (type_identifier)))))
247247

248248
===========================================
249249
Function
@@ -299,6 +299,7 @@ type t = {
299299
"my-field-two": string,
300300
...rest
301301
}
302+
type t<'a> = {.."name": string} as 'a
302303

303304
---
304305

@@ -318,7 +319,13 @@ type t = {
318319
(object_type
319320
(field (property_identifier (string_fragment)) (type_identifier))
320321
(field (property_identifier (string_fragment)) (type_identifier))
321-
(field (type_identifier)))))
322+
(field (type_identifier))))
323+
(type_declaration
324+
(type_identifier)
325+
(type_parameters (type_identifier))
326+
(object_type
327+
(field (property_identifier (string_fragment)) (type_identifier))
328+
(as_aliasing_type (type_identifier)))))
322329

323330
===========================================
324331
Generic

0 commit comments

Comments
 (0)