Skip to content

Commit

Permalink
Make subscripts proper references
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikvanantwerpen committed Oct 13, 2023
1 parent 4be77c5 commit 80d73ca
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3064,7 +3064,6 @@ inherit .return_or_yield
edge subscript_expr_push_dot -> @object.value

; this is done differently depending on what the index is
; attr @index.push "push" = @index, "reference"
edge @subscript_expr.value -> @subscript_expr.index_push
edge @subscript_expr.index_push -> subscript_expr_push_dot

Expand All @@ -3075,7 +3074,8 @@ inherit .return_or_yield
index: (string)@index)@subscript_expr
{

attr (@subscript_expr.index_push) push_symbol = (replace (source-text @index) "[\"\']" "")
attr (@subscript_expr.index_push) symbol_reference = (replace (source-text @index) "[\"\']" ""), source_node = @index

}

(subscript_expression
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
let obj = { x: 1, y: 2, 0: "z" };
let obj = {
x: 1, y: 2, 0: "z" };

let obj_x = obj.x;
// ^ defined: 1
// ^ defined: 2
let x = obj_x;
// ^ defined: 1, 2
// ^ defined: 4, 2

let obj_y = obj["y"];
// ^ defined: 1
// ^ defined: 2
let y = obj_y;
// ^ defined: 1, 5
// ^ defined: 10, 2

let obj_z = obj[0];
// ^ defined: 1
// ^ defined: 2
let z = obj_z;
// ^ defined: 1, 9
// ^ defined: 16, 2

let obj2 = { x, y };
// ^ defined: 1, 2, 3
// ^ defined: 1, 5, 6
// ^ defined: 7, 4, 2
// ^ defined: 13, 10, 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let x = 1;
let y = (1, x);
// ^ defined: 1

let y = (1, x = 5);
let z = x;
// ^ defined: 1, 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let x = 1;

let y = `template ${ x } string`;
// ^ defined: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let x = 1;
let y = true ? x++ : 2;
let z = x;
// ^ defined: 1, 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let x = 1;
const y = 2;

var z = x + y;
// ^ defined: 1
// ^ defined: 2

let w = z;
// ^ defined: 1, 2, 4

0 comments on commit 80d73ca

Please sign in to comment.