Skip to content

Conversation

@TooTallNate
Copy link
Member

@TooTallNate TooTallNate commented Nov 25, 2025

Added support for nested "use step" declarations in non-workflow functions.

What changed?

This PR enhances the SWC plugin to properly handle "use step" declarations that appear inside regular functions, not just workflow functions. The implementation:

  • Tracks parent function names for all functions, not just workflow functions
  • Properly hoists nested step functions from any parent function context
  • Maintains correct variable references when hoisting
  • Preserves the step functions in client mode by just removing the directive
  • Adds comprehensive test cases for various nested step function scenarios

How to test?

Test by creating nested step functions inside regular functions:

function regularFunction(a, b) {
  // This now works properly
  async function nestedStep() {
    'use step';
    return a + b;
  }
  return nestedStep();
}

// Also works with arrow functions and return statements
function returnStepFunction(x) {
  return async () => {
    'use step';
    return x * 2;
  };
}

Verify that these functions are properly hoisted and transformed in step mode, and that they work correctly in workflow and client modes.

Why make this change?

Previously, "use step" declarations were only properly handled when they appeared at the module level or inside workflow functions. This limitation prevented developers from creating utility functions that return or contain step functions. This change enables more flexible code organization patterns, allowing step functions to be created and returned from any function context.

@changeset-bot
Copy link

changeset-bot bot commented Nov 25, 2025

🦋 Changeset detected

Latest commit: bef8c1c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@workflow/swc-plugin Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/sveltekit Patch
workflow Patch
@workflow/world-testing Patch
@workflow/nuxt Patch
@workflow/ai Patch

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

@vercel
Copy link
Contributor

vercel bot commented Nov 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview Comment Nov 26, 2025 1:35am
example-nextjs-workflow-webpack Ready Ready Preview Comment Nov 26, 2025 1:35am
example-workflow Ready Ready Preview Comment Nov 26, 2025 1:35am
workbench-express-workflow Ready Ready Preview Comment Nov 26, 2025 1:35am
workbench-fastify-workflow Error Error Nov 26, 2025 1:35am
workbench-hono-workflow Ready Ready Preview Comment Nov 26, 2025 1:35am
workbench-nitro-workflow Ready Ready Preview Comment Nov 26, 2025 1:35am
workbench-nuxt-workflow Ready Ready Preview Comment Nov 26, 2025 1:35am
workbench-sveltekit-workflow Ready Ready Preview Comment Nov 26, 2025 1:35am
workbench-vite-workflow Ready Ready Preview Comment Nov 26, 2025 1:35am
workflow-docs Ready Ready Preview Comment Nov 26, 2025 1:35am

Copy link
Member Author

TooTallNate commented Nov 25, 2025

@TooTallNate TooTallNate merged commit 0cacb99 into main Nov 27, 2025
54 of 57 checks passed
@TooTallNate TooTallNate deleted the 11-25-support_nested_use_step_declarations_in_non-workflow_functions branch November 27, 2025 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants