javascript/typescript/tsx: Highlight private properties (#31527)

Ben Kunkle created

Closes #28411

Release Notes:

- Fixed the lack of highlighting for private properties in classes for
JavaScript/TypeScript/TSX files

Change summary

crates/languages/src/javascript/highlights.scm | 11 ++++++-----
crates/languages/src/tsx/highlights.scm        | 11 ++++++-----
crates/languages/src/typescript/highlights.scm | 11 ++++++-----
3 files changed, 18 insertions(+), 15 deletions(-)

Detailed changes

crates/languages/src/javascript/highlights.scm 🔗

@@ -7,6 +7,7 @@
 (property_identifier) @property
 (shorthand_property_identifier) @property
 (shorthand_property_identifier_pattern) @property
+(private_property_identifier) @property
 
 ; Function and method calls
 
@@ -15,7 +16,7 @@
 
 (call_expression
   function: (member_expression
-    property: (property_identifier) @function.method))
+      property: [(property_identifier) (private_property_identifier)] @function.method))
 
 ; Function and method definitions
 
@@ -24,18 +25,18 @@
 (function_declaration
   name: (identifier) @function)
 (method_definition
-  name: (property_identifier) @function.method)
+  name: [(property_identifier) (private_property_identifier)] @function.method)
 (method_definition
     name: (property_identifier) @constructor
     (#eq? @constructor "constructor"))
 
 (pair
-  key: (property_identifier) @function.method
+  key: [(property_identifier) (private_property_identifier)] @function.method
   value: [(function_expression) (arrow_function)])
 
 (assignment_expression
   left: (member_expression
-    property: (property_identifier) @function.method)
+    property: [(property_identifier) (private_property_identifier)] @function.method)
   right: [(function_expression) (arrow_function)])
 
 (variable_declarator
@@ -248,4 +249,4 @@
 (jsx_closing_element (["</" ">"]) @punctuation.bracket.jsx)
 (jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx)
 (jsx_attribute "=" @punctuation.delimiter.jsx)
-(jsx_text) @text.jsx
+(jsx_text) @text.jsx

crates/languages/src/tsx/highlights.scm 🔗

@@ -7,6 +7,7 @@
 (property_identifier) @property
 (shorthand_property_identifier) @property
 (shorthand_property_identifier_pattern) @property
+(private_property_identifier) @property
 
 ; Function and method calls
 
@@ -15,7 +16,7 @@
 
 (call_expression
   function: (member_expression
-    property: (property_identifier) @function.method))
+    property: [(property_identifier) (private_property_identifier)] @function.method))
 
 ; Function and method definitions
 
@@ -24,18 +25,18 @@
 (function_declaration
   name: (identifier) @function)
 (method_definition
-  name: (property_identifier) @function.method)
+  name: [(property_identifier) (private_property_identifier)] @function.method)
 (method_definition
     name: (property_identifier) @constructor
     (#eq? @constructor "constructor"))
 
 (pair
-  key: (property_identifier) @function.method
+  key: [(property_identifier) (private_property_identifier)] @function.method
   value: [(function_expression) (arrow_function)])
 
 (assignment_expression
   left: (member_expression
-    property: (property_identifier) @function.method)
+    property: [(property_identifier) (private_property_identifier)] @function.method)
   right: [(function_expression) (arrow_function)])
 
 (variable_declarator
@@ -254,4 +255,4 @@
 (jsx_closing_element (["</" ">"]) @punctuation.bracket.jsx)
 (jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx)
 (jsx_attribute "=" @punctuation.delimiter.jsx)
-(jsx_text) @text.jsx
+(jsx_text) @text.jsx

crates/languages/src/typescript/highlights.scm 🔗

@@ -39,6 +39,7 @@
 (property_identifier) @property
 (shorthand_property_identifier) @property
 (shorthand_property_identifier_pattern) @property
+(private_property_identifier) @property
 
 ; Function and method calls
 
@@ -47,7 +48,7 @@
 
 (call_expression
   function: (member_expression
-    property: (property_identifier) @function.method))
+    property: [(property_identifier) (private_property_identifier)] @function.method))
 
 ; Function and method definitions
 
@@ -56,18 +57,18 @@
 (function_declaration
   name: (identifier) @function)
 (method_definition
-  name: (property_identifier) @function.method)
+  name: [(property_identifier) (private_property_identifier)] @function.method)
 (method_definition
     name: (property_identifier) @constructor
     (#eq? @constructor "constructor"))
 
 (pair
-  key: (property_identifier) @function.method
+  key: [(property_identifier) (private_property_identifier)] @function.method
   value: [(function_expression) (arrow_function)])
 
 (assignment_expression
   left: (member_expression
-    property: (property_identifier) @function.method)
+    property: [(property_identifier) (private_property_identifier)] @function.method)
   right: [(function_expression) (arrow_function)])
 
 (variable_declarator
@@ -270,4 +271,4 @@
   "while"
   "with"
   "yield"
-] @keyword
+] @keyword