Description
Depending on various rules (tsconfig, bundlers, runtimes, ...) relative imports in typescript can be: ./module
, ./module.js
, ./module.ts
(+ we might also want to consider mts, mjs, .d.ts).
Currently it seems that tree-sitter-stack-graphs-typecript
only resolves imports when no file extension is provided. Eg:
/* --- path: src/foo.ts --- */
export const bar = 42;
/* --- path: src/index.ts --- */
import { bar } from "./foo";
// ^ defined: 2
Works, but both:
/* --- path: src/foo.ts --- */
export const bar = 42;
/* --- path: src/index.ts --- */
import { bar } from "./foo.js";
// ^ defined: 2
/* --- path: src/foo.ts --- */
export const bar = 42;
/* --- path: src/index.ts --- */
import { bar } from "./foo.ts";
// ^ defined: 2
Don't
Module resolution in typescript is quite complicated, see: https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution
Tho I believe naively aliasing module.js
and module.ts
to module
could work in a majority of cases, maybe leading to some false positives, but that might be better than false negatives.
Also, I wonder if typescript and javascript definitions should be in fact merged, as typescript is only a superset of javascript, and can import it.
What do you think @hendrikvanantwerpen ? I can provide a fix for this (the quickfix one) but I'd prefer to discuss which approach you think is best.