diff --git a/packages/plugin-rsc/src/transforms/hoist.test.ts b/packages/plugin-rsc/src/transforms/hoist.test.ts index f239a7f6..22742a47 100644 --- a/packages/plugin-rsc/src/transforms/hoist.test.ts +++ b/packages/plugin-rsc/src/transforms/hoist.test.ts @@ -447,4 +447,20 @@ export async function kv() { " `) }) + + it('no ending new line', async () => { + const input = `\ +export async function test() { + "use server"; +}` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "export const test = /* #__PURE__ */ $$register($$hoist_0_test, "", "$$hoist_0_test"); + + ;export async function $$hoist_0_test() { + "use server"; + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_test, "name", { value: "test" }); + " + `) + }) }) diff --git a/packages/plugin-rsc/src/transforms/hoist.ts b/packages/plugin-rsc/src/transforms/hoist.ts index 7fcd0432..eb5bf15b 100644 --- a/packages/plugin-rsc/src/transforms/hoist.ts +++ b/packages/plugin-rsc/src/transforms/hoist.ts @@ -27,6 +27,10 @@ export function transformHoistInlineDirective( output: MagicString names: string[] } { + // ensure ending space so we can move node at the end without breaking magic-string + if (!input.endsWith('\n')) { + input += '\n' + } const output = new MagicString(input) const directive = typeof options.directive === 'string'