Skip to content

Commit 702ac92

Browse files
committed
feature: @putout/plugin-putout: check-replace-code: exclude BlockStatement
1 parent f86172e commit 702ac92

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const report = () => `Apply 'exports' to 'renameFiles()`;
2+
3+
export const replace = () => {
4+
return {
5+
'export default renameFiles(__args)': `{
6+
const {report, fix, scan} = matchFiles(__args);
7+
export {
8+
report,
9+
fix,
10+
scan,
11+
};
12+
}`,
13+
}
14+
};

packages/plugin-putout/lib/check-replace-code/index.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,16 @@ export const traverse = ({push, options}) => {
5757
};
5858

5959
function getProperties(path) {
60-
const props = `body.properties`;
61-
62-
if (path.isExportNamedDeclaration())
63-
return path.get(`declaration.declarations.0.init.${props}`);
60+
if (path.isExportNamedDeclaration()) {
61+
const bodyPath = path.get('declaration.declarations.0.init.body');
62+
63+
if (bodyPath.isObjectExpression())
64+
return bodyPath.get(`properties`);
65+
66+
return [];
67+
}
6468

65-
return path.get(`right.${props}`);
69+
return path.get(`right.body.properties`);
6670
}
6771

6872
const createTraverseReplacer = ({once, push}) => (path) => {

packages/plugin-putout/lib/check-replace-code/index.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,8 @@ test('plugin-putout: check-replace-code: no report: class-body', (t) => {
166166
t.noReport('class-body');
167167
t.end();
168168
});
169+
170+
test('plugin-putout: check-replace-code: no report: return', (t) => {
171+
t.noReport('return');
172+
t.end();
173+
});

0 commit comments

Comments
 (0)