Skip to content

Commit cf1a324

Browse files
committed
feature: @putout/plugin-nodejs: convert-commonjs-to-esm: require: chain: improve support
1 parent 5d5243d commit cf1a324

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

packages/plugin-nodejs/lib/convert-commonjs-to-esm/require/fixture/chain-fix.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@
33

44
const HOME = os.homedir();
55
}
6+
{
7+
import chai from 'chai';
8+
9+
chai
10+
.use(chaiJestSnapshot)
11+
.should(chaiJestSnapshot);
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
const HOME = require('os').homedir();
2+
3+
require('chai')
4+
.use(chaiJestSnapshot)
5+
.should();
6+

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ export const replace = () => ({
164164
const __a = ${name}.__c(__args);
165165
}`;
166166
},
167+
'require("__b").__c(__args).__d(__args)': ({__b}) => {
168+
const name = camelCase(__b.value);
169+
170+
return `{
171+
import ${name} from "__b";
172+
${name}.__c(__args).__d(__args);
173+
}`;
174+
},
167175
'export const __a = require("__b")': ({__a}) => {
168176
if (isObjectPattern(__a))
169177
return 'export __a from "__b"';

0 commit comments

Comments
 (0)