Skip to content

Commit cf4ac0e

Browse files
jketemaCopilot
andcommitted
JS: Recognize Workflow SDK 'use workflow' and 'use step' directives
Fixes #22701 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4841ad5 commit cf4ac0e

6 files changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The Workflow SDK directives `"use workflow"` and `"use step"` are now recognized as known directives, so the `js/unknown-directive` query no longer flags them.

‎javascript/ql/lib/semmle/javascript/Stmt.qll‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,36 @@ module Directive {
490490
class WorkletDirective extends KnownDirective {
491491
WorkletDirective() { this.getDirectiveText() = "worklet" }
492492
}
493+
494+
/**
495+
* A Workflow SDK `use workflow` directive.
496+
*
497+
* Example:
498+
*
499+
* ```
500+
* async function myWorkflow() {
501+
* "use workflow";
502+
* }
503+
* ```
504+
*/
505+
class UseWorkflowDirective extends KnownDirective {
506+
UseWorkflowDirective() { this.getDirectiveText() = "use workflow" }
507+
}
508+
509+
/**
510+
* A Workflow SDK `use step` directive.
511+
*
512+
* Example:
513+
*
514+
* ```
515+
* async function myStep() {
516+
* "use step";
517+
* }
518+
* ```
519+
*/
520+
class UseStepDirective extends KnownDirective {
521+
UseStepDirective() { this.getDirectiveText() = "use step" }
522+
}
493523
}
494524

495525
/**

‎javascript/ql/test/library-tests/Directives/KnownDirective.expected‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@
2020
| tst.js:28:3:28:22 | 'use cache: remote'; | use cache: remote |
2121
| tst.js:29:3:29:23 | 'use ca ... ivate'; | use cache: private |
2222
| tst.js:36:5:36:17 | 'use strict'; | use strict |
23+
| tst.js:40:3:40:17 | 'use workflow'; | use workflow |
24+
| tst.js:45:3:45:13 | 'use step'; | use step |

‎javascript/ql/test/library-tests/Directives/tst.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,13 @@ function g() {
3535
"";
3636
'use strict'; // this is a directive
3737
}
38+
39+
async function workflow() {
40+
'use workflow';
41+
return await step();
42+
}
43+
44+
async function step() {
45+
'use step';
46+
return 42;
47+
}

‎javascript/ql/test/query-tests/Expressions/UnknownDirective/UnknownDirective.expected‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
| UnknownDirective.js:44:5:44:65 | "[0, 0, ... , 0];"; | Unknown directive: '[0, 0, 0, 0, 0, 0, 0 ... (truncated)'. |
1616
| UnknownDirective.js:50:5:50:15 | ":nomunge"; | Unknown directive: ':nomunge'. |
1717
| UnknownDirective.js:51:5:51:30 | "foo(), ... munge"; | Unknown directive: 'foo(), bar, baz:nomu ... (truncated)'. |
18+
| UnknownDirective.js:69:5:69:20 | "use workflows"; | Unknown directive: 'use workflows'. |
19+
| UnknownDirective.js:70:5:70:16 | "use steps"; | Unknown directive: 'use steps'. |

‎javascript/ql/test/query-tests/Expressions/UnknownDirective/UnknownDirective.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,18 @@ function yui() {
5454
function babel_typeof(obj) {
5555
"@babel/helpers - typeof"
5656
}
57+
58+
async function workflow() {
59+
"use workflow";
60+
return await step();
61+
}
62+
63+
async function step() {
64+
"use step";
65+
return 42;
66+
}
67+
68+
function workflowTypos() {
69+
"use workflows"; // $ Alert
70+
"use steps"; // $ Alert
71+
}

0 commit comments

Comments
 (0)