Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefer-export-from: Fix bug on fixing export namespace as default #1583

Merged
merged 1 commit into from Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion rules/prefer-export-from.js
Expand Up @@ -230,7 +230,7 @@ function * getProblems({
```
*/
if (imported.name === '*' && exported.name === 'default') {
return;
continue;
}

yield {
Expand Down
9 changes: 0 additions & 9 deletions test/prefer-export-from.mjs
Expand Up @@ -264,20 +264,11 @@ test.snapshot({
export {named} from './foo.js?query';
export default defaultExport;
`,
],
});

// Strange case
// TODO: confirm how should this work
test.snapshot({
valid: [
outdent`
import * as namespace from 'foo';
export default namespace;
export {namespace};
`,
],
invalid: [
outdent`
import * as namespace from 'foo';
export {namespace};
Expand Down
41 changes: 38 additions & 3 deletions test/snapshots/prefer-export-from.mjs.md
Expand Up @@ -440,11 +440,12 @@ Generated by [AVA](https://avajs.dev).
2 | namespace.bar = 1;␊
3 |␊
4 | export {namespace as default};␊
5 | export const variable = namespace;
5 |␊
6 | export * as named from 'foo';␊
7 | export * as variable from 'foo';␊
`

> Error 1/1
> Error 1/2

`␊
1 | import * as namespace from 'foo';␊
Expand All @@ -455,6 +456,17 @@ Generated by [AVA](https://avajs.dev).
5 | export const variable = namespace;␊
`

> Error 2/2

`␊
1 | import * as namespace from 'foo';␊
2 | namespace.bar = 1;␊
3 | export {namespace as named};␊
4 | export {namespace as default};␊
> 5 | export const variable = namespace;␊
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use \`export…from\` to re-export \`variable\`.␊
`

## Invalid #20
1 | import {named1, named2} from 'foo';
2 | export {named1};
Expand Down Expand Up @@ -1024,7 +1036,30 @@ Generated by [AVA](https://avajs.dev).
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use \`export…from\` to re-export \`default\`.␊
`

## Invalid #1
## Invalid #43
1 | import * as namespace from 'foo';
2 | export default namespace;
3 | export {namespace};

> Output

`␊
1 | import * as namespace from 'foo';␊
2 | export default namespace;␊
3 |␊
4 | export * as namespace from 'foo';␊
`

> Error 1/1

`␊
1 | import * as namespace from 'foo';␊
2 | export default namespace;␊
> 3 | export {namespace};␊
| ^^^^^^^^^ Use \`export…from\` to re-export \`namespace\`.␊
`

## Invalid #44
1 | import * as namespace from 'foo';
2 | export {namespace};
3 | export default namespace;
Expand Down
Binary file modified test/snapshots/prefer-export-from.mjs.snap
Binary file not shown.