Skip to content

Commit b1cc894

Browse files
authored
Add tests for import attributes with with keyword (#2576)
1 parent ca1e432 commit b1cc894

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

test/prefer-export-from.js

+26
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,32 @@ test.snapshot({
477477
],
478478
});
479479

480+
// Import attributes
481+
test.snapshot({
482+
valid: [
483+
],
484+
invalid: [
485+
outdent`
486+
import json from './foo.json' with { type: 'json' };
487+
export default json;
488+
`,
489+
outdent`
490+
import * as json from './foo.json' with { type: 'json' };
491+
export {json};
492+
`,
493+
outdent`
494+
import {foo} from './foo.json' with { type: 'unknown' };
495+
export {foo};
496+
export {bar} from './foo.json';
497+
`,
498+
outdent`
499+
import {foo} from './foo.json';
500+
export {foo};
501+
export {bar} from './foo.json' with { type: 'unknown' };
502+
`,
503+
],
504+
});
505+
480506
// `ignoreUsedVariables`
481507
test.snapshot({
482508
valid: [

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

+104
Original file line numberDiff line numberDiff line change
@@ -2227,6 +2227,110 @@ Generated by [AVA](https://avajs.dev).
22272227
3 | export {bar} from './foo.json' assert { type: 'unknown' };␊
22282228
`
22292229

2230+
## invalid(1): import json from './foo.json' with { type: 'json' }; export default json;
2231+
2232+
> Input
2233+
2234+
`␊
2235+
1 | import json from './foo.json' with { type: 'json' };␊
2236+
2 | export default json;␊
2237+
`
2238+
2239+
> Output
2240+
2241+
`␊
2242+
1 |␊
2243+
2 |␊
2244+
3 | export {default} from './foo.json' with { type: 'json' };␊
2245+
`
2246+
2247+
> Error 1/1
2248+
2249+
`␊
2250+
1 | import json from './foo.json' with { type: 'json' };␊
2251+
> 2 | export default json;␊
2252+
| ^^^^^^^^^^^^^^^^^^^^ Use \`export…from\` to re-export \`default\`.␊
2253+
`
2254+
2255+
## invalid(2): import * as json from './foo.json' with { type: 'json' }; export {json};
2256+
2257+
> Input
2258+
2259+
`␊
2260+
1 | import * as json from './foo.json' with { type: 'json' };␊
2261+
2 | export {json};␊
2262+
`
2263+
2264+
> Output
2265+
2266+
`␊
2267+
1 |␊
2268+
2 |␊
2269+
3 | export * as json from './foo.json' with { type: 'json' };␊
2270+
`
2271+
2272+
> Error 1/1
2273+
2274+
`␊
2275+
1 | import * as json from './foo.json' with { type: 'json' };␊
2276+
> 2 | export {json};␊
2277+
| ^^^^ Use \`export…from\` to re-export \`json\`.␊
2278+
`
2279+
2280+
## invalid(3): import {foo} from './foo.json' with { type: 'unknown' }; export {foo}; export {bar} from './foo.json';
2281+
2282+
> Input
2283+
2284+
`␊
2285+
1 | import {foo} from './foo.json' with { type: 'unknown' };␊
2286+
2 | export {foo};␊
2287+
3 | export {bar} from './foo.json';␊
2288+
`
2289+
2290+
> Output
2291+
2292+
`␊
2293+
1 |␊
2294+
2 |␊
2295+
3 | export {bar, foo} from './foo.json';␊
2296+
`
2297+
2298+
> Error 1/1
2299+
2300+
`␊
2301+
1 | import {foo} from './foo.json' with { type: 'unknown' };␊
2302+
> 2 | export {foo};␊
2303+
| ^^^ Use \`export…from\` to re-export \`foo\`.␊
2304+
3 | export {bar} from './foo.json';␊
2305+
`
2306+
2307+
## invalid(4): import {foo} from './foo.json'; export {foo}; export {bar} from './foo.json' with { type: 'unknown' };
2308+
2309+
> Input
2310+
2311+
`␊
2312+
1 | import {foo} from './foo.json';␊
2313+
2 | export {foo};␊
2314+
3 | export {bar} from './foo.json' with { type: 'unknown' };␊
2315+
`
2316+
2317+
> Output
2318+
2319+
`␊
2320+
1 |␊
2321+
2 |␊
2322+
3 | export {bar, foo} from './foo.json' with { type: 'unknown' };␊
2323+
`
2324+
2325+
> Error 1/1
2326+
2327+
`␊
2328+
1 | import {foo} from './foo.json';␊
2329+
> 2 | export {foo};␊
2330+
| ^^^ Use \`export…from\` to re-export \`foo\`.␊
2331+
3 | export {bar} from './foo.json' with { type: 'unknown' };␊
2332+
`
2333+
22302334
## invalid(1): import defaultExport from 'foo'; export {defaultExport as default}; export {defaultExport as named};
22312335

22322336
> Input
149 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)