diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-assignment.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-assignment.js new file mode 100644 index 000000000..08092632b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-assignment.js @@ -0,0 +1,12 @@ +// Writing to a captured local only mutates the hoisted action's bound +// parameter copy, not the original outer binding. +function Counter() { + let local = 0 + + async function updateLocal() { + 'use server' + local = 1 + } + + return 'something' +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-assignment.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-assignment.js.snap.encode.js new file mode 100644 index 000000000..ca81ab8a1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-assignment.js.snap.encode.js @@ -0,0 +1,16 @@ +// Writing to a captured local only mutates the hoisted action's bound +// parameter copy, not the original outer binding. +function Counter() { + let local = 0 + + const updateLocal = /* #__PURE__ */ $$register($$hoist_0_updateLocal, "", "$$hoist_0_updateLocal").bind(null, __enc([local])); + + return 'something' +} + +;export async function $$hoist_0_updateLocal($$hoist_encoded) { + const [local] = __dec($$hoist_encoded); +'use server' + local = 1 + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_updateLocal, "name", { value: "updateLocal" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-assignment.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-assignment.js.snap.js new file mode 100644 index 000000000..1a0f9c92b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-assignment.js.snap.js @@ -0,0 +1,15 @@ +// Writing to a captured local only mutates the hoisted action's bound +// parameter copy, not the original outer binding. +function Counter() { + let local = 0 + + const updateLocal = /* #__PURE__ */ $$register($$hoist_0_updateLocal, "", "$$hoist_0_updateLocal").bind(null, local); + + return 'something' +} + +;export async function $$hoist_0_updateLocal(local) { + 'use server' + local = 1 + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_updateLocal, "name", { value: "updateLocal" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-increment.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-increment.js new file mode 100644 index 000000000..6493ffd8f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-increment.js @@ -0,0 +1,11 @@ +// Mutating a captured local is local to the hoisted invocation copy. +function Counter() { + let local = 0 + + async function updateLocal() { + 'use server' + local++ + } + + return 'something' +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-increment.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-increment.js.snap.encode.js new file mode 100644 index 000000000..aec55a67d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-increment.js.snap.encode.js @@ -0,0 +1,15 @@ +// Mutating a captured local is local to the hoisted invocation copy. +function Counter() { + let local = 0 + + const updateLocal = /* #__PURE__ */ $$register($$hoist_0_updateLocal, "", "$$hoist_0_updateLocal").bind(null, __enc([local])); + + return 'something' +} + +;export async function $$hoist_0_updateLocal($$hoist_encoded) { + const [local] = __dec($$hoist_encoded); +'use server' + local++ + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_updateLocal, "name", { value: "updateLocal" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-increment.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-increment.js.snap.js new file mode 100644 index 000000000..940152fe7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/captured-local-increment.js.snap.js @@ -0,0 +1,14 @@ +// Mutating a captured local is local to the hoisted invocation copy. +function Counter() { + let local = 0 + + const updateLocal = /* #__PURE__ */ $$register($$hoist_0_updateLocal, "", "$$hoist_0_updateLocal").bind(null, local); + + return 'something' +} + +;export async function $$hoist_0_updateLocal(local) { + 'use server' + local++ + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_updateLocal, "name", { value: "updateLocal" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/catch-binding-shadow.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/catch-binding-shadow.js new file mode 100644 index 000000000..464f2e787 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/catch-binding-shadow.js @@ -0,0 +1,10 @@ +function outer(config, err) { + async function action() { + 'use server' + try { + return config.value + } catch (err) { + return err.message + } + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/catch-binding-shadow.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/catch-binding-shadow.js.snap.encode.js new file mode 100644 index 000000000..709ff5ae7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/catch-binding-shadow.js.snap.encode.js @@ -0,0 +1,14 @@ +function outer(config, err) { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([{ value: config.value }])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [config] = __dec($$hoist_encoded); +'use server' + try { + return config.value + } catch (err) { + return err.message + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/catch-binding-shadow.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/catch-binding-shadow.js.snap.js new file mode 100644 index 000000000..9dd9ba7db --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/catch-binding-shadow.js.snap.js @@ -0,0 +1,13 @@ +function outer(config, err) { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, { value: config.value }); +} + +;export async function $$hoist_0_action(config) { + 'use server' + try { + return config.value + } catch (err) { + return err.message + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/class-declaration-in-body.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/class-declaration-in-body.js new file mode 100644 index 000000000..60a37c1f1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/class-declaration-in-body.js @@ -0,0 +1,11 @@ +function outer(config) { + async function action() { + 'use server' + class Helper { + run() { + return config.value + } + } + return new Helper().run() + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/class-declaration-in-body.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/class-declaration-in-body.js.snap.encode.js new file mode 100644 index 000000000..5d23bd6a5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/class-declaration-in-body.js.snap.encode.js @@ -0,0 +1,15 @@ +function outer(config) { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([{ value: config.value }])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [config] = __dec($$hoist_encoded); +'use server' + class Helper { + run() { + return config.value + } + } + return new Helper().run() + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/class-declaration-in-body.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/class-declaration-in-body.js.snap.js new file mode 100644 index 000000000..1fc5046a5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/class-declaration-in-body.js.snap.js @@ -0,0 +1,14 @@ +function outer(config) { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, { value: config.value }); +} + +;export async function $$hoist_0_action(config) { + 'use server' + class Helper { + run() { + return config.value + } + } + return new Helper().run() + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/computed-destructuring-key-captures-outer-binding.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/computed-destructuring-key-captures-outer-binding.js new file mode 100644 index 000000000..6aba1d531 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/computed-destructuring-key-captures-outer-binding.js @@ -0,0 +1,8 @@ +function outer() { + const key = 'value' + async function action(data) { + 'use server' + const { [key]: val } = data + return val + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/computed-destructuring-key-captures-outer-binding.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/computed-destructuring-key-captures-outer-binding.js.snap.encode.js new file mode 100644 index 000000000..87e2b7939 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/computed-destructuring-key-captures-outer-binding.js.snap.encode.js @@ -0,0 +1,12 @@ +function outer() { + const key = 'value' + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([key])); +} + +;export async function $$hoist_0_action($$hoist_encoded, data) { + const [key] = __dec($$hoist_encoded); +'use server' + const { [key]: val } = data + return val + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/computed-destructuring-key-captures-outer-binding.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/computed-destructuring-key-captures-outer-binding.js.snap.js new file mode 100644 index 000000000..bd621b5fa --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/computed-destructuring-key-captures-outer-binding.js.snap.js @@ -0,0 +1,11 @@ +function outer() { + const key = 'value' + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, key); +} + +;export async function $$hoist_0_action(key, data) { + 'use server' + const { [key]: val } = data + return val + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/destructured-param-default-bound.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/destructured-param-default-bound.js new file mode 100644 index 000000000..05f199bfa --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/destructured-param-default-bound.js @@ -0,0 +1,6 @@ +function outer(outerDefault) { + async function action({ x = outerDefault } = {}) { + 'use server' + return x + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/destructured-param-default-bound.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/destructured-param-default-bound.js.snap.encode.js new file mode 100644 index 000000000..8a04144c2 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/destructured-param-default-bound.js.snap.encode.js @@ -0,0 +1,10 @@ +function outer(outerDefault) { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([outerDefault])); +} + +;export async function $$hoist_0_action($$hoist_encoded, { x = outerDefault } = {}) { + const [outerDefault] = __dec($$hoist_encoded); +'use server' + return x + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/destructured-param-default-bound.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/destructured-param-default-bound.js.snap.js new file mode 100644 index 000000000..657698ecd --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/destructured-param-default-bound.js.snap.js @@ -0,0 +1,9 @@ +function outer(outerDefault) { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, outerDefault); +} + +;export async function $$hoist_0_action(outerDefault, { x = outerDefault } = {}) { + 'use server' + return x + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/direct-recursion-self-binding.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/direct-recursion-self-binding.js new file mode 100644 index 000000000..44bc7140f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/direct-recursion-self-binding.js @@ -0,0 +1,12 @@ +// TODO: follow up if this edge case matters. +// The current transform self-binds `action`, which is suspicious enough to +// keep as an intentionally verified TODO fixture for now. +function outer() { + async function action() { + 'use server' + if (false) { + return action() + } + return 0 + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/direct-recursion-self-binding.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/direct-recursion-self-binding.js.snap.encode.js new file mode 100644 index 000000000..ca382bab0 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/direct-recursion-self-binding.js.snap.encode.js @@ -0,0 +1,16 @@ +// TODO: follow up if this edge case matters. +// The current transform self-binds `action`, which is suspicious enough to +// keep as an intentionally verified TODO fixture for now. +function outer() { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([action])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [action] = __dec($$hoist_encoded); +'use server' + if (false) { + return action() + } + return 0 + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/direct-recursion-self-binding.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/direct-recursion-self-binding.js.snap.js new file mode 100644 index 000000000..496266dd4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/direct-recursion-self-binding.js.snap.js @@ -0,0 +1,15 @@ +// TODO: follow up if this edge case matters. +// The current transform self-binds `action`, which is suspicious enough to +// keep as an intentionally verified TODO fixture for now. +function outer() { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, action); +} + +;export async function $$hoist_0_action(action) { + 'use server' + if (false) { + return action() + } + return 0 + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/for-of-iterable-bound.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/for-of-iterable-bound.js new file mode 100644 index 000000000..67387cca6 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/for-of-iterable-bound.js @@ -0,0 +1,8 @@ +function outer(outerList) { + async function action() { + 'use server' + for (const item of outerList) { + process(item) + } + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/for-of-iterable-bound.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/for-of-iterable-bound.js.snap.encode.js new file mode 100644 index 000000000..1fdf42ee7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/for-of-iterable-bound.js.snap.encode.js @@ -0,0 +1,12 @@ +function outer(outerList) { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([outerList])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [outerList] = __dec($$hoist_encoded); +'use server' + for (const item of outerList) { + process(item) + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/for-of-iterable-bound.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/for-of-iterable-bound.js.snap.js new file mode 100644 index 000000000..9de212a4f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/for-of-iterable-bound.js.snap.js @@ -0,0 +1,11 @@ +function outer(outerList) { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, outerList); +} + +;export async function $$hoist_0_action(outerList) { + 'use server' + for (const item of outerList) { + process(item) + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist-block.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist-block.js new file mode 100644 index 000000000..8d5d52057 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist-block.js @@ -0,0 +1,10 @@ +function outer() { + const value = 0 + async function action() { + 'use server' + console.log({ value }) + { + function value() {} + } + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist-block.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist-block.js.snap.encode.js new file mode 100644 index 000000000..437b405bf --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist-block.js.snap.encode.js @@ -0,0 +1,14 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([value])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [value] = __dec($$hoist_encoded); +'use server' + console.log({ value }) + { + function value() {} + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist-block.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist-block.js.snap.js new file mode 100644 index 000000000..bacf64a04 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist-block.js.snap.js @@ -0,0 +1,13 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, value); +} + +;export async function $$hoist_0_action(value) { + 'use server' + console.log({ value }) + { + function value() {} + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist.js new file mode 100644 index 000000000..d33acbdd6 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist.js @@ -0,0 +1,8 @@ +function outer() { + const value = 0 + async function action() { + 'use server' + console.log({ value }) + function value() {} + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist.js.snap.encode.js new file mode 100644 index 000000000..8a133afcd --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist.js.snap.encode.js @@ -0,0 +1,11 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + console.log({ value }) + function value() {} + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist.js.snap.js new file mode 100644 index 000000000..8a133afcd --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/function-hoist.js.snap.js @@ -0,0 +1,11 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + console.log({ value }) + function value() {} + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-callee.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-callee.js.snap.encode.js new file mode 100644 index 000000000..fcd1ec224 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-callee.js.snap.encode.js @@ -0,0 +1,11 @@ +function outer() { + const x = {} + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([{ y: x.y }])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [x] = __dec($$hoist_encoded); +'use server' + return x.y.fn() + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-computed.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-computed.js.snap.encode.js new file mode 100644 index 000000000..38d517469 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-computed.js.snap.encode.js @@ -0,0 +1,12 @@ +function outer() { + const x = {} + const k = 'y' + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([x, k])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [x,k] = __dec($$hoist_encoded); +'use server' + return x[k].z + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-dedupe.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-dedupe.js.snap.encode.js new file mode 100644 index 000000000..b4f6f74db --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-dedupe.js.snap.encode.js @@ -0,0 +1,11 @@ +function outer() { + const x = {} + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([{ y: x.y, w: x.w }])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [x] = __dec($$hoist_encoded); +'use server' + return [x.y.z, x.y, x.w, x.w.v] + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-optional.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-optional.js.snap.encode.js new file mode 100644 index 000000000..629110a07 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-optional.js.snap.encode.js @@ -0,0 +1,23 @@ +function outer() { + const x = {} + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([x])); +} + +function outer2() { + const a = {} + const action = /* #__PURE__ */ $$register($$hoist_1_action, "", "$$hoist_1_action").bind(null, __enc([{ b: a.b }])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [x] = __dec($$hoist_encoded); +'use server' + return x?.y.z + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + +;export async function $$hoist_1_action($$hoist_encoded) { + const [a] = __dec($$hoist_encoded); +'use server' + return a.b?.c + }; +/* #__PURE__ */ Object.defineProperty($$hoist_1_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-proto.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-proto.js.snap.encode.js new file mode 100644 index 000000000..722967536 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-proto.js.snap.encode.js @@ -0,0 +1,11 @@ +function outer() { + const x = {} + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([{ ["__proto__"]: { y: x.__proto__.y }, a: { ["__proto__"]: { b: x.a.__proto__.b } } }])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [x] = __dec($$hoist_encoded); +'use server' + return [x.__proto__.y, x.a.__proto__.b] + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-root.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-root.js.snap.encode.js new file mode 100644 index 000000000..32139085c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-root.js.snap.encode.js @@ -0,0 +1,11 @@ +function outer() { + const x = {} + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([x])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [x] = __dec($$hoist_encoded); +'use server' + return [x.y.z, Object.keys(x)] + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-siblings.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-siblings.js.snap.encode.js new file mode 100644 index 000000000..b0187235a --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-siblings.js.snap.encode.js @@ -0,0 +1,11 @@ +function outer() { + const x = {} + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([{ y: { z: x.y.z, w: x.y.w } }])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [x] = __dec($$hoist_encoded); +'use server' + return [x.y.z, x.y.w] + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-unsupported.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-unsupported.js.snap.encode.js new file mode 100644 index 000000000..bf6a2e1f3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain-unsupported.js.snap.encode.js @@ -0,0 +1,99 @@ +function outer1() { + const x = {} + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([x])); +} + +function outer2() { + const x = {} + const action = /* #__PURE__ */ $$register($$hoist_1_action, "", "$$hoist_1_action").bind(null, __enc([{ y: x.y }])); +} + +function outer3() { + const x = {} + const action = /* #__PURE__ */ $$register($$hoist_2_action, "", "$$hoist_2_action").bind(null, __enc([x])); +} + +function outer4() { + const x = {} + const y = 'y' + const action = /* #__PURE__ */ $$register($$hoist_3_action, "", "$$hoist_3_action").bind(null, __enc([x, y])); +} + +function outer5() { + const x = {} + const k = 'k' + const action = /* #__PURE__ */ $$register($$hoist_4_action, "", "$$hoist_4_action").bind(null, __enc([{ y: x.y }, k])); +} + +function outer6() { + const x = {} + const y = 'y' + const action = /* #__PURE__ */ $$register($$hoist_5_action, "", "$$hoist_5_action").bind(null, __enc([x, y])); +} + +function outer7() { + const a = {} + const action = /* #__PURE__ */ $$register($$hoist_6_action, "", "$$hoist_6_action").bind(null, __enc([{ b: a.b }])); +} + +function outer8() { + const a = {} + const b = 'b' + const action = /* #__PURE__ */ $$register($$hoist_7_action, "", "$$hoist_7_action").bind(null, __enc([a, b])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [x] = __dec($$hoist_encoded); +'use server' + return x?.y.z + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + +;export async function $$hoist_1_action($$hoist_encoded) { + const [x] = __dec($$hoist_encoded); +'use server' + return x.y?.z + }; +/* #__PURE__ */ Object.defineProperty($$hoist_1_action, "name", { value: "action" }); + +;export async function $$hoist_2_action($$hoist_encoded) { + const [x] = __dec($$hoist_encoded); +'use server' + return x?.y?.z + }; +/* #__PURE__ */ Object.defineProperty($$hoist_2_action, "name", { value: "action" }); + +;export async function $$hoist_3_action($$hoist_encoded) { + const [x,y] = __dec($$hoist_encoded); +'use server' + return x[y].z + }; +/* #__PURE__ */ Object.defineProperty($$hoist_3_action, "name", { value: "action" }); + +;export async function $$hoist_4_action($$hoist_encoded) { + const [x,k] = __dec($$hoist_encoded); +'use server' + return x.y[k] + }; +/* #__PURE__ */ Object.defineProperty($$hoist_4_action, "name", { value: "action" }); + +;export async function $$hoist_5_action($$hoist_encoded) { + const [x,y] = __dec($$hoist_encoded); +'use server' + return x[y]?.z + }; +/* #__PURE__ */ Object.defineProperty($$hoist_5_action, "name", { value: "action" }); + +;export async function $$hoist_6_action($$hoist_encoded) { + const [a] = __dec($$hoist_encoded); +'use server' + return a.b?.c + }; +/* #__PURE__ */ Object.defineProperty($$hoist_6_action, "name", { value: "action" }); + +;export async function $$hoist_7_action($$hoist_encoded) { + const [a,b] = __dec($$hoist_encoded); +'use server' + return a[b].c + }; +/* #__PURE__ */ Object.defineProperty($$hoist_7_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain.js.snap.encode.js new file mode 100644 index 000000000..45025b608 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/member-chain.js.snap.encode.js @@ -0,0 +1,11 @@ +function outer() { + const x = {} + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([{ y: { z: x.y.z } }])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [x] = __dec($$hoist_encoded); +'use server' + return x.y.z + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/named-function-expression-self-ref.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/named-function-expression-self-ref.js new file mode 100644 index 000000000..27d2f227d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/named-function-expression-self-ref.js @@ -0,0 +1,8 @@ +// TODO: named function expression self-reference `self` is left dangling in hoisted body +function outer(count) { + const action = async function self(n) { + 'use server' + if (n > 0) return self(n - 1) + return count + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/named-function-expression-self-ref.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/named-function-expression-self-ref.js.snap.encode.js new file mode 100644 index 000000000..cde5076af --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/named-function-expression-self-ref.js.snap.encode.js @@ -0,0 +1,12 @@ +// TODO: named function expression self-reference `self` is left dangling in hoisted body +function outer(count) { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([count])) +} + +;export async function $$hoist_0_action($$hoist_encoded, n) { + const [count] = __dec($$hoist_encoded); +'use server' + if (n > 0) return self(n - 1) + return count + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/named-function-expression-self-ref.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/named-function-expression-self-ref.js.snap.js new file mode 100644 index 000000000..4a3e4e729 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/named-function-expression-self-ref.js.snap.js @@ -0,0 +1,11 @@ +// TODO: named function expression self-reference `self` is left dangling in hoisted body +function outer(count) { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, count) +} + +;export async function $$hoist_0_action(count, n) { + 'use server' + if (n > 0) return self(n - 1) + return count + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/outer-binding-used-in-nested-block.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/outer-binding-used-in-nested-block.js new file mode 100644 index 000000000..5eb91928e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/outer-binding-used-in-nested-block.js @@ -0,0 +1,9 @@ +function outer() { + const value = 0 + async function action() { + 'use server' + if (true) { + return value + } + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/outer-binding-used-in-nested-block.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/outer-binding-used-in-nested-block.js.snap.encode.js new file mode 100644 index 000000000..6534bbf48 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/outer-binding-used-in-nested-block.js.snap.encode.js @@ -0,0 +1,13 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([value])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [value] = __dec($$hoist_encoded); +'use server' + if (true) { + return value + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/outer-binding-used-in-nested-block.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/outer-binding-used-in-nested-block.js.snap.js new file mode 100644 index 000000000..b269a3214 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/outer-binding-used-in-nested-block.js.snap.js @@ -0,0 +1,12 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, value); +} + +;export async function $$hoist_0_action(value) { + 'use server' + if (true) { + return value + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/reexport-import-not-bound.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/reexport-import-not-bound.js new file mode 100644 index 000000000..bf657b194 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/reexport-import-not-bound.js @@ -0,0 +1,9 @@ +export { redirect } from 'react-router/rsc' +import { redirect } from 'react-router/rsc' + +export default () => { + const f = async () => { + 'use server' + throw redirect() + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/reexport-import-not-bound.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/reexport-import-not-bound.js.snap.encode.js new file mode 100644 index 000000000..5c8c83965 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/reexport-import-not-bound.js.snap.encode.js @@ -0,0 +1,12 @@ +export { redirect } from 'react-router/rsc' +import { redirect } from 'react-router/rsc' + +export default () => { + const f = /* #__PURE__ */ $$register($$hoist_0_f, "", "$$hoist_0_f") +} + +;export async function $$hoist_0_f() { + 'use server' + throw redirect() + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_f, "name", { value: "f" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/reexport-import-not-bound.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/reexport-import-not-bound.js.snap.js new file mode 100644 index 000000000..5c8c83965 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/reexport-import-not-bound.js.snap.js @@ -0,0 +1,12 @@ +export { redirect } from 'react-router/rsc' +import { redirect } from 'react-router/rsc' + +export default () => { + const f = /* #__PURE__ */ $$register($$hoist_0_f, "", "$$hoist_0_f") +} + +;export async function $$hoist_0_f() { + 'use server' + throw redirect() + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_f, "name", { value: "f" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-inner-shadow.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-inner-shadow.js new file mode 100644 index 000000000..b9645f189 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-inner-shadow.js @@ -0,0 +1,13 @@ +function Parent() { + const count = 0 + + async function recurse(n) { + 'use server' + const result = (function recurse(m) { + return m > 0 ? recurse(m - 1) : 0 + })(n) + return count + result + } + + return recurse +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-inner-shadow.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-inner-shadow.js.snap.encode.js new file mode 100644 index 000000000..5599b1f86 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-inner-shadow.js.snap.encode.js @@ -0,0 +1,17 @@ +function Parent() { + const count = 0 + + const recurse = /* #__PURE__ */ $$register($$hoist_0_recurse, "", "$$hoist_0_recurse").bind(null, __enc([count])); + + return recurse +} + +;export async function $$hoist_0_recurse($$hoist_encoded, n) { + const [count] = __dec($$hoist_encoded); +'use server' + const result = (function recurse(m) { + return m > 0 ? recurse(m - 1) : 0 + })(n) + return count + result + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_recurse, "name", { value: "recurse" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-inner-shadow.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-inner-shadow.js.snap.js new file mode 100644 index 000000000..cf424225c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-inner-shadow.js.snap.js @@ -0,0 +1,16 @@ +function Parent() { + const count = 0 + + const recurse = /* #__PURE__ */ $$register($$hoist_0_recurse, "", "$$hoist_0_recurse").bind(null, count); + + return recurse +} + +;export async function $$hoist_0_recurse(count, n) { + 'use server' + const result = (function recurse(m) { + return m > 0 ? recurse(m - 1) : 0 + })(n) + return count + result + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_recurse, "name", { value: "recurse" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-nested-function.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-nested-function.js new file mode 100644 index 000000000..853d7498f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-nested-function.js @@ -0,0 +1,12 @@ +// TODO: recursive action bound to itself causes TDZ (`const recurse = $$register(...).bind(null, recurse, ...)`) +function Parent() { + const count = 0 + + async function recurse(n) { + 'use server' + const helper = () => recurse(n - 1) + return count + helper() + } + + return recurse +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-nested-function.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-nested-function.js.snap.encode.js new file mode 100644 index 000000000..224cdbaa2 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-nested-function.js.snap.encode.js @@ -0,0 +1,16 @@ +// TODO: recursive action bound to itself causes TDZ (`const recurse = $$register(...).bind(null, recurse, ...)`) +function Parent() { + const count = 0 + + const recurse = /* #__PURE__ */ $$register($$hoist_0_recurse, "", "$$hoist_0_recurse").bind(null, __enc([recurse, count])); + + return recurse +} + +;export async function $$hoist_0_recurse($$hoist_encoded, n) { + const [recurse,count] = __dec($$hoist_encoded); +'use server' + const helper = () => recurse(n - 1) + return count + helper() + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_recurse, "name", { value: "recurse" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-nested-function.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-nested-function.js.snap.js new file mode 100644 index 000000000..360d8dabe --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/self-ref-nested-function.js.snap.js @@ -0,0 +1,15 @@ +// TODO: recursive action bound to itself causes TDZ (`const recurse = $$register(...).bind(null, recurse, ...)`) +function Parent() { + const count = 0 + + const recurse = /* #__PURE__ */ $$register($$hoist_0_recurse, "", "$$hoist_0_recurse").bind(null, recurse, count); + + return recurse +} + +;export async function $$hoist_0_recurse(recurse, count, n) { + 'use server' + const helper = () => recurse(n - 1) + return count + helper() + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_recurse, "name", { value: "recurse" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-param.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-param.js new file mode 100644 index 000000000..c8a6e9bdc --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-param.js @@ -0,0 +1,9 @@ +function buildAction(cookies) { + async function submitAction(formData) { + 'use server' + const cookies = formData.get('value') + return cookies + } + + return submitAction +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-param.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-param.js.snap.encode.js new file mode 100644 index 000000000..5a56a0e28 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-param.js.snap.encode.js @@ -0,0 +1,12 @@ +function buildAction(cookies) { + const submitAction = /* #__PURE__ */ $$register($$hoist_0_submitAction, "", "$$hoist_0_submitAction"); + + return submitAction +} + +;export async function $$hoist_0_submitAction(formData) { + 'use server' + const cookies = formData.get('value') + return cookies + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_submitAction, "name", { value: "submitAction" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-param.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-param.js.snap.js new file mode 100644 index 000000000..5a56a0e28 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-param.js.snap.js @@ -0,0 +1,12 @@ +function buildAction(cookies) { + const submitAction = /* #__PURE__ */ $$register($$hoist_0_submitAction, "", "$$hoist_0_submitAction"); + + return submitAction +} + +;export async function $$hoist_0_submitAction(formData) { + 'use server' + const cookies = formData.get('value') + return cookies + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_submitAction, "name", { value: "submitAction" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-var.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-var.js new file mode 100644 index 000000000..bd3b27de3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-var.js @@ -0,0 +1,11 @@ +function buildAction(config) { + const cookies = getCookies() + + async function submitAction(formData) { + 'use server' + const cookies = formData.get('value') + return doSomething(config, cookies) + } + + return submitAction +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-var.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-var.js.snap.encode.js new file mode 100644 index 000000000..e1cd516a3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-var.js.snap.encode.js @@ -0,0 +1,15 @@ +function buildAction(config) { + const cookies = getCookies() + + const submitAction = /* #__PURE__ */ $$register($$hoist_0_submitAction, "", "$$hoist_0_submitAction").bind(null, __enc([config])); + + return submitAction +} + +;export async function $$hoist_0_submitAction($$hoist_encoded, formData) { + const [config] = __dec($$hoist_encoded); +'use server' + const cookies = formData.get('value') + return doSomething(config, cookies) + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_submitAction, "name", { value: "submitAction" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-var.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-var.js.snap.js new file mode 100644 index 000000000..60b1e3882 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-const-outer-var.js.snap.js @@ -0,0 +1,14 @@ +function buildAction(config) { + const cookies = getCookies() + + const submitAction = /* #__PURE__ */ $$register($$hoist_0_submitAction, "", "$$hoist_0_submitAction").bind(null, config); + + return submitAction +} + +;export async function $$hoist_0_submitAction(config, formData) { + 'use server' + const cookies = formData.get('value') + return doSomething(config, cookies) + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_submitAction, "name", { value: "submitAction" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-destructured-local.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-destructured-local.js new file mode 100644 index 000000000..4af960931 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-destructured-local.js @@ -0,0 +1,11 @@ +function buildAction(config) { + const cookies = getCookies() + + async function submitAction(formData) { + 'use server' + const { cookies } = parseForm(formData) + return doSomething(config, cookies) + } + + return submitAction +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-destructured-local.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-destructured-local.js.snap.encode.js new file mode 100644 index 000000000..0066032e4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-destructured-local.js.snap.encode.js @@ -0,0 +1,15 @@ +function buildAction(config) { + const cookies = getCookies() + + const submitAction = /* #__PURE__ */ $$register($$hoist_0_submitAction, "", "$$hoist_0_submitAction").bind(null, __enc([config])); + + return submitAction +} + +;export async function $$hoist_0_submitAction($$hoist_encoded, formData) { + const [config] = __dec($$hoist_encoded); +'use server' + const { cookies } = parseForm(formData) + return doSomething(config, cookies) + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_submitAction, "name", { value: "submitAction" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-destructured-local.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-destructured-local.js.snap.js new file mode 100644 index 000000000..f5c27dd3d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-destructured-local.js.snap.js @@ -0,0 +1,14 @@ +function buildAction(config) { + const cookies = getCookies() + + const submitAction = /* #__PURE__ */ $$register($$hoist_0_submitAction, "", "$$hoist_0_submitAction").bind(null, config); + + return submitAction +} + +;export async function $$hoist_0_submitAction(config, formData) { + 'use server' + const { cookies } = parseForm(formData) + return doSomething(config, cookies) + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_submitAction, "name", { value: "submitAction" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-and-if-block-over-outer-local.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-and-if-block-over-outer-local.js new file mode 100644 index 000000000..9a3b0e963 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-and-if-block-over-outer-local.js @@ -0,0 +1,12 @@ +function outer() { + const value = 0 + async function action() { + 'use server' + if (true) { + const value = 0 + return value + } + const value = 0 + return value + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-and-if-block-over-outer-local.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-and-if-block-over-outer-local.js.snap.encode.js new file mode 100644 index 000000000..b49ef17ea --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-and-if-block-over-outer-local.js.snap.encode.js @@ -0,0 +1,15 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + if (true) { + const value = 0 + return value + } + const value = 0 + return value + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-and-if-block-over-outer-local.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-and-if-block-over-outer-local.js.snap.js new file mode 100644 index 000000000..b49ef17ea --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-and-if-block-over-outer-local.js.snap.js @@ -0,0 +1,15 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + if (true) { + const value = 0 + return value + } + const value = 0 + return value + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-over-outer-local.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-over-outer-local.js new file mode 100644 index 000000000..a1ab82945 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-over-outer-local.js @@ -0,0 +1,8 @@ +function outer() { + const value = 0 + async function action() { + 'use server' + const value = 0 + return value + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-over-outer-local.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-over-outer-local.js.snap.encode.js new file mode 100644 index 000000000..1bb8ca657 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-over-outer-local.js.snap.encode.js @@ -0,0 +1,11 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + const value = 0 + return value + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-over-outer-local.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-over-outer-local.js.snap.js new file mode 100644 index 000000000..1bb8ca657 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-body-over-outer-local.js.snap.js @@ -0,0 +1,11 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + const value = 0 + return value + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-global.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-global.js new file mode 100644 index 000000000..dec2967b6 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-global.js @@ -0,0 +1,10 @@ +const value = 0 +function outer() { + async function action() { + 'use server' + if (true) { + const value = 1 + return value + } + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-global.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-global.js.snap.encode.js new file mode 100644 index 000000000..40c4bb213 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-global.js.snap.encode.js @@ -0,0 +1,13 @@ +const value = 0 +function outer() { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + if (true) { + const value = 1 + return value + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-global.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-global.js.snap.js new file mode 100644 index 000000000..40c4bb213 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-global.js.snap.js @@ -0,0 +1,13 @@ +const value = 0 +function outer() { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + if (true) { + const value = 1 + return value + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-and-global.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-and-global.js new file mode 100644 index 000000000..6aca5b304 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-and-global.js @@ -0,0 +1,11 @@ +const value = 0 +function outer() { + const value = 0 + async function action() { + 'use server' + if (true) { + const value = 1 + return value + } + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-and-global.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-and-global.js.snap.encode.js new file mode 100644 index 000000000..1ff577738 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-and-global.js.snap.encode.js @@ -0,0 +1,14 @@ +const value = 0 +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + if (true) { + const value = 1 + return value + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-and-global.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-and-global.js.snap.js new file mode 100644 index 000000000..1ff577738 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-and-global.js.snap.js @@ -0,0 +1,14 @@ +const value = 0 +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + if (true) { + const value = 1 + return value + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-local.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-local.js new file mode 100644 index 000000000..bdf14762f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-local.js @@ -0,0 +1,10 @@ +function outer() { + const value = 0 + async function action() { + 'use server' + if (true) { + const value = 0 + return value + } + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-local.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-local.js.snap.encode.js new file mode 100644 index 000000000..85a5c64c5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-local.js.snap.encode.js @@ -0,0 +1,13 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + if (true) { + const value = 0 + return value + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-local.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-local.js.snap.js new file mode 100644 index 000000000..85a5c64c5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-local-if-block-over-outer-local.js.snap.js @@ -0,0 +1,13 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + if (true) { + const value = 0 + return value + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-global.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-global.js new file mode 100644 index 000000000..c2f923599 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-global.js @@ -0,0 +1,11 @@ +const value = 0 +function outer() { + async function action() { + 'use server' + if (true) { + const value = 1 + return value + } + return value + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-global.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-global.js.snap.encode.js new file mode 100644 index 000000000..0b2077000 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-global.js.snap.encode.js @@ -0,0 +1,14 @@ +const value = 0 +function outer() { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + if (true) { + const value = 1 + return value + } + return value + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-global.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-global.js.snap.js new file mode 100644 index 000000000..0b2077000 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-global.js.snap.js @@ -0,0 +1,14 @@ +const value = 0 +function outer() { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + if (true) { + const value = 1 + return value + } + return value + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-and-global.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-and-global.js new file mode 100644 index 000000000..941f42176 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-and-global.js @@ -0,0 +1,12 @@ +const value = 0 +function outer() { + const value = 0 + async function action() { + 'use server' + if (true) { + const value = 1 + return value + } + return value + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-and-global.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-and-global.js.snap.encode.js new file mode 100644 index 000000000..99edc5dd0 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-and-global.js.snap.encode.js @@ -0,0 +1,16 @@ +const value = 0 +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([value])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [value] = __dec($$hoist_encoded); +'use server' + if (true) { + const value = 1 + return value + } + return value + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-and-global.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-and-global.js.snap.js new file mode 100644 index 000000000..33d23c45c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-and-global.js.snap.js @@ -0,0 +1,15 @@ +const value = 0 +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, value); +} + +;export async function $$hoist_0_action(value) { + 'use server' + if (true) { + const value = 1 + return value + } + return value + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-local.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-local.js new file mode 100644 index 000000000..4a04f1276 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-local.js @@ -0,0 +1,11 @@ +function outer() { + const value = 0 + async function action() { + 'use server' + if (true) { + const value = 1 + return value + } + return value + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-local.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-local.js.snap.encode.js new file mode 100644 index 000000000..425761c80 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-local.js.snap.encode.js @@ -0,0 +1,15 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, __enc([value])); +} + +;export async function $$hoist_0_action($$hoist_encoded) { + const [value] = __dec($$hoist_encoded); +'use server' + if (true) { + const value = 1 + return value + } + return value + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-local.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-local.js.snap.js new file mode 100644 index 000000000..f98c9f642 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-partial-if-block-over-outer-local.js.snap.js @@ -0,0 +1,14 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, value); +} + +;export async function $$hoist_0_action(value) { + 'use server' + if (true) { + const value = 1 + return value + } + return value + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-nested-block.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-nested-block.js new file mode 100644 index 000000000..910fc9d2c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-nested-block.js @@ -0,0 +1,13 @@ +function buildAction(config) { + const cookies = getCookies() + + async function submitAction(formData) { + 'use server' + if (condition) { + var cookies = formData.get('value') + } + return doSomething(config, cookies) + } + + return submitAction +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-nested-block.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-nested-block.js.snap.encode.js new file mode 100644 index 000000000..5600b97f0 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-nested-block.js.snap.encode.js @@ -0,0 +1,17 @@ +function buildAction(config) { + const cookies = getCookies() + + const submitAction = /* #__PURE__ */ $$register($$hoist_0_submitAction, "", "$$hoist_0_submitAction").bind(null, __enc([config])); + + return submitAction +} + +;export async function $$hoist_0_submitAction($$hoist_encoded, formData) { + const [config] = __dec($$hoist_encoded); +'use server' + if (condition) { + var cookies = formData.get('value') + } + return doSomething(config, cookies) + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_submitAction, "name", { value: "submitAction" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-nested-block.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-nested-block.js.snap.js new file mode 100644 index 000000000..a0bd158a1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-nested-block.js.snap.js @@ -0,0 +1,16 @@ +function buildAction(config) { + const cookies = getCookies() + + const submitAction = /* #__PURE__ */ $$register($$hoist_0_submitAction, "", "$$hoist_0_submitAction").bind(null, config); + + return submitAction +} + +;export async function $$hoist_0_submitAction(config, formData) { + 'use server' + if (condition) { + var cookies = formData.get('value') + } + return doSomething(config, cookies) + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_submitAction, "name", { value: "submitAction" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-top-body.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-top-body.js new file mode 100644 index 000000000..70d2a57c1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-top-body.js @@ -0,0 +1,11 @@ +function buildAction(config) { + const cookies = getCookies() + + async function submitAction(formData) { + 'use server' + var cookies = formData.get('value') + return doSomething(config, cookies) + } + + return submitAction +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-top-body.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-top-body.js.snap.encode.js new file mode 100644 index 000000000..620e2d3ba --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-top-body.js.snap.encode.js @@ -0,0 +1,15 @@ +function buildAction(config) { + const cookies = getCookies() + + const submitAction = /* #__PURE__ */ $$register($$hoist_0_submitAction, "", "$$hoist_0_submitAction").bind(null, __enc([config])); + + return submitAction +} + +;export async function $$hoist_0_submitAction($$hoist_encoded, formData) { + const [config] = __dec($$hoist_encoded); +'use server' + var cookies = formData.get('value') + return doSomething(config, cookies) + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_submitAction, "name", { value: "submitAction" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-top-body.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-top-body.js.snap.js new file mode 100644 index 000000000..378dc4405 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/shadow-var-top-body.js.snap.js @@ -0,0 +1,14 @@ +function buildAction(config) { + const cookies = getCookies() + + const submitAction = /* #__PURE__ */ $$register($$hoist_0_submitAction, "", "$$hoist_0_submitAction").bind(null, config); + + return submitAction +} + +;export async function $$hoist_0_submitAction(config, formData) { + 'use server' + var cookies = formData.get('value') + return doSomething(config, cookies) + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_submitAction, "name", { value: "submitAction" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist-block.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist-block.js new file mode 100644 index 000000000..f41698bfd --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist-block.js @@ -0,0 +1,10 @@ +function outer() { + const value = 0 + async function action() { + 'use server' + console.log({ value }) + { + var value = 1 + } + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist-block.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist-block.js.snap.encode.js new file mode 100644 index 000000000..35a91af0b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist-block.js.snap.encode.js @@ -0,0 +1,13 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + console.log({ value }) + { + var value = 1 + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist-block.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist-block.js.snap.js new file mode 100644 index 000000000..35a91af0b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist-block.js.snap.js @@ -0,0 +1,13 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + console.log({ value }) + { + var value = 1 + } + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist.js new file mode 100644 index 000000000..7eef631e7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist.js @@ -0,0 +1,8 @@ +function outer() { + const value = 0 + async function action() { + 'use server' + console.log({ value }) + var value = 1 + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist.js.snap.encode.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist.js.snap.encode.js new file mode 100644 index 000000000..66c9170ce --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist.js.snap.encode.js @@ -0,0 +1,11 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + console.log({ value }) + var value = 1 + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist.js.snap.js b/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist.js.snap.js new file mode 100644 index 000000000..66c9170ce --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/hoist/var-hoist.js.snap.js @@ -0,0 +1,11 @@ +function outer() { + const value = 0 + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); +} + +;export async function $$hoist_0_action() { + 'use server' + console.log({ value }) + var value = 1 + }; +/* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); diff --git a/packages/plugin-rsc/src/transforms/hoist.test.ts b/packages/plugin-rsc/src/transforms/hoist.test.ts index d6b9b642c..3dde6bc91 100644 --- a/packages/plugin-rsc/src/transforms/hoist.test.ts +++ b/packages/plugin-rsc/src/transforms/hoist.test.ts @@ -6,24 +6,42 @@ import { debugSourceMap } from './test-utils' describe('fixtures', () => { const fixtures = import.meta.glob( - ['./fixtures/hoist/**/*.js', '!**/*.snap.js'], + ['./fixtures/hoist/**/*.js', '!**/*.snap.*'], { query: 'raw', }, ) + + async function transformFixture( + input: string, + options?: { encode?: boolean }, + ) { + const ast = await parseAstAsync(input) + const { output } = transformHoistInlineDirective(input, ast, { + directive: 'use server', + runtime: (value, name) => + `$$register(${value}, "", ${JSON.stringify(name)})`, + encode: options?.encode ? (v) => `__enc(${v})` : undefined, + decode: options?.encode ? (v) => `__dec(${v})` : undefined, + }) + if (!output.hasChanged()) { + return '/* NO CHANGE */' + } + const transformed = output.toString() + // verify transform produces valid js + await parseAstAsync(transformed) + return transformed + } + for (const [file, mod] of Object.entries(fixtures)) { it(path.basename(file), async () => { const input = ((await mod()) as any).default as string - const ast = await parseAstAsync(input) - const result = transformHoistInlineDirective(input, ast, { - runtime: (value, name) => - `$$register(${value}, "", ${JSON.stringify(name)})`, - directive: 'use server', - }) - const snapshot = result.output.hasChanged() - ? result.output.toString() - : '/* NO CHANGE */' - await expect(snapshot).toMatchFileSnapshot(file + '.snap.js') + await expect + .soft(await transformFixture(input)) + .toMatchFileSnapshot(file + '.snap.js') + await expect + .soft(await transformFixture(input, { encode: true })) + .toMatchFileSnapshot(file + '.snap.encode.js') }) } }) @@ -57,7 +75,9 @@ describe(transformHoistInlineDirective, () => { if (process.env['DEBUG_SOURCEMAP']) { await debugSourceMap(output) } - return output.toString() + const transformed = output.toString() + await parseAstAsync(transformed) + return transformed } async function testTransformNames(input: string) { @@ -488,546 +508,4 @@ export async function test() { " `) }) - - // ok: should not bind - it('shadowing local if over local', async () => { - const input = `\ -function outer() { - const value = 0; - async function action() { - "use server"; - if (true) { - const value = 0; - return value; - } - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "function outer() { - const value = 0; - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); - } - - ;export async function $$hoist_0_action() { - "use server"; - if (true) { - const value = 0; - return value; - } - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - // ok: should not bind - it('shadowing local body over local', async () => { - const input = `\ -function outer() { - const value = 0; - async function action() { - "use server"; - const value = 0; - return value; - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "function outer() { - const value = 0; - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); - } - - ;export async function $$hoist_0_action() { - "use server"; - const value = 0; - return value; - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - // ok: should not bind - it('shadowing local body and if over local', async () => { - const input = `\ -function outer() { - const value = 0; - async function action() { - "use server"; - if (true) { - const value = 0; - return value; - } - const value = 0; - return value; - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "function outer() { - const value = 0; - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); - } - - ;export async function $$hoist_0_action() { - "use server"; - if (true) { - const value = 0; - return value; - } - const value = 0; - return value; - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - // ok: should bind - it('shadowing partial local over local', async () => { - const input = `\ -function outer() { - const value = 0; - async function action() { - "use server"; - if (true) { - const value = 1; - return value; - } - return value; - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "function outer() { - const value = 0; - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, value); - } - - ;export async function $$hoist_0_action(value) { - "use server"; - if (true) { - const value = 1; - return value; - } - return value; - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - // ok: should not bind - it('shadowing local over global', async () => { - const input = `\ -const value = 0; -function outer() { - async function action() { - "use server"; - if (true) { - const value = 1; - return value; - } - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "const value = 0; - function outer() { - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); - } - - ;export async function $$hoist_0_action() { - "use server"; - if (true) { - const value = 1; - return value; - } - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - // ok: should not bind - it('shadowing partial local over global', async () => { - const input = `\ -const value = 0; -function outer() { - async function action() { - "use server"; - if (true) { - const value = 1; - return value; - } - return value; - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "const value = 0; - function outer() { - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); - } - - ;export async function $$hoist_0_action() { - "use server"; - if (true) { - const value = 1; - return value; - } - return value; - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - // ok: should not bind - it('shadowing local over local over global', async () => { - const input = `\ -const value = 0; -function outer() { - const value = 0; - async function action() { - "use server"; - if (true) { - const value = 1; - return value; - } - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "const value = 0; - function outer() { - const value = 0; - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); - } - - ;export async function $$hoist_0_action() { - "use server"; - if (true) { - const value = 1; - return value; - } - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - // ok: should bind - it('shadowing partial local over local over global', async () => { - const input = `\ -const value = 0; -function outer() { - const value = 0; - async function action() { - "use server"; - if (true) { - const value = 1; - return value; - } - return value; - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "const value = 0; - function outer() { - const value = 0; - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, value); - } - - ;export async function $$hoist_0_action(value) { - "use server"; - if (true) { - const value = 1; - return value; - } - return value; - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - it('deeper', async () => { - const input = `\ -function outer() { - const value = 0; - async function action() { - "use server"; - if (true) { - return value; - } - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "function outer() { - const value = 0; - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, value); - } - - ;export async function $$hoist_0_action(value) { - "use server"; - if (true) { - return value; - } - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - it('var hoisting', async () => { - const input = `\ -function outer() { - const value = 0; - async function action() { - "use server"; - console.log({ value }) - var value = 1; - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "function outer() { - const value = 0; - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); - } - - ;export async function $$hoist_0_action() { - "use server"; - console.log({ value }) - var value = 1; - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - it('var hoisting block', async () => { - const input = `\ -function outer() { - const value = 0; - async function action() { - "use server"; - console.log({ value }) - { - var value = 1; - } - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "function outer() { - const value = 0; - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); - } - - ;export async function $$hoist_0_action() { - "use server"; - console.log({ value }) - { - var value = 1; - } - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - it('function hoisting', async () => { - const input = `\ -function outer() { - const value = 0; - async function action() { - "use server"; - console.log({ value }) - function value() {} - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "function outer() { - const value = 0; - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); - } - - ;export async function $$hoist_0_action() { - "use server"; - console.log({ value }) - function value() {} - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - it('function hoisting block', async () => { - const input = `\ -function outer() { - const value = 0; - async function action() { - "use server"; - console.log({ value }) - { - function value() {} - } - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "function outer() { - const value = 0; - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, value); - } - - ;export async function $$hoist_0_action(value) { - "use server"; - console.log({ value }) - { - function value() {} - } - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - // TODO: follow up if this edge case matters. - // Next.js's closure-collection logic suggests recursive self-reference is also - // treated as a captured outer name, but we didn't find a direct fixture proving the - // final emitted shape. Our current output self-binds `action`, which is suspicious - // enough to leave as an intentionally-unverified edge case. - it('recursion', async () => { - const input = `\ -function outer() { - async function action() { - "use server"; - if (false) { - return action(); - } - return 0; - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "function outer() { - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, action); - } - - ;export async function $$hoist_0_action(action) { - "use server"; - if (false) { - return action(); - } - return 0; - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - it('computed destructuring key in body', async () => { - const input = `\ -function outer() { - const key = 'value' - async function action(data) { - "use server"; - const { [key]: val } = data - return val - } -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - "function outer() { - const key = 'value' - const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, key); - } - - ;export async function $$hoist_0_action(key, data) { - "use server"; - const { [key]: val } = data - return val - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); - " - `) - }) - - // Edge case: writing to a captured local only mutates the hoisted action's bound - // parameter copy, not the original outer binding. Next.js appears to have the same - // effective behavior, although via `$$ACTION_ARG_n` rewriting instead of plain params. - it('assignment', async () => { - const input = ` -function Counter() { - let local = 0; - - async function updateLocal() { - "use server"; - local = 1; - } - - return "something"; -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - " - function Counter() { - let local = 0; - - const updateLocal = /* #__PURE__ */ $$register($$hoist_0_updateLocal, "", "$$hoist_0_updateLocal").bind(null, local); - - return "something"; - } - - ;export async function $$hoist_0_updateLocal(local) { - "use server"; - local = 1; - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_updateLocal, "name", { value: "updateLocal" }); - " - `) - }) - - // Same framing as plain assignment above: mutating a captured local is local to the - // hoisted invocation copy. This is probably an unintended edge case rather than a - // behavior worth matching exactly. - it('increment', async () => { - const input = ` -function Counter() { - let local = 0; - - async function updateLocal() { - "use server"; - local++; - } - - return "something"; -} -` - expect(await testTransform(input)).toMatchInlineSnapshot(` - " - function Counter() { - let local = 0; - - const updateLocal = /* #__PURE__ */ $$register($$hoist_0_updateLocal, "", "$$hoist_0_updateLocal").bind(null, local); - - return "something"; - } - - ;export async function $$hoist_0_updateLocal(local) { - "use server"; - local++; - }; - /* #__PURE__ */ Object.defineProperty($$hoist_0_updateLocal, "name", { value: "updateLocal" }); - " - `) - }) })