@@ -4,7 +4,7 @@ export { logResult }
4
4
// For ./generateShield.spec.ts
5
5
export { testGenerateShield }
6
6
7
- import { Project , VariableDeclarationKind , SourceFile , getCompilerOptionsFromTsConfig , SyntaxKind } from 'ts-morph'
7
+ import { Project , VariableDeclarationKind , SourceFile , getCompilerOptionsFromTsConfig } from 'ts-morph'
8
8
import {
9
9
assert ,
10
10
assertUsage ,
@@ -123,16 +123,14 @@ function generate({
123
123
telefuncFilePath : string
124
124
exportList : ExportList
125
125
} ) : string {
126
- const exportedFunctions = getExportedFunctions ( telefuncFileSource , exportList )
127
-
128
126
shieldGenSource . addImportDeclaration ( {
129
127
moduleSpecifier : getTelefuncFileImportPath ( telefuncFilePath ) ,
130
- namedImports : exportedFunctions . map ( ( e ) => e . exportName ) ,
128
+ namedImports : exportList . map ( ( e ) => e . exportName ) ,
131
129
} )
132
130
133
131
// assign the template literal type to a string
134
132
// then diagnostics are used to get the value of the template literal type
135
- for ( const exportedFunction of exportedFunctions ) {
133
+ for ( const exportedFunction of exportList ) {
136
134
shieldGenSource . addTypeAlias ( {
137
135
name : getShieldName ( exportedFunction . exportName ) ,
138
136
type : `ShieldArrStr<Parameters<typeof ${ exportedFunction . exportName } >>` ,
@@ -165,7 +163,7 @@ function generate({
165
163
// We need `compilerOptions.strict` to avoid `TS2589: Type instantiation is excessively deep and possibly infinite.`
166
164
assert ( project . compilerOptions . get ( ) . strict === true )
167
165
168
- for ( const exportedFunction of exportedFunctions ) {
166
+ for ( const exportedFunction of exportList ) {
169
167
const typeAliasName = getShieldName ( exportedFunction . exportName )
170
168
const typeAlias = shieldGenSource . getTypeAlias ( typeAliasName )
171
169
assert ( typeAlias , `Failed to get type alias \`${ typeAliasName } \`.` )
@@ -442,35 +440,3 @@ function assertTelefuncFilesSource(
442
440
assert ( false , debugInfo )
443
441
}
444
442
}
445
-
446
- function getExportedFunctions ( telefuncFileSource : SourceFile , exportList : ExportList ) {
447
- const exportNames : string [ ] = Array . from ( telefuncFileSource . getExportedDeclarations ( ) )
448
- . filter ( ( [ _ , declarations ] ) =>
449
- declarations . some (
450
- ( decl ) =>
451
- // Regular function
452
- decl . isKind ( SyntaxKind . FunctionDeclaration ) ||
453
- // Arrow function
454
- ( decl . isKind ( SyntaxKind . VariableDeclaration ) && decl . getInitializer ( ) ?. isKind ( SyntaxKind . ArrowFunction ) ) ,
455
- ) ,
456
- )
457
- . map ( ( [ exportName ] ) => exportName )
458
-
459
- // Double check for regular functions (the following doesn't catch arrow functions)
460
- telefuncFileSource
461
- . getFunctions ( )
462
- . filter ( ( f ) => f . isExported ( ) )
463
- . flatMap ( ( telefunction ) => {
464
- const name = telefunction . getName ( )
465
- if ( ! name ) return
466
- assert ( exportNames . includes ( name ) )
467
- } )
468
-
469
- const exportedFunctions = exportNames . map ( ( exportName ) => {
470
- const e = exportList . find ( ( e ) => e . exportName === exportName )
471
- assert ( e )
472
- return e
473
- } )
474
-
475
- return exportedFunctions
476
- }
0 commit comments