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
35 changes: 35 additions & 0 deletions common/corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1025,3 +1025,38 @@ class Foo {
(property_identifier)
(formal_parameters)
(statement_block)))))

=====================
Override modifier
=====================

abstract class Foo {
abstract baz(): void;
}

class Bar extends Foo {
override baz() {}
}

---

(program
(abstract_class_declaration
name: (type_identifier)
body: (class_body
(abstract_method_signature
name: (property_identifier)
parameters: (formal_parameters)
return_type: (type_annotation
(predefined_type)))))
(class_declaration
name: (type_identifier)
(class_heritage
(extends_clause
(type_identifier)))
body: (class_body
(method_definition
(override_modifier)
name: (property_identifier)
parameters: (formal_parameters)
body: (statement_block)))))
10 changes: 9 additions & 1 deletion common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports = function defineGrammar(dialect) {
[$._type_query_subscript_expression, $.primary_expression],
[$._type_query_call_expression, $.primary_expression],
[$.type_query, $.primary_expression],
[$.override_modifier, $.primary_expression],
]),

conflicts: ($, previous) => previous.concat([
Expand Down Expand Up @@ -130,7 +131,7 @@ module.exports = function defineGrammar(dialect) {
optional('declare'),
optional($.accessibility_modifier),
choice(
seq(optional('static'), optional('readonly')),
seq(optional('static'), optional($.override_modifier), optional('readonly')),
seq(optional('abstract'), optional('readonly')),
seq(optional('readonly'), optional('abstract')),
),
Expand Down Expand Up @@ -287,6 +288,7 @@ module.exports = function defineGrammar(dialect) {
method_signature: $ => seq(
optional($.accessibility_modifier),
optional('static'),
optional($.override_modifier),
optional('readonly'),
optional('async'),
optional(choice('get', 'set', '*')),
Expand Down Expand Up @@ -356,6 +358,7 @@ module.exports = function defineGrammar(dialect) {
method_definition: $ => prec.left(seq(
optional($.accessibility_modifier),
optional('static'),
optional($.override_modifier),
optional('readonly'),
optional('async'),
optional(choice('get', 'set', '*')),
Expand Down Expand Up @@ -530,6 +533,8 @@ module.exports = function defineGrammar(dialect) {
'protected'
),

override_modifier: _ => 'override',

required_parameter: $ => seq(
$._parameter_name,
optional($.type_annotation),
Expand All @@ -546,6 +551,7 @@ module.exports = function defineGrammar(dialect) {
_parameter_name: $ => seq(
repeat(field('decorator', $.decorator)),
optional($.accessibility_modifier),
optional($.override_modifier),
optional('readonly'),
choice($.pattern, $.this)
),
Expand Down Expand Up @@ -788,6 +794,7 @@ module.exports = function defineGrammar(dialect) {
property_signature: $ => seq(
optional($.accessibility_modifier),
optional('static'),
optional($.override_modifier),
optional('readonly'),
field('name', $._property_name),
optional('?'),
Expand Down Expand Up @@ -881,6 +888,7 @@ module.exports = function defineGrammar(dialect) {
'public',
'private',
'protected',
'override',
'readonly',
'module',
'any',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"name": "tree-sitter-typescript",
"version": "0.19.0",
"description": "Typescript grammar for tree-sitter",
Expand Down
4 changes: 2 additions & 2 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

; Keywords

[
"abstract"
[ "abstract"
"declare"
"enum"
"export"
Expand All @@ -31,4 +30,5 @@
"public"
"type"
"readonly"
"override"
] @keyword
78 changes: 78 additions & 0 deletions tsx/src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -6526,6 +6526,18 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "override_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -6743,6 +6755,10 @@
"type": "STRING",
"value": "protected"
},
{
"type": "STRING",
"value": "override"
},
{
"type": "STRING",
"value": "readonly"
Expand Down Expand Up @@ -6860,6 +6876,18 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "override_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -7117,6 +7145,18 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "override_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -8061,6 +8101,10 @@
}
]
},
"override_modifier": {
"type": "STRING",
"value": "override"
},
"required_parameter": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -8157,6 +8201,18 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "override_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -9419,6 +9475,18 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "override_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -10631,6 +10699,16 @@
"type": "SYMBOL",
"name": "primary_expression"
}
],
[
{
"type": "SYMBOL",
"name": "override_modifier"
},
{
"type": "SYMBOL",
"name": "primary_expression"
}
]
],
"externals": [
Expand Down
45 changes: 39 additions & 6 deletions tsx/src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -3618,12 +3618,16 @@
}
},
"children": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
"type": "accessibility_modifier",
"named": true
},
{
"type": "override_modifier",
"named": true
}
]
}
Expand Down Expand Up @@ -3698,12 +3702,16 @@
}
},
"children": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
"type": "accessibility_modifier",
"named": true
},
{
"type": "override_modifier",
"named": true
}
]
}
Expand Down Expand Up @@ -4106,6 +4114,10 @@
"type": "accessibility_modifier",
"named": true
},
{
"type": "override_modifier",
"named": true
},
{
"type": "pattern",
"named": true
Expand Down Expand Up @@ -4160,6 +4172,11 @@
]
}
},
{
"type": "override_modifier",
"named": true,
"fields": {}
},
{
"type": "pair",
"named": true,
Expand Down Expand Up @@ -4372,12 +4389,16 @@
}
},
"children": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
"type": "accessibility_modifier",
"named": true
},
{
"type": "override_modifier",
"named": true
}
]
}
Expand Down Expand Up @@ -4434,12 +4455,16 @@
}
},
"children": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
"type": "accessibility_modifier",
"named": true
},
{
"type": "override_modifier",
"named": true
}
]
}
Expand Down Expand Up @@ -4542,6 +4567,10 @@
"type": "accessibility_modifier",
"named": true
},
{
"type": "override_modifier",
"named": true
},
{
"type": "pattern",
"named": true
Expand Down Expand Up @@ -5999,11 +6028,11 @@
},
{
"type": "number",
"named": false
"named": true
},
{
"type": "number",
"named": true
"named": false
},
{
"type": "object",
Expand All @@ -6013,6 +6042,10 @@
"type": "of",
"named": false
},
{
"type": "override",
"named": false
},
{
"type": "private",
"named": false
Expand Down
Loading