Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 764d972

Browse files
author
Bastiaan Marinus van de Weerd
committed
Fix literal subscript expressions in array patterns in TypeScript.
1 parent d0b5947 commit 764d972

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

languages/tree-sitter-stack-graphs-typescript/src/stack-graphs.tsg

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4270,17 +4270,30 @@ if none @is_async {
42704270
}
42714271

42724272
(array_pattern
4273-
(_)@pat
4273+
[
4274+
(_)
4275+
(subscript_expression
4276+
index:(number)@subidx
4277+
)
4278+
]@pat
42744279
)@array_pat {
4275-
node @pat.comp_index
4280+
; There’s a `(subscript_expression … index:(number)@…)` stanza above that also
4281+
; creates the `comp_index` and its `push_symbol` attribute.
4282+
let is_number_subscript = (not (is-null @subidx))
4283+
4284+
if (not is_number_subscript) {
4285+
node @pat.comp_index
4286+
}
42764287

42774288
; propagate lexical scope
42784289
edge @pat.lexical_scope -> @array_pat.lexical_scope
42794290

42804291
; propagate cotype components
42814292
edge @pat.cotype -> @pat.comp_index
42824293
;
4283-
attr (@pat.comp_index) push_symbol = (named-child-index @pat)
4294+
if (not is_number_subscript) {
4295+
attr (@pat.comp_index) push_symbol = (named-child-index @pat)
4296+
}
42844297
edge @pat.comp_index -> @array_pat.indexable
42854298

42864299
; propagate defs
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const items = [13, 37];
2+
[items[0], items[1]] = [items[1], items[0]];

0 commit comments

Comments
 (0)