Skip to content

Commit 24b853e

Browse files
committed
fix
1 parent f72f207 commit 24b853e

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/rules/export.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import ExportMapBuilder from '../exportMap/builder';
22
import recursivePatternCapture from '../exportMap/patternCapture';
33
import docsUrl from '../docsUrl';
44
import includes from 'array-includes';
5-
import flatMap from 'array.prototype.flatmap';
65

76
/*
87
Notes on TypeScript namespaces aka TSModuleDeclaration:
@@ -39,17 +38,21 @@ const tsTypePrefix = 'type:';
3938
function isTypescriptFunctionOverloads(nodes) {
4039
const nodesArr = Array.from(nodes);
4140

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;
41+
if (nodesArr[0].type === 'ExportDefaultDeclaration') {
42+
let num = 0;
43+
for (const node of nodesArr) {
44+
if (
45+
// eslint 6+
46+
node.declaration.type === 'TSDeclareFunction'
47+
// eslint 4-5
48+
|| node.declaration.type === 'TSEmptyBodyFunctionDeclaration'
49+
) {
50+
num++;
51+
}
52+
}
53+
if (num === nodesArr.length - 1) {
54+
return true;
55+
}
5356
}
5457

5558
const types = new Set(nodesArr.map((node) => node.parent.type));

tests/src/rules/export.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ ruleTester.run('export', rule, {
5656
`,
5757
parser,
5858
})),
59+
getTSParsers().map((parser) => ({
60+
code: `
61+
export default function foo(param: string): boolean;
62+
export default function foo(param: string, param1?: number): boolean {
63+
return param && param1;
64+
}
65+
`,
66+
parser,
67+
})),
5968
),
6069

6170
invalid: [].concat(

0 commit comments

Comments
 (0)