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

Commit d76841f

Browse files
Merge pull request #167 from github/ts-fix-inheritance
2 parents 0b81f63 + 36274e1 commit d76841f

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

languages/tree-sitter-stack-graphs-typescript/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*.html
12
/Cargo.lock
23
/node_modules
34
/package-lock.json

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

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,9 +1435,14 @@ if none @is_async {
14351435

14361436
; class type inherits from heritage type
14371437
edge @class_decl.generic_inner_type -> @heritage.type_members
1438+
attr (@class_decl.generic_inner_type -> @heritage.type_members) precedence = 1
14381439

14391440
; class object inherits from super class object
14401441
edge @class_decl.static_type -> @heritage.static_members
1442+
attr (@class_decl.static_type -> @heritage.static_members) precedence = 1
1443+
1444+
; expose super definition
1445+
edge @class_decl.generic_inner_lexical_scope -> @heritage.lexical_defs
14411446
}
14421447
[
14431448
(interface_declaration (extends_type_clause)@extends)
@@ -1468,7 +1473,7 @@ if none @is_async {
14681473
attr (@class_decl.this__expr_def__ns) pop_symbol = "%E"
14691474
edge @class_decl.this__expr_def__ns -> @class_decl.this__expr_def
14701475
;
1471-
attr (@class_decl.this__expr_def) pop_symbol = "this"
1476+
attr (@class_decl.this__expr_def) pop_symbol = "this", source_node = @class_decl, empty_source_span
14721477
edge @class_decl.this__expr_def -> @class_decl.this__expr_def__typeof
14731478
;
14741479
attr (@class_decl.this__expr_def__typeof) pop_symbol = ":"
@@ -1512,9 +1517,11 @@ if none @is_async {
15121517

15131518
; class type consists of body members
15141519
edge @class_decl.generic_inner_type -> @body.type_members
1520+
attr (@class_decl.generic_inner_type -> @body.type_members) precedence = 2
15151521

15161522
; class object consists of static members
15171523
edge @class_decl.static_type -> @body.static_members
1524+
attr (@class_decl.static_type -> @body.static_members) precedence = 2
15181525
}
15191526
[
15201527
(interface_declaration body:(_)@body)
@@ -2826,7 +2833,7 @@ if none @is_def {
28262833
node @this.expr_ref__typeof
28272834

28282835
; expression reference
2829-
attr (@this.expr_ref) symbol_reference = "this", source_node = @this
2836+
attr (@this.expr_ref) node_reference = @this
28302837
edge @this.expr_ref -> @this.expr_ref__ns
28312838
;
28322839
attr (@this.expr_ref__ns) push_symbol = "%E"
@@ -2844,6 +2851,22 @@ if none @is_def {
28442851
;; super
28452852

28462853
(super)@super {
2854+
node @super.expr_ref
2855+
node @super.expr_ref__ns
2856+
node @super.expr_ref__typeof
2857+
2858+
; expression reference
2859+
attr (@super.expr_ref) node_reference = @super
2860+
edge @super.expr_ref -> @super.expr_ref__ns
2861+
;
2862+
attr (@super.expr_ref__ns) push_symbol = "%E"
2863+
edge @super.expr_ref__ns -> @super.lexical_scope
2864+
2865+
; type is type of the reference
2866+
edge @super.type -> @super.expr_ref__typeof
2867+
;
2868+
attr (@super.expr_ref__typeof) push_symbol = ":"
2869+
edge @super.expr_ref__typeof -> @super.expr_ref
28472870
}
28482871

28492872

@@ -3848,13 +3871,18 @@ if none @is_async {
38483871

38493872
; class type inherits from heritage type
38503873
edge @class_expr.generic_inner_type -> @heritage.type_members
3874+
attr (@class_expr.generic_inner_type -> @heritage.type_members) precedence = 1
38513875

38523876
; type of class expression inherits heritage static members
38533877
edge @class_expr.type -> @heritage.static_members
3878+
attr (@class_expr.type -> @heritage.static_members) precedence = 1
38543879

38553880
; mark type scope as endpoint
38563881
attr (@class_expr.type) is_endpoint
38573882
attr (@class_expr.generic_inner_type) is_endpoint
3883+
3884+
; expose super definition
3885+
edge @class_expr.generic_inner_lexical_scope -> @heritage.lexical_defs
38583886
}
38593887

38603888
; this
@@ -4654,6 +4682,7 @@ if none @is_acc {
46544682
(implements_clause)
46554683
]@heritage {
46564684
node @heritage.lexical_scope
4685+
node @heritage.lexical_defs
46574686
node @heritage.type_members
46584687
node @heritage.static_members
46594688
}
@@ -4664,8 +4693,24 @@ if none @is_acc {
46644693
; propagate lexical scope
46654694
edge @extends_or_implements.lexical_scope -> @class_heritage.lexical_scope
46664695

4696+
node super__expr_def
4697+
node super__expr_def__ns
4698+
node super__expr_def__typeof
4699+
;
4700+
; super expr definition
4701+
edge @class_heritage.lexical_defs -> super__expr_def__ns
4702+
;
4703+
attr (super__expr_def__ns) pop_symbol = "%E"
4704+
edge super__expr_def__ns -> super__expr_def
4705+
;
4706+
attr (super__expr_def) pop_symbol = "super", source_node = @class_heritage, empty_source_span
4707+
edge super__expr_def -> super__expr_def__typeof
4708+
;
4709+
attr (super__expr_def__typeof) pop_symbol = ":"
4710+
46674711
; type members inherited from extends & implements clauses
46684712
edge @class_heritage.type_members -> @extends_or_implements.type_members
4713+
edge super__expr_def__typeof -> @extends_or_implements.type_members
46694714

46704715
; static members inherited from extends & implements clauses
46714716
edge @class_heritage.static_members -> @extends_or_implements.static_members

languages/tree-sitter-stack-graphs-typescript/test/expressions/call-class-super-interface-method.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let foo: C;
1515

1616
foo.m(null).value;
1717
//^ defined: 13
18-
// ^ defined: 4, 10
18+
// ^ defined: 10
1919
// ^ defined: 1
2020

2121
export {};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Super {
2+
bar() { }
3+
}
4+
5+
class Sub extends Super {
6+
main() {
7+
this.bar();
8+
// ^ defined: 13
9+
super.bar();
10+
// ^ defined: 2
11+
}
12+
13+
bar() { }
14+
}

0 commit comments

Comments
 (0)