Skip to content

Commit 9aca205

Browse files
authoredMar 13, 2025··
fix(typescript): Skip the body of ArrowExpr in type usage analysis (#10187)
1 parent a3856ca commit 9aca205

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed
 

‎.changeset/unlucky-olives-whisper.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_typescript: patch
3+
swc_core: patch
4+
---
5+
6+
fix(typescript): Skip the body of ArrowExpr in type usage analysis

‎crates/swc_typescript/src/fast_dts/visitors/type_usage.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use petgraph::{
66
use rustc_hash::{FxHashMap, FxHashSet};
77
use swc_common::{BytePos, Spanned, SyntaxContext};
88
use swc_ecma_ast::{
9-
Accessibility, Class, ClassMember, Decl, ExportDecl, ExportDefaultDecl, ExportDefaultExpr,
10-
Function, Id, Ident, ModuleExportName, ModuleItem, NamedExport, TsEntityName,
11-
TsExportAssignment, TsExprWithTypeArgs, TsPropertySignature, TsTypeElement,
9+
Accessibility, ArrowExpr, Class, ClassMember, Decl, ExportDecl, ExportDefaultDecl,
10+
ExportDefaultExpr, Function, Id, Ident, ModuleExportName, ModuleItem, NamedExport,
11+
TsEntityName, TsExportAssignment, TsExprWithTypeArgs, TsPropertySignature, TsTypeElement,
1212
};
1313
use swc_ecma_visit::{Visit, VisitWith};
1414

@@ -230,6 +230,13 @@ impl Visit for TypeUsageAnalyzer<'_> {
230230
});
231231
}
232232

233+
fn visit_arrow_expr(&mut self, node: &ArrowExpr) {
234+
// Skip body
235+
node.params.visit_with(self);
236+
node.type_params.visit_with(self);
237+
node.return_type.visit_with(self);
238+
}
239+
233240
fn visit_function(&mut self, node: &Function) {
234241
// Skip body
235242
node.params.visit_with(self);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
```==================== .D.TS ====================
2+
3+
export declare const Externals: {
4+
Pinkie: string;
5+
};
6+
export declare const magical: () => string;
7+
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export const Externals = {
2+
Pinkie: "Pinkie Pie",
3+
};
4+
5+
const Ponies = {
6+
name: Externals.Pinkie,
7+
};
8+
9+
type Pony = keyof typeof Ponies;
10+
11+
export const magical = (): string => {
12+
const pinkie = (): Pony => "name";
13+
14+
console.log(Ponies.name);
15+
return pinkie();
16+
};

0 commit comments

Comments
 (0)
Please sign in to comment.