File tree Expand file tree Collapse file tree 5 files changed +48
-11
lines changed
packages/swc-plugin-workflow/transform
tests/fixture/factory-with-step-method Expand file tree Collapse file tree 5 files changed +48
-11
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @workflow/swc-plugin " : patch
3+ ---
4+
5+ Apply SWC transformation on step functions returned from factory function
Original file line number Diff line number Diff line change @@ -858,7 +858,40 @@ impl StepTransform {
858858 stmt. visit_mut_children_with ( self ) ;
859859 }
860860 }
861- Stmt :: Decl ( Decl :: Var ( _) ) => {
861+ Stmt :: Decl ( Decl :: Var ( var_decl) ) => {
862+ // Check if any declarators contain arrow functions with object literal bodies
863+ for declarator in & mut var_decl. decls {
864+ if let Some ( init) = & mut declarator. init {
865+ if let Pat :: Ident ( binding) = & declarator. name {
866+ let name = binding. id . sym . to_string ( ) ;
867+
868+ // Check if the initializer is an arrow function with object literal body
869+ if let Expr :: Arrow ( arrow_expr) = & mut * * init {
870+ match & mut * arrow_expr. body {
871+ BlockStmtOrExpr :: Expr ( expr) => {
872+ // Handle both direct object literals and parenthesized ones
873+ let obj_lit_mut = match & mut * * expr {
874+ Expr :: Object ( obj) => Some ( obj) ,
875+ Expr :: Paren ( paren) => {
876+ if let Expr :: Object ( obj) = & mut * paren. expr {
877+ Some ( obj)
878+ } else {
879+ None
880+ }
881+ }
882+ _ => None ,
883+ } ;
884+
885+ if let Some ( obj_lit) = obj_lit_mut {
886+ self . process_object_properties_for_step_functions ( obj_lit, & name) ;
887+ }
888+ }
889+ _ => { }
890+ }
891+ }
892+ }
893+ }
894+ }
862895 stmt. visit_mut_children_with ( self ) ;
863896 }
864897 _ => {
Original file line number Diff line number Diff line change 11import fs from 'fs/promises' ;
22const myFactory = ( ) => ( {
33 myStep : async ( ) => {
4- 'use step' ;
54 await fs . mkdir ( 'test' ) ;
65 }
76 } ) ;
Original file line number Diff line number Diff line change 1+ import { registerStepFunction } from "workflow/internal/private" ;
12import fs from 'fs/promises' ;
3+ /**__internal_workflows{"steps":{"input.js":{"myFactory/myStep":{"stepId":"step//input.js//myFactory/myStep"}}}}*/ ;
4+ var myFactory$myStep = async ( ) => {
5+ await fs . mkdir ( 'test' ) ;
6+ } ;
27const myFactory = ( ) => ( {
3- myStep : async ( ) => {
4- 'use step' ;
5- await fs . mkdir ( 'test' ) ;
6- }
8+ myStep : myFactory$myStep
79 } ) ;
810export default myFactory ;
11+ registerStepFunction ( "step//input.js//myFactory/myStep" , myFactory$myStep ) ;
Original file line number Diff line number Diff line change 1- import fs from 'fs/promises' ;
1+ /**__internal_workflows{"steps":{"input.js":{"myFactory/myStep":{"stepId":"step//input.js//myFactory/myStep"}}}}*/ ;
22const myFactory = ( ) => ( {
3- myStep : async ( ) => {
4- 'use step' ;
5- await fs . mkdir ( 'test' ) ;
6- }
3+ myStep : globalThis [ Symbol . for ( "WORKFLOW_USE_STEP" ) ] ( "step//input.js//myFactory/myStep" )
74 } ) ;
85export default myFactory ;
You can’t perform that action at this time.
0 commit comments