@@ -2,7 +2,6 @@ import ExportMapBuilder from '../exportMap/builder';
22import  recursivePatternCapture  from  '../exportMap/patternCapture' ; 
33import  docsUrl  from  '../docsUrl' ; 
44import  includes  from  'array-includes' ; 
5- import  flatMap  from  'array.prototype.flatmap' ; 
65
76/* 
87Notes on TypeScript namespaces aka TSModuleDeclaration: 
@@ -27,42 +26,25 @@ const rootProgram = 'root';
2726const  tsTypePrefix  =  'type:' ; 
2827
2928/** 
30-  * Detect  function overloads like: 
29+  * remove  function overloads like: 
3130 * ```ts 
3231 * export function foo(a: number); 
3332 * export function foo(a: string); 
34-  * export function foo(a: number|string) { return a; } 
3533 * ``` 
3634 * @param  {Set<Object> } nodes 
37-  * @returns  {boolean } 
3835 */ 
39- function  isTypescriptFunctionOverloads ( nodes )  { 
40-   const  nodesArr  =  Array . from ( nodes ) ; 
41- 
42-   const  idents  =  flatMap ( 
43-     nodesArr , 
44-     ( node )  =>  node . declaration  &&  ( 
45-       node . declaration . type  ===  'TSDeclareFunction'  // eslint 6+ 
46-       ||  node . declaration . type  ===  'TSEmptyBodyFunctionDeclaration'  // eslint 4-5 
47-     ) 
48-       ? node . declaration . id . name 
49-       : [ ] , 
50-   ) ; 
51-   if  ( new  Set ( idents ) . size  !==  idents . length )  { 
52-     return  true ; 
53-   } 
54- 
55-   const  types  =  new  Set ( nodesArr . map ( ( node )  =>  node . parent . type ) ) ; 
56-   if  ( ! types . has ( 'TSDeclareFunction' ) )  { 
57-     return  false ; 
58-   } 
59-   if  ( types . size  ===  1 )  { 
60-     return  true ; 
61-   } 
62-   if  ( types . size  ===  2  &&  types . has ( 'FunctionDeclaration' ) )  { 
63-     return  true ; 
64-   } 
65-   return  false ; 
36+ function  removeTypescriptFunctionOverloads ( nodes )  { 
37+   nodes . forEach ( ( node )  =>  { 
38+     const  declType  =  node . type  ===  'ExportDefaultDeclaration'  ? node . declaration . type  : node . parent . type ; 
39+     if  ( 
40+       // eslint 6+ 
41+       declType  ===  'TSDeclareFunction' 
42+       // eslint 4-5 
43+       ||  declType  ===  'TSEmptyBodyFunctionDeclaration' 
44+     )  { 
45+       nodes . delete ( node ) ; 
46+     } 
47+   } ) ; 
6648} 
6749
6850/** 
@@ -227,9 +209,11 @@ module.exports = {
227209      'Program:exit' ( )  { 
228210        for  ( const  [ ,  named ]  of  namespace )  { 
229211          for  ( const  [ name ,  nodes ]  of  named )  { 
212+             removeTypescriptFunctionOverloads ( nodes ) ; 
213+ 
230214            if  ( nodes . size  <=  1 )  {  continue ;  } 
231215
232-             if  ( isTypescriptFunctionOverloads ( nodes )   ||   isTypescriptNamespaceMerging ( nodes ) )  {  continue ;  } 
216+             if  ( isTypescriptNamespaceMerging ( nodes ) )  {  continue ;  } 
233217
234218            for  ( const  node  of  nodes )  { 
235219              if  ( shouldSkipTypescriptNamespace ( node ,  nodes ) )  {  continue ;  } 
0 commit comments