@@ -54,39 +54,8 @@ export function elideImports(
54
54
return ;
55
55
}
56
56
57
- let symbol : ts . Symbol | undefined ;
58
- if ( ts . isTypeReferenceNode ( node ) ) {
59
- if ( ! compilerOptions . emitDecoratorMetadata ) {
60
- // Skip and mark as unused if emitDecoratorMetadata is disabled.
61
- return ;
62
- }
63
-
64
- const parent = node . parent ;
65
- let isTypeReferenceForDecoratoredNode = false ;
66
-
67
- switch ( parent . kind ) {
68
- case ts . SyntaxKind . GetAccessor :
69
- case ts . SyntaxKind . PropertyDeclaration :
70
- case ts . SyntaxKind . MethodDeclaration :
71
- isTypeReferenceForDecoratoredNode = ! ! parent . decorators ?. length ;
72
- break ;
73
- case ts . SyntaxKind . Parameter :
74
- // - A constructor parameter can be decorated or the class itself is decorated.
75
- // - The parent of the parameter is decorated example a method declaration or a set accessor.
76
- // In all cases we need the type reference not to be elided.
77
- isTypeReferenceForDecoratoredNode = ! ! (
78
- parent . decorators ?. length ||
79
- ( ts . isSetAccessor ( parent . parent ) && ! ! parent . parent . decorators ?. length ) ||
80
- ( ts . isConstructorDeclaration ( parent . parent ) &&
81
- ! ! parent . parent . parent . decorators ?. length )
82
- ) ;
83
- break ;
84
- }
85
-
86
- if ( isTypeReferenceForDecoratoredNode ) {
87
- symbol = typeChecker . getSymbolAtLocation ( node . typeName ) ;
88
- }
89
- } else {
57
+ if ( ! ts . isTypeReferenceNode ( node ) ) {
58
+ let symbol : ts . Symbol | undefined ;
90
59
switch ( node . kind ) {
91
60
case ts . SyntaxKind . Identifier :
92
61
const parent = node . parent ;
@@ -106,10 +75,10 @@ export function elideImports(
106
75
symbol = typeChecker . getShorthandAssignmentValueSymbol ( node ) ;
107
76
break ;
108
77
}
109
- }
110
78
111
- if ( symbol ) {
112
- usedSymbols . add ( symbol ) ;
79
+ if ( symbol ) {
80
+ usedSymbols . add ( symbol ) ;
81
+ }
113
82
}
114
83
115
84
ts . forEachChild ( node , visit ) ;
@@ -153,7 +122,7 @@ export function elideImports(
153
122
clausesCount += namedBindings . elements . length ;
154
123
155
124
for ( const specifier of namedBindings . elements ) {
156
- if ( isUnused ( specifier . name ) ) {
125
+ if ( specifier . isTypeOnly || isUnused ( specifier . name ) ) {
157
126
removedClausesCount ++ ;
158
127
// in case we don't have any more namedImports we should remove the parent ie the {}
159
128
const nodeToRemove =
@@ -168,7 +137,7 @@ export function elideImports(
168
137
if ( node . importClause . name ) {
169
138
clausesCount ++ ;
170
139
171
- if ( isUnused ( node . importClause . name ) ) {
140
+ if ( node . importClause . isTypeOnly || isUnused ( node . importClause . name ) ) {
172
141
specifierNodeRemovals . push ( node . importClause . name ) ;
173
142
}
174
143
}
0 commit comments