Skip to content

Commit 6a40242

Browse files
committed
better support for aliased type
1 parent 14e7605 commit 6a40242

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

grammar.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ module.exports = grammar({
313313
$._inline_type,
314314
$.variant_type,
315315
$.record_type,
316+
$.as_aliasing_type,
316317
),
317318

318319
_inline_type: $ => choice(
@@ -375,7 +376,6 @@ module.exports = grammar({
375376
optional('|'),
376377
barSep1($.polyvar_declaration),
377378
']',
378-
optional($.as_aliasing_type)
379379
)),
380380

381381
polyvar_declaration: $ => prec.right(
@@ -417,7 +417,6 @@ module.exports = grammar({
417417
seq('..', commaSept($._object_type_field)),
418418
),
419419
'}',
420-
optional($.as_aliasing_type)
421420
)),
422421

423422
_object_type_field: $ => alias($.object_type_field, $.field),
@@ -436,7 +435,6 @@ module.exports = grammar({
436435
generic_type: $ => prec.left(seq(
437436
$._type_identifier,
438437
$.type_arguments,
439-
optional($.as_aliasing_type)
440438
)),
441439

442440
type_arguments: $ => seq(
@@ -734,7 +732,7 @@ module.exports = grammar({
734732
optional($.type_annotation)
735733
)),
736734

737-
as_aliasing_type: $ => seq('as', $.type_identifier),
735+
as_aliasing_type: $ => seq($._type, 'as', $.type_identifier),
738736

739737
assert_expression: $ => prec.left(seq('assert', $.expression)),
740738

test/corpus/type_declarations.txt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,13 @@ type t<'w> = [M.t<'w>]
264264
(type_binding
265265
(type_identifier)
266266
(type_parameters (type_identifier))
267-
(polyvar_type
268-
(decorator (decorator_identifier))
269-
(polyvar_declaration (polyvar_identifier))
270-
(polyvar_declaration (polyvar_identifier))
271-
(polyvar_declaration (polyvar_identifier))
272-
(as_aliasing_type (type_identifier)))))
267+
(as_aliasing_type
268+
(polyvar_type
269+
(decorator (decorator_identifier))
270+
(polyvar_declaration (polyvar_identifier))
271+
(polyvar_declaration (polyvar_identifier))
272+
(polyvar_declaration (polyvar_identifier)))
273+
(type_identifier))))
273274

274275
(type_declaration
275276
(type_binding
@@ -368,9 +369,10 @@ type t<'a> = {.."name": string} as 'a
368369
(type_binding
369370
(type_identifier)
370371
(type_parameters (type_identifier))
371-
(object_type
372-
(field (property_identifier (string_fragment)) (type_identifier))
373-
(as_aliasing_type (type_identifier))))))
372+
(as_aliasing_type
373+
(object_type
374+
(field (property_identifier (string_fragment)) (type_identifier)))
375+
(type_identifier)))))
374376

375377
===========================================
376378
Generic
@@ -403,10 +405,11 @@ type t<'a> = generic<'a> as 's
403405
(type_binding
404406
(type_identifier)
405407
(type_parameters (type_identifier))
406-
(generic_type
407-
(type_identifier)
408-
(type_arguments (type_identifier))
409-
(as_aliasing_type (type_identifier))))))
408+
(as_aliasing_type
409+
(generic_type
410+
(type_identifier)
411+
(type_arguments (type_identifier)))
412+
(type_identifier)))))
410413

411414
===========================================
412415
Recursive

0 commit comments

Comments
 (0)