ts2workflows 0.3.0 → 0.5.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 +6 -2
- package/dist/ast/expressions.d.ts.map +1 -1
- package/dist/ast/expressions.js +7 -10
- package/dist/ast/stepnames.d.ts.map +1 -1
- package/dist/ast/stepnames.js +11 -1
- package/dist/ast/steps.d.ts +24 -13
- package/dist/ast/steps.d.ts.map +1 -1
- package/dist/ast/steps.js +54 -38
- package/dist/transpiler/expressions.d.ts +8 -4
- package/dist/transpiler/expressions.d.ts.map +1 -1
- package/dist/transpiler/expressions.js +162 -42
- package/dist/transpiler/index.d.ts.map +1 -1
- package/dist/transpiler/index.js +29 -28
- package/dist/transpiler/statements.d.ts +2 -1
- package/dist/transpiler/statements.d.ts.map +1 -1
- package/dist/transpiler/statements.js +137 -155
- package/dist/transpiler/transformations.d.ts.map +1 -1
- package/dist/transpiler/transformations.js +216 -110
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +6 -0
- package/language_reference.md +55 -33
- package/package.json +11 -4
- package/types/global.d.ts +124 -0
- package/dist/transpiler/asserts.d.ts +0 -7
- package/dist/transpiler/asserts.d.ts.map +0 -1
- package/dist/transpiler/asserts.js +0 -11
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
|
|
3
2
|
import { BinaryExpression, FunctionInvocationExpression, MemberExpression, PrimitiveExpression, UnaryExpression, VariableReferenceExpression, isExpression, isFullyQualifiedName, } from '../ast/expressions.js';
|
|
4
|
-
import { WorkflowSyntaxError } from '../errors.js';
|
|
5
|
-
import {
|
|
6
|
-
const { ArrayExpression, AwaitExpression, CallExpression, ConditionalExpression, Identifier, Literal, LogicalExpression, ObjectExpression, TemplateLiteral, TSAsExpression, } = AST_NODE_TYPES;
|
|
3
|
+
import { InternalTranspilingError, WorkflowSyntaxError } from '../errors.js';
|
|
4
|
+
import { mapRecordValues } from '../utils.js';
|
|
7
5
|
export function convertExpression(instance) {
|
|
8
6
|
const expOrPrimitive = convertExpressionOrPrimitive(instance);
|
|
9
7
|
if (isExpression(expOrPrimitive)) {
|
|
@@ -14,14 +12,12 @@ export function convertExpression(instance) {
|
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
14
|
export function convertObjectExpression(node) {
|
|
17
|
-
|
|
18
|
-
const properties = node.properties;
|
|
19
|
-
return Object.fromEntries(properties.map(({ key, value }) => {
|
|
15
|
+
return Object.fromEntries(throwIfSpread(node.properties).map(({ key, value }) => {
|
|
20
16
|
let keyPrimitive;
|
|
21
|
-
if (key.type === Identifier) {
|
|
17
|
+
if (key.type === AST_NODE_TYPES.Identifier) {
|
|
22
18
|
keyPrimitive = key.name;
|
|
23
19
|
}
|
|
24
|
-
else if (key.type === Literal) {
|
|
20
|
+
else if (key.type === AST_NODE_TYPES.Literal) {
|
|
25
21
|
if (typeof key.value === 'string') {
|
|
26
22
|
keyPrimitive = key.value;
|
|
27
23
|
}
|
|
@@ -32,28 +28,34 @@ export function convertObjectExpression(node) {
|
|
|
32
28
|
else {
|
|
33
29
|
throw new WorkflowSyntaxError(`Not implemented object key type: ${key.type}`, key.loc);
|
|
34
30
|
}
|
|
31
|
+
if (value.type === AST_NODE_TYPES.AssignmentPattern ||
|
|
32
|
+
value.type === AST_NODE_TYPES.TSEmptyBodyFunctionExpression) {
|
|
33
|
+
throw new WorkflowSyntaxError('Value not supported', value.loc);
|
|
34
|
+
}
|
|
35
35
|
return [keyPrimitive, convertExpressionOrPrimitive(value)];
|
|
36
36
|
}));
|
|
37
37
|
}
|
|
38
38
|
export function convertObjectAsExpressionValues(node) {
|
|
39
|
-
const primitiveOrExpArguments = convertObjectExpression(node);
|
|
40
39
|
// Convert Primitive values to PrimitiveExpressions
|
|
41
|
-
return
|
|
42
|
-
const valEx = isExpression(val) ? val : new PrimitiveExpression(val);
|
|
43
|
-
return [key, valEx];
|
|
44
|
-
}));
|
|
40
|
+
return mapRecordValues(convertObjectExpression(node), (val) => isExpression(val) ? val : new PrimitiveExpression(val));
|
|
45
41
|
}
|
|
46
42
|
function convertExpressionOrPrimitive(instance) {
|
|
47
43
|
switch (instance.type) {
|
|
48
|
-
case ArrayExpression:
|
|
49
|
-
return instance
|
|
50
|
-
case ObjectExpression:
|
|
44
|
+
case AST_NODE_TYPES.ArrayExpression:
|
|
45
|
+
return convertArrayExpression(instance);
|
|
46
|
+
case AST_NODE_TYPES.ObjectExpression:
|
|
51
47
|
return convertObjectExpression(instance);
|
|
52
|
-
case Literal:
|
|
48
|
+
case AST_NODE_TYPES.Literal:
|
|
49
|
+
if (instance.value instanceof RegExp) {
|
|
50
|
+
throw new WorkflowSyntaxError('RegExp is not supported', instance.loc);
|
|
51
|
+
}
|
|
52
|
+
if (typeof instance.value === 'bigint') {
|
|
53
|
+
throw new WorkflowSyntaxError('BigInt in not supported', instance.loc);
|
|
54
|
+
}
|
|
53
55
|
return instance.value;
|
|
54
|
-
case TemplateLiteral:
|
|
56
|
+
case AST_NODE_TYPES.TemplateLiteral:
|
|
55
57
|
return convertTemplateLiteralToExpression(instance);
|
|
56
|
-
case Identifier:
|
|
58
|
+
case AST_NODE_TYPES.Identifier:
|
|
57
59
|
if (instance.name === 'null' || instance.name === 'undefined') {
|
|
58
60
|
return null;
|
|
59
61
|
}
|
|
@@ -69,27 +71,32 @@ function convertExpressionOrPrimitive(instance) {
|
|
|
69
71
|
case AST_NODE_TYPES.UnaryExpression:
|
|
70
72
|
return convertUnaryExpression(instance);
|
|
71
73
|
case AST_NODE_TYPES.BinaryExpression:
|
|
72
|
-
case LogicalExpression:
|
|
74
|
+
case AST_NODE_TYPES.LogicalExpression:
|
|
73
75
|
return convertBinaryExpression(instance);
|
|
74
76
|
case AST_NODE_TYPES.MemberExpression:
|
|
75
77
|
return convertMemberExpression(instance);
|
|
76
|
-
case
|
|
78
|
+
case AST_NODE_TYPES.ChainExpression:
|
|
79
|
+
return convertChainExpression(instance);
|
|
80
|
+
case AST_NODE_TYPES.CallExpression:
|
|
77
81
|
return convertCallExpression(instance);
|
|
78
|
-
case ConditionalExpression:
|
|
82
|
+
case AST_NODE_TYPES.ConditionalExpression:
|
|
79
83
|
return convertConditionalExpression(instance);
|
|
80
|
-
case TSAsExpression:
|
|
84
|
+
case AST_NODE_TYPES.TSAsExpression:
|
|
85
|
+
return convertExpressionOrPrimitive(instance.expression);
|
|
86
|
+
case AST_NODE_TYPES.TSNonNullExpression:
|
|
81
87
|
return convertExpressionOrPrimitive(instance.expression);
|
|
82
|
-
case AwaitExpression:
|
|
88
|
+
case AST_NODE_TYPES.AwaitExpression:
|
|
83
89
|
return convertExpressionOrPrimitive(instance.argument);
|
|
84
90
|
default:
|
|
85
91
|
throw new WorkflowSyntaxError(`Not implemented expression type: ${instance.type}`, instance.loc);
|
|
86
92
|
}
|
|
87
93
|
}
|
|
94
|
+
function convertArrayExpression(instance) {
|
|
95
|
+
return throwIfSpread(instance.elements).map((e) => e === null
|
|
96
|
+
? new PrimitiveExpression(null)
|
|
97
|
+
: convertExpressionOrPrimitive(e));
|
|
98
|
+
}
|
|
88
99
|
function convertBinaryExpression(instance) {
|
|
89
|
-
assertOneOfManyTypes(instance, [
|
|
90
|
-
AST_NODE_TYPES.BinaryExpression,
|
|
91
|
-
LogicalExpression,
|
|
92
|
-
]);
|
|
93
100
|
// Special case for nullish coalescing becuase the result is a function call
|
|
94
101
|
// expression, not a binary expression
|
|
95
102
|
if (instance.operator === '??') {
|
|
@@ -126,6 +133,9 @@ function convertBinaryExpression(instance) {
|
|
|
126
133
|
default:
|
|
127
134
|
throw new WorkflowSyntaxError(`Unsupported binary operator: ${instance.operator}`, instance.loc);
|
|
128
135
|
}
|
|
136
|
+
if (instance.left.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
137
|
+
throw new WorkflowSyntaxError('Private identifier not supported', instance.left.loc);
|
|
138
|
+
}
|
|
129
139
|
return new BinaryExpression(convertExpression(instance.left), op, convertExpression(instance.right));
|
|
130
140
|
}
|
|
131
141
|
function nullishCoalescingExpression(left, right) {
|
|
@@ -135,7 +145,6 @@ function nullishCoalescingExpression(left, right) {
|
|
|
135
145
|
]);
|
|
136
146
|
}
|
|
137
147
|
function convertUnaryExpression(instance) {
|
|
138
|
-
assertType(instance, AST_NODE_TYPES.UnaryExpression);
|
|
139
148
|
if (instance.prefix === false) {
|
|
140
149
|
throw new WorkflowSyntaxError('only prefix unary operators are supported', instance.loc);
|
|
141
150
|
}
|
|
@@ -165,37 +174,140 @@ function convertUnaryExpression(instance) {
|
|
|
165
174
|
return op ? new UnaryExpression(op, ex) : ex;
|
|
166
175
|
}
|
|
167
176
|
export function convertMemberExpression(node) {
|
|
168
|
-
|
|
177
|
+
if (node.property.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
178
|
+
throw new WorkflowSyntaxError('Private identifier not supported', node.property.loc);
|
|
179
|
+
}
|
|
169
180
|
const object = convertExpression(node.object);
|
|
170
181
|
return new MemberExpression(object, convertExpression(node.property), node.computed);
|
|
171
182
|
}
|
|
183
|
+
function convertChainExpression(node) {
|
|
184
|
+
const properties = chainExpressionToFlatArray(node.expression);
|
|
185
|
+
const args = optinalChainToMapGetArguments(properties);
|
|
186
|
+
return new FunctionInvocationExpression('map.get', args);
|
|
187
|
+
}
|
|
188
|
+
function chainExpressionToFlatArray(node) {
|
|
189
|
+
if (node.type === AST_NODE_TYPES.MemberExpression) {
|
|
190
|
+
if (node.property.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
191
|
+
throw new WorkflowSyntaxError('Private identifier not supported', node.property.loc);
|
|
192
|
+
}
|
|
193
|
+
const data = {
|
|
194
|
+
property: node.property,
|
|
195
|
+
optional: node.optional,
|
|
196
|
+
computed: node.computed,
|
|
197
|
+
};
|
|
198
|
+
return chainExpressionToFlatArray(node.object).concat([data]);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
return [
|
|
202
|
+
{
|
|
203
|
+
property: node,
|
|
204
|
+
optional: false,
|
|
205
|
+
computed: false,
|
|
206
|
+
},
|
|
207
|
+
];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function optinalChainToMapGetArguments(properties) {
|
|
211
|
+
if (properties.length <= 0) {
|
|
212
|
+
// this shouldn't happen
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
215
|
+
let base;
|
|
216
|
+
let optionalSliceStart;
|
|
217
|
+
const firstOptional = properties.findIndex((p) => p.optional);
|
|
218
|
+
if (firstOptional > 2) {
|
|
219
|
+
const baseProperties = properties.slice(0, firstOptional - 1);
|
|
220
|
+
base = memberExpressionFromList(baseProperties);
|
|
221
|
+
optionalSliceStart = firstOptional - 1;
|
|
222
|
+
}
|
|
223
|
+
else if (firstOptional >= 0) {
|
|
224
|
+
base = convertExpression(properties[0].property);
|
|
225
|
+
optionalSliceStart = 1;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
// firstOptional < 0, this shouldn't happen
|
|
229
|
+
base = memberExpressionFromList(properties);
|
|
230
|
+
optionalSliceStart = properties.length;
|
|
231
|
+
}
|
|
232
|
+
const optionals = properties.slice(optionalSliceStart).map((opt) => {
|
|
233
|
+
const propertyExp = convertExpression(opt.property);
|
|
234
|
+
if (opt.computed) {
|
|
235
|
+
return propertyExp;
|
|
236
|
+
}
|
|
237
|
+
else if (isFullyQualifiedName(propertyExp)) {
|
|
238
|
+
return new PrimitiveExpression(propertyExp.toString());
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
throw new WorkflowSyntaxError('Unexpected property in an optional chain', opt.property.loc);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
const args = [base];
|
|
245
|
+
if (optionals.length > 1) {
|
|
246
|
+
args.push(new PrimitiveExpression(optionals));
|
|
247
|
+
}
|
|
248
|
+
else if (optionals.length === 1) {
|
|
249
|
+
args.push(optionals[0]);
|
|
250
|
+
}
|
|
251
|
+
return args;
|
|
252
|
+
}
|
|
253
|
+
function memberExpressionFromList(properties) {
|
|
254
|
+
if (properties.length >= 2) {
|
|
255
|
+
const base = new MemberExpression(convertExpression(properties[0].property), convertExpression(properties[1].property), properties[1].computed);
|
|
256
|
+
return properties
|
|
257
|
+
.slice(2)
|
|
258
|
+
.reduce((exp, current) => new MemberExpression(exp, convertExpression(current.property), current.computed), base);
|
|
259
|
+
}
|
|
260
|
+
else if (properties.length === 1) {
|
|
261
|
+
return convertExpression(properties[0].property);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
throw new InternalTranspilingError('Empty array in memberExpressionFromList()');
|
|
265
|
+
}
|
|
266
|
+
}
|
|
172
267
|
function convertCallExpression(node) {
|
|
173
|
-
|
|
268
|
+
if (node.optional) {
|
|
269
|
+
throw new WorkflowSyntaxError('Optional call expressions are not supported', node.loc);
|
|
270
|
+
}
|
|
174
271
|
const calleeExpression = convertExpression(node.callee);
|
|
175
272
|
if (isFullyQualifiedName(calleeExpression)) {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
273
|
+
const calleeName = calleeExpression.toString();
|
|
274
|
+
if (isMagicFunction(calleeName)) {
|
|
275
|
+
let msg;
|
|
276
|
+
if (calleeName === 'call_step') {
|
|
277
|
+
msg =
|
|
278
|
+
'Calling call_step as part of an expression is not yet implemented';
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
msg = `"${calleeName}" can't be called as part of an expression`;
|
|
282
|
+
}
|
|
283
|
+
throw new WorkflowSyntaxError(msg, node.callee.loc);
|
|
284
|
+
}
|
|
285
|
+
const argumentExpressions = throwIfSpread(node.arguments).map(convertExpression);
|
|
286
|
+
return new FunctionInvocationExpression(calleeName, argumentExpressions);
|
|
179
287
|
}
|
|
180
288
|
else {
|
|
181
289
|
throw new WorkflowSyntaxError('Callee should be a qualified name', node.loc);
|
|
182
290
|
}
|
|
183
291
|
}
|
|
292
|
+
export function isMagicFunction(calleeName) {
|
|
293
|
+
const magicFunctions = ['parallel', 'retry_policy', 'call_step'];
|
|
294
|
+
return magicFunctions.includes(calleeName);
|
|
295
|
+
}
|
|
296
|
+
export function isMagicFunctionStatmentOnly(calleeName) {
|
|
297
|
+
const statementNames = ['parallel', 'retry_policy'];
|
|
298
|
+
return statementNames.includes(calleeName);
|
|
299
|
+
}
|
|
184
300
|
function convertConditionalExpression(node) {
|
|
185
|
-
assertType(node, ConditionalExpression);
|
|
186
301
|
const test = convertExpression(node.test);
|
|
187
302
|
const consequent = convertExpression(node.consequent);
|
|
188
303
|
const alternate = convertExpression(node.alternate);
|
|
189
304
|
return new FunctionInvocationExpression('if', [test, consequent, alternate]);
|
|
190
305
|
}
|
|
191
306
|
function convertTemplateLiteralToExpression(node) {
|
|
192
|
-
|
|
193
|
-
const elements = node.quasis;
|
|
194
|
-
const stringTerms = elements
|
|
307
|
+
const stringTerms = node.quasis
|
|
195
308
|
.map((x) => x.value.cooked)
|
|
196
309
|
.map((x) => new PrimitiveExpression(x));
|
|
197
|
-
const
|
|
198
|
-
const templateTerms = expressionNodes.map(convertExpression);
|
|
310
|
+
const templateTerms = node.expressions.map(convertExpression);
|
|
199
311
|
// interleave string parts and the expression parts starting with strings
|
|
200
312
|
const interleavedTerms = stringTerms
|
|
201
313
|
.slice(0, stringTerms.length - 1)
|
|
@@ -221,3 +333,11 @@ function convertTemplateLiteralToExpression(node) {
|
|
|
221
333
|
});
|
|
222
334
|
}
|
|
223
335
|
}
|
|
336
|
+
export function throwIfSpread(nodes) {
|
|
337
|
+
const unsupported = nodes.find((x) => x?.type === AST_NODE_TYPES.SpreadElement);
|
|
338
|
+
if (unsupported) {
|
|
339
|
+
throw new WorkflowSyntaxError('The spread syntax is not supported', unsupported.loc);
|
|
340
|
+
}
|
|
341
|
+
const argumentExpressions = nodes.filter((x) => x?.type !== AST_NODE_TYPES.SpreadElement);
|
|
342
|
+
return argumentExpressions;
|
|
343
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transpiler/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transpiler/index.ts"],"names":[],"mappings":"AAYA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAW9C"}
|
package/dist/transpiler/index.js
CHANGED
|
@@ -1,67 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
import * as parser from '@typescript-eslint/typescript-estree';
|
|
3
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
1
|
+
import { parse, AST_NODE_TYPES, } from '@typescript-eslint/typescript-estree';
|
|
4
2
|
import * as YAML from 'yaml';
|
|
5
3
|
import { SubworkflowAST } from '../ast/steps.js';
|
|
6
4
|
import { WorkflowSyntaxError } from '../errors.js';
|
|
7
5
|
import { generateStepNames } from '../ast/stepnames.js';
|
|
8
|
-
import {
|
|
9
|
-
import { parseBlockStatement } from './statements.js';
|
|
10
|
-
const { AssignmentPattern, ExportNamedDeclaration, FunctionDeclaration, Identifier, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, Literal, Program, TSDeclareFunction, TSTypeAliasDeclaration, TSInterfaceDeclaration, } = AST_NODE_TYPES;
|
|
6
|
+
import { parseStatement } from './statements.js';
|
|
11
7
|
export function transpile(code) {
|
|
12
8
|
const parserOptions = {
|
|
13
9
|
jsDocParsingMode: 'none',
|
|
14
10
|
loc: true,
|
|
15
11
|
range: false,
|
|
16
12
|
};
|
|
17
|
-
const ast =
|
|
18
|
-
assertType(ast, Program);
|
|
13
|
+
const ast = parse(code, parserOptions);
|
|
19
14
|
const workflowAst = { subworkflows: ast.body.flatMap(parseTopLevelStatement) };
|
|
20
15
|
const workflow = generateStepNames(workflowAst);
|
|
21
16
|
return YAML.stringify(workflow.render(), { lineWidth: 100 });
|
|
22
17
|
}
|
|
23
18
|
function parseTopLevelStatement(node) {
|
|
24
|
-
switch (node
|
|
25
|
-
case FunctionDeclaration:
|
|
19
|
+
switch (node.type) {
|
|
20
|
+
case AST_NODE_TYPES.FunctionDeclaration:
|
|
26
21
|
return [parseSubworkflows(node)];
|
|
27
|
-
case ImportDeclaration:
|
|
28
|
-
if (node.specifiers.some((spec) => spec.type === ImportNamespaceSpecifier ||
|
|
29
|
-
spec.type === ImportDefaultSpecifier)) {
|
|
22
|
+
case AST_NODE_TYPES.ImportDeclaration:
|
|
23
|
+
if (node.specifiers.some((spec) => spec.type === AST_NODE_TYPES.ImportNamespaceSpecifier ||
|
|
24
|
+
spec.type === AST_NODE_TYPES.ImportDefaultSpecifier)) {
|
|
30
25
|
throw new WorkflowSyntaxError('Only named imports are allowed', node.loc);
|
|
31
26
|
}
|
|
32
27
|
return [];
|
|
33
|
-
case ExportNamedDeclaration:
|
|
28
|
+
case AST_NODE_TYPES.ExportNamedDeclaration:
|
|
34
29
|
// "export" keyword is ignored, but a possible function declaration is transpiled.
|
|
35
|
-
if (node?.
|
|
30
|
+
if (node.declaration?.type === AST_NODE_TYPES.FunctionDeclaration &&
|
|
31
|
+
node.declaration.id?.type === AST_NODE_TYPES.Identifier) {
|
|
32
|
+
// Why is "as" needed here?
|
|
36
33
|
return parseTopLevelStatement(node.declaration);
|
|
37
34
|
}
|
|
38
35
|
else {
|
|
39
36
|
return [];
|
|
40
37
|
}
|
|
41
|
-
case TSInterfaceDeclaration:
|
|
42
|
-
case TSTypeAliasDeclaration:
|
|
43
|
-
case TSDeclareFunction:
|
|
38
|
+
case AST_NODE_TYPES.TSInterfaceDeclaration:
|
|
39
|
+
case AST_NODE_TYPES.TSTypeAliasDeclaration:
|
|
40
|
+
case AST_NODE_TYPES.TSDeclareFunction:
|
|
44
41
|
// Ignore "type", "interface" and "declare function" at the top-level
|
|
45
42
|
return [];
|
|
46
43
|
default:
|
|
47
|
-
throw new WorkflowSyntaxError(`Only function definitions, imports and type aliases allowed at the top level, encountered ${node
|
|
44
|
+
throw new WorkflowSyntaxError(`Only function definitions, imports and type aliases allowed at the top level, encountered ${node.type}`, node.loc);
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
47
|
function parseSubworkflows(node) {
|
|
51
|
-
assertType(node, FunctionDeclaration);
|
|
52
|
-
if (node.id.type !== Identifier) {
|
|
53
|
-
throw new WorkflowSyntaxError('Expected Identifier as a function name', node.id.loc);
|
|
54
|
-
}
|
|
55
48
|
const nodeParams = node.params;
|
|
56
49
|
const workflowParams = nodeParams.map((param) => {
|
|
57
50
|
switch (param.type) {
|
|
58
|
-
case Identifier:
|
|
51
|
+
case AST_NODE_TYPES.Identifier:
|
|
59
52
|
return { name: param.name };
|
|
60
|
-
case AssignmentPattern:
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
case AST_NODE_TYPES.AssignmentPattern:
|
|
54
|
+
if (param.left.type !== AST_NODE_TYPES.Identifier) {
|
|
55
|
+
throw new WorkflowSyntaxError('The default value must be an identifier', param.left.loc);
|
|
56
|
+
}
|
|
57
|
+
if (param.right.type !== AST_NODE_TYPES.Literal) {
|
|
63
58
|
throw new WorkflowSyntaxError('The default value must be a literal', param.right.loc);
|
|
64
59
|
}
|
|
60
|
+
if (!(typeof param.right.value === 'string' ||
|
|
61
|
+
typeof param.right.value === 'number' ||
|
|
62
|
+
typeof param.right.value === 'boolean' ||
|
|
63
|
+
param.right.value === null)) {
|
|
64
|
+
throw new WorkflowSyntaxError('The default value must be a string, number, boolean or null', param.left.loc);
|
|
65
|
+
}
|
|
65
66
|
return {
|
|
66
67
|
name: param.left.name,
|
|
67
68
|
default: param.right.value,
|
|
@@ -70,6 +71,6 @@ function parseSubworkflows(node) {
|
|
|
70
71
|
throw new WorkflowSyntaxError('Function parameter must be an identifier or an assignment', param.loc);
|
|
71
72
|
}
|
|
72
73
|
});
|
|
73
|
-
const steps =
|
|
74
|
+
const steps = parseStatement(node.body, {});
|
|
74
75
|
return new SubworkflowAST(node.id.name, steps, workflowParams);
|
|
75
76
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/typescript-estree';
|
|
1
2
|
import { StepName, WorkflowStepAST } from '../ast/steps.js';
|
|
2
3
|
export interface ParsingContext {
|
|
3
4
|
breakTarget?: StepName;
|
|
4
5
|
continueTarget?: StepName;
|
|
5
6
|
}
|
|
6
|
-
export declare function
|
|
7
|
+
export declare function parseStatement(node: TSESTree.Statement, ctx: ParsingContext, postSteps?: WorkflowStepAST[]): WorkflowStepAST[];
|
|
7
8
|
//# sourceMappingURL=statements.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../src/transpiler/statements.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../src/transpiler/statements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,QAAQ,EAAE,MAAM,sCAAsC,CAAA;AAC/E,OAAO,EASL,QAAQ,EAMR,eAAe,EAChB,MAAM,iBAAiB,CAAA;AA2BxB,MAAM,WAAW,cAAc;IAE7B,WAAW,CAAC,EAAE,QAAQ,CAAA;IAEtB,cAAc,CAAC,EAAE,QAAQ,CAAA;CAC1B;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,QAAQ,CAAC,SAAS,EACxB,GAAG,EAAE,cAAc,EACnB,SAAS,CAAC,EAAE,eAAe,EAAE,GAC5B,eAAe,EAAE,CAGnB"}
|