Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-default-export-workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workflow/swc-plugin": patch
---

Fix default export workflow function transformation in workflow mode
572 changes: 521 additions & 51 deletions packages/swc-plugin-workflow/transform/src/lib.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test anonymous default export workflow
export default async function() {
'use workflow';
const result = await someStep();
return result;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test anonymous default export workflow
/**__internal_workflows{"workflows":{"input.js":{"default":{"workflowId":"workflow//input.js//__default"}}}}*/;
const __default = async function() {
throw new Error("You attempted to execute workflow __default function directly. To start a workflow, use start(__default) from workflow/api");
};
__default.workflowId = "workflow//input.js//__default";
export default __default;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test anonymous default export workflow
/**__internal_workflows{"workflows":{"input.js":{"default":{"workflowId":"workflow//input.js//__default"}}}}*/;
export default async function() {
'use workflow';
const result = await someStep();
return result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Test anonymous default export workflow
/**__internal_workflows{"workflows":{"input.js":{"default":{"workflowId":"workflow//input.js//__default"}}}}*/;
const __default = async function() {
const result = await someStep();
return result;
};
__default.workflowId = "workflow//input.js//__default";
export default __default;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test default export arrow workflow
export default async (data) => {
'use workflow';
const processed = await processData(data);
return processed;
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test default export arrow workflow
/**__internal_workflows{"workflows":{"input.js":{"default":{"workflowId":"workflow//input.js//__default"}}}}*/;
const __default = async (data)=>{
throw new Error("You attempted to execute workflow __default function directly. To start a workflow, use start(__default) from workflow/api");
};
__default.workflowId = "workflow//input.js//__default";
export default __default;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test default export arrow workflow
/**__internal_workflows{"workflows":{"input.js":{"default":{"workflowId":"workflow//input.js//__default"}}}}*/;
export default (async (data)=>{
'use workflow';
const processed = await processData(data);
return processed;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Test default export arrow workflow
/**__internal_workflows{"workflows":{"input.js":{"default":{"workflowId":"workflow//input.js//__default"}}}}*/;
const __default = async (data)=>{
const processed = await processData(data);
return processed;
};
__default.workflowId = "workflow//input.js//__default";
export default __default;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Existing variable named __default
const __default = "existing variable";

// Use it to avoid unused variable
console.log(__default);

// Anonymous default export should get unique name (__default$1)
export default async function() {
'use workflow';
const result = await someStep();
return result;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Existing variable named __default
/**__internal_workflows{"workflows":{"input.js":{"default":{"workflowId":"workflow//input.js//__default$1"}}}}*/;
const __default = "existing variable";
// Use it to avoid unused variable
console.log(__default);
const __default$1 = async function() {
throw new Error("You attempted to execute workflow __default$1 function directly. To start a workflow, use start(__default$1) from workflow/api");
};
__default$1.workflowId = "workflow//input.js//__default$1";
export default __default$1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Existing variable named __default
/**__internal_workflows{"workflows":{"input.js":{"default":{"workflowId":"workflow//input.js//__default$1"}}}}*/;
const __default = "existing variable";
// Use it to avoid unused variable
console.log(__default);
// Anonymous default export should get unique name (__default$1)
export default async function() {
'use workflow';
const result = await someStep();
return result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Existing variable named __default
/**__internal_workflows{"workflows":{"input.js":{"default":{"workflowId":"workflow//input.js//__default$1"}}}}*/;
const __default = "existing variable";
// Use it to avoid unused variable
console.log(__default);
const __default$1 = async function() {
const result = await someStep();
return result;
};
__default$1.workflowId = "workflow//input.js//__default$1";
export default __default$1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default async function() {
'use workflow';
const result = await someStep();
return result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**__internal_workflows{"workflows":{"input.js":{"default":{"workflowId":"workflow//input.js//__default"}}}}*/;
const __default = async function() {
throw new Error("You attempted to execute workflow __default function directly. To start a workflow, use start(__default) from workflow/api");
};
__default.workflowId = "workflow//input.js//__default";
export default __default;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**__internal_workflows{"workflows":{"input.js":{"default":{"workflowId":"workflow//input.js//__default"}}}}*/;
export default async function() {
'use workflow';
const result = await someStep();
return result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**__internal_workflows{"workflows":{"input.js":{"default":{"workflowId":"workflow//input.js//__default"}}}}*/;
const __default = async function() {
const result = await someStep();
return result;
};
__default.workflowId = "workflow//input.js//__default";
export default __default;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Test workflow functions in client mode
/**__internal_workflows{"workflows":{"input.js":{"arrowWorkflow":{"workflowId":"workflow//input.js//arrowWorkflow"},"defaultWorkflow":{"workflowId":"workflow//input.js//defaultWorkflow"},"internalWorkflow":{"workflowId":"workflow//input.js//internalWorkflow"},"myWorkflow":{"workflowId":"workflow//input.js//myWorkflow"}}}}*/;
/**__internal_workflows{"workflows":{"input.js":{"arrowWorkflow":{"workflowId":"workflow//input.js//arrowWorkflow"},"default":{"workflowId":"workflow//input.js//defaultWorkflow"},"internalWorkflow":{"workflowId":"workflow//input.js//internalWorkflow"},"myWorkflow":{"workflowId":"workflow//input.js//myWorkflow"}}}}*/;
export async function myWorkflow() {
throw new Error("You attempted to execute workflow myWorkflow function directly. To start a workflow, use start(myWorkflow) from workflow/api");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Test workflow functions in client mode
/**__internal_workflows{"workflows":{"input.js":{"arrowWorkflow":{"workflowId":"workflow//input.js//arrowWorkflow"},"defaultWorkflow":{"workflowId":"workflow//input.js//defaultWorkflow"},"internalWorkflow":{"workflowId":"workflow//input.js//internalWorkflow"},"myWorkflow":{"workflowId":"workflow//input.js//myWorkflow"}}}}*/;
/**__internal_workflows{"workflows":{"input.js":{"arrowWorkflow":{"workflowId":"workflow//input.js//arrowWorkflow"},"default":{"workflowId":"workflow//input.js//defaultWorkflow"},"internalWorkflow":{"workflowId":"workflow//input.js//internalWorkflow"},"myWorkflow":{"workflowId":"workflow//input.js//myWorkflow"}}}}*/;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a bug no? the function here is called defaultWorkflow

export async function myWorkflow() {
'use workflow';
const result = await someStep();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Test workflow functions in client mode
/**__internal_workflows{"workflows":{"input.js":{"arrowWorkflow":{"workflowId":"workflow//input.js//arrowWorkflow"},"defaultWorkflow":{"workflowId":"workflow//input.js//defaultWorkflow"},"internalWorkflow":{"workflowId":"workflow//input.js//internalWorkflow"},"myWorkflow":{"workflowId":"workflow//input.js//myWorkflow"}}}}*/;
/**__internal_workflows{"workflows":{"input.js":{"arrowWorkflow":{"workflowId":"workflow//input.js//arrowWorkflow"},"default":{"workflowId":"workflow//input.js//defaultWorkflow"},"internalWorkflow":{"workflowId":"workflow//input.js//internalWorkflow"},"myWorkflow":{"workflowId":"workflow//input.js//myWorkflow"}}}}*/;
export async function myWorkflow() {
const result = await someStep();
return result;
Expand All @@ -23,4 +23,4 @@ export function regularFunction() {
}
myWorkflow.workflowId = "workflow//input.js//myWorkflow";
arrowWorkflow.workflowId = "workflow//input.js//arrowWorkflow";
$$default.workflowId = "workflow//input.js//$$default";
defaultWorkflow.workflowId = "workflow//input.js//defaultWorkflow";
Loading