Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Sep 19, 2024
1 parent 09476d7 commit bd89a43
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/rules/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ExportMapBuilder from '../exportMap/builder';
import recursivePatternCapture from '../exportMap/patternCapture';
import docsUrl from '../docsUrl';
import includes from 'array-includes';
import flatMap from 'array.prototype.flatmap';

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

const idents = flatMap(
nodesArr,
(node) => node.declaration && (
node.declaration.type === 'TSDeclareFunction' // eslint 6+
|| node.declaration.type === 'TSEmptyBodyFunctionDeclaration' // eslint 4-5
)
? node.declaration.id.name
: [],
);
if (new Set(idents).size !== idents.length) {
return true;
if (nodesArr[0].type === "ExportDefaultDeclaration") {
let num = 0;
for (const node of nodesArr) {
if (
// eslint 6+
node.declaration.type === 'TSDeclareFunction' ||
// eslint 4-5
node.declaration.type === 'TSEmptyBodyFunctionDeclaration'
) {
num++;
}
}
if (num === nodesArr.length - 1) {
return true;
}
}

const types = new Set(nodesArr.map((node) => node.parent.type));
Expand Down
9 changes: 9 additions & 0 deletions tests/src/rules/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ ruleTester.run('export', rule, {
`,
parser,
})),
getTSParsers().map((parser) => ({
code: `
export default function foo(param: string): boolean;
export default function foo(param: string, param1?: number): boolean {
return param && param1;
}
`,
parser,
})),
),

invalid: [].concat(
Expand Down

0 comments on commit bd89a43

Please sign in to comment.