@@ -41,9 +41,7 @@ function main(inputLocation: string, outputLocation: string): void {
41
41
const sourceFile = program . getSourceFile ( inputLocation ) ! ;
42
42
const result : ts . TransformationResult < ts . SourceFile > = ts . transform <
43
43
ts . SourceFile
44
- > ( sourceFile , [
45
- dropPrivateApiTransformer . bind ( null , program , host )
46
- ] ) ;
44
+ > ( sourceFile , [ dropPrivateApiTransformer . bind ( null , program , host ) ] ) ;
47
45
const transformedSourceFile : ts . SourceFile = result . transformed [ 0 ] ;
48
46
const content = printer . printFile ( transformedSourceFile ) ;
49
47
fs . writeFileSync ( outputLocation , content ) ;
@@ -103,13 +101,18 @@ function verifyMatchingTypeArguments(
103
101
privateType : ts . NodeWithTypeArguments ,
104
102
publicSymbol : ts . Symbol
105
103
) : boolean {
106
- if ( ! ts . isClassDeclaration ( publicSymbol . valueDeclaration ) || ! ts . isInterfaceDeclaration ( publicSymbol . valueDeclaration ) ) {
104
+ if (
105
+ ! ts . isClassDeclaration ( publicSymbol . valueDeclaration ) ||
106
+ ! ts . isInterfaceDeclaration ( publicSymbol . valueDeclaration )
107
+ ) {
107
108
return false ;
108
109
}
109
-
110
- const privateTypeArguments = ( privateType . typeArguments as ts . TypeReferenceNode [ ] | undefined ) ?? [ ] ;
111
- const publicTypeArguments = publicSymbol . valueDeclaration . typeParameters ?? [ ] ;
112
-
110
+
111
+ const privateTypeArguments =
112
+ ( privateType . typeArguments as ts . TypeReferenceNode [ ] | undefined ) ?? [ ] ;
113
+ const publicTypeArguments =
114
+ publicSymbol . valueDeclaration . typeParameters ?? [ ] ;
115
+
113
116
if ( privateTypeArguments . length !== publicTypeArguments . length ) {
114
117
return false ;
115
118
}
@@ -154,7 +157,7 @@ function prunePrivateImports<
154
157
sourceFile : ts . SourceFile ,
155
158
node : T
156
159
) : T {
157
- const typeChecker = program . getTypeChecker ( ) ;
160
+ const typeChecker = program . getTypeChecker ( ) ;
158
161
const currentType = typeChecker . getTypeAtLocation ( node ) ;
159
162
const currentName = currentType ?. symbol ?. name ;
160
163
@@ -196,9 +199,10 @@ function prunePrivateImports<
196
199
additionalMembers . push (
197
200
...convertPropertiesForEnclosingClass (
198
201
program ,
199
- host , sourceFile ,
202
+ host ,
203
+ sourceFile ,
200
204
privateType . getProperties ( ) ,
201
- node ,
205
+ node
202
206
)
203
207
) ;
204
208
}
@@ -242,18 +246,18 @@ function prunePrivateImports<
242
246
* symbols if they are missing from `currentClass`. This allows us to merge
243
247
* class hierarchies for classes whose inherited types are not part of the
244
248
* public API.
245
- *
249
+ *
246
250
* This method relies on a private API in TypeScript's `codefix` package.
247
251
*/
248
252
function convertPropertiesForEnclosingClass (
249
253
program : ts . Program ,
250
- host : ts . CompilerHost ,
254
+ host : ts . CompilerHost ,
251
255
sourceFile : ts . SourceFile ,
252
256
parentClassSymbols : ts . Symbol [ ] ,
253
- currentClass : ts . ClassDeclaration | ts . InterfaceDeclaration ,
257
+ currentClass : ts . ClassDeclaration | ts . InterfaceDeclaration
254
258
) : Array < ts . NamedDeclaration > {
255
259
const newMembers : ts . NamedDeclaration [ ] = [ ] ;
256
- // The `codefix` package is not public but it does exactly what we want. We
260
+ // The `codefix` package is not public but it does exactly what we want. We
257
261
// can explore adding a slimmed down version of this package to our repository
258
262
// if this dependency should ever break.
259
263
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -361,12 +365,7 @@ const dropPrivateApiTransformer = (
361
365
) {
362
366
// Remove any imports that reference internal APIs, while retaining
363
367
// their public members.
364
- return prunePrivateImports (
365
- program ,
366
- host ,
367
- sourceFile ,
368
- node
369
- ) ;
368
+ return prunePrivateImports ( program , host , sourceFile , node ) ;
370
369
} else if (
371
370
ts . isPropertyDeclaration ( node ) ||
372
371
ts . isMethodDeclaration ( node ) ||
0 commit comments