Skip to content

Commit 7e9829c

Browse files
committed
feature: @putout/plugin-esm: apply-namespace-to-imported-file: ImportExpression: exclude
1 parent b15bcf4 commit 7e9829c

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

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

File renamed without changes.

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

File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
__putout_processor_filesystem([
2+
'/',
3+
'/lib/',
4+
['/lib/index.js', `
5+
const is = await import('./b/index.js');
6+
`],
7+
'/lib/b/',
8+
['/lib/b/index.js', 'export const a = 7\\n'],
9+
]);

packages/plugin-esm/lib/apply-namespace-to-imported-file/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {determineImportType} from '#determine-import-type';
99
import {getImportsTuples} from '#get-imports-tuples';
1010
import {transformNamespaceImport} from './transform-namespace-import.js';
1111

12+
const isDeclaration = ([, , , type]) => type !== 'dynamic';
1213
const {
1314
getFilename,
1415
readFileContent,
@@ -53,7 +54,9 @@ export const scan = (rootPath, {push, trackFile, crawlFile}) => {
5354
aliasBased: true,
5455
});
5556

56-
for (const [name, source, importedFilename] of importsTuples) {
57+
const declarations = importsTuples.filter(isDeclaration);
58+
59+
for (const [name, source, importedFilename] of declarations) {
5760
const importType = determineImportType({
5861
name,
5962
rootPath,

packages/plugin-esm/lib/apply-namespace-to-imported-file/index.spec.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import * as plugin from './index.js';
33

44
const test = createTest(import.meta.url, {
55
plugins: [
6-
['apply-import-by-type-to-file', plugin],
6+
['apply-namespace-to-imported-file', plugin],
77
],
88
});
99

10-
test('esm: apply-namespace-to-imported-file: report: apply-import-by-type-to-file', (t) => {
11-
t.report('apply-import-by-type-to-file', `Use \`import * as dotdot from './b/index.js'\` in '/lib/index.js'`);
10+
test('esm: apply-namespace-to-imported-file: report: apply-namespace-to-imported-file', (t) => {
11+
t.report('apply-namespace-to-imported-file', `Use \`import * as dotdot from './b/index.js'\` in '/lib/index.js'`);
1212
t.end();
1313
});
1414

15-
test('esm: apply-namespace-to-imported-file: transform: apply-import-by-type-to-file', (t) => {
16-
t.transform('apply-import-by-type-to-file');
15+
test('esm: apply-namespace-to-imported-file: transform: apply-namespace-to-imported-file', (t) => {
16+
t.transform('apply-namespace-to-imported-file');
1717
t.end();
1818
});
1919

@@ -41,3 +41,8 @@ test('esm: apply-namespace-to-imported-file: transform: not-equal', (t) => {
4141
t.transform('not-equal');
4242
t.end();
4343
});
44+
45+
test('esm: apply-namespace-to-imported-file: no report: dynamic', (t) => {
46+
t.noReport('dynamic');
47+
t.end();
48+
});

0 commit comments

Comments
 (0)