Skip to content

Commit

Permalink
prefer-export-from: Fix bug on fixing export namespace as default (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 9, 2021
1 parent 6423799 commit b564ff1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
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.

0 comments on commit b564ff1

Please sign in to comment.