Skip to content

Commit 7dfac16

Browse files
committed
feature: @putout/plugin-putout: convert-traverse-to-scan: ESM
1 parent 4042526 commit 7dfac16

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const FS = '__putout_processor_filesystem(__object)';
2+
3+
export const report = () => `Remove vim swap file`;
4+
5+
export const fix = (filePath) => {
6+
removeFile(filePath);
7+
};
8+
9+
export const traverse = (path, {push}) => {
10+
findFile(path, '*.swp').map(push);
11+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const FS = '__putout_processor_filesystem(__object)';
2+
3+
export const report = () => `Remove vim swap file`;
4+
5+
export const fix = (filePath) => {
6+
removeFile(filePath);
7+
};
8+
9+
export const traverse = ({push}) => ({
10+
[FS](path) {
11+
findFile(path, '*.swp').map(push);
12+
}
13+
});

packages/plugin-putout/lib/convert-traverse-to-scan/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const {
1616
isObjectProperty,
1717
isObjectExpression,
1818
identifier,
19+
isVariableDeclarator,
1920
} = types;
2021

2122
module.exports.report = () => `Use Scanner instead of Traverser`;
@@ -25,7 +26,13 @@ module.exports.fix = ({path, pathProperty}) => {
2526
replaceWith(path.parentPath, path.get('body'));
2627
path.parentPath.parentPath.node.params.unshift(identifier('path'));
2728

28-
path.parentPath.parentPath.parentPath.node.left.property.name = 'scan';
29+
const currentPath = path.parentPath.parentPath.parentPath;
30+
31+
if (isVariableDeclarator(currentPath))
32+
currentPath.node.init.name = 'scan';
33+
else
34+
currentPath.node.left.property.name = 'scan';
35+
2936
return;
3037
}
3138

packages/plugin-putout/lib/convert-traverse-to-scan/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,8 @@ test('packages: convert-traverse-to-scan: transform: create-traverse', (t) => {
7373
t.transform('create-traverse');
7474
t.end();
7575
});
76+
77+
test('packages: convert-traverse-to-scan: transform: esm', (t) => {
78+
t.transform('esm');
79+
t.end();
80+
});

0 commit comments

Comments
 (0)