Skip to content

Commit 2a4a55b

Browse files
authored
fix: do not do execution resolution for declaration file dependencies (#602)
1 parent fa290db commit 2a4a55b

File tree

3 files changed

+95
-18
lines changed

3 files changed

+95
-18
lines changed

src/graph.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3589,23 +3589,25 @@ fn fill_module_dependencies(
35893589
maybe_resolver,
35903590
);
35913591
}
3592-
} else if dep.maybe_code.is_none() {
3593-
// This is a code import, the first one of that specifier in this module.
3594-
// Resolve and determine the initial `is_dynamic` value from it.
3595-
dep.maybe_code = resolve(
3596-
&import.specifier,
3597-
import.specifier_range.clone(),
3598-
ResolutionKind::Execution,
3599-
jsr_url_provider,
3600-
maybe_resolver,
3601-
);
3602-
dep.is_dynamic = import.is_dynamic;
3603-
} else {
3604-
// This is a code import, but not the first one of that specifier in this
3605-
// module. Maybe update the `is_dynamic` value. Static imports take
3606-
// precedence. Note that `@jsxImportSource` and `/// <reference path />`
3607-
// count as static imports for this purpose.
3608-
dep.is_dynamic = dep.is_dynamic && import.is_dynamic;
3592+
} else if !media_type.is_declaration() {
3593+
if dep.maybe_code.is_none() {
3594+
// This is a code import, the first one of that specifier in this module.
3595+
// Resolve and determine the initial `is_dynamic` value from it.
3596+
dep.maybe_code = resolve(
3597+
&import.specifier,
3598+
import.specifier_range.clone(),
3599+
ResolutionKind::Execution,
3600+
jsr_url_provider,
3601+
maybe_resolver,
3602+
);
3603+
dep.is_dynamic = import.is_dynamic;
3604+
} else {
3605+
// This is a code import, but not the first one of that specifier in this
3606+
// module. Maybe update the `is_dynamic` value. Static imports take
3607+
// precedence. Note that `@jsxImportSource` and `/// <reference path />`
3608+
// count as static imports for this purpose.
3609+
dep.is_dynamic = dep.is_dynamic && import.is_dynamic;
3610+
}
36093611
}
36103612
if graph_kind.include_types() && dep.maybe_type.is_none() {
36113613
let maybe_type = resolve(

tests/specs/graph/dts_files.txt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# mod.ts
2+
export type * from "./declarations.d.ts";
3+
4+
# declarations.d.ts
5+
import { Test } from "./a.d.ts";
6+
7+
export { Test }
8+
9+
# a.d.ts
10+
export class Test {}
11+
12+
# output
13+
{
14+
"roots": [
15+
"file:///mod.ts"
16+
],
17+
"modules": [
18+
{
19+
"kind": "esm",
20+
"size": 21,
21+
"mediaType": "Dts",
22+
"specifier": "file:///a.d.ts"
23+
},
24+
{
25+
"kind": "esm",
26+
"dependencies": [
27+
{
28+
"specifier": "./a.d.ts",
29+
"type": {
30+
"specifier": "file:///a.d.ts",
31+
"span": {
32+
"start": {
33+
"line": 0,
34+
"character": 21
35+
},
36+
"end": {
37+
"line": 0,
38+
"character": 31
39+
}
40+
}
41+
}
42+
}
43+
],
44+
"size": 50,
45+
"mediaType": "Dts",
46+
"specifier": "file:///declarations.d.ts"
47+
},
48+
{
49+
"kind": "esm",
50+
"dependencies": [
51+
{
52+
"specifier": "./declarations.d.ts",
53+
"type": {
54+
"specifier": "file:///declarations.d.ts",
55+
"resolutionMode": "import",
56+
"span": {
57+
"start": {
58+
"line": 0,
59+
"character": 19
60+
},
61+
"end": {
62+
"line": 0,
63+
"character": 40
64+
}
65+
}
66+
}
67+
}
68+
],
69+
"size": 42,
70+
"mediaType": "TypeScript",
71+
"specifier": "file:///mod.ts"
72+
}
73+
],
74+
"redirects": {}
75+
}

tests/specs/graph/fast_check/dts.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ import 'jsr:@scope/a/foo'
118118
"dependencies": [
119119
{
120120
"specifier": "./other.d.ts",
121-
"code": {
121+
"type": {
122122
"specifier": "https://jsr.io/@scope/a/1.0.0/other.d.ts",
123123
"span": {
124124
"start": {

0 commit comments

Comments
 (0)