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

Fix deep property access in TypeScript.#482

Closed
bm-w wants to merge 1 commit intogithub:mainfrom
bm-w:bm-w/fix-typescript-deep-property-access
Closed

Fix deep property access in TypeScript.#482
bm-w wants to merge 1 commit intogithub:mainfrom
bm-w:bm-w/fix-typescript-deep-property-access

Conversation

@bm-w
Copy link

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

A couple of stanzas were only matching member_expression syntax nodes that had as their object: field either another member_expression or an identifier syntax node. E.g.:

[
  (nested_identifier object:(_)@mod)
  (member_expression object:[(member_expression) (identifier)]@mod)
]@nested {
  node @nested.expr_def
  node @nested.type_def

  edge @nested.expr_def -> @mod.expr_def
  edge @nested.type_def -> @mod.type_def
}

However, if that object was itself a member_expression the stanzas would create edges to its expr_[dr]ef graph nodes indiscriminately, regardless of whether it would itself be matched and thus those nodes created. In a “deep” property access involving two nested member_expressions and a third non-matching inner syntax node, e.g. a parenthesized_expression, these stanzas would cause errors, e.g.:

0: Error executing statement edge @nested.expr_def -> @mod.expr_def at (2377, 3)
     src/stack-graphs.tsg:2377:3:
     2377 |   edge @nested.expr_def -> @mod.expr_def
          |   ^
     in stanza
     src/stack-graphs.tsg:2371:1:
     2371 | [
          | ^
     matching (member_expression) node
     test/expressions/access-properties.ts:15:5:
     15 |     (x).y.z;
        |     ^
1: Evaluating edge sink
2: Undefined scoped variable [syntax node member_expression (15, 5)].expr_def

The fragment of the parsed Tree-sitter tree for such a deep property access is:

(member_expression ; Matching fine, `expr_[dr]ef` graph nodes created, but edge creation would fail
  object: (member_expression; Not matching, so `expr_[dr]ef` graph nodes not created
    object: (parenthesized_expression …)
    …)
  …)

Separating graph nodes and edges creation fixes the issue. Copious testing (on our TS test suite and on all of microsoft/vscode) reveals no negative side effects.

Loading
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.

4 participants