Skip to content

Commit 1b3ba31

Browse files
authored
Fix extends (#204)
* support extends (abstract) * regenerate parser Co-authored-by: resolritter <[email protected]>
1 parent 8e9dba7 commit 1b3ba31

File tree

6 files changed

+255349
-258871
lines changed

6 files changed

+255349
-258871
lines changed

common/corpus/types.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,3 +1356,54 @@ type T = Foo<any, unknown, number, string, void, true, false, null, undefined, 0
13561356
(literal_type
13571357
(string
13581358
(string_fragment)))))))
1359+
1360+
==================================
1361+
Extends
1362+
==================================
1363+
1364+
type Foo<T extends abstract new (...args: any) => any> = T;
1365+
type Foo<T extends new (...args: any) => any> = T;
1366+
1367+
---
1368+
1369+
(program
1370+
(type_alias_declaration
1371+
(type_identifier)
1372+
(type_parameters
1373+
(type_parameter
1374+
(type_identifier)
1375+
(constraint
1376+
(constructor_type
1377+
(formal_parameters
1378+
(required_parameter
1379+
(rest_pattern
1380+
(identifier))
1381+
(type_annotation
1382+
(predefined_type))))
1383+
(predefined_type)))))
1384+
(type_identifier))
1385+
(type_alias_declaration
1386+
(type_identifier)
1387+
(type_parameters
1388+
(type_parameter
1389+
(type_identifier)
1390+
(constraint
1391+
(constructor_type
1392+
(formal_parameters
1393+
(required_parameter
1394+
(rest_pattern
1395+
(identifier))
1396+
(type_annotation
1397+
(predefined_type))))
1398+
(predefined_type)))))
1399+
(type_identifier)))
1400+
1401+
========
1402+
Abstract
1403+
========
1404+
1405+
type Foo<T> = abstract new () => T;
1406+
1407+
---
1408+
1409+
(program (type_alias_declaration (type_identifier) (type_parameters (type_parameter (type_identifier))) (constructor_type (formal_parameters) (type_identifier))))

common/define-grammar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ module.exports = function defineGrammar(dialect) {
624624
),
625625

626626
constructor_type: $ => prec.left(seq(
627+
optional('abstract'),
627628
'new',
628629
field('type_parameters', optional($.type_parameters)),
629630
field('parameters', $.formal_parameters),
@@ -857,6 +858,7 @@ module.exports = function defineGrammar(dialect) {
857858
),
858859

859860
construct_signature: $ => seq(
861+
optional('abstract'),
860862
'new',
861863
field('type_parameters', optional($.type_parameters)),
862864
field('parameters', $.formal_parameters),

tsx/src/grammar.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8503,6 +8503,18 @@
85038503
"content": {
85048504
"type": "SEQ",
85058505
"members": [
8506+
{
8507+
"type": "CHOICE",
8508+
"members": [
8509+
{
8510+
"type": "STRING",
8511+
"value": "abstract"
8512+
},
8513+
{
8514+
"type": "BLANK"
8515+
}
8516+
]
8517+
},
85068518
{
85078519
"type": "STRING",
85088520
"value": "new"
@@ -9787,6 +9799,18 @@
97879799
"construct_signature": {
97889800
"type": "SEQ",
97899801
"members": [
9802+
{
9803+
"type": "CHOICE",
9804+
"members": [
9805+
{
9806+
"type": "STRING",
9807+
"value": "abstract"
9808+
},
9809+
{
9810+
"type": "BLANK"
9811+
}
9812+
]
9813+
},
97909814
{
97919815
"type": "STRING",
97929816
"value": "new"

0 commit comments

Comments
 (0)