Skip to content

Commit 0a56a1c

Browse files
committed
feature: @putout/plugin-esm: apply-import-by-type-to-file: merge named and namespaced imports to speed things up
1 parent 14e5bab commit 0a56a1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+136
-421
lines changed

packages/plugin-esm/README.md

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ npm i putout @putout/plugin-esm -D
3434

3535
## File rules
3636

37-
-[apply-namespace-import-to-file](#apply-namespace-import-file]);
38-
-[apply-named-import-to-file](#apply-named-import-to-file);
37+
-[apply-import-by-type-to-file](#apply-import-by-type-to-file]);
3938
-[apply-privately-imported-file](#apply-privately-imported-file);
4039
-[apply-js-imported-file](#apply-js-imported-file);
4140
-[resolve-imported-file](#resolve-imported-file);
@@ -62,8 +61,7 @@ npm i putout @putout/plugin-esm -D
6261
"esm/apply-js-imported-file": "off",
6362
"esm/resolve-imported-file": "off",
6463
"esm/shorten-imported-file": "off",
65-
"esm/apply-namespace-import-to-file": "off",
66-
"esm/apply-named-import-to-file": "off",
64+
"esm/apply-import-by-type-to-file": "off",
6765
"esm/apply-privately-imported-file": "off",
6866
"esm/remove-useless-export-specifiers": "off"
6967
}
@@ -401,18 +399,22 @@ import('foo.json', {
401399

402400
## File Rules
403401

404-
### apply-named-import-to-file
402+
### apply-import-by-type-to-file
405403

406404
The rule fixes:
407405

408406
> `SyntaxError: The requested module './a.js' does not provide an export named 'default'`
409407
410408
Check out in 🐊**Putout Editor**:
411409

410+
-[`apply-namespace-import-to-file`](https://putout.cloudcmd.io/#/gist/1492d584559e5798325047de679222a0/c6a37a803b80823de1b64ab944f2427aecefb51b);
412411
-[`get-imports`](https://putout.cloudcmd.io/#/gist/5d7687215e9fbdf705935c444503dded/75a98d2db9d3847c73017e41637924b1cfd5a598);
413412
-[`has-export-default`](https://putout.cloudcmd.io/#/gist/b50ccfe5cc8c0c97e2fc98b37903ade4/fbc026e6f1027581f7aa4879dcafcaa7754bf8f4);
413+
-[`apply-namespace-import`](https://putout.cloudcmd.io/#/gist/23a6dc6741b772c03fbed95feda2b451/1fbecac6fc40282bcda0593aa666a8c213ef85b7);
414414
-[`is-esm`](https://putout.cloudcmd.io/#/gist/fa080be2bf3a6560e289d84b5873c2bc/2601091f6bf97148843767968c3afcb36dde31de);
415415

416+
#### named import
417+
416418
Let's consider file structure:
417419

418420
```
@@ -424,31 +426,19 @@ Let's consider file structure:
424426

425427
In this case `index.js` can be fixed:
426428

427-
#### ❌ Example of incorrect code
429+
##### ❌ Example of incorrect code
428430

429431
```js
430432
import a from './a.js';
431433
```
432434

433-
#### ✅ Example of correct code
435+
##### ✅ Example of correct code
434436

435437
```js
436438
import {a} from './a.js';
437439
```
438440

439-
### apply-namespace-import-to-file
440-
441-
The rule fixes:
442-
443-
> `SyntaxError: The requested module './a.js' does not provide an export named 'default'`
444-
445-
Check out in 🐊**Putout Editor**:
446-
447-
-[`apply-namespace-import-to-file`](https://putout.cloudcmd.io/#/gist/1492d584559e5798325047de679222a0/c6a37a803b80823de1b64ab944f2427aecefb51b);
448-
-[`get-imports`](https://putout.cloudcmd.io/#/gist/5d7687215e9fbdf705935c444503dded/75a98d2db9d3847c73017e41637924b1cfd5a598);
449-
-[`has-export-default`](https://putout.cloudcmd.io/#/gist/b50ccfe5cc8c0c97e2fc98b37903ade4/fbc026e6f1027581f7aa4879dcafcaa7754bf8f4);
450-
-[`apply-namespace-import`](https://putout.cloudcmd.io/#/gist/23a6dc6741b772c03fbed95feda2b451/1fbecac6fc40282bcda0593aa666a8c213ef85b7);
451-
-[`is-esm`](https://putout.cloudcmd.io/#/gist/fa080be2bf3a6560e289d84b5873c2bc/2601091f6bf97148843767968c3afcb36dde31de);
441+
#### namespace import
452442

453443
Let's consider file structure:
454444

@@ -461,13 +451,13 @@ Let's consider file structure:
461451

462452
In this case `index.js` can be fixed:
463453

464-
#### ❌ Example of incorrect code
454+
##### ❌ Example of incorrect code
465455

466456
```js
467457
import a from './a.js';
468458
```
469459

470-
#### ✅ Example of correct code
460+
##### ✅ Example of correct code
471461

472462
```js
473463
import * as a from './a.js';

packages/plugin-esm/lib/apply-named-import-to-file/apply-named-import/fixture/apply-named-import-fix.js renamed to packages/plugin-esm/lib/apply-import-by-type-to-file/apply-named-import/fixture/apply-named-import-fix.js

File renamed without changes.

packages/plugin-esm/lib/apply-named-import-to-file/apply-named-import/fixture/apply-named-import.js renamed to packages/plugin-esm/lib/apply-import-by-type-to-file/apply-named-import/fixture/apply-named-import.js

File renamed without changes.

packages/plugin-esm/lib/apply-named-import-to-file/apply-named-import/index.js renamed to packages/plugin-esm/lib/apply-import-by-type-to-file/apply-named-import/index.js

File renamed without changes.

packages/plugin-esm/lib/apply-named-import-to-file/apply-named-import/index.spec.js renamed to packages/plugin-esm/lib/apply-import-by-type-to-file/apply-named-import/index.spec.js

File renamed without changes.

packages/plugin-esm/lib/apply-namespace-import-to-file/apply-namespace-import/fixture/apply-namespace-import-fix.js renamed to packages/plugin-esm/lib/apply-import-by-type-to-file/apply-namespace-import/fixture/apply-namespace-import-fix.js

File renamed without changes.

packages/plugin-esm/lib/apply-namespace-import-to-file/apply-namespace-import/fixture/apply-namespace-import.js renamed to packages/plugin-esm/lib/apply-import-by-type-to-file/apply-namespace-import/fixture/apply-namespace-import.js

File renamed without changes.

packages/plugin-esm/lib/apply-namespace-import-to-file/apply-namespace-import/index.js renamed to packages/plugin-esm/lib/apply-import-by-type-to-file/apply-namespace-import/index.js

File renamed without changes.

packages/plugin-esm/lib/apply-namespace-import-to-file/apply-namespace-import/index.spec.js renamed to packages/plugin-esm/lib/apply-import-by-type-to-file/apply-namespace-import/index.spec.js

File renamed without changes.

packages/plugin-esm/lib/apply-named-import-to-file/determine-import-type.js renamed to packages/plugin-esm/lib/apply-import-by-type-to-file/determine-import-type.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {putout, operator} from 'putout';
2-
import * as isESMPlugin from '#is-esm';
32
import * as hasExportDefaultPlugin from '#has-export-default';
3+
import * as isESMPlugin from '#is-esm';
44

55
const isESM = (a) => a.rule === 'is-esm';
66
const hasExportDefault = (a) => a.rule === 'has-export-default';
@@ -48,10 +48,7 @@ export const determineImportType = ({name, rootPath, importedFilename, privateIm
4848
return 'equal';
4949
}
5050

51-
if (esm.length)
52-
return 'named';
53-
54-
return '';
51+
return 'named';
5552
};
5653

5754
function parseImportedFilename({importedFilename, privateImports}) {

0 commit comments

Comments
 (0)