Skip to content

Commit 3e10bd2

Browse files
committed
feature: @putout/plugin-putout: check-replace-code: commonjs
1 parent 4ed4216 commit 3e10bd2

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports.replace = () => {
2+
return {
3+
'export default createRenameProperty(__args)': `{
4+
export const {report, fix, traverse} = createRenameProperty(__args);
5+
export {
6+
report,
7+
fix,
8+
traverse,
9+
}
10+
}`,
11+
}
12+
};

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
import generateCode from './generate-code/index.js';
99

1010
const noop = () => {};
11-
1211
const {
1312
compare,
1413
extract,
@@ -66,7 +65,12 @@ function getProperties(path) {
6665
return [];
6766
}
6867

69-
return path.get(`right.body.properties`);
68+
const bodyPath = path.get('right.body');
69+
70+
if (bodyPath.isObjectExpression())
71+
return bodyPath.get(`properties`);
72+
73+
return [];
7074
}
7175

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

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

+5
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,8 @@ test('plugin-putout: check-replace-code: no report: return', (t) => {
171171
t.noReport('return');
172172
t.end();
173173
});
174+
175+
test('plugin-putout: check-replace-code: no report: return-commonjs', (t) => {
176+
t.noReport('return-commonjs');
177+
t.end();
178+
});

0 commit comments

Comments
 (0)