Skip to content

Commit 85389c3

Browse files
authored
Merge pull request #163 from rmagatti/add-override-modifier
Add override modifier
2 parents 3383ceb + 557319e commit 85389c3

File tree

11 files changed

+259752
-248803
lines changed

11 files changed

+259752
-248803
lines changed

common/corpus/declarations.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,3 +1025,38 @@ class Foo {
10251025
(property_identifier)
10261026
(formal_parameters)
10271027
(statement_block)))))
1028+
1029+
=====================
1030+
Override modifier
1031+
=====================
1032+
1033+
abstract class Foo {
1034+
abstract baz(): void;
1035+
}
1036+
1037+
class Bar extends Foo {
1038+
override baz() {}
1039+
}
1040+
1041+
---
1042+
1043+
(program
1044+
(abstract_class_declaration
1045+
name: (type_identifier)
1046+
body: (class_body
1047+
(abstract_method_signature
1048+
name: (property_identifier)
1049+
parameters: (formal_parameters)
1050+
return_type: (type_annotation
1051+
(predefined_type)))))
1052+
(class_declaration
1053+
name: (type_identifier)
1054+
(class_heritage
1055+
(extends_clause
1056+
(type_identifier)))
1057+
body: (class_body
1058+
(method_definition
1059+
(override_modifier)
1060+
name: (property_identifier)
1061+
parameters: (formal_parameters)
1062+
body: (statement_block)))))

common/define-grammar.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ module.exports = function defineGrammar(dialect) {
5353
[$._type_query_subscript_expression, $.primary_expression],
5454
[$._type_query_call_expression, $.primary_expression],
5555
[$.type_query, $.primary_expression],
56+
[$.override_modifier, $.primary_expression],
5657
]),
5758

