Skip to content

Commit e39df74

Browse files
committed
Support aliased inline types
This allows adding aliased types to record fields without allowing illegal non-inline types such as record or variants.
1 parent e0bc632 commit e39df74

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

grammar.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ module.exports = grammar({
318318
$.module_pack,
319319
$.unit,
320320
$.polymorphic_type,
321+
alias($._as_aliasing_non_function_inline_type, $.as_aliasing_type)
321322
),
322323

323324
polymorphic_type: $ => seq(
@@ -706,6 +707,9 @@ module.exports = grammar({
706707

707708
as_aliasing_type: $ => seq($._type, 'as', $.type_identifier),
708709

710+
_as_aliasing_non_function_inline_type: $ =>
711+
prec(2, seq($._non_function_inline_type, 'as', $.type_identifier)),
712+
709713
assert_expression: $ => prec.left(seq('assert', $.expression)),
710714

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

test/corpus/type_declarations.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ type t = {
9999

100100
mutable x: int,
101101

102-
opt?: string
102+
opt?: string,
103+
104+
env: {..} as 'env
103105
}
104106

105107
type t = Mod.t = {a: int}
@@ -140,7 +142,13 @@ type t = {
140142
(record_type_field
141143
(property_identifier)
142144
(type_annotation
143-
(type_identifier))))))
145+
(type_identifier)))
146+
(record_type_field
147+
(property_identifier)
148+
(type_annotation
149+
(as_aliasing_type
150+
(object_type)
151+
(type_identifier)))))))
144152
(type_declaration
145153
(type_binding
146154
(type_identifier)

0 commit comments

Comments
 (0)