Skip to content

Commit 9b08062

Browse files
committed
feature: @putout/plugin-remove-nested-blocks: ImportDeclaration: assert: exclude
1 parent 57a7aa3 commit 9b08062

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

packages/plugin-remove-nested-blocks/lib/remove-nested-blocks.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {types, operator} from 'putout';
33
const {
44
isReturnStatement,
55
isExportNamedDeclaration,
6+
isIdentifier,
67
} = types;
78

89
const {replaceWithMultiple} = operator;
@@ -27,6 +28,9 @@ export const filter = (path) => {
2728
if (isReturnWithoutArg(path))
2829
return false;
2930

31+
if (isImportAssert(path))
32+
return false;
33+
3034
const {parentPath} = path;
3135
const {bindings} = path.scope;
3236

@@ -65,3 +69,14 @@ const isIntersect = (path, bindings) => {
6569

6670
return false;
6771
};
72+
73+
function isImportAssert(path) {
74+
const prev = path.getPrevSibling();
75+
76+
if (!prev.isExpressionStatement())
77+
return false;
78+
79+
return isIdentifier(prev.node.expression, {
80+
name: 'assert',
81+
});
82+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import a from 'a' assert {type: 'json'}

packages/plugin-remove-nested-blocks/test/remove-nested-blocks.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,8 @@ test('plugin-remove-nested-blocks: no report: arrow', (t) => {
8383
t.noReport('arrow');
8484
t.end();
8585
});
86+
87+
test('plugin-remove-nested-blocks: no report: import-assert', (t) => {
88+
t.noReport('import-assert');
89+
t.end();
90+
});

0 commit comments

Comments
 (0)