Skip to content

Commit 2f6f665

Browse files
committed
feature: @putout/plugin-nodejs: convert-esm-to-commonjs: destructuring
1 parent 3989c8d commit 2f6f665

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
const {a, b} = fn();
3+
module.exports = {a, b};
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const {
2+
a,
3+
b,
4+
} = fn();

packages/plugin-nodejs/lib/convert-esm-to-commonjs/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export const replace = () => ({
1616
[`export ${FN}`]: `module.exports.__a = ${FN}`,
1717
[`export ${ASYNC_FN}`]: `module.exports.__a = ${ASYNC_FN}`,
1818
[`export ${GEN_FN}`]: `module.exports.__a = ${GEN_FN}`,
19+
'export const __object = __b': `{
20+
const __object = __b;
21+
module.exports = __object;
22+
}`,
1923
'export const __a = __b': 'module.exports.__a = __b',
2024
'export {__exports}': ({__exports}) => {
2125
let result = 'module.exports = {\n';

packages/plugin-nodejs/lib/convert-esm-to-commonjs/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ test('plugin-convert-esm-to-commonjs: transform: export: export-multiple', (t) =
9191
t.end();
9292
});
9393

94+
test('plugin-convert-esm-to-commonjs: transform: export: destructuring', (t) => {
95+
t.transform('destructuring');
96+
t.end();
97+
});
98+
9499
test('plugin-convert-esm-to-commonjs: transform: export: no-arg', (t) => {
95100
t.transform('no-arg', {
96101
'add-path-arg-to-fix': putout.rules['add-path-arg-to-fix'],

0 commit comments

Comments
 (0)