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 7d16cc0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions rules/prefer-export-from.js
Expand Up @@ -109,6 +109,7 @@ 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) {
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 7d16cc0

Please sign in to comment.