deno_graph
deno_graph copied to clipboard
Support multiple ranges for an import in the graph
Currently the graph cannot represent multiple locations an import specifier might be imported in a file. For example, an import can be like this:
import * as a from "https://example.com/a";
import { default as b } from "https://example.com/a";
In addition, in theory, a module can be statically and dynamically imported:
import * as a from "https://example.com/a";
const b = await import("https://example.com/a";
Or in TypeScript the same specifier can be provided for a type only import:
import { a } from "https://example.com/a";
import type { A } from "https://example.com/a";
Currently we only store the last range for the specifier in the graph. This makes it difficult when trying to rewrite specifiers (like in dnt or deno vendor) as well as means that diagnostics are only issued for the "last" import location, not all import locations for a given specifier.
We should enhance the graph to be able to store this information, which is likely going to be a breaking change, but one that increases the usability of the graph.
This is a must for proper import assertion handling. Import assertion errors should be stored under each of these, not occupy module slots.
I've run into needing this for deno vendor again while working on the import map only solution. It also needs to know the text for the // @deno-types="..." and /// <reference types="..." /> directives so that it can tell if it needs to map those.
Closed in #251.