Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,22 @@ module.exports = grammar({
optional('export'),
'type',
optional('rec'),
$._type_declaration,
$._type_declaration
),

_type_declaration: $ => seq(
choice($.type_identifier, $.type_identifier_path),
optional($.type_parameters),
optional(seq(
choice('=', '+='),
optional('private'),
$._type,
repeat($.type_constraint),
optional(seq('=', $._type)),
optional(alias($._type_declaration_and, $.type_declaration)),
optional(seq(
choice('=', '+='),
optional('private'),
$._type,
)),
repeat($.type_constraint),
)),
optional(alias($._type_declaration_and, $.type_declaration))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change type t and b is valid.

),

_type_declaration_and: $ => seq(
Expand Down
15 changes: 13 additions & 2 deletions test/corpus/type_declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ Opaque
type t
type t'
type \"type"
type t and b

---

(source_file
(type_declaration (type_identifier))
(type_declaration (type_identifier))
(type_declaration (type_identifier)))
(type_declaration (type_identifier))
(type_declaration (type_identifier)
(type_declaration (type_identifier))))

===========================================
Export
Expand Down Expand Up @@ -530,6 +533,7 @@ Type constraint

type t<'a> = 'a constraint 'a = int
type decorator<'a, 'b> = 'a => 'b constraint 'a = int constraint 'b = _ => _
type t<'a> constraint 'a = t

---

Expand All @@ -553,4 +557,11 @@ type decorator<'a, 'b> = 'a => 'b constraint 'a = int constraint 'b = _ => _
(type_identifier)
(function_type
(function_type_parameters (type_identifier))
(type_identifier)))))
(type_identifier))))

(type_declaration
(type_identifier)
(type_parameters (type_identifier))
(type_constraint
(type_identifier)
(type_identifier))))