Skip to content

Fix literal subscript expressions in array patterns in TypeScript. #485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -4270,17 +4270,30 @@ if none @is_async {
}

(array_pattern
(_)@pat
[
(_)
(subscript_expression
index:(number)@subidx
)
]@pat
)@array_pat {
node @pat.comp_index
; There’s a `(subscript_expression … index:(number)@…)` stanza above that also
; creates the `comp_index` and its `push_symbol` attribute.
let is_number_subscript = (not (is-null @subidx))

if (not is_number_subscript) {
node @pat.comp_index
}

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

; propagate cotype components
edge @pat.cotype -> @pat.comp_index
;
attr (@pat.comp_index) push_symbol = (named-child-index @pat)
if (not is_number_subscript) {
attr (@pat.comp_index) push_symbol = (named-child-index @pat)
}
edge @pat.comp_index -> @array_pat.indexable

; propagate defs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const items = [13, 37];
[items[0], items[1]] = [items[1], items[0]];
Loading