5859
conflicts: ($, previous) => previous.concat([
@@ -130,7 +131,7 @@ module.exports = function defineGrammar(dialect) {
130131
optional('declare'),
131132
optional($.accessibility_modifier),
132133
choice(
133-
seq(optional('static'), optional('readonly')),
134+
seq(optional('static'), optional($.override_modifier), optional('readonly')),
134135
seq(optional('abstract'), optional('readonly')),
135136
seq(optional('readonly'), optional('abstract')),
136137
),
@@ -287,6 +288,7 @@ module.exports = function defineGrammar(dialect) {
287288
method_signature: $ => seq(
288289
optional($.accessibility_modifier),
289290
optional('static'),
291+
optional($.override_modifier),
290292
optional('readonly'),
291293
optional('async'),
292294
optional(choice('get', 'set', '*')),
@@ -356,6 +358,7 @@ module.exports = function defineGrammar(dialect) {
356358
method_definition: $ => prec.left(seq(
357359
optional($.accessibility_modifier),
358360
optional('static'),
361+
optional($.override_modifier),
359362
optional('readonly'),
360363
optional('async'),
361364
optional(choice('get', 'set', '*')),
@@ -530,6 +533,8 @@ module.exports = function defineGrammar(dialect) {
530533
'protected'
531534
),
532535

536+
override_modifier: _ => 'override',
537+
533538
required_parameter: $ => seq(
534539
$._parameter_name,
535540
optional($.type_annotation),
@@ -546,6 +551,7 @@ module.exports = function defineGrammar(dialect) {
546551
_parameter_name: $ => seq(
547552
repeat(field('decorator', $.decorator)),
548553
optional($.accessibility_modifier),
554+
optional($.override_modifier),
549555
optional('readonly'),
550556
choice($.pattern, $.this)
551557
),
@@ -788,6 +794,7 @@ module.exports = function defineGrammar(dialect) {
788794
property_signature: $ => seq(
789795
optional($.accessibility_modifier),
790796
optional('static'),
797+
optional($.override_modifier),
791798
optional('readonly'),
792799
field('name', $._property_name),
793800
optional('?'),
@@ -881,6 +888,7 @@ module.exports = function defineGrammar(dialect) {
881888
'public',
882889
'private',
883890
'protected',
891+
'override',
884892
'readonly',
885893
'module',
886894
'any',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"name": "tree-sitter-typescript",
33
"version": "0.19.0",
44
"description": "Typescript grammar for tree-sitter",

queries/highlights.scm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
; Keywords
1919

20-
[
21-
"abstract"
20+
[ "abstract"
2221
"declare"
2322
"enum"
2423
"export"
@@ -31,4 +30,5 @@
3130
"public"
3231
"type"
3332
"readonly"
33+
"override"
3434
] @keyword

tsx/src/grammar.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6526,6 +6526,18 @@
65266526
}
65276527
]
65286528
},
6529+
{
6530+
"type": "CHOICE",
6531+
"members": [
6532+
{
6533+
"type": "SYMBOL",
6534+
"name": "override_modifier"
6535+
},
6536+
{
6537+
"type": "BLANK"
6538+
}
6539+
]
6540+
},
65296541
{
65306542
"type": "CHOICE",
65316543
"members": [
@@ -6743,6 +6755,10 @@
67436755
"type": "STRING",
67446756
"value": "protected"
67456757
},
6758+
{
6759+
"type": "STRING",
6760+
"value": "override"
6761+
},
67466762
{
67476763
"type": "STRING",
67486764
"value": "readonly"
@@ -6860,6 +6876,18 @@
68606876
}
68616877
]
68626878
},
6879+
{
6880+
"type": "CHOICE",
6881+
"members": [
6882+
{
6883+
"type": "SYMBOL",
6884+
"name": "override_modifier"
6885+
},
6886+
{
6887+
"type": "BLANK"
6888+
}
6889+
]
6890+
},
68636891
{
68646892
"type": "CHOICE",
68656893
"members": [
@@ -7117,6 +7145,18 @@
71177145
}
71187146
]
71197147
},
7148+
{
7149+
"type": "CHOICE",
7150+
"members": [
7151+
{
7152+
"type": "SYMBOL",
7153+
"name": "override_modifier"
7154+
},
7155+
{
7156+
"type": "BLANK"
7157+
}
7158+
]
7159+
},
71207160
{
71217161
"type": "CHOICE",
71227162
"members": [
@@ -8061,6 +8101,10 @@
80618101
}
80628102
]
80638103
},
8104+
"override_modifier": {
8105+
"type": "STRING",
8106+
"value": "override"
8107+
},
80648108
"required_parameter": {
80658109
"type": "SEQ",
80668110
"members": [
@@ -8157,6 +8201,18 @@
81578201
}
81588202
]
81598203
},
8204+
{
8205+
"type": "CHOICE",
8206+
"members": [
8207+
{
8208+
"type": "SYMBOL",
8209+
"name": "override_modifier"
8210+
},
8211+
{
8212+
"type": "BLANK"
8213+
}
8214+
]
8215+
},
81608216
{
81618217
"type": "CHOICE",
81628218
"members": [
@@ -9419,6 +9475,18 @@
94199475
}
94209476
]
94219477
},
9478+
{
9479+
"type": "CHOICE",
9480+
"members": [
9481+
{
9482+
"type": "SYMBOL",
9483+
"name": "override_modifier"
9484+
},
9485+
{
9486+
"type": "BLANK"
9487+
}
9488+
]
9489+
},
94229490
{
94239491
"type": "CHOICE",
94249492
"members": [
@@ -10631,6 +10699,16 @@
1063110699
"type": "SYMBOL",
1063210700
"name": "primary_expression"
1063310701
}
10702+
],
10703+
[
10704+
{
10705+
"type": "SYMBOL",
10706+
"name": "override_modifier"
10707+
},
10708+
{
10709+
"type": "SYMBOL",
10710+
"name": "primary_expression"
10711+
}
1063410712
]
1063510713
],
1063610714
"externals": [

tsx/src/node-types.json

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3618,12 +3618,16 @@
36183618
}
36193619
},
36203620
"children": {
3621-
"multiple": false,
3621+
"multiple": true,
36223622
"required": false,
36233623
"types": [
36243624
{
36253625
"type": "accessibility_modifier",
36263626
"named": true
3627+
},
3628+
{
3629+
"type": "override_modifier",
3630+
"named": true
36273631
}
36283632
]
36293633
}
@@ -3698,12 +3702,16 @@
36983702
}
36993703
},
37003704
"children": {
3701-
"multiple": false,
3705+
"multiple": true,
37023706
"required": false,
37033707
"types": [
37043708
{
37053709
"type": "accessibility_modifier",
37063710
"named": true
3711+
},
3712+
{
3713+
"type": "override_modifier",
3714+
"named": true
37073715
}
37083716
]
37093717
}
@@ -4106,6 +4114,10 @@
41064114
"type": "accessibility_modifier",
41074115
"named": true
41084116
},
4117+
{
4118+
"type": "override_modifier",
4119+
"named": true
4120+
},
41094121
{
41104122
"type": "pattern",
41114123
"named": true
@@ -4160,6 +4172,11 @@
41604172
]
41614173
}
41624174
},
4175+
{
4176+
"type": "override_modifier",
4177+
"named": true,
4178+
"fields": {}
4179+
},
41634180
{
41644181
"type": "pair",
41654182
"named": true,
@@ -4372,12 +4389,16 @@
43724389
}
43734390
},
43744391
"children": {
4375-
"multiple": false,
4392+
"multiple": true,
43764393
"required": false,
43774394
"types": [
43784395
{
43794396
"type": "accessibility_modifier",
43804397
"named": true
4398+
},
4399+
{
4400+
"type": "override_modifier",
4401+
"named": true
43814402
}
43824403
]
43834404
}
@@ -4434,12 +4455,16 @@
44344455
}
44354456
},
44364457
"children": {
4437-
"multiple": false,
4458+
"multiple": true,
44384459
"required": false,
44394460
"types": [
44404461
{
44414462
"type": "accessibility_modifier",
44424463
"named": true
4464+
},
4465+
{
4466+
"type": "override_modifier",
4467+
"named": true
44434468
}
44444469
]
44454470
}
@@ -4542,6 +4567,10 @@
45424567
"type": "accessibility_modifier",
45434568
"named": true
45444569
},
4570+
{
4571+
"type": "override_modifier",
4572+
"named": true
4573+
},
45454574
{
45464575
"type": "pattern",
45474576
"named": true
@@ -5999,11 +6028,11 @@
59996028
},
60006029
{
60016030
"type": "number",
6002-
"named": false
6031+
"named": true
60036032
},
60046033
{
60056034
"type": "number",
6006-
"named": true
6035+
"named": false
60076036
},
60086037
{
60096038
"type": "object",
@@ -6013,6 +6042,10 @@
60136042
"type": "of",
60146043
"named": false
60156044
},
6045+
{
6046+
"type": "override",
6047+
"named": false
6048+
},
60166049
{
60176050
"type": "private",
60186051
"named": false

0 commit comments

Comments
 (0)