ts2workflows 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/dist/ast/steps.d.ts +5 -2
- package/dist/ast/steps.d.ts.map +1 -1
- package/dist/ast/steps.js +5 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +4 -0
- package/dist/transpiler/expressions.d.ts +4 -3
- package/dist/transpiler/expressions.d.ts.map +1 -1
- package/dist/transpiler/expressions.js +15 -7
- package/dist/transpiler/index.js +3 -0
- package/dist/transpiler/statements.d.ts.map +1 -1
- package/dist/transpiler/statements.js +200 -79
- package/dist/transpiler/transformations.js +14 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,10 +61,6 @@ npm run build
|
|
|
61
61
|
npm run test
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
## Publishing the package to npmjs.com
|
|
65
|
-
|
|
66
|
-
Update CHANGELOG.md, the version number in package.json, npm install, commit, tag with v1.2.3 and push. A Github Actions worklfow will build the package and publish it on tag pushes.
|
|
67
|
-
|
|
68
64
|
## Architecture
|
|
69
65
|
|
|
70
66
|
A transpilation using ts2workflows consists of five phases:
|
package/dist/ast/steps.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { Expression, VariableName } from './expressions.js';
|
|
1
|
+
import { Expression, MemberExpression, VariableName, VariableReferenceExpression } from './expressions.js';
|
|
2
2
|
import { Subworkflow, WorkflowParameter } from './workflows.js';
|
|
3
3
|
export type StepName = string;
|
|
4
|
-
export
|
|
4
|
+
export interface VariableAssignment {
|
|
5
|
+
name: VariableReferenceExpression | MemberExpression;
|
|
6
|
+
value: Expression;
|
|
7
|
+
}
|
|
5
8
|
export type WorkflowParameters = Record<VariableName, Expression>;
|
|
6
9
|
export interface CustomRetryPolicy {
|
|
7
10
|
predicate?: string;
|
package/dist/ast/steps.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"steps.d.ts","sourceRoot":"","sources":["../../src/ast/steps.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,EAEV,YAAY,
|
|
1
|
+
{"version":3,"file":"steps.d.ts","sourceRoot":"","sources":["../../src/ast/steps.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,EAEV,gBAAgB,EAChB,YAAY,EACZ,2BAA2B,EAE5B,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAE/D,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAA;AAC7B,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,2BAA2B,GAAG,gBAAgB,CAAA;IACpD,KAAK,EAAE,UAAU,CAAA;CAClB;AACD,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;AAQjE,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,UAAU,CAAA;IACtB,OAAO,EAAE;QACP,YAAY,CAAC,EAAE,UAAU,CAAA;QACzB,QAAQ,CAAC,EAAE,UAAU,CAAA;QACrB,UAAU,CAAC,EAAE,UAAU,CAAA;KACxB,CAAA;CACF;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,YAAY,EAAE,cAAc,EAAE,CAAA;CACxC;AAED,qBAAa,cAAc;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,eAAe,EAAE,CAAA;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,iBAAiB,EAAE,CAAA;gBAGnC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,eAAe,EAAE,EACxB,MAAM,CAAC,EAAE,iBAAiB,EAAE;IAO9B,aAAa,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,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AQ;IACpB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAA;IACjD,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAA;IAEhC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,EAAE,CAAA;IAEtC,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,EAAE,CAAA;gBAGxC,KAAK,EAAE,iBAAiB,EAAE,EAC1B,WAAW,CAAC,EAAE,iBAAiB,EAAE,EACjC,WAAW,CAAC,EAAE,MAAM,GAAG,iBAAiB,EACxC,QAAQ,CAAC,EAAE,YAAY;CAO1B;AAKD,qBAAa,aAAa;IACxB,QAAQ,CAAC,GAAG,gBAAe;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;;IAMtB,gBAAgB,IAAI,aAAa;CAGlC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,eAAe,EACrB,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GACvC,iBAAiB,CAyCnB;AAwHD;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,8BAA8B,GACnC,iBAAiB,EAAE,EAAE,CAuBvB;AA6BD;;GAEG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,8BAA8B,GACnC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAkEzB"}
|
package/dist/ast/steps.js
CHANGED
|
@@ -476,8 +476,10 @@ export function renderStep(step) {
|
|
|
476
476
|
switch (step.tag) {
|
|
477
477
|
case 'assign':
|
|
478
478
|
return {
|
|
479
|
-
assign: step.assignments.map((
|
|
480
|
-
return {
|
|
479
|
+
assign: step.assignments.map(({ name, value }) => {
|
|
480
|
+
return {
|
|
481
|
+
[name.toString()]: expressionToLiteralValueOrLiteralExpression(value),
|
|
482
|
+
};
|
|
481
483
|
}),
|
|
482
484
|
...(step.next && { next: step.next }),
|
|
483
485
|
};
|
|
@@ -540,7 +542,7 @@ function renderCallStep(step) {
|
|
|
540
542
|
}
|
|
541
543
|
return {
|
|
542
544
|
call: step.call,
|
|
543
|
-
...(args
|
|
545
|
+
...(args && Object.keys(args).length > 0 && { args }),
|
|
544
546
|
...(step.result !== undefined && { result: step.result }),
|
|
545
547
|
};
|
|
546
548
|
}
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;IACvC,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CACtC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;IACvC,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CACtC;AAID,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,EAAE,kBAAkB,CAAA;gBAEhB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB;CAI1D;AAID,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAG5B"}
|
package/dist/errors.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// WorkflowSyntaxError is thrown when the input contains a syntax error.
|
|
2
|
+
// The error is in user's input.
|
|
1
3
|
export class WorkflowSyntaxError extends Error {
|
|
2
4
|
location;
|
|
3
5
|
constructor(message, location) {
|
|
@@ -5,6 +7,8 @@ export class WorkflowSyntaxError extends Error {
|
|
|
5
7
|
this.location = location;
|
|
6
8
|
}
|
|
7
9
|
}
|
|
10
|
+
// InternalTranspilingError is thrown when ts2workflow ends up in an unexpected state.
|
|
11
|
+
// The error is in ts2workflow.
|
|
8
12
|
export class InternalTranspilingError extends Error {
|
|
9
13
|
constructor(message) {
|
|
10
14
|
super(`Internal error: ${message}`);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/typescript-estree';
|
|
2
|
-
import { Expression, Primitive } from '../ast/expressions.js';
|
|
2
|
+
import { Expression, MemberExpression, Primitive, VariableReferenceExpression } from '../ast/expressions.js';
|
|
3
3
|
export declare function convertExpression(instance: TSESTree.Expression): Expression;
|
|
4
4
|
export declare function convertObjectExpression(node: TSESTree.ObjectExpression): Record<string, Primitive | Expression>;
|
|
5
5
|
export declare function convertObjectAsExpressionValues(node: TSESTree.ObjectExpression): Record<string, Expression>;
|
|
6
6
|
export declare function convertMemberExpression(node: TSESTree.MemberExpression): Expression;
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
7
|
+
export declare function isIntrinsic(calleeName: string): boolean;
|
|
8
|
+
export declare function isIntrinsicStatment(calleeName: string): boolean;
|
|
9
9
|
export declare function throwIfSpread<T extends TSESTree.Expression | TSESTree.Property | TSESTree.SpreadElement | null>(nodes: T[]): Exclude<T, TSESTree.SpreadElement>[];
|
|
10
|
+
export declare function convertVariableNameExpression(instance: TSESTree.Expression): VariableReferenceExpression | MemberExpression;
|
|
10
11
|
//# sourceMappingURL=expressions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../../src/transpiler/expressions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAkB,MAAM,sCAAsC,CAAA;AAC/E,OAAO,EAGL,UAAU,
|
|
1
|
+
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../../src/transpiler/expressions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAkB,MAAM,sCAAsC,CAAA;AAC/E,OAAO,EAGL,UAAU,EAEV,gBAAgB,EAChB,SAAS,EAGT,2BAA2B,EAI5B,MAAM,uBAAuB,CAAA;AAG9B,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,UAAU,GAAG,UAAU,CAiE3E;AAcD,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,QAAQ,CAAC,gBAAgB,GAC9B,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,CAAC,CAgCxC;AAED,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,QAAQ,CAAC,gBAAgB,GAC9B,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAG5B;AAwJD,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,QAAQ,CAAC,gBAAgB,GAC9B,UAAU,CAcZ;AA0JD,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAGvD;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAG/D;AAoDD,wBAAgB,aAAa,CAC3B,CAAC,SACG,QAAQ,CAAC,UAAU,GACnB,QAAQ,CAAC,QAAQ,GACjB,QAAQ,CAAC,aAAa,GACtB,IAAI,EACR,KAAK,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,CAgBlD;AAED,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,QAAQ,CAAC,UAAU,GAC5B,2BAA2B,GAAG,gBAAgB,CAchD"}
|
|
@@ -201,7 +201,7 @@ export function convertMemberExpression(node) {
|
|
|
201
201
|
}
|
|
202
202
|
function convertChainExpression(node) {
|
|
203
203
|
const properties = chainExpressionToFlatArray(node.expression);
|
|
204
|
-
const args =
|
|
204
|
+
const args = optionalChainToMapGetArguments(properties);
|
|
205
205
|
return new FunctionInvocationExpression('map.get', args);
|
|
206
206
|
}
|
|
207
207
|
function chainExpressionToFlatArray(node) {
|
|
@@ -226,7 +226,7 @@ function chainExpressionToFlatArray(node) {
|
|
|
226
226
|
];
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
-
function
|
|
229
|
+
function optionalChainToMapGetArguments(properties) {
|
|
230
230
|
if (properties.length <= 0) {
|
|
231
231
|
// this shouldn't happen
|
|
232
232
|
return [];
|
|
@@ -290,7 +290,7 @@ function convertCallExpression(node) {
|
|
|
290
290
|
const calleeExpression = convertExpression(node.callee);
|
|
291
291
|
if (isFullyQualifiedName(calleeExpression)) {
|
|
292
292
|
const calleeName = calleeExpression.toString();
|
|
293
|
-
if (
|
|
293
|
+
if (isIntrinsic(calleeName)) {
|
|
294
294
|
let msg;
|
|
295
295
|
if (calleeName === 'call_step') {
|
|
296
296
|
msg =
|
|
@@ -308,11 +308,11 @@ function convertCallExpression(node) {
|
|
|
308
308
|
throw new WorkflowSyntaxError('Callee should be a qualified name', node.loc);
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
|
-
export function
|
|
312
|
-
const
|
|
313
|
-
return
|
|
311
|
+
export function isIntrinsic(calleeName) {
|
|
312
|
+
const intrinsics = ['parallel', 'retry_policy', 'call_step'];
|
|
313
|
+
return intrinsics.includes(calleeName);
|
|
314
314
|
}
|
|
315
|
-
export function
|
|
315
|
+
export function isIntrinsicStatment(calleeName) {
|
|
316
316
|
const statementNames = ['parallel', 'retry_policy'];
|
|
317
317
|
return statementNames.includes(calleeName);
|
|
318
318
|
}
|
|
@@ -360,3 +360,11 @@ export function throwIfSpread(nodes) {
|
|
|
360
360
|
const argumentExpressions = nodes.filter((x) => x?.type !== AST_NODE_TYPES.SpreadElement);
|
|
361
361
|
return argumentExpressions;
|
|
362
362
|
}
|
|
363
|
+
export function convertVariableNameExpression(instance) {
|
|
364
|
+
const ex = convertExpression(instance);
|
|
365
|
+
if (ex.expressionType !== 'variableReference' &&
|
|
366
|
+
ex.expressionType !== 'member') {
|
|
367
|
+
throw new WorkflowSyntaxError('The left-hand side of an assignment must be a variable or member expression', instance.loc);
|
|
368
|
+
}
|
|
369
|
+
return ex;
|
|
370
|
+
}
|
package/dist/transpiler/index.js
CHANGED
|
@@ -54,6 +54,9 @@ function parseTopLevelStatement(node) {
|
|
|
54
54
|
function parseSubworkflows(node) {
|
|
55
55
|
const workflowParams = parseWorkflowParams(node.params);
|
|
56
56
|
const steps = transformAST(parseStatement(node.body, {}));
|
|
57
|
+
if (steps.length === 0) {
|
|
58
|
+
throw new WorkflowSyntaxError('Empty subworkflow body is not allowed on GCP Workflows', node.body.loc);
|
|
59
|
+
}
|
|
57
60
|
return new SubworkflowAST(node.id.name, steps, workflowParams);
|
|
58
61
|
}
|
|
59
62
|
function parseWorkflowParams(nodeParams) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../src/transpiler/statements.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,QAAQ,EAAE,MAAM,sCAAsC,CAAA;AAC/E,OAAO,EAWL,QAAQ,EAOR,eAAe,EAChB,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../src/transpiler/statements.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,QAAQ,EAAE,MAAM,sCAAsC,CAAA;AAC/E,OAAO,EAWL,QAAQ,EAOR,eAAe,EAChB,MAAM,iBAAiB,CAAA;AAkCxB,MAAM,WAAW,cAAc;IAE7B,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAA;IAE/B,QAAQ,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAA;IAGlC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAKtC,gBAAgB,CAAC,EAAE,QAAQ,EAAE,CAAA;CAC9B;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,QAAQ,CAAC,SAAS,EACxB,GAAG,EAAE,cAAc,GAClB,eAAe,EAAE,CAEnB"}
|
|
@@ -4,7 +4,7 @@ import { AssignStepAST, CallStepAST, ForRangeStepAST, ForStepAST, JumpTargetAST,
|
|
|
4
4
|
import { BinaryExpression, FunctionInvocationExpression, MemberExpression, PrimitiveExpression, VariableReferenceExpression, asExpression, isExpression, isFullyQualifiedName, isLiteral, isPure, nullEx, safeAsExpression, trueEx, } from '../ast/expressions.js';
|
|
5
5
|
import { InternalTranspilingError, WorkflowSyntaxError } from '../errors.js';
|
|
6
6
|
import { chainPairs, isRecord } from '../utils.js';
|
|
7
|
-
import { convertExpression, convertMemberExpression, convertObjectExpression, convertObjectAsExpressionValues,
|
|
7
|
+
import { convertExpression, convertMemberExpression, convertObjectExpression, convertObjectAsExpressionValues, isIntrinsic, throwIfSpread, isIntrinsicStatment as isIntrinsicStatement, convertVariableNameExpression, } from './expressions.js';
|
|
8
8
|
import { blockingFunctions } from './generated/functionMetadata.js';
|
|
9
9
|
export function parseStatement(node, ctx) {
|
|
10
10
|
return parseStatementRecursively(node, undefined, ctx);
|
|
@@ -89,14 +89,15 @@ function convertInitializer(targetVariableName, initializer, ctx) {
|
|
|
89
89
|
const calleeName = initializer.callee.type === AST_NODE_TYPES.Identifier
|
|
90
90
|
? initializer.callee.name
|
|
91
91
|
: undefined;
|
|
92
|
-
if (calleeName &&
|
|
92
|
+
if (calleeName && isIntrinsicStatement(calleeName)) {
|
|
93
93
|
throw new WorkflowSyntaxError(`"${calleeName}" can't be called as part of an expression`, initializer.callee.loc);
|
|
94
94
|
}
|
|
95
95
|
return callExpressionToStep(initializer, targetVariableName, ctx);
|
|
96
96
|
}
|
|
97
97
|
else {
|
|
98
|
+
const name = new VariableReferenceExpression(targetVariableName);
|
|
98
99
|
const value = initializer === null ? nullEx : convertExpression(initializer);
|
|
99
|
-
return [new AssignStepAST([
|
|
100
|
+
return [new AssignStepAST([{ name, value }])];
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
function convertArrayDestructuring(arrayPattern, initializer, ctx) {
|
|
@@ -124,12 +125,12 @@ function arrayDestructuringSteps(patterns, initializerExpression, ctx) {
|
|
|
124
125
|
if (patterns.filter((p) => p !== null).length === 0) {
|
|
125
126
|
return [];
|
|
126
127
|
}
|
|
127
|
-
const __temp_len = `${tempName(ctx)}_len
|
|
128
|
+
const __temp_len = new VariableReferenceExpression(`${tempName(ctx)}_len`);
|
|
128
129
|
const initializeVariables = [
|
|
129
|
-
|
|
130
|
-
__temp_len,
|
|
131
|
-
new FunctionInvocationExpression('len', [initializerExpression]),
|
|
132
|
-
|
|
130
|
+
{
|
|
131
|
+
name: __temp_len,
|
|
132
|
+
value: new FunctionInvocationExpression('len', [initializerExpression]),
|
|
133
|
+
},
|
|
133
134
|
];
|
|
134
135
|
const branches = R.reverse(patterns).flatMap((pat, i) => {
|
|
135
136
|
if (pat === null) {
|
|
@@ -138,7 +139,7 @@ function arrayDestructuringSteps(patterns, initializerExpression, ctx) {
|
|
|
138
139
|
else {
|
|
139
140
|
return [
|
|
140
141
|
{
|
|
141
|
-
condition: new BinaryExpression(
|
|
142
|
+
condition: new BinaryExpression(__temp_len, '>=', new PrimitiveExpression(patterns.length - i)),
|
|
142
143
|
steps: arrayElementsDestructuringSteps(patterns, initializerExpression, patterns.length - i, ctx),
|
|
143
144
|
},
|
|
144
145
|
];
|
|
@@ -161,14 +162,15 @@ function arrayElementsDestructuringSteps(patterns, initializerExpression, take,
|
|
|
161
162
|
switch (pat?.type) {
|
|
162
163
|
case AST_NODE_TYPES.MemberExpression:
|
|
163
164
|
case AST_NODE_TYPES.Identifier: {
|
|
164
|
-
const name =
|
|
165
|
-
return [new AssignStepAST([
|
|
165
|
+
const name = convertVariableNameExpression(pat);
|
|
166
|
+
return [new AssignStepAST([{ name, value: iElement }])];
|
|
166
167
|
}
|
|
167
168
|
case AST_NODE_TYPES.AssignmentPattern: {
|
|
168
169
|
if (pat.left.type !== AST_NODE_TYPES.Identifier) {
|
|
169
170
|
throw new WorkflowSyntaxError('Default value can be used only with an identifier', pat.left.loc);
|
|
170
171
|
}
|
|
171
|
-
|
|
172
|
+
const name = new VariableReferenceExpression(pat.left.name);
|
|
173
|
+
return [new AssignStepAST([{ name, value: iElement }])];
|
|
172
174
|
}
|
|
173
175
|
case AST_NODE_TYPES.ObjectPattern:
|
|
174
176
|
return objectDestructuringSteps(pat.properties, iElement, ctx);
|
|
@@ -192,11 +194,18 @@ function extractDefaultAssignmentsFromDestructuringPattern(pat) {
|
|
|
192
194
|
if (pat.left.type !== AST_NODE_TYPES.Identifier) {
|
|
193
195
|
throw new WorkflowSyntaxError('Default value can be used only with an identifier', pat.left.loc);
|
|
194
196
|
}
|
|
195
|
-
return [
|
|
197
|
+
return [
|
|
198
|
+
{
|
|
199
|
+
name: new VariableReferenceExpression(pat.left.name),
|
|
200
|
+
value: convertExpression(pat.right),
|
|
201
|
+
},
|
|
202
|
+
];
|
|
196
203
|
case AST_NODE_TYPES.Identifier:
|
|
197
|
-
return [
|
|
204
|
+
return [
|
|
205
|
+
{ name: new VariableReferenceExpression(pat.name), value: nullEx },
|
|
206
|
+
];
|
|
198
207
|
case AST_NODE_TYPES.MemberExpression:
|
|
199
|
-
return [
|
|
208
|
+
return [{ name: convertVariableNameExpression(pat), value: nullEx }];
|
|
200
209
|
case AST_NODE_TYPES.ObjectPattern:
|
|
201
210
|
return pat.properties.flatMap((p) => {
|
|
202
211
|
if (p.type === AST_NODE_TYPES.RestElement) {
|
|
@@ -217,7 +226,12 @@ function extractDefaultAssignmentsFromDestructuringPattern(pat) {
|
|
|
217
226
|
if (pat.argument.type !== AST_NODE_TYPES.Identifier) {
|
|
218
227
|
throw new WorkflowSyntaxError('Identifier expected', pat.argument.loc);
|
|
219
228
|
}
|
|
220
|
-
return [
|
|
229
|
+
return [
|
|
230
|
+
{
|
|
231
|
+
name: new VariableReferenceExpression(pat.argument.name),
|
|
232
|
+
value: new PrimitiveExpression([]),
|
|
233
|
+
},
|
|
234
|
+
];
|
|
221
235
|
default:
|
|
222
236
|
return [];
|
|
223
237
|
}
|
|
@@ -233,23 +247,23 @@ function arrayRestDestructuringSteps(patterns, rest, initializerExpression, star
|
|
|
233
247
|
if (rest.argument.type !== AST_NODE_TYPES.Identifier) {
|
|
234
248
|
throw new WorkflowSyntaxError('Identifier expected', rest.argument.loc);
|
|
235
249
|
}
|
|
236
|
-
const restName = rest.argument.name;
|
|
250
|
+
const restName = new VariableReferenceExpression(rest.argument.name);
|
|
237
251
|
const __temp_len = new VariableReferenceExpression(`${tempName(ctx)}_len`);
|
|
238
252
|
const __temp_index = `${tempName(ctx)}_index`;
|
|
239
253
|
const one = new PrimitiveExpression(1);
|
|
240
254
|
const emptyArray = new PrimitiveExpression([]);
|
|
241
255
|
const copyLoop = new ForRangeStepAST([
|
|
242
256
|
new AssignStepAST([
|
|
243
|
-
|
|
244
|
-
restName,
|
|
245
|
-
new FunctionInvocationExpression('list.concat', [
|
|
246
|
-
|
|
257
|
+
{
|
|
258
|
+
name: restName,
|
|
259
|
+
value: new FunctionInvocationExpression('list.concat', [
|
|
260
|
+
restName,
|
|
247
261
|
new MemberExpression(initializerExpression, new VariableReferenceExpression(__temp_index), true),
|
|
248
262
|
]),
|
|
249
|
-
|
|
263
|
+
},
|
|
250
264
|
]),
|
|
251
265
|
], __temp_index, startIndex, new BinaryExpression(__temp_len, '-', one));
|
|
252
|
-
return [new AssignStepAST([
|
|
266
|
+
return [new AssignStepAST([{ name: restName, value: emptyArray }]), copyLoop];
|
|
253
267
|
}
|
|
254
268
|
function convertObjectDestructuring(objectPattern, initializer, ctx) {
|
|
255
269
|
let initExpression;
|
|
@@ -289,7 +303,14 @@ function objectDestructuringSteps(properties, initializerExpression, ctx) {
|
|
|
289
303
|
initializerExpression,
|
|
290
304
|
new PrimitiveExpression(prop.key.name),
|
|
291
305
|
]);
|
|
292
|
-
return [
|
|
306
|
+
return [
|
|
307
|
+
new AssignStepAST([
|
|
308
|
+
{
|
|
309
|
+
name: new VariableReferenceExpression(prop.value.name),
|
|
310
|
+
value: safeKeyExpression,
|
|
311
|
+
},
|
|
312
|
+
]),
|
|
313
|
+
];
|
|
293
314
|
}
|
|
294
315
|
else if (prop.value.type === AST_NODE_TYPES.AssignmentPattern) {
|
|
295
316
|
return objectAssignmentPatternSteps(prop.value, initializerExpression, keyExpression);
|
|
@@ -305,16 +326,17 @@ function objectAssignmentPatternSteps(pat, initializerExpression, keyExpression)
|
|
|
305
326
|
}
|
|
306
327
|
// Using Switch step instead of default() because pat.right must be evaluated only
|
|
307
328
|
// in the default value branch (in case it has side effects)
|
|
329
|
+
const name = new VariableReferenceExpression(pat.left.name);
|
|
308
330
|
return [
|
|
309
331
|
new SwitchStepAST([
|
|
310
332
|
{
|
|
311
333
|
condition: new BinaryExpression(new PrimitiveExpression(pat.left.name), 'in', initializerExpression),
|
|
312
|
-
steps: [new AssignStepAST([
|
|
334
|
+
steps: [new AssignStepAST([{ name, value: keyExpression }])],
|
|
313
335
|
},
|
|
314
336
|
{
|
|
315
337
|
condition: trueEx,
|
|
316
338
|
steps: [
|
|
317
|
-
new AssignStepAST([
|
|
339
|
+
new AssignStepAST([{ name, value: convertExpression(pat.right) }]),
|
|
318
340
|
],
|
|
319
341
|
},
|
|
320
342
|
]),
|
|
@@ -335,13 +357,14 @@ function objectDestructuringRestSteps(properties, rest, initializerExpression) {
|
|
|
335
357
|
return p;
|
|
336
358
|
})
|
|
337
359
|
.map((p) => p.name);
|
|
360
|
+
const name = new VariableReferenceExpression(rest.argument.name);
|
|
338
361
|
const value = nonRestKeys.reduce((acc, propertyName) =>
|
|
339
362
|
// map.delete returns a copy of the object and removes the specified property
|
|
340
363
|
new FunctionInvocationExpression('map.delete', [
|
|
341
364
|
acc,
|
|
342
365
|
new PrimitiveExpression(propertyName),
|
|
343
366
|
]), initializerExpression);
|
|
344
|
-
return [new AssignStepAST([
|
|
367
|
+
return [new AssignStepAST([{ name, value }])];
|
|
345
368
|
}
|
|
346
369
|
function assignmentExpressionToSteps(node, ctx) {
|
|
347
370
|
let compoundOperator = undefined;
|
|
@@ -373,54 +396,132 @@ function assignmentExpressionToSteps(node, ctx) {
|
|
|
373
396
|
default:
|
|
374
397
|
throw new WorkflowSyntaxError(`Operator ${node.operator} is not supported in assignment expressions`, node.loc);
|
|
375
398
|
}
|
|
376
|
-
if (
|
|
377
|
-
|
|
378
|
-
return convertArrayDestructuring(node.left, node.right, ctx);
|
|
379
|
-
}
|
|
380
|
-
else {
|
|
381
|
-
throw new WorkflowSyntaxError(`Invalid left-hand side in assignment`, node.left.loc);
|
|
382
|
-
}
|
|
399
|
+
if (compoundOperator === undefined) {
|
|
400
|
+
return assignmentSteps(node.left, node.right, ctx);
|
|
383
401
|
}
|
|
384
|
-
else
|
|
385
|
-
|
|
386
|
-
return convertObjectDestructuring(node.left, node.right, ctx);
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
throw new WorkflowSyntaxError(`Invalid left-hand side in assignment`, node.left.loc);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
const targetExpression = convertExpression(node.left);
|
|
393
|
-
if (!isFullyQualifiedName(targetExpression)) {
|
|
394
|
-
throw new WorkflowSyntaxError('The left-hand side of an assignment must be an identifier or a property access', node.loc);
|
|
402
|
+
else {
|
|
403
|
+
return compoundAssignmentSteps(node.left, node.right, compoundOperator, ctx);
|
|
395
404
|
}
|
|
405
|
+
}
|
|
406
|
+
function assignmentSteps(left, right, ctx) {
|
|
396
407
|
let valueExpression;
|
|
397
408
|
const steps = [];
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
if (!needsTempVariable) {
|
|
411
|
-
return steps;
|
|
412
|
-
}
|
|
413
|
-
valueExpression = new VariableReferenceExpression(tempName(ctx));
|
|
409
|
+
if (left.type === AST_NODE_TYPES.ArrayPattern) {
|
|
410
|
+
return convertArrayDestructuring(left, right, ctx);
|
|
411
|
+
}
|
|
412
|
+
else if (left.type === AST_NODE_TYPES.ObjectPattern) {
|
|
413
|
+
return convertObjectDestructuring(left, right, ctx);
|
|
414
|
+
}
|
|
415
|
+
if (right.type === AST_NODE_TYPES.CallExpression &&
|
|
416
|
+
right.callee.type === AST_NODE_TYPES.Identifier &&
|
|
417
|
+
isIntrinsic(right.callee.name)) {
|
|
418
|
+
const tr = convertAssignmentExpressionIntrinsicRHS(right, ctx);
|
|
419
|
+
steps.push(...tr.steps);
|
|
420
|
+
valueExpression = tr.tempVariable;
|
|
414
421
|
}
|
|
415
422
|
else {
|
|
416
|
-
valueExpression = convertExpression(
|
|
423
|
+
valueExpression = convertExpression(right);
|
|
417
424
|
}
|
|
418
|
-
|
|
419
|
-
|
|
425
|
+
const targetExpression = convertVariableNameExpression(left);
|
|
426
|
+
steps.push(new AssignStepAST([{ name: targetExpression, value: valueExpression }]));
|
|
427
|
+
return steps;
|
|
428
|
+
}
|
|
429
|
+
function compoundAssignmentSteps(left, right, operator, ctx) {
|
|
430
|
+
let valueExpression;
|
|
431
|
+
const { expression: targetExpression, steps } = convertCompoundAssignmentLeftHandSide(left, ctx);
|
|
432
|
+
if (right.type === AST_NODE_TYPES.CallExpression &&
|
|
433
|
+
right.callee.type === AST_NODE_TYPES.Identifier &&
|
|
434
|
+
isIntrinsic(right.callee.name)) {
|
|
435
|
+
const tr = convertAssignmentExpressionIntrinsicRHS(right, ctx);
|
|
436
|
+
steps.push(...tr.steps);
|
|
437
|
+
valueExpression = tr.tempVariable;
|
|
420
438
|
}
|
|
421
|
-
|
|
439
|
+
else {
|
|
440
|
+
valueExpression = convertExpression(right);
|
|
441
|
+
}
|
|
442
|
+
valueExpression = new BinaryExpression(targetExpression, operator, valueExpression);
|
|
443
|
+
steps.push(new AssignStepAST([{ name: targetExpression, value: valueExpression }]));
|
|
422
444
|
return steps;
|
|
423
445
|
}
|
|
446
|
+
function convertCompoundAssignmentLeftHandSide(left, ctx) {
|
|
447
|
+
if (left.type === AST_NODE_TYPES.ArrayPattern ||
|
|
448
|
+
left.type === AST_NODE_TYPES.ObjectPattern) {
|
|
449
|
+
throw new WorkflowSyntaxError(`Invalid left-hand side in assignment`, left.loc);
|
|
450
|
+
}
|
|
451
|
+
const leftEx = convertVariableNameExpression(left);
|
|
452
|
+
if (leftEx.expressionType === 'member') {
|
|
453
|
+
const { transformed, assignments } = extractSideEffectsFromMemberExpression(leftEx, tempName(ctx), 0);
|
|
454
|
+
const steps = [new AssignStepAST(assignments)];
|
|
455
|
+
return { expression: transformed, steps };
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
return {
|
|
459
|
+
expression: leftEx,
|
|
460
|
+
steps: [],
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Extract side-effecting computed properties into temporary variable assignments.
|
|
466
|
+
*
|
|
467
|
+
* This is used on the left-hand side of a compound assignment expression, which
|
|
468
|
+
* should only be evaluted once.
|
|
469
|
+
*/
|
|
470
|
+
function extractSideEffectsFromMemberExpression(ex, tempPrefix, tempIndex) {
|
|
471
|
+
if (ex.computed && !isPure(ex.property)) {
|
|
472
|
+
let transformedObject;
|
|
473
|
+
let objectAssignments;
|
|
474
|
+
if (ex.object.expressionType === 'member') {
|
|
475
|
+
const object2 = extractSideEffectsFromMemberExpression(ex.object, tempPrefix, tempIndex + 1);
|
|
476
|
+
transformedObject = object2.transformed;
|
|
477
|
+
objectAssignments = object2.assignments;
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
transformedObject = ex.object;
|
|
481
|
+
objectAssignments = [];
|
|
482
|
+
}
|
|
483
|
+
const tmp = new VariableReferenceExpression(`${tempPrefix}${tempIndex}`);
|
|
484
|
+
const transformed = new MemberExpression(transformedObject, tmp, true);
|
|
485
|
+
const assignments = objectAssignments;
|
|
486
|
+
assignments.push({
|
|
487
|
+
name: tmp,
|
|
488
|
+
value: ex.property,
|
|
489
|
+
});
|
|
490
|
+
return { transformed, assignments };
|
|
491
|
+
}
|
|
492
|
+
else if (ex.object.expressionType === 'member') {
|
|
493
|
+
const { transformed: object2, assignments: assignments } = extractSideEffectsFromMemberExpression(ex.object, tempPrefix, tempIndex);
|
|
494
|
+
const transformed = new MemberExpression(object2, ex.property, ex.computed);
|
|
495
|
+
return {
|
|
496
|
+
transformed,
|
|
497
|
+
assignments,
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
return {
|
|
502
|
+
transformed: ex,
|
|
503
|
+
assignments: [],
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Special case for handling call_step() RHS in assignment expressions.
|
|
509
|
+
*
|
|
510
|
+
* This can be removed once the generic convertExpression() is able to handle call_step.
|
|
511
|
+
*/
|
|
512
|
+
function convertAssignmentExpressionIntrinsicRHS(callEx, ctx) {
|
|
513
|
+
if (callEx.callee.type !== AST_NODE_TYPES.Identifier) {
|
|
514
|
+
throw new InternalTranspilingError('The callee should be an identifier');
|
|
515
|
+
}
|
|
516
|
+
const calleeName = callEx.callee.name;
|
|
517
|
+
if (isIntrinsicStatement(calleeName)) {
|
|
518
|
+
throw new WorkflowSyntaxError(`"${calleeName}" can't be called as part of an expression`, callEx.callee.loc);
|
|
519
|
+
}
|
|
520
|
+
const resultVariable = tempName(ctx);
|
|
521
|
+
const steps = callExpressionToStep(callEx, resultVariable, ctx);
|
|
522
|
+
const tempVariable = new VariableReferenceExpression(resultVariable);
|
|
523
|
+
return { steps, tempVariable };
|
|
524
|
+
}
|
|
424
525
|
function callExpressionToStep(node, resultVariable, ctx) {
|
|
425
526
|
const calleeExpression = convertExpression(node.callee);
|
|
426
527
|
if (isFullyQualifiedName(calleeExpression)) {
|
|
@@ -456,10 +557,10 @@ function callExpressionToStep(node, resultVariable, ctx) {
|
|
|
456
557
|
function callExpressionAssignStep(functionName, argumentsNode, resultVariable) {
|
|
457
558
|
const argumentExpressions = throwIfSpread(argumentsNode).map(convertExpression);
|
|
458
559
|
return new AssignStepAST([
|
|
459
|
-
|
|
460
|
-
resultVariable,
|
|
461
|
-
new FunctionInvocationExpression(functionName, argumentExpressions),
|
|
462
|
-
|
|
560
|
+
{
|
|
561
|
+
name: new VariableReferenceExpression(resultVariable),
|
|
562
|
+
value: new FunctionInvocationExpression(functionName, argumentExpressions),
|
|
563
|
+
},
|
|
463
564
|
]);
|
|
464
565
|
}
|
|
465
566
|
function createCallStep(node, argumentsNode, resultVariable) {
|
|
@@ -600,7 +701,12 @@ function parseParallelOptions(node) {
|
|
|
600
701
|
};
|
|
601
702
|
}
|
|
602
703
|
function generalExpressionToAssignStep(node, ctx) {
|
|
603
|
-
return new AssignStepAST([
|
|
704
|
+
return new AssignStepAST([
|
|
705
|
+
{
|
|
706
|
+
name: new VariableReferenceExpression(tempName(ctx)),
|
|
707
|
+
value: convertExpression(node),
|
|
708
|
+
},
|
|
709
|
+
]);
|
|
604
710
|
}
|
|
605
711
|
function returnStatementToReturnStep(node, ctx) {
|
|
606
712
|
const value = node.argument ? convertExpression(node.argument) : undefined;
|
|
@@ -852,8 +958,14 @@ function extractErrorVariableName(param) {
|
|
|
852
958
|
*/
|
|
853
959
|
function finalizerInitializer(conditionVariable, valueVariable) {
|
|
854
960
|
return new AssignStepAST([
|
|
855
|
-
|
|
856
|
-
|
|
961
|
+
{
|
|
962
|
+
name: new VariableReferenceExpression(conditionVariable),
|
|
963
|
+
value: nullEx,
|
|
964
|
+
},
|
|
965
|
+
{
|
|
966
|
+
name: new VariableReferenceExpression(valueVariable),
|
|
967
|
+
value: nullEx,
|
|
968
|
+
},
|
|
857
969
|
]);
|
|
858
970
|
}
|
|
859
971
|
/**
|
|
@@ -887,11 +999,14 @@ function finalizerFooter(conditionVariable, valueVariable) {
|
|
|
887
999
|
function finalizerDelayedException(exceptionVariableName, conditionVariableName, valueVariableName) {
|
|
888
1000
|
return [
|
|
889
1001
|
new AssignStepAST([
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
1002
|
+
{
|
|
1003
|
+
name: new VariableReferenceExpression(conditionVariableName),
|
|
1004
|
+
value: new PrimitiveExpression('raise'),
|
|
1005
|
+
},
|
|
1006
|
+
{
|
|
1007
|
+
name: new VariableReferenceExpression(valueVariableName),
|
|
1008
|
+
value: new VariableReferenceExpression(exceptionVariableName),
|
|
1009
|
+
},
|
|
895
1010
|
]),
|
|
896
1011
|
];
|
|
897
1012
|
}
|
|
@@ -901,8 +1016,14 @@ function delayedReturnAndJumpToFinalizer(value, ctx) {
|
|
|
901
1016
|
: undefined;
|
|
902
1017
|
const [conditionVariable, valueVariable] = finalizerVariables(ctx);
|
|
903
1018
|
return new AssignStepAST([
|
|
904
|
-
|
|
905
|
-
|
|
1019
|
+
{
|
|
1020
|
+
name: new VariableReferenceExpression(conditionVariable),
|
|
1021
|
+
value: new PrimitiveExpression('return'),
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
name: new VariableReferenceExpression(valueVariable),
|
|
1025
|
+
value: value ?? nullEx,
|
|
1026
|
+
},
|
|
906
1027
|
], finalizerTarget);
|
|
907
1028
|
}
|
|
908
1029
|
function labeledStep(node, ctx) {
|
|
@@ -179,10 +179,16 @@ const transformStepExpressions = R.curry(function (transform, step) {
|
|
|
179
179
|
function transformExpressionsAssign(transform, step) {
|
|
180
180
|
if (step.assignments) {
|
|
181
181
|
const newSteps = [];
|
|
182
|
-
const newAssignments = step.assignments.map((
|
|
183
|
-
const [steps2,
|
|
182
|
+
const newAssignments = step.assignments.map(({ name, value }) => {
|
|
183
|
+
const [steps2, transformedKey] = transform(name);
|
|
184
|
+
const [steps3, transformedValue] = transform(value);
|
|
184
185
|
newSteps.push(...steps2);
|
|
185
|
-
|
|
186
|
+
newSteps.push(...steps3);
|
|
187
|
+
if (transformedKey.expressionType !== 'variableReference' &&
|
|
188
|
+
transformedKey.expressionType !== 'member') {
|
|
189
|
+
throw new InternalTranspilingError('Unexpected key type when transforming assign step');
|
|
190
|
+
}
|
|
191
|
+
return { name: transformedKey, value: transformedValue };
|
|
186
192
|
});
|
|
187
193
|
newSteps.push(new AssignStepAST(newAssignments, step.next, step.label));
|
|
188
194
|
return newSteps;
|
|
@@ -407,9 +413,11 @@ function extractMapsInMap(primitiveEx, generateName, nestingLevel) {
|
|
|
407
413
|
newValue = properties;
|
|
408
414
|
}
|
|
409
415
|
else {
|
|
410
|
-
|
|
411
|
-
tempVariables.push(
|
|
412
|
-
|
|
416
|
+
newValue = new VariableReferenceExpression(generateName());
|
|
417
|
+
tempVariables.push({
|
|
418
|
+
name: newValue,
|
|
419
|
+
value: new PrimitiveExpression(properties),
|
|
420
|
+
});
|
|
413
421
|
}
|
|
414
422
|
return {
|
|
415
423
|
transformed: newValue,
|