Skip to content

Commit 246547a

Browse files
authored
Merge pull request #210 from aspeddro/as-type-parameter
Better support for aliased type
2 parents ce1ef35 + 6a40242 commit 246547a

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
@@ -322,6 +322,7 @@ module.exports = grammar({
322322
$._inline_type,
323323
$.variant_type,
324324
$.record_type,
325+
$.as_aliasing_type,
325326
),
326327

327328
_inline_type: $ => choice(
@@ -384,7 +385,6 @@ module.exports = grammar({
384385
optional('|'),
385386
barSep1($.polyvar_declaration),
386387
']',
387-
optional($.as_aliasing_type)
388388
)),
389389

390390
polyvar_declaration: $ => prec.right(
@@ -426,7 +426,6 @@ module.exports = grammar({
426426
seq('..', commaSept($._object_type_field)),
427427
),
428428
'}',
429-
optional($.as_aliasing_type)
430429
)),
431430

432431
_object_type_field: $ => alias($.object_type_field, $.field),
@@ -445,7 +444,6 @@ module.exports = grammar({
445444
generic_type: $ => prec.left(seq(
446445
$._type_identifier,
447446
$.type_arguments,
448-
optional($.as_aliasing_type)
449447
)),
450448

451449
type_arguments: $ => seq(
@@ -740,7 +738,7 @@ module.exports = grammar({
740738
optional($.type_annotation)
741739
)),
742740

743-
as_aliasing_type: $ => seq('as', $.type_identifier),
741+
as_aliasing_type: $ => seq($._type, 'as', $.type_identifier),
744742

745743
assert_expression: $ => prec.left(seq('assert', $.expression)),
746744

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)