@@ -26,47 +26,25 @@ const rootProgram = 'root';
26
26
const tsTypePrefix = 'type:' ;
27
27
28
28
/**
29
- * Detect function overloads like:
29
+ * remove function overloads like:
30
30
* ```ts
31
31
* export function foo(a: number);
32
32
* export function foo(a: string);
33
- * export function foo(a: number|string) { return a; }
34
33
* ```
35
34
* @param {Set<Object> } nodes
36
- * @returns {boolean }
37
35
*/
38
- function isTypescriptFunctionOverloads ( nodes ) {
39
- const nodesArr = Array . from ( nodes ) ;
40
-
41
- if ( nodesArr [ 0 ] . type === 'ExportDefaultDeclaration' ) {
42
- let num = 0 ;
43
- for ( let i = 0 ; i < nodesArr . length ; i ++ ) {
44
- const type = nodesArr [ i ] . declaration . type ;
45
- if (
46
- // eslint 6+
47
- type === 'TSDeclareFunction'
48
- // eslint 4-5
49
- || type === 'TSEmptyBodyFunctionDeclaration'
50
- ) {
51
- num ++ ;
52
- }
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 ) ;
53
46
}
54
- if ( num === nodesArr . length - 1 ) {
55
- return true ;
56
- }
57
- }
58
-
59
- const types = new Set ( nodesArr . map ( ( node ) => node . parent . type ) ) ;
60
- if ( ! types . has ( 'TSDeclareFunction' ) ) {
61
- return false ;
62
- }
63
- if ( types . size === 1 ) {
64
- return true ;
65
- }
66
- if ( types . size === 2 && types . has ( 'FunctionDeclaration' ) ) {
67
- return true ;
68
- }
69
- return false ;
47
+ } ) ;
70
48
}
71
49
72
50
/**
@@ -231,9 +209,11 @@ module.exports = {
231
209
'Program:exit' ( ) {
232
210
for ( const [ , named ] of namespace ) {
233
211
for ( const [ name , nodes ] of named ) {
212
+ removeTypescriptFunctionOverloads ( nodes ) ;
213
+
234
214
if ( nodes . size <= 1 ) { continue ; }
235
215
236
- if ( isTypescriptFunctionOverloads ( nodes ) || isTypescriptNamespaceMerging ( nodes ) ) { continue ; }
216
+ if ( isTypescriptNamespaceMerging ( nodes ) ) { continue ; }
237
217
238
218
for ( const node of nodes ) {
239
219
if ( shouldSkipTypescriptNamespace ( node , nodes ) ) { continue ; }
0 commit comments