Skip to content

Commit

Permalink
[language-(java|type)script] Scope ??=, ++, etc., as assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
savetheclocktower committed Sep 8, 2024
1 parent c674d8f commit 265d7e0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/language-javascript/grammars/tree-sitter/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,25 @@
(augmented_assignment_expression
left: (identifier) @variable.other.assignment.js)

; The "bar" in `foo.bar += 1`.
(augmented_assignment_expression
left: (member_expression
property: (property_identifier) @variable.other.assignment.property.js)
(#is-not? test.rangeWithData isFunctionProperty)
(#set! capture.final))

; The "foo" in `foo++`.
(update_expression
argument: (identifier) @variable.other.assignment.js)

; The "bar" in `foo.bar++`.
(update_expression
argument: (member_expression
property: (property_identifier) @variable.other.assignment.property.js)
(#is-not? test.rangeWithData isFunctionProperty)
(#set! capture.final))


; Public field definition in a class body:
; The "foo" in `foo = "bar";`
(field_definition
Expand Down
14 changes: 14 additions & 0 deletions packages/language-typescript/grammars/common/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,24 @@
(augmented_assignment_expression
left: (identifier) @variable.other.assignment._LANG_)

; The "bar" in `foo.bar += 1`.
(augmented_assignment_expression
left: (member_expression
property: (property_identifier) @variable.other.assignment.property._LANG_)
(#is-not? test.rangeWithData isFunctionProperty)
(#set! capture.final))

; The "foo" in `foo++`.
(update_expression
argument: (identifier) @variable.other.assignment._LANG_)

; The "bar" in `foo.bar++`.
(update_expression
argument: (member_expression
property: (property_identifier) @variable.other.assignment.property._LANG_)
(#is-not? test.rangeWithData isFunctionProperty)
(#set! capture.final))

; `object_pattern` appears to only be encountered in assignment expressions, so
; this won't match other uses of object/prop shorthand.
((object_pattern
Expand Down

0 comments on commit 265d7e0

Please sign in to comment.