diff --git a/rules/prefer-export-from.js b/rules/prefer-export-from.js index d92d62a220..35c1a62916 100644 --- a/rules/prefer-export-from.js +++ b/rules/prefer-export-from.js @@ -83,16 +83,17 @@ function getFixFunction({ /** @param {import('eslint').Rule.RuleFixer} fixer */ return function * (fixer) { if (imported.name === NAMESPACE_SPECIFIER_NAME) { + const maybeType = imported.isTypeImport ? 'type ' : ''; yield fixer.insertTextAfter( program, - `\nexport * as ${exported.text} ${getSourceAndAssertionsText(importDeclaration, sourceCode)}`, + `\nexport ${maybeType}* as ${exported.text} ${getSourceAndAssertionsText(importDeclaration, sourceCode)}`, ); } else { let specifierText = exported.name === imported.name ? exported.text : `${imported.text} as ${exported.text}`; - // Add an inline type specifier if the value is a type and the export deceleration is a value deceleration + // Add an inline type specifier if the value is a type and the export declaration is a value declaration if (shouldExportAsType && (!exportDeclaration || exportDeclaration.exportKind !== 'type')) { specifierText = `type ${specifierText}`; } diff --git a/test/prefer-export-from.js b/test/prefer-export-from.js index c5aa7a8f24..e6419d2588 100644 --- a/test/prefer-export-from.js +++ b/test/prefer-export-from.js @@ -474,6 +474,22 @@ test.snapshot({ export {foo}; export {bar} from './foo.json' assert { type: 'unknown' }; `, + outdent` + import type * as X from 'foo'; + export { X }; + `, + outdent` + import * as X from 'foo'; + export type { X }; + `, + outdent` + import type * as X from 'foo'; + export type { X }; + `, + outdent` + import * as X from 'foo'; + export { X }; + `, ], }); diff --git a/test/snapshots/prefer-export-from.js.md b/test/snapshots/prefer-export-from.js.md index 7034b94b51..082fabcc3f 100644 --- a/test/snapshots/prefer-export-from.js.md +++ b/test/snapshots/prefer-export-from.js.md @@ -2227,6 +2227,106 @@ Generated by [AVA](https://avajs.dev). 3 | export {bar} from './foo.json' assert { type: 'unknown' };␊ ` +## invalid(26): import type * as X from 'foo'; export { X }; + +> Input + + `␊ + 1 | import type * as X from 'foo';␊ + 2 | export { X };␊ + ` + +> Output + + `␊ + 1 |␊ + 2 |␊ + 3 | export type * as X from 'foo';␊ + ` + +> Error 1/1 + + `␊ + 1 | import type * as X from 'foo';␊ + > 2 | export { X };␊ + | ^ Use \`export…from\` to re-export \`X\`.␊ + ` + +## invalid(27): import * as X from 'foo'; export type { X }; + +> Input + + `␊ + 1 | import * as X from 'foo';␊ + 2 | export type { X };␊ + ` + +> Output + + `␊ + 1 |␊ + 2 |␊ + 3 | export * as X from 'foo';␊ + ` + +> Error 1/1 + + `␊ + 1 | import * as X from 'foo';␊ + > 2 | export type { X };␊ + | ^ Use \`export…from\` to re-export \`X\`.␊ + ` + +## invalid(28): import type * as X from 'foo'; export type { X }; + +> Input + + `␊ + 1 | import type * as X from 'foo';␊ + 2 | export type { X };␊ + ` + +> Output + + `␊ + 1 |␊ + 2 |␊ + 3 | export type * as X from 'foo';␊ + ` + +> Error 1/1 + + `␊ + 1 | import type * as X from 'foo';␊ + > 2 | export type { X };␊ + | ^ Use \`export…from\` to re-export \`X\`.␊ + ` + +## invalid(29): import * as X from 'foo'; export { X }; + +> Input + + `␊ + 1 | import * as X from 'foo';␊ + 2 | export { X };␊ + ` + +> Output + + `␊ + 1 |␊ + 2 |␊ + 3 | export * as X from 'foo';␊ + ` + +> Error 1/1 + + `␊ + 1 | import * as X from 'foo';␊ + > 2 | export { X };␊ + | ^ Use \`export…from\` to re-export \`X\`.␊ + ` + ## invalid(1): import json from './foo.json' with { type: 'json' }; export default json; > Input diff --git a/test/snapshots/prefer-export-from.js.snap b/test/snapshots/prefer-export-from.js.snap index 9e9b1ac487..83f41d0bc1 100644 Binary files a/test/snapshots/prefer-export-from.js.snap and b/test/snapshots/prefer-export-from.js.snap differ