diff --git a/test/prefer-export-from.mjs b/test/prefer-export-from.mjs index 537fa815b3..5ee7584630 100644 --- a/test/prefer-export-from.mjs +++ b/test/prefer-export-from.mjs @@ -456,6 +456,24 @@ test.snapshot({ import {type foo as bar} from 'foo'; export {type bar as foo}; `, + outdent` + import json from './foo.json' assert { type: 'json' }; + export default json; + `, + outdent` + import * as json from './foo.json' assert { type: 'json' }; + export {json}; + `, + outdent` + import {foo} from './foo.json' assert { type: 'unknown' }; + export {foo}; + export {bar} from './foo.json'; + `, + outdent` + import {foo} from './foo.json'; + export {foo}; + export {bar} from './foo.json' assert { type: 'unknown' }; + `, ], }); @@ -564,64 +582,3 @@ test.snapshot({ ].map(code => ({code, options: [{ignoreUsedVariables: true}]})), }); -// TODO: Run test with default parser when it support "import assertions" -test.babel({ - testerOptions: { - parserOptions: { - babelOptions: { - parserOpts: { - plugins: ['importAssertions'], - }, - }, - }, - }, - valid: [], - invalid: [ - { - code: outdent` - import json from './foo.json' assert { type: 'json' }; - export default json; - `, - errors: 1, - output: outdent` - \n - export {default} from './foo.json' assert { type: 'json' }; - `, - }, - { - code: outdent` - import * as json from './foo.json' assert { type: 'json' }; - export {json}; - `, - errors: 1, - output: outdent` - \n - export * as json from './foo.json' assert { type: 'json' }; - `, - }, - { - code: outdent` - import {foo} from './foo.json' assert { type: 'unknown' }; - export {foo}; - export {bar} from './foo.json'; - `, - errors: 1, - output: outdent` - \n - export {bar, foo} from './foo.json'; - `, - }, - { - code: outdent` - import {foo} from './foo.json'; - export {foo}; - export {bar} from './foo.json' assert { type: 'unknown' }; - `, - errors: 1, - output: outdent` - \n - export {bar, foo} from './foo.json' assert { type: 'unknown' }; - `, - }, - ], -}); diff --git a/test/snapshots/prefer-export-from.mjs.md b/test/snapshots/prefer-export-from.mjs.md index 0b437ae40b..23e6a29191 100644 --- a/test/snapshots/prefer-export-from.mjs.md +++ b/test/snapshots/prefer-export-from.mjs.md @@ -1748,6 +1748,90 @@ Generated by [AVA](https://avajs.dev). | ^^^^^^^^^^^^^^^ Use \`export…from\` to re-export \`foo\`.␊ ` +## Invalid #22 + 1 | import json from './foo.json' assert { type: 'json' }; + 2 | export default json; + +> Output + + `␊ + 1 |␊ + 2 |␊ + 3 | export {default} from './foo.json' assert { type: 'json' };␊ + ` + +> Error 1/1 + + `␊ + 1 | import json from './foo.json' assert { type: 'json' };␊ + > 2 | export default json;␊ + | ^^^^^^^^^^^^^^^^^^^^ Use \`export…from\` to re-export \`default\`.␊ + ` + +## Invalid #23 + 1 | import * as json from './foo.json' assert { type: 'json' }; + 2 | export {json}; + +> Output + + `␊ + 1 |␊ + 2 |␊ + 3 | export * as json from './foo.json' assert { type: 'json' };␊ + ` + +> Error 1/1 + + `␊ + 1 | import * as json from './foo.json' assert { type: 'json' };␊ + > 2 | export {json};␊ + | ^^^^ Use \`export…from\` to re-export \`json\`.␊ + ` + +## Invalid #24 + 1 | import {foo} from './foo.json' assert { type: 'unknown' }; + 2 | export {foo}; + 3 | export {bar} from './foo.json'; + +> Output + + `␊ + 1 |␊ + 2 |␊ + 3 | export {bar, foo} from './foo.json';␊ + ` + +> Error 1/1 + + `␊ + 1 | import {foo} from './foo.json' assert { type: 'unknown' };␊ + > 2 | export {foo};␊ + | ^^^ Use \`export…from\` to re-export \`foo\`.␊ + 3 | export {bar} from './foo.json';␊ + ` + +## Invalid #25 + 1 | import {foo} from './foo.json'; + 2 | export {foo}; + 3 | export {bar} from './foo.json' assert { type: 'unknown' }; + +> Output + + `␊ + 1 |␊ + 2 |␊ + 3 | export {bar, foo} from './foo.json' assert { type: 'unknown' };␊ + ` + +> Error 1/1 + + `␊ + 1 | import {foo} from './foo.json';␊ + > 2 | export {foo};␊ + | ^^^ Use \`export…from\` to re-export \`foo\`.␊ + 3 | export {bar} from './foo.json' assert { type: 'unknown' };␊ + ` + ## Invalid #1 1 | import defaultExport from 'foo'; 2 | export {defaultExport as default}; diff --git a/test/snapshots/prefer-export-from.mjs.snap b/test/snapshots/prefer-export-from.mjs.snap index 15f693095d..8187649de0 100644 Binary files a/test/snapshots/prefer-export-from.mjs.snap and b/test/snapshots/prefer-export-from.mjs.snap differ