Skip to content

Backport #3971: fix(swc-plugin): register class expressions via an IIFE instead of by name - #4013

Merged
TooTallNate merged 1 commit into
stablefrom
backport/pr-3971-to-stable
Sep 8, 2026
Merged

TooTallNate merged 1 commit into
stablefrom
backport/pr-3971-to-stable

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Automated backport of #3971 to stable (backport job run).

AI recommendation: This is a correctness fix to code generation that exists on stable (packages/swc-plugin-workflow is fully present there): class expressions were registered by module-level statements referencing a name that may not be in scope, emitting a guaranteed ReferenceError (AnonymousClass is not defined) and, in multi-declarator cases, registering one class's steps under another class's name. The changeset is a patch and the change is scoped to the plugin's emitted registration code plus fixtures/spec; the only behavior addition (a compile error for classes declared inside functions) replaces output that could only ever throw at module evaluation. Reviewers should note it is a sizable codegen refactor, so the 133 fixtures/24 error cases are the thing to verify on stable.

Merge conflicts were resolved by AI (opencode with anthropic/claude-opus-5). Please review the conflict resolution carefully before merging.

… name (#3971)

* fix(swc-plugin): register class expressions via an IIFE and reject unnameable classes

Class expressions with "use step" methods or custom serialization were
registered by module-level statements referencing the class by name. When no
module-scope binding could be resolved the plugin fell back to a placeholder
`AnonymousClass` identifier, which is a guaranteed ReferenceError at module
evaluation (#3929). Other shapes were silently wrong as well:
`var A = class {}, B = class {}` registered A's steps under B, `X = class {}`
assignments and classes nested inside functions emitted unresolvable
references.

Class expressions are now wrapped in a single IIFE that receives the class,
performs every registration recorded for it, and returns it, so the
registration no longer depends on a name being in scope. The class name is
still needed for step/class IDs and is derived from the assigned variable,
the class's own identifier, or the property key it is assigned to
(`exports.Foo = class {}`, `{ Foo: class {} }`). When none is available, or
the class is declared inside a function, the plugin emits a compile error
instead of broken code.

Class declarations keep their existing module-level output; the emitters
were factored so both paths share the same statement builders.

* fix(swc-plugin): generate names for anonymous class expressions instead of erroring

With registration happening inside the IIFE, an anonymous class expression
in a position that provides no name (`foo(class { ... })`, an array element,
a conditional branch) only needs a name for its step/class IDs. Generate a
deterministic `AnonymousClass<N>`, counting only anonymous classes that have
something to register, instead of rejecting them. Classes declared inside a
function remain an error.

Dead-code elimination now keeps module-level declarations whose initializer
contains a wrapped class expression: evaluating the initializer is what
registers the class, and the binding may be otherwise unreferenced.

Signed-off-by: Nathan Rajlich <n@n8.io>
@changeset-bot

changeset-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 630795b

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

This PR includes changesets to release 17 packages
Name Type
@workflow/swc-plugin Patch
@workflow/astro Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/nest Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
workflow Patch
@workflow/vite Patch
@workflow/vitest Patch
@workflow/world-testing Patch
@workflow/nuxt Patch
@workflow/core Patch
@workflow/web-shared Patch
@workflow/web 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

vercel Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
example-nextjs-workflow-turbopack Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
example-nextjs-workflow-webpack Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
example-workflow Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
workbench-astro-workflow Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
workbench-express-workflow Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
workbench-fastify-workflow Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
workbench-hono-workflow Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
workbench-nestjs-workflow Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
workbench-nitro-workflow Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
workbench-nuxt-workflow Building Building Preview, v0 Sep 8, 2026 5:40pm UTC
workbench-python-workflow Error Error v0 Sep 8, 2026 5:40pm UTC
workbench-sveltekit-workflow Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
workbench-tanstack-start-workflow Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
workbench-vite-workflow Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
workflow-docs Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
workflow-swc-playground Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
workflow-tarballs Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC
workflow-web Ready Ready Preview, v0 Sep 8, 2026 5:40pm UTC

@TooTallNate
TooTallNate enabled auto-merge (squash) September 8, 2026 17:57
@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor Author

🧪 E2E Test Results

❌ Some tests failed

Summary

Passed Failed Skipped Total
✅ ▲ Vercel Production 1099 0 78 1177
✅ 💻 Local Development 1198 0 86 1284
✅ 📦 Local Production 1198 0 86 1284
✅ 🐘 Local Postgres 1198 0 86 1284
✅ 🪟 Windows 107 0 0 107
❌ 🌍 Community Worlds 82 106 9 197
✅ 📋 Other 606 0 36 642
Total 5488 106 381 5975

❌ Failed Tests

🌍 Community Worlds (106 failed)

redis (21 failed):

  • hookWorkflow | wrun_01M212TZY2GQNRM3PJVY1VCHDB
  • hookWorkflow is not resumable via public webhook endpoint | wrun_01M212V9RJBMK9ZVG71BAEW2NY
  • parallelStepsThenWebhookWorkflow - no hook_conflict from same-tick replay race | wrun_01M212VP99YQYCR0HJPNZE3E6R
  • sleepingWorkflow | wrun_01M212WNZK1Q5X5RW526W82PDT
  • outputStreamWorkflow negative startIndex (reads from end)
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns correct index after stream completes
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns -1 before any chunks are written
  • outputStreamWorkflow - getTailIndex and getStreamChunks getStreamChunks returns same content as reading the stream
  • error handling serialization failures step-argument serialization failure is catchable in workflow code
  • error handling serialization failures uncaught step-argument serialization failure fails the run as USER_ERROR without redelivery retries
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01M2134ZZTQ8QKQ4B3V0YWA3XK
  • hookGetConflictWorkflow - awaiting hook.getConflict() registers hook without payload | wrun_01M2135CYPS1RZ3YR0S0WEY3AQ
  • hookGetConflictThenStepParallelWorkflow - hook.getConflict() continuation step runs alongside other steps | wrun_01M2135MR4CQH1P0EWTZ7MSKS0
  • hookGetConflictWorkflow - hook.getConflict() resolves with the conflicting run when token is already registered | wrun_01M21362Y49YBV3G5VPGJEG9M2
  • hookClaimOnlyMutexWorkflow - hook works as a pure run mutex without payload data | wrun_01M2136YR0E03609B6X8PFX7K6
  • hookAdoptOwnerResultWorkflow - duplicate adopts the owner result via conflict.returnValue | wrun_01M21373ZVSRJE94KKG4HGJJHC
  • hookSignalOwnerWorkflow - duplicate forwards its payload to the owner via resumeHook | wrun_01M2137D4E97GYMRTWS40JYF40
  • hookSupersedeOwnerWorkflow - duplicate cancels the owner and claims the released token | wrun_01M2137JJX07HTGF47FNEFD1P6
  • resume-or-start route pattern - resumeHook retried after start() reaches the new run | wrun_01M2137W53PP3JC9VPDRKWJF9Q
  • pages router sleepingWorkflow via pages router
  • resilient start: addTenWorkflow completes when run_created returns 500 | wrun_01M213DRQ3MMYWRP6Z10NAGPAN

turso (85 failed):

  • addTenWorkflow | wrun_01M212T1J5VEYE78ASK2GMR267
  • addTenWorkflow | wrun_01M212T1J5VEYE78ASK2GMR267
  • deploymentId: 'latest' is a no-op in non-Vercel worlds
  • wellKnownAgentWorkflow (.well-known/agent) | wrun_01M212TMX0D9PG7M1KHE922RHP
  • should work with react rendering in step
  • promiseAllWorkflow | wrun_01M212T8V0BFCFX5EWJY30Z087
  • promiseRaceWorkflow | wrun_01M212TDQNZY6254CKRW27JE0V
  • promiseAnyWorkflow | wrun_01M212TG4RWHJ7M9HYEY45KDB6
  • importedStepOnlyWorkflow | wrun_01M212V03AQS611N2MSJ0QR9R9
  • readableStreamWorkflow | wrun_01M212TK9F6CBMSSA840SMGA53
  • hookWorkflow | wrun_01M212TZY2GQNRM3PJVY1VCHDB
  • hookWorkflow is not resumable via public webhook endpoint | wrun_01M212V9RJBMK9ZVG71BAEW2NY
  • webhookWorkflow | wrun_01M212VFC5N570E6XS4F682FC6
  • parallelStepsThenWebhookWorkflow - no hook_conflict from same-tick replay race | wrun_01M212VP99YQYCR0HJPNZE3E6R
  • sleepingWorkflow | wrun_01M212WNZK1Q5X5RW526W82PDT
  • parallelSleepWorkflow | wrun_01M212X5QM5KJBED7V1N6AX4RH
  • sleepWinsRaceWorkflow | wrun_01M212X9DG50KWBDMKD2JSHQS3
  • stepWinsRaceWorkflow | wrun_01M212XD117AKVBWTTSZVAJ54W
  • nullByteWorkflow | wrun_01M212XGNCGAZYRN3NKT1QV1FD
  • workflowAndStepMetadataWorkflow | wrun_01M212XJYFRVR6QBC450ZMMB1F
  • outputStreamWorkflow no startIndex (reads all chunks)
  • outputStreamWorkflow positive startIndex (skips first chunk)
  • outputStreamWorkflow negative startIndex (reads from end)
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns correct index after stream completes
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns -1 before any chunks are written
  • outputStreamWorkflow - getTailIndex and getStreamChunks getStreamChunks returns same content as reading the stream
  • outputStreamInsideStepWorkflow - getWritable() called inside step functions | wrun_01M212ZW898MV54K1K5VAE90GP
  • writableForwardedFromWorkflowWorkflow | wrun_01M21308S1N86YGS9RE657D8G0
  • writableForwardedFromStepWorkflow | wrun_01M2130C5D33AN0V64EKMH8ZJM
  • fetchWorkflow | wrun_01M2130EPAX849TDJC3Z5JJGD5
  • promiseRaceStressTestWorkflow | wrun_01M2130J6GF4CPDHF5KRV0GJZC
  • error handling error propagation workflow errors nested function calls preserve message and stack trace
  • error handling error propagation workflow errors cross-file imports preserve message and stack trace
  • error handling error propagation step errors basic step error preserves message and stack trace
  • error handling error propagation step errors cross-file step error preserves message and function names in stack
  • error handling retry behavior regular Error retries until success
  • error handling retry behavior FatalError fails immediately without retries
  • error handling retry behavior RetryableError respects custom retryAfter delay
  • error handling retry behavior maxRetries=0 disables retries
  • error handling catchability FatalError can be caught and detected with FatalError.is()
  • error handling serialization failures step-argument serialization failure is catchable in workflow code
  • error handling serialization failures uncaught step-argument serialization failure fails the run as USER_ERROR without redelivery retries
  • error handling not registered WorkflowNotRegisteredError fails the run when workflow does not exist
  • error handling not registered StepNotRegisteredError fails the step but workflow can catch it
  • error handling not registered StepNotRegisteredError fails the run when not caught in workflow
  • hookCleanupTestWorkflow - hook token reuse after workflow completion | wrun_01M2134JMPN629DV7N9ETWW62Q
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01M2134ZZTQ8QKQ4B3V0YWA3XK
  • hookGetConflictWorkflow - awaiting hook.getConflict() registers hook without payload | wrun_01M2135CYPS1RZ3YR0S0WEY3AQ
  • 'hookGetConflictWithPriorStepWorkflow' - hook.getConflict() does not block step execution | wrun_01M2135FJNSZ9BQJ74FM7EWRD9
  • 'hookGetConflictWithParallelStepWorkfl…' - hook.getConflict() does not block step execution | wrun_01M2135J4YXKZXNF1XQDTD6TJB
  • hookGetConflictThenStepParallelWorkflow - hook.getConflict() continuation step runs alongside other steps | wrun_01M2135MR4CQH1P0EWTZ7MSKS0
  • hookGetConflictWorkflow - hook.getConflict() resolves with the conflicting run when token is already registered | wrun_01M21362Y49YBV3G5VPGJEG9M2
  • hookClaimOnlyMutexWorkflow - hook works as a pure run mutex without payload data | wrun_01M2136YR0E03609B6X8PFX7K6
  • hookAdoptOwnerResultWorkflow - duplicate adopts the owner result via conflict.returnValue | wrun_01M21373ZVSRJE94KKG4HGJJHC
  • hookSignalOwnerWorkflow - duplicate forwards its payload to the owner via resumeHook | wrun_01M2137D4E97GYMRTWS40JYF40
  • hookSupersedeOwnerWorkflow - duplicate cancels the owner and claims the released token | wrun_01M2137JJX07HTGF47FNEFD1P6
  • resume-or-start route pattern - resumeHook retried after start() reaches the new run | wrun_01M2137W53PP3JC9VPDRKWJF9Q
  • hookDisposeTestWorkflow - hook token reuse after explicit disposal while workflow still running | wrun_01M21383TGGTW8Z0QY1Y41BHFP
  • stepFunctionPassingWorkflow - step function references can be passed as arguments (without closure vars) | wrun_01M2138M6BXHG299J3D0NSSCWN
  • stepFunctionWithClosureWorkflow - step function with closure variables passed as argument | wrun_01M2138YG13CG9D0WHEMH765R0
  • closureVariableWorkflow - nested step functions with closure variables | wrun_01M213958N0H5FXSX6M2HB14Q6
  • spawnWorkflowFromStepWorkflow - spawning a child workflow using start() inside a step | wrun_01M21397KMNTBEQTE5520G9QA2
  • health check (queue-based) - workflow and step endpoints respond to health check messages
  • health check (CLI) - workflow health command reports healthy endpoints
  • pathsAliasWorkflow - TypeScript path aliases resolve correctly | wrun_01M2139QDD910AD8P7K1QW8CQS
  • Calculator.calculate - static workflow method using static step methods from another class | wrun_01M2139XKG1KEEJ9GQCZ82C0T9
  • AllInOneService.processNumber - static workflow method using sibling static step methods | wrun_01M213A5154KKW7AF3QKPYEX7W
  • ChainableService.processWithThis - static step methods using this to reference the class | wrun_01M213AC86CB1VGZN5F01GFHWM
  • thisSerializationWorkflow - step function invoked with .call() and .apply() | wrun_01M213AJAB101GV0HERNMW3DN4
  • customSerializationWorkflow - custom class serialization with WORKFLOW_SERIALIZE/WORKFLOW_DESERIALIZE | wrun_01M213ASJ3SS118ZD1V8R5218Y
  • instanceMethodStepWorkflow - instance methods with "use step" directive | wrun_01M213B12ERJC33VB0HQG6XYXK
  • crossContextSerdeWorkflow - classes defined in step code are deserializable in workflow context | wrun_01M213BD58H3X5RM58RBWZQJCE
  • stepFunctionAsStartArgWorkflow - step function reference passed as start() argument | wrun_01M213BNNZHTRX4RD03P5Q2KMC
  • cancelRun - cancelling a running workflow | wrun_01M213BX22DJJY4661S3RYENJF
  • cancelRun via CLI - cancelling a running workflow | wrun_01M213C26V6Q651KG0CTT00T86
  • pages router addTenWorkflow via pages router
  • pages router promiseAllWorkflow via pages router
  • pages router sleepingWorkflow via pages router
  • hookWithSleepWorkflow - hook payloads delivered correctly with concurrent sleep | wrun_01M213CA6EKAF8HQPG7GBHT2FH
  • hookWithSleepFinalStepWorkflow - step only on final payload | wrun_01M213CPV561SDYSQYCTQGN3PY
  • sleepInLoopWorkflow - sleep inside loop with steps actually delays each iteration | wrun_01M213D0A605NGCS5M3B7X197T
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control) | wrun_01M213DB3KNKMREECHCWZ75BSK
  • importMetaUrlWorkflow - import.meta.url is available in step bundles | wrun_01M213DKZ0KN1XP23EQBCDWZYD
  • metadataFromHelperWorkflow - getWorkflowMetadata/getStepMetadata work from module-level helper (#1577) | wrun_01M213DPBWPD0TAVV1GGPS79VK
  • resilient start: addTenWorkflow completes when run_created returns 500 | wrun_01M213DRQ3MMYWRP6Z10NAGPAN

Details by Category

✅ ▲ Vercel Production
App Passed Failed Skipped
✅ astro 99 0 8
✅ example 99 0 8
✅ express 99 0 8
✅ fastify 99 0 8
✅ hono 99 0 8
✅ nextjs-turbopack 104 0 3
✅ nextjs-webpack 104 0 3
✅ nitro 99 0 8
✅ nuxt 99 0 8
✅ sveltekit 99 0 8
✅ vite 99 0 8
✅ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 101 0 6
✅ express-stable 101 0 6
✅ fastify-stable 101 0 6
✅ hono-stable 101 0 6
✅ nextjs-turbopack-canary 88 0 19
✅ nextjs-turbopack-stable 107 0 0
✅ nextjs-webpack-canary 88 0 19
✅ nextjs-webpack-stable 107 0 0
✅ nitro-stable 101 0 6
✅ nuxt-stable 101 0 6
✅ sveltekit-stable 101 0 6
✅ vite-stable 101 0 6
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 101 0 6
✅ express-stable 101 0 6
✅ fastify-stable 101 0 6
✅ hono-stable 101 0 6
✅ nextjs-turbopack-canary 88 0 19
✅ nextjs-turbopack-stable 107 0 0
✅ nextjs-webpack-canary 88 0 19
✅ nextjs-webpack-stable 107 0 0
✅ nitro-stable 101 0 6
✅ nuxt-stable 101 0 6
✅ sveltekit-stable 101 0 6
✅ vite-stable 101 0 6
✅ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 101 0 6
✅ express-stable 101 0 6
✅ fastify-stable 101 0 6
✅ hono-stable 101 0 6
✅ nextjs-turbopack-canary 88 0 19
✅ nextjs-turbopack-stable 107 0 0
✅ nextjs-webpack-canary 88 0 19
✅ nextjs-webpack-stable 107 0 0
✅ nitro-stable 101 0 6
✅ nuxt-stable 101 0 6
✅ sveltekit-stable 101 0 6
✅ vite-stable 101 0 6
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 107 0 0
❌ 🌍 Community Worlds
App Passed Failed Skipped
✅ mongodb-dev 4 0 3
✅ redis-dev 4 0 3
❌ redis 67 21 0
✅ turso-dev 4 0 3
❌ turso 3 85 0
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 101 0 6
✅ e2e-local-dev-tanstack-start-stable 101 0 6
✅ e2e-local-postgres-nest-stable 101 0 6
✅ e2e-local-postgres-tanstack-start-stable 101 0 6
✅ e2e-local-prod-nest-stable 101 0 6
✅ e2e-local-prod-tanstack-start-stable 101 0 6

📋 View full workflow run

@TooTallNate
TooTallNate merged commit 0b9867e into stable Sep 8, 2026
157 of 166 checks passed
@TooTallNate
TooTallNate deleted the backport/pr-3971-to-stable branch September 8, 2026 19:59

This branch had an error being deployed

1 failed and 17 active deployments
Preview – workflow-swc-playground — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workbench-nuxt-workflow — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – example-nextjs-workflow-webpack — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – example-nextjs-workflow-turbopack — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workbench-astro-workflow — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workbench-sveltekit-workflow — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – example-workflow — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workbench-express-workflow — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workbench-tanstack-start-workflow — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workbench-nitro-workflow — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workbench-fastify-workflow — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workbench-hono-workflow — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workflow-tarballs — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workbench-nestjs-workflow — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workbench-vite-workflow — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workflow-web — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workflow-docs — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
Preview – workbench-python-workflow — 630795b2 Deployed Sep 8, 2026 by vercel[bot]
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.

1 participant