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

Commit 3d28315

Browse files
committed
fix: ignore .ts and .js extensions form imports
1 parent ea70811 commit 3d28315

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ attribute node_symbol = node => symbol = (source-text node), source_n
260260

261261
; expose globals
262262
edge proj_scope -> @prog.globals
263-
263+
264264
var mod_scope = proj_scope
265265
if (not (is-empty @imexs)) {
266266
; module definition
@@ -541,7 +541,9 @@ attribute node_symbol = node => symbol = (source-text node), source_n
541541
; module reference
542542
var mod_scope = mod_ref__ns
543543
scan (path-normalize mod_path) {
544-
"([^/]+)/?" {
544+
; ignore .js and .ts extensions on imports, as ts allows this
545+
; this might lead to false positives
546+
"([^/|(\.j|ts)]+)/?" {
545547
node mod_ref
546548
attr (mod_ref) push_symbol = $1
547549
edge mod_ref -> mod_scope
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* --- path: src/foo.ts --- */
2+
export const bar = 42;
3+
4+
/* --- path: src/index.ts --- */
5+
import { bar } from "./foo.js";
6+
// ^ defined: 2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* --- path: src/foo.ts --- */
2+
export const bar = 42;
3+
4+
/* --- path: src/index.ts --- */
5+
import { bar } from "./foo";
6+
// ^ defined: 2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* --- path: src/foo.ts --- */
2+
export const bar = 42;
3+
4+
/* --- path: src/index.ts --- */
5+
import { bar } from "./foo.ts";
6+
// ^ defined: 2

0 commit comments

Comments
 (0)