Skip to content

Commit f1842b4

Browse files
committed
fix(rsc): keep hoisted require order
1 parent e5c3517 commit f1842b4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/plugin-rsc/src/transforms/cjs.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,32 @@ if (true) {
6868
`)
6969
})
7070

71+
it('edge cases', async () => {
72+
const input = `\
73+
const x = require("te" + "st");
74+
75+
function test() {
76+
const y = require("te" + "st");
77+
}
78+
79+
require("test")();
80+
require("test").test;
81+
`
82+
expect(await testTransform(input)).toMatchInlineSnapshot(`
83+
"const exports = {}; const module = { exports };
84+
const __cjs_to_esm_hoist_0 = await import("te" + "st");
85+
const x = (await import("te" + "st"));
86+
87+
function test() {
88+
const y = __cjs_to_esm_hoist_0;
89+
}
90+
91+
(await import("test"))();
92+
(await import("test")).test;
93+
"
94+
`)
95+
})
96+
7197
it('local require', async () => {
7298
const input = `\
7399
{

0 commit comments

Comments
 (0)