Skip to content

Commit

Permalink
fix: prefer-export-from do not convert type exports to value exports
Browse files Browse the repository at this point in the history
  • Loading branch information
nrgnrg committed Feb 10, 2022
1 parent e8ab176 commit 670afc3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions rules/prefer-export-from.js
Expand Up @@ -109,9 +109,10 @@ function getFixFunction({
const sourceNode = importDeclaration.source;
const sourceValue = sourceNode.value;
const exportDeclaration = exportDeclarations.find(({source}) => source.value === sourceValue);
const isTypeExport = exported.node.parent.exportKind === "type"

/** @param {import('eslint').Rule.RuleFixer} fixer */
return function * (fixer) {
return function* (fixer) {
if (imported.name === NAMESPACE_SPECIFIER_NAME) {
yield fixer.insertTextAfter(
program,
Expand All @@ -122,20 +123,22 @@ function getFixFunction({
? exported.text
: `${imported.text} as ${exported.text}`;

const specifierWithKind = isTypeExport ? `type ${specifier}` : specifier

if (exportDeclaration) {
const lastSpecifier = exportDeclaration.specifiers[exportDeclaration.specifiers.length - 1];

// `export {} from 'foo';`
if (lastSpecifier) {
yield fixer.insertTextAfter(lastSpecifier, `, ${specifier}`);
yield fixer.insertTextAfter(lastSpecifier, `, ${specifierWithKind}`);
} else {
const openingBraceToken = sourceCode.getFirstToken(exportDeclaration, isOpeningBraceToken);
yield fixer.insertTextAfter(openingBraceToken, specifier);
yield fixer.insertTextAfter(openingBraceToken, specifierWithKind);
}
} else {
yield fixer.insertTextAfter(
program,
`\nexport {${specifier}} ${getSourceAndAssertionsText(importDeclaration, sourceCode)}`,
`\nexport {${specifierWithKind}} ${getSourceAndAssertionsText(importDeclaration, sourceCode)}`,
);
}
}
Expand Down

0 comments on commit 670afc3

Please sign in to comment.