Skip to content

Commit 23c66a7

Browse files
WIP
1 parent 3ed69db commit 23c66a7

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

src/fast_check/transform.rs

+10
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,14 @@ impl CommentsMut {
142142
pub struct FastCheckModule {
143143
pub module_info: ModuleInfo,
144144
pub text: String,
145+
pub dts_text: Option<String>,
145146
pub source_map: Vec<u8>,
146147
}
147148

148149
pub struct TransformOptions<'a> {
149150
pub workspace_members: &'a [WorkspaceMember],
150151
pub should_error_on_first_diagnostic: bool,
152+
pub generate_dts: bool,
151153
}
152154

153155
pub fn transform(
@@ -177,6 +179,13 @@ pub fn transform(
177179
&comments,
178180
);
179181

182+
let dts_text = if options.generate_dts {
183+
//
184+
None
185+
} else {
186+
None
187+
};
188+
180189
// now emit
181190
let comments = comments.into_single_threaded();
182191
let (text, source_map) =
@@ -190,6 +199,7 @@ pub fn transform(
190199
Ok(FastCheckModule {
191200
module_info,
192201
text,
202+
dts_text,
193203
source_map,
194204
})
195205
}

src/graph.rs

+9
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ pub struct FastCheckTypeModule {
815815
pub dependencies: IndexMap<String, Dependency>,
816816
pub source: Arc<str>,
817817
pub source_map: Arc<[u8]>,
818+
pub dts: Option<Arc<str>>,
818819
}
819820

820821
#[derive(Debug, Clone, Serialize)]
@@ -2761,6 +2762,7 @@ struct Builder<'a, 'graph> {
27612762
#[cfg_attr(not(feature = "fast_check"), allow(dead_code))]
27622763
workspace_fast_check: bool,
27632764
workspace_members: Vec<WorkspaceMember>,
2765+
fast_check_dts: bool,
27642766
diagnostics: Vec<BuildDiagnostic>,
27652767
}
27662768

@@ -2800,6 +2802,7 @@ impl<'a, 'graph> Builder<'a, 'graph> {
28002802
fill_pass_mode,
28012803
workspace_fast_check,
28022804
workspace_members,
2805+
fast_check_dts: true,
28032806
diagnostics: Vec::new(),
28042807
};
28052808
builder.fill(roots, imports).await;
@@ -3963,6 +3966,7 @@ impl<'a, 'graph> Builder<'a, 'graph> {
39633966
&[]
39643967
},
39653968
should_error_on_first_diagnostic: !self.workspace_fast_check,
3969+
generate_dts: self.fast_check_dts,
39663970
},
39673971
);
39683972
for (specifier, fast_check_module_result) in modules {
@@ -3992,6 +3996,11 @@ impl<'a, 'graph> Builder<'a, 'graph> {
39923996
dependencies,
39933997
source: fast_check_module.text.into(),
39943998
source_map: fast_check_module.source_map.into(),
3999+
dts: if let Some(dts_text) = fast_check_module.dts_text {
4000+
Some(dts_text.into())
4001+
} else {
4002+
None
4003+
},
39954004
}))
39964005
}
39974006
Err(diagnostic) => FastCheckTypeModuleSlot::Error(diagnostic),

tests/specs/symbols/Foo.txt

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# mod.ts
2+
export const foo = 1;
3+
4+
# output
5+
file:///mod.ts: EsModuleInfo {
6+
module_id: ModuleId(
7+
0,
8+
),
9+
specifier: "file:///mod.ts",
10+
re_exports: [],
11+
swc_id_to_symbol_id: {
12+
(
13+
"foo",
14+
#2,
15+
): 1,
16+
},
17+
symbols: {
18+
0: Symbol {
19+
module_id: ModuleId(
20+
0,
21+
),
22+
symbol_id: 0,
23+
parent_id: None,
24+
decls: [
25+
SymbolDecl {
26+
kind: Definition(
27+
SymbolNode(
28+
"export const foo = 1;",
29+
),
30+
),
31+
range: SourceRange {
32+
start: SourcePos(
33+
0,
34+
),
35+
end: SourcePos(
36+
21,
37+
),
38+
},
39+
flags: 0,
40+
},
41+
],
42+
child_ids: {
43+
1,
44+
},
45+
exports: {
46+
"foo": 1,
47+
},
48+
members: {},
49+
},
50+
1: Symbol {
51+
module_id: ModuleId(
52+
0,
53+
),
54+
symbol_id: 1,
55+
parent_id: Some(
56+
0,
57+
),
58+
decls: [
59+
SymbolDecl {
60+
kind: Definition(
61+
SymbolNode(
62+
"export const foo = 1;",
63+
),
64+
),
65+
range: SourceRange {
66+
start: SourcePos(
67+
13,
68+
),
69+
end: SourcePos(
70+
20,
71+
),
72+
},
73+
flags: 0,
74+
},
75+
],
76+
child_ids: {},
77+
exports: {},
78+
members: {},
79+
},
80+
},
81+
}
82+
== export definitions ==
83+
[foo]: file:///mod.ts:13..20
84+
foo = 1

0 commit comments

Comments
 (0)