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

Conversation

@bm-w
Copy link

@bm-w bm-w commented Apr 3, 2025

The Tree-sitter TypeScript grammar “overloads” the subscript_expression syntax node with use in LHS assignment patterns. This causes duplicate node & attribute creation in the stanza dealing with array_pattern syntax nodes, giving an error — e.g.:

0: Error executing statement node @pat.comp_index at (4275, 3)
   src/stack-graphs.tsg:4275:3:
   4275 |   node @pat.comp_index
        |   ^
   in stanza
   src/stack-graphs.tsg:4272:1:
   4272 | (array_pattern
        | ^
   matching (array_pattern) node
   test/statements/array-pattern.ts:2:1:
   2 | [items[0], items[1]] = [items[1], items[0]];
     | ^
 > and executing statement node @subscript_expr.comp_index at (3602, 3)
   src/stack-graphs.tsg:3602:3:
   3602 |   node @subscript_expr.comp_index
        |   ^
   in stanza
   src/stack-graphs.tsg:3598:1:
   3598 | (subscript_expression
        | ^
   matching (subscript_expression) node
   test/statements/array-pattern.ts:2:2:
   2 | [items[0], items[1]] = [items[1], items[0]];
     |  ^
1: Duplicate variable [syntax node subscript_expression (2, 2)].comp_index

A somewhat inelegant fix is to check whether the array pattern component is a subscript_expression with a number and if so avoid creating the node & attribute within the array_pattern stanza. Copious testing (on this repo’s TypeScript test suite and on all of microsoft/vscode) reveals no negative side effects.

Copilot AI review requested due to automatic review settings April 3, 2025 18:51
@bm-w bm-w requested review from a team as code owners April 3, 2025 18:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses an error in TypeScript's literal subscript expressions when used in array patterns by modifying how the Tree-sitter TypeScript grammar handles subscript expressions.

  • Fixes duplicate node and attribute creation for subscript expressions in array patterns.
  • Adds a new test case in the TypeScript test suite to validate the fix.
Files not reviewed (1)
  • languages/tree-sitter-stack-graphs-typescript/src/stack-graphs.tsg: Language not supported
Comments suppressed due to low confidence (1)

languages/tree-sitter-stack-graphs-typescript/test/statements/array-pattern.ts:1

  • [nitpick] Consider adding additional test cases to cover more complex scenarios or edge cases for subscript expressions in array patterns.
const items = [13, 37];

@CleanCut
Copy link
Contributor

CleanCut commented Sep 9, 2025

The github/stack-graphs repository is no longer being maintained. As per #502, I'm closing all issues and pull requests before archiving the repository.

@CleanCut CleanCut closed this Sep 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants