Skip to content

Commit 8d6b1da

Browse files
committed
prefer-export-from: type-import removed when using namespace import
1 parent 2caa9fe commit 8d6b1da

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

rules/prefer-export-from.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ function getFixFunction({
8686
if (imported.name === NAMESPACE_SPECIFIER_NAME) {
8787
yield fixer.insertTextAfter(
8888
program,
89-
`\nexport * as ${exported.text} ${getSourceAndAssertionsText(importDeclaration, context)}`,
89+
`\nexport ${shouldExportAsType ? 'type ' : ''}* as ${exported.text} ${getSourceAndAssertionsText(importDeclaration, context)}`,
9090
);
9191
} else {
9292
let specifierText = exported.name === imported.name
9393
? exported.text
9494
: `${imported.text} as ${exported.text}`;
9595

96-
// Add an inline type specifier if the value is a type and the export deceleration is a value deceleration
96+
// Add an inline type specifier if the value is a type and the export declaration is a value declaration
9797
if (shouldExportAsType && (!exportDeclaration || exportDeclaration.exportKind !== 'type')) {
9898
specifierText = `type ${specifierText}`;
9999
}
@@ -116,7 +116,8 @@ function getFixFunction({
116116
}
117117
}
118118

119-
if (imported.variable.references.length === 1) {
119+
const importHasSideEffects = exported.isTypeExport && !imported.isTypeImport;
120+
if (imported.variable.references.length === 1 && !importHasSideEffects) {
120121
yield removeImportOrExport(imported.node, fixer, context);
121122
}
122123

test/snapshots/prefer-export-from.js.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ Generated by [AVA](https://avajs.dev).
18711871
| ^^^ Use \`export…from\` to re-export \`foo\`.␊
18721872
18731873
Output:␊
1874-
1 |␊
1874+
1 | import { foo } from 'foo';
18751875
2 |␊
18761876
3 | export {type foo} from 'foo';␊
18771877
`
@@ -2178,7 +2178,7 @@ Generated by [AVA](https://avajs.dev).
21782178
Output:␊
21792179
1 |␊
21802180
2 |␊
2181-
3 | export * as X from 'foo';␊
2181+
3 | export type * as X from 'foo';␊
21822182
`
21832183

21842184
## invalid(27): import * as X from 'foo'; export type { X };
@@ -2199,9 +2199,9 @@ Generated by [AVA](https://avajs.dev).
21992199
| ^ Use \`export…from\` to re-export \`X\`.␊
22002200
22012201
Output:␊
2202-
1 |␊
2202+
1 | import * as X from 'foo';
22032203
2 |␊
2204-
3 | export * as X from 'foo';␊
2204+
3 | export type * as X from 'foo';␊
22052205
`
22062206

22072207
## invalid(28): import type * as X from 'foo'; export type { X };
@@ -2224,7 +2224,7 @@ Generated by [AVA](https://avajs.dev).
22242224
Output:␊
22252225
1 |␊
22262226
2 |␊
2227-
3 | export * as X from 'foo';␊
2227+
3 | export type * as X from 'foo';␊
22282228
`
22292229

22302230
## invalid(29): import * as X from 'foo'; export { X };
8 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)