Skip to content

Commit

Permalink
Prefer re-use value export
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Feb 16, 2022
1 parent 0a52e03 commit 3020b59
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
9 changes: 2 additions & 7 deletions rules/prefer-export-from.js
Expand Up @@ -113,17 +113,12 @@ function getFixFunction({
const sourceNode = importDeclaration.source;
const sourceValue = sourceNode.value;
const isTypeSpecifier = imported.isType || exported.isType;
let exportDeclaration;
let exportDeclaration = exportDeclarations.find(({source, exportKind}) => source.value === sourceValue && exportKind !== 'type');

if (isTypeSpecifier) {
// If a type export declaration already exists, reuse it, else use a value export declaration with an inline type specifier.
if (isTypeSpecifier && !exportDeclaration) {
exportDeclaration = exportDeclarations.find(({source, exportKind}) => source.value === sourceValue && exportKind === 'type');
}

if (!exportDeclaration) {
exportDeclaration = exportDeclarations.find(({source, exportKind}) => source.value === sourceValue && exportKind !== 'type');
}

/** @param {import('eslint').Rule.RuleFixer} fixer */
return function * (fixer) {
if (imported.name === NAMESPACE_SPECIFIER_NAME) {
Expand Down
8 changes: 4 additions & 4 deletions test/snapshots/prefer-export-from.mjs.md
Expand Up @@ -1457,8 +1457,8 @@ Generated by [AVA](https://avajs.dev).
`␊
1 |␊
2 |␊
3 | export type { bar, foo } from "foo";␊
4 | export { baz } from "foo";␊
3 | export type { bar } from "foo";␊
4 | export { baz, type foo } from "foo";␊
`

> Error 1/1
Expand All @@ -1482,8 +1482,8 @@ Generated by [AVA](https://avajs.dev).
`␊
1 |␊
2 |␊
3 | export { baz } from "foo";␊
4 | export type { bar, foo } from "foo";␊
3 | export { baz, type foo } from "foo";␊
4 | export type { bar } from "foo";␊
`

> Error 1/1
Expand Down
Binary file modified test/snapshots/prefer-export-from.mjs.snap
Binary file not shown.

0 comments on commit 3020b59

Please sign in to comment.