Repository navigation
Backport #5503: [swc-plugin] Compile a "use step" function expression bound to a variable inside a function as a nested step - #5509
Merged
Conversation
…able inside a function as a nested step (#5503) A `"use step"` function expression bound to a variable inside a workflow (or any other function) was compiled as a module-level step, so the run failed when it reached it: ```ts export async function receiptWorkflow(n: number, label: string) { 'use workflow'; const send = async function () { 'use step'; return `${label}:${n}`; }; return send(); // Step "step//./workflows/receipt//send" is not registered } ``` The arrow form (`const send = async () => { 'use step'; ... }`) and a function declaration already worked. **Cause:** in `visit_mut_var_decl`, the `Expr::Fn` step branch had no nested-scope check, unlike the `Expr::Arrow` branch next to it. As a result: - step mode emitted a registration for a binding that doesn't exist at module scope, so nothing was registered; - workflow mode called the un-namespaced step ID (`…//send`) without a closure-variable getter. **Fix:** inside a function, this branch now takes the same path as the arrow form. The step is hoisted and namespaced by the enclosing function (`receiptWorkflow/send`), it gets the variables it captures, and the original function is kept with the directive stripped for direct calls. A step bound to a variable takes the variable's name, as it already did at module scope and for arrows. Module-level function expressions are unchanged. - **New fixture** (`nested-step-function-expression`): named and anonymous function expressions inside a workflow, one inside a plain helper function, and a module-level control. The step and workflow outputs agree on every step ID, which `step_id_consistency` checks. All 421 Rust tests pass, and existing fixture outputs are unchanged. - **Runtime:** the vitest workbench runs a workflow with a named and an anonymous function-expression step, both capturing workflow variables. On the previous plugin build it fails with `Step "step//./workflows/nested-step-ids//named" is not registered`; with this change it passes. The full vitest workbench passes (77 tests, plus one marked as an expected failure). - **Spec:** `spec.md` lists the nested-step forms and how each is named. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com> Co-authored-by: Pranay Prakash <1797812+pranaygp@users.noreply.github.com> Signed-off-by: Pranay Prakash <pranay.gp@gmail.com>
🦋 Changeset detectedLatest commit: 37665b8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
TooTallNate
approved these changes
Nov 17, 2026
TooTallNate
enabled auto-merge (squash)
November 17, 2026 18:24
Contributor
Author
🧪 E2E Test Results❌ Some tests failed Summary
❌ Failed Tests🌍 Community Worlds (106 failed)redis (20 failed):
turso (86 failed):
Details by Category✅ ▲ Vercel Production
✅ 💻 Local Development
✅ 📦 Local Production
✅ 🐘 Local Postgres
✅ 🪟 Windows
❌ 🌍 Community Worlds
✅ 📋 Other
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Automated backport of #5503 to
stable(backport job run).AI recommendation: This fixes a bug in a feature
stablealready has. A"use step"function expression bound to a variable inside a workflow is compiled as a module-level step, so the run fails with "Step ... is not registered". The same un-scopedExpr::Fnbranch invisit_mut_var_declexists onstable, which already supports nested arrow steps and closure variables. The plugin code onstablehas diverged frommain(different helper signatures and aClientmode), so expect the cherry-pick to conflict and review it carefully.Merge conflicts were resolved by AI (opencode with
anthropic/claude-opus-5.5). Please review the conflict resolution carefully before merging.