ts2workflows 0.7.0 → 0.9.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 +8 -2
- package/dist/ast/expressions.d.ts +9 -0
- package/dist/ast/expressions.d.ts.map +1 -1
- package/dist/ast/expressions.js +43 -19
- package/dist/ast/steps.d.ts +27 -7
- package/dist/ast/steps.d.ts.map +1 -1
- package/dist/ast/steps.js +104 -21
- package/dist/cli.js +85 -28
- package/dist/transpiler/expressions.d.ts +0 -1
- package/dist/transpiler/expressions.d.ts.map +1 -1
- package/dist/transpiler/expressions.js +52 -61
- package/dist/transpiler/index.d.ts +1 -1
- package/dist/transpiler/index.d.ts.map +1 -1
- package/dist/transpiler/index.js +16 -7
- package/dist/transpiler/statements.d.ts +4 -3
- package/dist/transpiler/statements.d.ts.map +1 -1
- package/dist/transpiler/statements.js +379 -103
- package/dist/transpiler/transformations.d.ts +0 -6
- package/dist/transpiler/transformations.d.ts.map +1 -1
- package/dist/transpiler/transformations.js +88 -148
- package/dist/utils.d.ts +1 -5
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +3 -16
- package/language_reference.md +120 -61
- package/package.json +9 -5
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
3
5
|
import { program } from 'commander';
|
|
4
6
|
import { transpile } from './transpiler/index.js';
|
|
5
7
|
import { WorkflowSyntaxError } from './errors.js';
|
|
@@ -7,11 +9,16 @@ import { TSError } from '@typescript-eslint/typescript-estree';
|
|
|
7
9
|
function parseArgs() {
|
|
8
10
|
program
|
|
9
11
|
.name('ts2workflow')
|
|
10
|
-
.version(
|
|
12
|
+
.version(versionFromPackageJson())
|
|
11
13
|
.description('Transpile a Typescript program into GCP Workflows YAML syntax.')
|
|
12
|
-
.
|
|
13
|
-
|
|
14
|
+
.option('--project <path>', 'Path to TSConfig for the Typescript sources files.')
|
|
15
|
+
.option('--outdir <path>', 'Specify an output directory for where transpilation result are written.')
|
|
16
|
+
.option('--generated-file-comment', 'Include a comment stating that the result is a generated file', true)
|
|
17
|
+
.option('--no-generated-file-comment', "Don't include a comment about file being generated")
|
|
18
|
+
.argument('[FILES...]', 'Path to source file(s) to compile. If not given, reads from stdin.')
|
|
19
|
+
.parse();
|
|
14
20
|
return {
|
|
21
|
+
...program.opts(),
|
|
15
22
|
sourceFiles: program.args,
|
|
16
23
|
};
|
|
17
24
|
}
|
|
@@ -25,32 +32,27 @@ function cliMain() {
|
|
|
25
32
|
files = args.sourceFiles;
|
|
26
33
|
}
|
|
27
34
|
files.forEach((inputFile) => {
|
|
28
|
-
const inp = inputFile === '-' ? process.stdin.fd : inputFile;
|
|
29
|
-
let sourceCode = '';
|
|
30
35
|
try {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
if (isIoError(err, 'ENOENT')) {
|
|
36
|
-
console.error(`Error: "${inp}" not found`);
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
39
|
-
else if (isIoError(err, 'EISDIR')) {
|
|
40
|
-
console.error(`Error: "${inp}" is a directory`);
|
|
36
|
+
const transpiled = generateTranspiledText(inputFile, args.generatedFileComment, args.project);
|
|
37
|
+
if (transpiled === undefined) {
|
|
41
38
|
process.exit(1);
|
|
42
39
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
writeOutput(transpiled, inputFile, args.outdir);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
if (isIoError(err)) {
|
|
44
|
+
let message;
|
|
45
|
+
if ('code' in err && err.code === 'EAGAIN' && inputFile === '-') {
|
|
46
|
+
// Reading from stdin if there's no input causes error. This is a bug in node
|
|
47
|
+
message = 'Error: Failed to read from stdin';
|
|
48
|
+
}
|
|
49
|
+
else if ('code' in err && err.code === 'EISDIR') {
|
|
50
|
+
message = `Error: "${inputFile}" is a directory`;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
message = err.message;
|
|
54
|
+
}
|
|
55
|
+
console.error(message);
|
|
54
56
|
process.exit(1);
|
|
55
57
|
}
|
|
56
58
|
else {
|
|
@@ -59,8 +61,56 @@ function cliMain() {
|
|
|
59
61
|
}
|
|
60
62
|
});
|
|
61
63
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
+
function generateTranspiledText(inputFile, addGeneratedFileComment, project) {
|
|
65
|
+
const inputIsStdIn = inputFile === '-';
|
|
66
|
+
const inp = inputIsStdIn ? process.stdin.fd : inputFile;
|
|
67
|
+
const sourceCode = fs.readFileSync(inp, 'utf8');
|
|
68
|
+
try {
|
|
69
|
+
const needsHeader = addGeneratedFileComment && !inputIsStdIn;
|
|
70
|
+
const header = needsHeader ? generatedFileComment(inputFile) : '';
|
|
71
|
+
const transpiled = transpile(sourceCode, inputFile, project);
|
|
72
|
+
return `${header}${transpiled}`;
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
if (err instanceof WorkflowSyntaxError) {
|
|
76
|
+
prettyPrintSyntaxError(err, inputFile, sourceCode);
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
else if (err instanceof TSError) {
|
|
80
|
+
prettyPrintSyntaxError(err, inputFile, sourceCode);
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function writeOutput(transpiled, inputFile, outdir) {
|
|
89
|
+
if (outdir !== undefined) {
|
|
90
|
+
if (!fs.existsSync(outdir)) {
|
|
91
|
+
fs.mkdirSync(outdir, { recursive: true });
|
|
92
|
+
}
|
|
93
|
+
const outputFile = createOutputFilename(inputFile, outdir);
|
|
94
|
+
fs.writeFileSync(outputFile, transpiled);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
process.stdout.write(transpiled);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function createOutputFilename(inputFile, outdir) {
|
|
101
|
+
const parsedInput = path.parse(inputFile);
|
|
102
|
+
return path.format({
|
|
103
|
+
dir: outdir,
|
|
104
|
+
name: parsedInput.name,
|
|
105
|
+
ext: '.yaml',
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function generatedFileComment(inputFile) {
|
|
109
|
+
return (`# This file has been generated by "ts2workflows ${inputFile}"\n` +
|
|
110
|
+
'# Do not edit!\n\n');
|
|
111
|
+
}
|
|
112
|
+
function isIoError(err) {
|
|
113
|
+
return err instanceof Error && 'code' in err;
|
|
64
114
|
}
|
|
65
115
|
function prettyPrintSyntaxError(exception, inputFile, sourceCode) {
|
|
66
116
|
console.error(errorDisplay(inputFile, sourceCode, exception.location));
|
|
@@ -108,6 +158,13 @@ function highlightedSourceCodeLine(sourceCode, lineNumber, start, end) {
|
|
|
108
158
|
const markerLine = `${' '.repeat(start)}${'^'.repeat(markerLength)}`;
|
|
109
159
|
return `${sourceLine}\n${markerLine}`;
|
|
110
160
|
}
|
|
161
|
+
function versionFromPackageJson() {
|
|
162
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
163
|
+
const currentDir = path.dirname(currentFile);
|
|
164
|
+
const packagePath = path.join(currentDir, '..', 'package.json');
|
|
165
|
+
const pjson = JSON.parse(fs.readFileSync(packagePath, 'utf-8'));
|
|
166
|
+
return pjson.version ?? '???';
|
|
167
|
+
}
|
|
111
168
|
if (import.meta.url.endsWith(process.argv[1]) ||
|
|
112
169
|
process.argv[1].endsWith('/ts2workflows')) {
|
|
113
170
|
cliMain();
|
|
@@ -7,5 +7,4 @@ export declare function convertMemberExpression(node: TSESTree.MemberExpression)
|
|
|
7
7
|
export declare function isMagicFunction(calleeName: string): boolean;
|
|
8
8
|
export declare function isMagicFunctionStatmentOnly(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 asExpression(x: Primitive | Expression): Expression;
|
|
11
10
|
//# sourceMappingURL=expressions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../../src/transpiler/expressions.ts"],"names":[],"mappings":"
|
|
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,EAGV,SAAS,EAOV,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,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAG3D;AAED,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAGvE;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"}
|
|
@@ -1,69 +1,26 @@
|
|
|
1
|
+
import * as R from 'ramda';
|
|
1
2
|
import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
|
|
2
|
-
import { BinaryExpression, FunctionInvocationExpression, MemberExpression, PrimitiveExpression, UnaryExpression, VariableReferenceExpression,
|
|
3
|
+
import { BinaryExpression, FunctionInvocationExpression, MemberExpression, PrimitiveExpression, UnaryExpression, VariableReferenceExpression, asExpression, isFullyQualifiedName, nullEx, } from '../ast/expressions.js';
|
|
3
4
|
import { InternalTranspilingError, WorkflowSyntaxError } from '../errors.js';
|
|
4
|
-
import { mapRecordValues } from '../utils.js';
|
|
5
5
|
export function convertExpression(instance) {
|
|
6
|
-
const expOrPrimitive = convertExpressionOrPrimitive(instance);
|
|
7
|
-
if (isExpression(expOrPrimitive)) {
|
|
8
|
-
return expOrPrimitive;
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
return new PrimitiveExpression(expOrPrimitive);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export function convertObjectExpression(node) {
|
|
15
|
-
return Object.fromEntries(throwIfSpread(node.properties).map(({ key, value }) => {
|
|
16
|
-
let keyPrimitive;
|
|
17
|
-
if (key.type === AST_NODE_TYPES.Identifier) {
|
|
18
|
-
keyPrimitive = key.name;
|
|
19
|
-
}
|
|
20
|
-
else if (key.type === AST_NODE_TYPES.Literal) {
|
|
21
|
-
if (typeof key.value === 'string') {
|
|
22
|
-
keyPrimitive = key.value;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
throw new WorkflowSyntaxError(`Map keys must be identifiers or strings, encountered: ${typeof key.value}`, key.loc);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
throw new WorkflowSyntaxError(`Not implemented object key type: ${key.type}`, key.loc);
|
|
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
|
-
return [keyPrimitive, convertExpressionOrPrimitive(value)];
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
export function convertObjectAsExpressionValues(node) {
|
|
39
|
-
// Convert Primitive values to PrimitiveExpressions
|
|
40
|
-
return mapRecordValues(convertObjectExpression(node), asExpression);
|
|
41
|
-
}
|
|
42
|
-
function convertExpressionOrPrimitive(instance) {
|
|
43
6
|
switch (instance.type) {
|
|
44
7
|
case AST_NODE_TYPES.ArrayExpression:
|
|
45
|
-
return convertArrayExpression(instance);
|
|
8
|
+
return asExpression(convertArrayExpression(instance));
|
|
46
9
|
case AST_NODE_TYPES.ObjectExpression:
|
|
47
|
-
return convertObjectExpression(instance);
|
|
10
|
+
return asExpression(convertObjectExpression(instance));
|
|
48
11
|
case AST_NODE_TYPES.Literal:
|
|
49
12
|
if (instance.value instanceof RegExp) {
|
|
50
13
|
throw new WorkflowSyntaxError('RegExp is not supported', instance.loc);
|
|
51
14
|
}
|
|
52
15
|
if (typeof instance.value === 'bigint') {
|
|
53
|
-
throw new WorkflowSyntaxError('BigInt
|
|
16
|
+
throw new WorkflowSyntaxError('BigInt is not supported', instance.loc);
|
|
54
17
|
}
|
|
55
|
-
return instance.value;
|
|
18
|
+
return new PrimitiveExpression(instance.value);
|
|
56
19
|
case AST_NODE_TYPES.TemplateLiteral:
|
|
57
20
|
return convertTemplateLiteralToExpression(instance);
|
|
58
21
|
case AST_NODE_TYPES.Identifier:
|
|
59
22
|
if (instance.name === 'null' || instance.name === 'undefined') {
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
else if (instance.name === 'True' || instance.name === 'TRUE') {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
else if (instance.name === 'False' || instance.name === 'FALSE') {
|
|
66
|
-
return false;
|
|
23
|
+
return nullEx;
|
|
67
24
|
}
|
|
68
25
|
else {
|
|
69
26
|
return new VariableReferenceExpression(instance.name);
|
|
@@ -82,22 +39,59 @@ function convertExpressionOrPrimitive(instance) {
|
|
|
82
39
|
case AST_NODE_TYPES.ConditionalExpression:
|
|
83
40
|
return convertConditionalExpression(instance);
|
|
84
41
|
case AST_NODE_TYPES.TSAsExpression:
|
|
85
|
-
return
|
|
42
|
+
return convertExpression(instance.expression);
|
|
86
43
|
case AST_NODE_TYPES.TSNonNullExpression:
|
|
87
|
-
return
|
|
44
|
+
return convertExpression(instance.expression);
|
|
88
45
|
case AST_NODE_TYPES.AwaitExpression:
|
|
89
|
-
return
|
|
46
|
+
return convertExpression(instance.argument);
|
|
47
|
+
case AST_NODE_TYPES.TSInstantiationExpression:
|
|
48
|
+
return convertExpression(instance.expression);
|
|
90
49
|
default:
|
|
91
50
|
throw new WorkflowSyntaxError(`Not implemented expression type: ${instance.type}`, instance.loc);
|
|
92
51
|
}
|
|
93
52
|
}
|
|
53
|
+
function convertExpressionOrPrimitive(instance) {
|
|
54
|
+
const ex = convertExpression(instance);
|
|
55
|
+
if (ex.expressionType === 'primitive') {
|
|
56
|
+
return ex.value;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return ex;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function convertObjectExpression(node) {
|
|
63
|
+
return Object.fromEntries(throwIfSpread(node.properties).map(({ key, value }) => {
|
|
64
|
+
let keyPrimitive;
|
|
65
|
+
if (key.type === AST_NODE_TYPES.Identifier) {
|
|
66
|
+
keyPrimitive = key.name;
|
|
67
|
+
}
|
|
68
|
+
else if (key.type === AST_NODE_TYPES.Literal) {
|
|
69
|
+
if (typeof key.value === 'string') {
|
|
70
|
+
keyPrimitive = key.value;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new WorkflowSyntaxError(`Map keys must be identifiers or strings, encountered: ${typeof key.value}`, key.loc);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
throw new WorkflowSyntaxError(`Not implemented object key type: ${key.type}`, key.loc);
|
|
78
|
+
}
|
|
79
|
+
if (value.type === AST_NODE_TYPES.AssignmentPattern ||
|
|
80
|
+
value.type === AST_NODE_TYPES.TSEmptyBodyFunctionExpression) {
|
|
81
|
+
throw new WorkflowSyntaxError('Value not supported', value.loc);
|
|
82
|
+
}
|
|
83
|
+
return [keyPrimitive, convertExpressionOrPrimitive(value)];
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
export function convertObjectAsExpressionValues(node) {
|
|
87
|
+
// Convert Primitive values to PrimitiveExpressions
|
|
88
|
+
return R.map(asExpression, convertObjectExpression(node));
|
|
89
|
+
}
|
|
94
90
|
function convertArrayExpression(instance) {
|
|
95
|
-
return throwIfSpread(instance.elements).map((e) => e === null
|
|
96
|
-
? new PrimitiveExpression(null)
|
|
97
|
-
: convertExpressionOrPrimitive(e));
|
|
91
|
+
return throwIfSpread(instance.elements).map((e) => e === null ? nullEx : convertExpressionOrPrimitive(e));
|
|
98
92
|
}
|
|
99
93
|
function convertBinaryExpression(instance) {
|
|
100
|
-
// Special case for nullish coalescing
|
|
94
|
+
// Special case for nullish coalescing because the result is a function call
|
|
101
95
|
// expression, not a binary expression
|
|
102
96
|
if (instance.operator === '??') {
|
|
103
97
|
return nullishCoalescingExpression(instance.left, instance.right);
|
|
@@ -187,7 +181,7 @@ function convertUnaryExpression(instance) {
|
|
|
187
181
|
}
|
|
188
182
|
}
|
|
189
183
|
function convertTypeOfExpression(value) {
|
|
190
|
-
// Note for future
|
|
184
|
+
// Note for future refactoring: evalute value only once (in case it has side effects)
|
|
191
185
|
return new FunctionInvocationExpression('text.replace_all_regex', [
|
|
192
186
|
new FunctionInvocationExpression('text.replace_all_regex', [
|
|
193
187
|
new FunctionInvocationExpression('get_type', [value]),
|
|
@@ -366,6 +360,3 @@ export function throwIfSpread(nodes) {
|
|
|
366
360
|
const argumentExpressions = nodes.filter((x) => x?.type !== AST_NODE_TYPES.SpreadElement);
|
|
367
361
|
return argumentExpressions;
|
|
368
362
|
}
|
|
369
|
-
export function asExpression(x) {
|
|
370
|
-
return isExpression(x) ? x : new PrimitiveExpression(x);
|
|
371
|
-
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function transpile(code: string): string;
|
|
1
|
+
export declare function transpile(code: string, inputFile?: string, tsconfigPath?: string): string;
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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":"AAcA,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,CAkBR"}
|
package/dist/transpiler/index.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AST_NODE_TYPES, parseAndGenerateServices, } from '@typescript-eslint/typescript-estree';
|
|
2
2
|
import * as YAML from 'yaml';
|
|
3
3
|
import { SubworkflowAST } from '../ast/steps.js';
|
|
4
4
|
import { WorkflowSyntaxError } from '../errors.js';
|
|
5
5
|
import { generateStepNames } from '../ast/stepnames.js';
|
|
6
6
|
import { parseStatement } from './statements.js';
|
|
7
|
-
|
|
7
|
+
import { transformAST } from './transformations.js';
|
|
8
|
+
export function transpile(code, inputFile, tsconfigPath) {
|
|
8
9
|
const parserOptions = {
|
|
9
10
|
jsDocParsingMode: 'none',
|
|
10
11
|
loc: true,
|
|
11
12
|
range: false,
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
+
if (tsconfigPath && inputFile && inputFile != '-') {
|
|
15
|
+
parserOptions.filePath = inputFile;
|
|
16
|
+
parserOptions.projectService = {
|
|
17
|
+
defaultProject: tsconfigPath,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const { ast } = parseAndGenerateServices(code, parserOptions);
|
|
14
21
|
const workflowAst = { subworkflows: ast.body.flatMap(parseTopLevelStatement) };
|
|
15
22
|
const workflow = generateStepNames(workflowAst);
|
|
16
23
|
return YAML.stringify(workflow.render(), { lineWidth: 100 });
|
|
@@ -45,8 +52,12 @@ function parseTopLevelStatement(node) {
|
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
function parseSubworkflows(node) {
|
|
48
|
-
const
|
|
49
|
-
const
|
|
55
|
+
const workflowParams = parseWorkflowParams(node.params);
|
|
56
|
+
const steps = transformAST(parseStatement(node.body, {}));
|
|
57
|
+
return new SubworkflowAST(node.id.name, steps, workflowParams);
|
|
58
|
+
}
|
|
59
|
+
function parseWorkflowParams(nodeParams) {
|
|
60
|
+
return nodeParams.map((param) => {
|
|
50
61
|
switch (param.type) {
|
|
51
62
|
case AST_NODE_TYPES.Identifier:
|
|
52
63
|
if (param.optional) {
|
|
@@ -61,8 +72,6 @@ function parseSubworkflows(node) {
|
|
|
61
72
|
throw new WorkflowSyntaxError('Function parameter must be an identifier or an assignment', param.loc);
|
|
62
73
|
}
|
|
63
74
|
});
|
|
64
|
-
const steps = parseStatement(node.body, {});
|
|
65
|
-
return new SubworkflowAST(node.id.name, steps, workflowParams);
|
|
66
75
|
}
|
|
67
76
|
function parseSubworkflowDefaultArgument(param) {
|
|
68
77
|
if (param.left.type !== AST_NODE_TYPES.Identifier) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/typescript-estree';
|
|
2
2
|
import { StepName, WorkflowStepAST } from '../ast/steps.js';
|
|
3
3
|
export interface ParsingContext {
|
|
4
|
-
breakTarget?: StepName;
|
|
5
|
-
continueTarget?: StepName;
|
|
4
|
+
readonly breakTarget?: StepName;
|
|
5
|
+
readonly continueTarget?: StepName;
|
|
6
|
+
readonly parallelNestingLevel?: number;
|
|
6
7
|
finalizerTargets?: StepName[];
|
|
7
8
|
}
|
|
8
|
-
export declare function parseStatement(node: TSESTree.Statement, ctx: ParsingContext
|
|
9
|
+
export declare function parseStatement(node: TSESTree.Statement, ctx: ParsingContext): WorkflowStepAST[];
|
|
9
10
|
//# 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":"AACA,OAAO,EAAkB,QAAQ,EAAE,MAAM,sCAAsC,CAAA;AAC/E,OAAO,EAWL,QAAQ,EAOR,eAAe,EAChB,MAAM,iBAAiB,CAAA;AAiCxB,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"}
|