@@ -44,6 +44,7 @@ function main(inputLocation: string, outputLocation: string): void {
44
44
> ( sourceFile , [ dropPrivateApiTransformer . bind ( null , typeChecker ) ] ) ;
45
45
const transformedSourceFile : ts . SourceFile = result . transformed [ 0 ] ;
46
46
const content = printer . printFile ( transformedSourceFile ) ;
47
+ console . log ( content ) ;
47
48
fs . writeFileSync ( outputLocation , content ) ;
48
49
}
49
50
@@ -92,6 +93,16 @@ function maybeHideConstructor(
92
93
}
93
94
}
94
95
96
+ function visit < T extends ts . Node > (
97
+ typeChecker : ts . TypeChecker ,
98
+ originalLocation : ts . Node ,
99
+ d : T
100
+ ) : T {
101
+ return ts . transform ( d , [
102
+ updateInheritedTypeTransformer . bind ( null , typeChecker , originalLocation )
103
+ ] ) . transformed [ 0 ] as T ;
104
+ }
105
+
95
106
/**
96
107
* Examines `extends` and `implements` clauses and removes or replaces them if
97
108
* they refer to a non-exported type. When an export is removed, all members
@@ -148,21 +159,32 @@ function prunePrivateImports<
148
159
// Iterate all members of the private type and add them to the
149
160
// public type if they are not already part of the public type.
150
161
const privateType = typeChecker . getTypeAtLocation ( type ) ;
151
- const symbolType = typeChecker . getTypeOfSymbolAtLocation (
152
- privateType . getProperties ( ) [ 0 ] ,
153
- type
154
- ) ;
155
- if ( symbolType ?. symbol ?. members ) {
162
+ if ( privateType ?. symbol ?. members ) {
156
163
privateType . symbol . members ! . forEach ( ( definition , memberName ) => {
157
164
if ( ! currentMembers || ! currentMembers . has ( memberName ) ) {
158
- additionalMembers . push ( ...definition . declarations ) ;
165
+ additionalMembers . push (
166
+ ...definition . declarations . map ( d =>
167
+ visit ( typeChecker , type , d )
168
+ )
169
+ ) ;
159
170
}
160
171
} ) ;
161
172
}
162
173
}
163
174
}
164
175
}
165
176
177
+ // for (const property of privateType.getProperties()) {
178
+ // for (const declaration of property.declarations) {
179
+ // if (ts.isPropertyDeclaration(declaration)) {
180
+ //
181
+ // const localType = typeChecker.typeToTypeNode(typeChecker.getTypeOfSymbolAtLocation(property, type), node, undefined);
182
+ //
183
+ // const updatedElement = ts.updateProperty(declaration, declaration.decorators, declaration.modifiers, declaration.name, declaration.questionToken || declaration.exclamationToken, localType, declaration.initializer);
184
+ // additionalMembers.push(updatedElement);
185
+ // }
186
+ // }
187
+ // }
166
188
if ( exportedTypes . length > 0 ) {
167
189
prunedHeritageClauses . push (
168
190
ts . updateHeritageClause ( heritageClause , exportedTypes )
@@ -257,6 +279,44 @@ function extractPublicSymbol(
257
279
return publicSymbolsForLocalType [ 0 ] ;
258
280
}
259
281
282
+ const updateInheritedTypeTransformer = (
283
+ typeChecker : ts . TypeChecker ,
284
+ originalLocation : ts . Node ,
285
+ context : ts . TransformationContext
286
+ ) => {
287
+ return ( sourceFile : ts . Node ) => {
288
+ function visit ( node : ts . Node ) : ts . Node {
289
+ if ( ts . isTypeReferenceNode ( node ) ) {
290
+ const symbol = typeChecker . getSymbolAtLocation ( node . typeName ) ;
291
+ const replacement = typeChecker . getTypeOfSymbolAtLocation (
292
+ symbol ! ,
293
+ originalLocation
294
+ ) ;
295
+ if ( replacement ) {
296
+ return ts . updateTypeReferenceNode (
297
+ node ,
298
+ ts . createIdentifier ( 'string' ) ,
299
+ node . typeArguments
300
+ ) ;
301
+ } else {
302
+ return node ;
303
+ }
304
+ }
305
+
306
+ return node ;
307
+ }
308
+
309
+ function visitNodeAndChildren < T extends ts . Node > ( node : T ) : T {
310
+ return ts . visitEachChild (
311
+ visit ( node ) ,
312
+ childNode => visitNodeAndChildren ( childNode ) ,
313
+ context
314
+ ) as T ;
315
+ }
316
+ return visitNodeAndChildren ( sourceFile ) ;
317
+ } ;
318
+ } ;
319
+
260
320
const dropPrivateApiTransformer = (
261
321
typeChecker : ts . TypeChecker ,
262
322
context : ts . TransformationContext
0 commit comments