@uipath/maestro-builder-sdk 6.120.19 → 6.120.20
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/dist/bpmn/bpmn-expr-check.d.ts +6 -0
- package/dist/bpmn/bpmn-expr-check.js +59 -245
- package/dist/bpmn/check.js +1 -86
- package/dist/bpmn/declared-vars.js +20 -0
- package/dist/bpmn/expr-fields.d.ts +106 -0
- package/dist/bpmn/expr-fields.js +321 -0
- package/dist/bpmn/script-js.d.ts +49 -0
- package/dist/bpmn/script-js.js +179 -0
- package/dist/core/expr-check.d.ts +7 -0
- package/dist/core/expr-check.js +14 -4
- package/package.json +2 -2
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
* A loop's item binds `iterator.<itemVar>`, and a script output writes `=result.…`
|
|
28
28
|
* — different namespaces, left alone (only `vars.` is the author's to get wrong).
|
|
29
29
|
* Variables are SCOPED: a sub-process sees the enclosing variables plus its own.
|
|
30
|
+
*
|
|
31
|
+
* WHICH fields carry an expression, and which names are in scope at each, is not decided
|
|
32
|
+
* here: `bpmnExpressionFields` (expr-fields.ts) yields every one, and a rule only judges
|
|
33
|
+
* what it is handed.
|
|
30
34
|
*/
|
|
31
35
|
import { type ExprDiagnostic } from '../core/expr-check.js';
|
|
32
36
|
import type { BuiltBpmn } from './bpmn-sdk.js';
|
|
@@ -36,6 +40,8 @@ export interface BpmnLocatedDiagnostic extends ExprDiagnostic {
|
|
|
36
40
|
where: string;
|
|
37
41
|
/** The id of the flow or element the expression is on. */
|
|
38
42
|
elementId?: string;
|
|
43
|
+
/** The field's path inside that element — see {@link BpmnExprField.path}. */
|
|
44
|
+
path?: string;
|
|
39
45
|
}
|
|
40
46
|
/** Every first-level expression problem in a built BPMN process, stamped with its location. */
|
|
41
47
|
export declare function checkBpmnExpressions(built: BuiltBpmn): BpmnLocatedDiagnostic[];
|
|
@@ -27,22 +27,26 @@
|
|
|
27
27
|
* A loop's item binds `iterator.<itemVar>`, and a script output writes `=result.…`
|
|
28
28
|
* — different namespaces, left alone (only `vars.` is the author's to get wrong).
|
|
29
29
|
* Variables are SCOPED: a sub-process sees the enclosing variables plus its own.
|
|
30
|
+
*
|
|
31
|
+
* WHICH fields carry an expression, and which names are in scope at each, is not decided
|
|
32
|
+
* here: `bpmnExpressionFields` (expr-fields.ts) yields every one, and a rule only judges
|
|
33
|
+
* what it is handed.
|
|
30
34
|
*/
|
|
31
|
-
import { checkExpression, extractRefs } from '../core/expr-check.js';
|
|
32
|
-
import {
|
|
35
|
+
import { checkExpression, checkRefs, extractRefs } from '../core/expr-check.js';
|
|
36
|
+
import { bpmnExpressionFields } from './expr-fields.js';
|
|
37
|
+
import { scriptVarReads } from './script-js.js';
|
|
33
38
|
import { CompileRefusal } from '../core/compile-refusal.js';
|
|
34
39
|
import { tsLiteral } from '../core/ts-literal.js';
|
|
35
|
-
import { isExpressionValue } from './expression-value.js';
|
|
36
40
|
const NOUN = 'variable';
|
|
37
41
|
const NAMESPACE = 'vars';
|
|
38
42
|
const BINDING_NOUN = 'binding';
|
|
39
43
|
const BINDING_NAMESPACE = 'bindings';
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
/** An `=`-expression field's findings. */
|
|
45
|
+
function checkExpr(f, out) {
|
|
46
|
+
const { text: expr, where, roots } = f;
|
|
43
47
|
for (const d of checkExpression(expr, { roots: roots.vars, noun: NOUN, namespace: NAMESPACE }))
|
|
44
48
|
out.push({ ...d, where });
|
|
45
|
-
argumentReads(expr,
|
|
49
|
+
argumentReads(extractRefs(expr, NAMESPACE), f, out);
|
|
46
50
|
for (const d of checkExpression(expr, { roots: roots.bindings, noun: BINDING_NOUN, namespace: BINDING_NAMESPACE }))
|
|
47
51
|
out.push({ ...d, where });
|
|
48
52
|
// A process variable is always read through the `vars` namespace. The bare
|
|
@@ -53,7 +57,9 @@ function checkExpr(expr, where, roots, out) {
|
|
|
53
57
|
// Keep this intentionally narrow (a single optionally-parenthesized name) so
|
|
54
58
|
// local declarations inside arbitrary `=js:` programs are not guessed at.
|
|
55
59
|
const bare = expr.match(/^\s*=(?:js:)?\s*\(?\s*([A-Za-z_$][\w$]*)\s*\)?\s*$/)?.[1];
|
|
56
|
-
|
|
60
|
+
// Not on an output row's source: that is read against the node's own result, where a
|
|
61
|
+
// bare name is a result field (a human task's `=category` answer), not a variable.
|
|
62
|
+
if (bare && !f.result && roots.varIds.has(bare)) {
|
|
57
63
|
out.push({
|
|
58
64
|
level: 'error',
|
|
59
65
|
code: 'EXPR_BARE_VAR_REF',
|
|
@@ -63,21 +69,43 @@ function checkExpr(expr, where, roots, out) {
|
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
72
|
+
* The `vars.<root>` reads in a script task's BODY, judged like an expression's
|
|
73
|
+
* (EXPR_UNDECLARED_REF). The platform runs the body with `vars` in scope, so a read of a
|
|
74
|
+
* name nothing declares is `undefined` at run time, exactly as it is in an expression.
|
|
75
|
+
*
|
|
76
|
+
* Read by parsing the JavaScript (`scriptVarReads`), never by scanning its text, so a
|
|
77
|
+
* `vars.` in a comment, a string or a property name is not taken for a read; a body that
|
|
78
|
+
* rebinds `vars`, asks `typeof vars.x`, or assigns the root itself is left alone. A body
|
|
79
|
+
* that does not parse is not judged. The bare-spelling rule does not apply: a bare name
|
|
80
|
+
* in a script is a JavaScript identifier, which SCRIPT_BARE_INPUT_REF (check.ts) owns.
|
|
81
|
+
*/
|
|
82
|
+
function checkScript(f, out) {
|
|
83
|
+
const reads = scriptVarReads(f.text);
|
|
84
|
+
if (!reads?.length)
|
|
85
|
+
return;
|
|
86
|
+
for (const d of checkRefs(reads, { roots: f.roots.vars, noun: NOUN, namespace: NAMESPACE }))
|
|
87
|
+
out.push({ ...d, where: f.where });
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Report each read of a process argument — see `BpmnRoots.args`. One finding per
|
|
91
|
+
* argument per field, naming the form that IS readable: the start-event mapping into a
|
|
92
|
+
* process variable for an input, the variable the end event maps from for an output.
|
|
93
|
+
* The element an argument is scoped to reads it freely: its mapping is the bridge.
|
|
94
|
+
*
|
|
95
|
+
* Expression fields only. What is known to reject the read is the canvas's expression
|
|
96
|
+
* resolution and `validate`; a script body is JavaScript in the code editor, and
|
|
97
|
+
* `validate` says nothing about a `vars.<input>` read there, so it is not reported.
|
|
70
98
|
*/
|
|
71
|
-
function argumentReads(
|
|
72
|
-
if (!roots.args.size)
|
|
99
|
+
function argumentReads(refs, f, out) {
|
|
100
|
+
if (!f.roots.args.size)
|
|
73
101
|
return;
|
|
74
102
|
const seen = new Set();
|
|
75
|
-
for (const ref of
|
|
76
|
-
const arg = roots.args.get(ref.root);
|
|
77
|
-
if (!arg || seen.has(arg.decl.id))
|
|
103
|
+
for (const ref of refs) {
|
|
104
|
+
const arg = f.roots.args.get(ref.root);
|
|
105
|
+
if (!arg || arg.scope === f.elementId || seen.has(arg.decl.id))
|
|
78
106
|
continue;
|
|
79
107
|
seen.add(arg.decl.id);
|
|
80
|
-
out.push({ level: 'error', code: 'EXPR_ARGUMENT_REF', message: argumentMessage(ref.root, arg), where });
|
|
108
|
+
out.push({ level: 'error', code: 'EXPR_ARGUMENT_REF', message: argumentMessage(ref.root, arg), where: f.where });
|
|
81
109
|
}
|
|
82
110
|
}
|
|
83
111
|
function argumentMessage(root, { decl, scope }) {
|
|
@@ -85,248 +113,34 @@ function argumentMessage(root, { decl, scope }) {
|
|
|
85
113
|
if (decl.direction === 'output') {
|
|
86
114
|
return (`\`vars.${root}\` reads process output \`${decl.id}\`, which is scoped to \`${scope}\` and only ` +
|
|
87
115
|
`written by its mapping: Studio Web reports "A variable is unresolved" on a read of it, and ` +
|
|
88
|
-
`\`validate\` reports VARIABLE_DOES_NOT_EXIST. Compute the value into a \`.var()\`, read that variable here, ` +
|
|
116
|
+
`\`validate\` reports VARIABLE_DOES_NOT_EXIST where it checks the read. Compute the value into a \`.var()\`, read that variable here, ` +
|
|
89
117
|
`and map it onto \`${decl.id}\` in \`${scope}\`'s payload.`);
|
|
90
118
|
}
|
|
91
119
|
const local = `${decl.id}In`;
|
|
92
120
|
return (`\`vars.${root}\` reads process input \`${decl.id}\`, which is scoped to \`${scope}\`: Studio Web ` +
|
|
93
121
|
`reports "A variable is unresolved" on a read of it from any other element, and \`validate\` reports ` +
|
|
94
|
-
`VARIABLE_NOT_SET (the engine runs it; the designer does not accept it). Map it, as the canvas ` +
|
|
122
|
+
`VARIABLE_NOT_SET where it checks the read (the engine runs it; the designer does not accept it). Map it, as the canvas ` +
|
|
95
123
|
`does, into a variable scoped to that start event and read the variable: ` +
|
|
96
124
|
`\`.var(${tsLiteral(local)}, ${tsLiteral(type)}, { elementId: ${tsLiteral(scope)} })\` and ` +
|
|
97
125
|
`\`.startEvent(${tsLiteral(scope)}, { payload: { type: ` +
|
|
98
126
|
`'BPMN.Variables', outputRows: [{ name: ${tsLiteral(decl.name)}, type: ${tsLiteral(type)}, ` +
|
|
99
127
|
`source: ${tsLiteral(`=vars.${decl.id}`)}, var: ${tsLiteral(local)} }] } })\`, then read \`=vars.${local}\`.`);
|
|
100
128
|
}
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
* A string is an expression only when `isExpressionValue` says so, the same rule
|
|
108
|
-
* `serialize` applies; literal text is not a read. `.task({ set })` and a script task's
|
|
109
|
-
* `inputs`: `set: { label: 'vars.amount' }` assigns the text "vars.amount".
|
|
110
|
-
*/
|
|
111
|
-
FieldValues[FieldValues["LiteralOrExpression"] = 1] = "LiteralOrExpression";
|
|
112
|
-
})(FieldValues || (FieldValues = {}));
|
|
113
|
-
/**
|
|
114
|
-
* Check every expression VALUE of a `field → value` map (keys are targets), as `kind` says.
|
|
115
|
-
*
|
|
116
|
-
* A value need not be a string. A script task's `inputs` are the keys of its `args`
|
|
117
|
-
* JSON body, and the designer nests objects there (`{"args":{"name":"=vars.x"}}`), so
|
|
118
|
-
* a nested value is walked for the `=`-strings inside it, as a connector's inputs are.
|
|
119
|
-
* Handing it to `checkExpr` as if it were a string is what crashed `build()` with
|
|
120
|
-
* `expr.replace is not a function` on six deployed processes.
|
|
121
|
-
*/
|
|
122
|
-
function checkExprValues(rec, where, roots, out, kind) {
|
|
123
|
-
for (const v of Object.values(rec ?? {})) {
|
|
124
|
-
if (typeof v === 'string') {
|
|
125
|
-
if (kind === FieldValues.Expressions || isExpressionValue(v))
|
|
126
|
-
checkExpr(v, where, roots, out);
|
|
127
|
-
}
|
|
128
|
-
else
|
|
129
|
-
deepExprStrings(v, where, roots, out);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/** Reach `=`-expression strings anywhere in a connector's (possibly nested) inputs. */
|
|
133
|
-
function deepExprStrings(val, where, roots, out) {
|
|
134
|
-
if (typeof val === 'string') {
|
|
135
|
-
if (isExpressionValue(val))
|
|
136
|
-
checkExpr(val, where, roots, out);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
if (Array.isArray(val)) {
|
|
140
|
-
for (const v of val)
|
|
141
|
-
deepExprStrings(v, where, roots, out);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
if (val && typeof val === 'object') {
|
|
145
|
-
for (const v of Object.values(val))
|
|
146
|
-
deepExprStrings(v, where, roots, out);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function walk(nodes, flows, rootsIn, out) {
|
|
150
|
-
// A node's output `var` IS a variable declaration to the platform (its canvas
|
|
151
|
-
// model keys a variable off each output's `var`), so a downstream read of one
|
|
152
|
-
// resolves without any `uipath:variables` entry — a connector's response, a
|
|
153
|
-
// script task's output, a variable task's assignment target. Collect them for
|
|
154
|
-
// the WHOLE scope before walking: a flow condition is checked first but may
|
|
155
|
-
// read a node declared later in authoring order.
|
|
156
|
-
const roots = { ...rootsIn, vars: new Set(rootsIn.vars), args: new Map(rootsIn.args) };
|
|
157
|
-
for (const n of nodes)
|
|
158
|
-
for (const name of nodeDeclaredVars(n)) {
|
|
159
|
-
roots.vars.add(name);
|
|
160
|
-
// A node writing that name makes it readable, whatever else declares it.
|
|
161
|
-
roots.args.delete(name);
|
|
162
|
-
}
|
|
163
|
-
for (const f of flows) {
|
|
164
|
-
const found = [];
|
|
165
|
-
checkExpr(f.condition, `flow "${f.id}" condition`, roots, found);
|
|
166
|
-
for (const d of found)
|
|
167
|
-
out.push({ ...d, elementId: f.id });
|
|
168
|
-
}
|
|
169
|
-
for (const n of nodes) {
|
|
170
|
-
walkNode(n, roots, out);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
/** The expressions on one node, each finding stamped with its id; a sub-process recurses into its own scope. */
|
|
174
|
-
function walkNode(n, roots, located) {
|
|
175
|
-
const at = `${n.kind} "${n.id}"`;
|
|
176
|
-
const out = [];
|
|
177
|
-
const flush = () => {
|
|
178
|
-
for (const d of out.splice(0))
|
|
179
|
-
located.push({ ...d, elementId: n.id });
|
|
180
|
-
};
|
|
181
|
-
{
|
|
182
|
-
// An errorMapping row's `condition` is an expression on EVERY activity kind, so
|
|
183
|
-
// it is checked before the per-kind arms rather than inside them. Worth checking
|
|
184
|
-
// here specifically because the CANVAS treats an undeclared reference in it as a
|
|
185
|
-
// blocking error while `uip maestro bpmn validate` says nothing at all — so
|
|
186
|
-
// without this the author's first sign of trouble is the designer refusing the
|
|
187
|
-
// artifact, long after every gate this repo runs went green.
|
|
188
|
-
// Events carry no errorMapping — the field exists on the activity arms only.
|
|
189
|
-
//
|
|
190
|
-
// `error` is a BUILT-IN root here, not an author declaration. The skill's
|
|
191
|
-
// expression reference says so outright — "Error mapping conditions may inspect the
|
|
192
|
-
// built-in error object through `vars.error`, for example
|
|
193
|
-
// `=vars.error.code == \"SERVICE_UNAVAILABLE\"`" — and that example is the whole
|
|
194
|
-
// point of the scenario: a row exists to classify a failure, so the only thing worth
|
|
195
|
-
// branching on is the failure. Requiring `.var('error', …)` first forced authors to
|
|
196
|
-
// declare a DECOY variable whose only purpose was to quiet this check, and which then
|
|
197
|
-
// shipped as a real `uipath:inputOutput` row in the artifact.
|
|
198
|
-
//
|
|
199
|
-
// Scoped to this one expression slot rather than added to the shared root set: outside
|
|
200
|
-
// an errorMapping condition there is no error object in scope, so `vars.error` there
|
|
201
|
-
// really is an undeclared reference and should still be reported.
|
|
202
|
-
// `error` joins `vars` (so `vars.error` resolves) but NOT `varIds`: it is a
|
|
203
|
-
// scoped runtime binding, not a declared variable, so `=error` is not a bare
|
|
204
|
-
// spelling of one.
|
|
205
|
-
const errRoots = { ...roots, vars: new Set(roots.vars).add('error') };
|
|
206
|
-
for (const row of ('errorMapping' in n ? n.errorMapping : undefined) ?? []) {
|
|
207
|
-
checkExpr(row.condition, `${at} errorMapping "${row.code}" condition`, errRoots, out);
|
|
208
|
-
}
|
|
209
|
-
// A loop's collection and completion condition, on every activity kind EXCEPT the
|
|
210
|
-
// sub-process, which checks its own below in the right scopes. Only that arm used to
|
|
211
|
-
// check them, so a `.scriptTask({ loop })` — the commonest looping shape — had
|
|
212
|
-
// neither expression checked. It matters more now the engine HONOURS the completion
|
|
213
|
-
// condition: an unevaluatable one is swallowed there and the loop runs the whole
|
|
214
|
-
// collection, so this is the gate that reports it.
|
|
215
|
-
if (n.kind !== 'subProcess' && 'loop' in n && n.loop !== undefined) {
|
|
216
|
-
checkExpr(n.loop.collection, `${at} loop collection`, roots, out);
|
|
217
|
-
// The iterator bindings (`iterator.item`, `iterator.<itemVar>`) are the loop's
|
|
218
|
-
// own, not author declarations, so a completion condition may read them.
|
|
219
|
-
const loopRoots = { ...roots, vars: new Set(roots.vars).add('iterator') };
|
|
220
|
-
checkExpr(n.loop.completion, `${at} loop completion`, loopRoots, out);
|
|
221
|
-
}
|
|
222
|
-
if (n.kind === 'scriptTask') {
|
|
223
|
-
checkExprValues(n.inputs, `${at} input`, roots, out, FieldValues.LiteralOrExpression);
|
|
224
|
-
checkExprValues(n.outputs, `${at} output`, roots, out, FieldValues.Expressions);
|
|
225
|
-
}
|
|
226
|
-
else if (n.kind === 'task') {
|
|
227
|
-
checkExprValues(n.set, `${at} assignment`, roots, out, FieldValues.LiteralOrExpression);
|
|
228
|
-
}
|
|
229
|
-
else if (n.kind === 'connector') {
|
|
230
|
-
deepExprStrings(n.inputs, `${at} input`, roots, out);
|
|
231
|
-
}
|
|
232
|
-
else if (n.kind === 'subProcess') {
|
|
233
|
-
// A sub-process is its own variable scope: it sees the enclosing variables
|
|
234
|
-
// plus the ones it declares. The loop COLLECTION is evaluated in the
|
|
235
|
-
// enclosing scope (before entry); the body and completion see the sub-scope.
|
|
236
|
-
checkExpr(n.loop?.collection, `${at} loop collection`, roots, out);
|
|
237
|
-
// Only the process's own arguments are reported: a sub-process's declarations,
|
|
238
|
-
// whatever their direction, are left to the platform's own scoping.
|
|
239
|
-
const subRoots = { ...roots, vars: new Set(roots.vars), varIds: new Set(roots.varIds), args: new Map(roots.args) };
|
|
240
|
-
// By ID as well as display name, exactly as the root scope below: an expression
|
|
241
|
-
// reads `vars.<id>`. This added the name alone, so a sub-process variable whose
|
|
242
|
-
// display name differed from its id — every `errorVar`, displayed as `Error` —
|
|
243
|
-
// was unreadable inside the very scope that declares it.
|
|
244
|
-
for (const v of n.variables) {
|
|
245
|
-
subRoots.vars.add(v.id);
|
|
246
|
-
subRoots.vars.add(v.name);
|
|
247
|
-
subRoots.varIds.add(v.id);
|
|
248
|
-
subRoots.args.delete(v.id);
|
|
249
|
-
subRoots.args.delete(v.name);
|
|
250
|
-
}
|
|
251
|
-
checkExpr(n.loop?.completion, `${at} loop completion`, subRoots, out);
|
|
252
|
-
flush();
|
|
253
|
-
walk(n.nodes, n.flows, subRoots, located);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
flush();
|
|
129
|
+
/** Every finding on one field. */
|
|
130
|
+
function checkField(f, out) {
|
|
131
|
+
if (f.form === 'script')
|
|
132
|
+
checkScript(f, out);
|
|
133
|
+
else
|
|
134
|
+
checkExpr(f, out);
|
|
257
135
|
}
|
|
258
136
|
/** Every first-level expression problem in a built BPMN process, stamped with its location. */
|
|
259
137
|
export function checkBpmnExpressions(built) {
|
|
260
|
-
const roots = {
|
|
261
|
-
// Keyed by ID, which is what an expression reads — `BpmnVarDecl.id` is documented as
|
|
262
|
-
// "what expressions read as `vars.<id>`", and every product-shaped artifact agrees:
|
|
263
|
-
// the fixtures under skills `edit/*/fixture` declare
|
|
264
|
-
// `<uipath:inputOutput id="Var_OrderId" name="OrderId">` and reference
|
|
265
|
-
// `=vars.Var_OrderId`, never the display name.
|
|
266
|
-
//
|
|
267
|
-
// This read `v.name`, so a variable given a friendly name became unreferenceable: the
|
|
268
|
-
// id an expression uses was not in the root set and every reference to it failed
|
|
269
|
-
// EXPR_UNDECLARED_REF. It only looked right because `.var()` defaults `name` to the id,
|
|
270
|
-
// so the bug was invisible until a display name differed — which is exactly what
|
|
271
|
-
// `bpmn-decompile` produces from any real artifact, so it blocked the whole
|
|
272
|
-
// decompile-edit-recompile round trip.
|
|
273
|
-
//
|
|
274
|
-
// The display name is accepted too. It is not what the wire uses, but an author who
|
|
275
|
-
// wrote `vars.<displayName>` in an existing process should get the reference resolved
|
|
276
|
-
// rather than a spurious error from a stricter check.
|
|
277
|
-
vars: new Set(built.variables.flatMap((v) => [v.id, v.name])),
|
|
278
|
-
varIds: new Set(built.variables.map((v) => v.id)),
|
|
279
|
-
// Author-declared bindings, plus the symbolic connection/folder names a
|
|
280
|
-
// connector turns into bindings at serialize time — the author's own spelling
|
|
281
|
-
// is what they would reference, so both are legitimate roots.
|
|
282
|
-
bindings: new Set([...built.bindings.map((b) => b.id), ...connectorBindingNames(built.nodes)]),
|
|
283
|
-
args: processArguments(built),
|
|
284
|
-
};
|
|
285
138
|
const out = [];
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
*
|
|
292
|
-
* An argument is one only where it is SCOPED TO AN ELEMENT: its `elementId`, or the
|
|
293
|
-
* element `publicDeclarationScope` writes for it (the manual start event for an input,
|
|
294
|
-
* the end event that writes an output). One scoped to the process itself is root state
|
|
295
|
-
* to `validate`, which counts every declaration whose `elementId` is the process as
|
|
296
|
-
* available everywhere, so it is left alone, as is one written with no `elementId` at
|
|
297
|
-
* all (`null`, a legacy import), which `validate` already reports as missing.
|
|
298
|
-
*
|
|
299
|
-
* Keyed by id and by display name, as `vars` is. A spelling an internal variable
|
|
300
|
-
* shares is left out: the canvas resolves the reference to that variable.
|
|
301
|
-
*/
|
|
302
|
-
function processArguments(built) {
|
|
303
|
-
const scopeOf = publicDeclarationScope(built.nodes, built.id);
|
|
304
|
-
const readable = new Set(built.variables.filter((v) => v.direction === 'inputOutput').flatMap((v) => [v.id, v.name]));
|
|
305
|
-
const args = new Map();
|
|
306
|
-
for (const v of built.variables) {
|
|
307
|
-
if (v.direction === 'inputOutput' || v.elementId === null)
|
|
308
|
-
continue;
|
|
309
|
-
const scope = v.elementId ?? scopeOf(v);
|
|
310
|
-
if (scope === built.id)
|
|
311
|
-
continue;
|
|
312
|
-
for (const key of [v.id, v.name])
|
|
313
|
-
if (!readable.has(key) && !args.has(key))
|
|
314
|
-
args.set(key, { decl: v, scope });
|
|
315
|
-
}
|
|
316
|
-
return args;
|
|
317
|
-
}
|
|
318
|
-
/** Every symbolic connection/folder name in a graph, at any nesting depth. */
|
|
319
|
-
function connectorBindingNames(nodes) {
|
|
320
|
-
const out = [];
|
|
321
|
-
for (const n of nodes) {
|
|
322
|
-
if (n.kind === 'connector') {
|
|
323
|
-
if (n.connection)
|
|
324
|
-
out.push(n.connection);
|
|
325
|
-
if (n.folder)
|
|
326
|
-
out.push(n.folder);
|
|
327
|
-
}
|
|
328
|
-
if (n.kind === 'subProcess')
|
|
329
|
-
out.push(...connectorBindingNames(n.nodes));
|
|
139
|
+
for (const f of bpmnExpressionFields(built)) {
|
|
140
|
+
const found = [];
|
|
141
|
+
checkField(f, found);
|
|
142
|
+
for (const d of found)
|
|
143
|
+
out.push({ ...d, elementId: f.elementId, path: f.path });
|
|
330
144
|
}
|
|
331
145
|
return out;
|
|
332
146
|
}
|
package/dist/bpmn/check.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* platform rule it corresponds to and how the two differ.
|
|
17
17
|
*/
|
|
18
18
|
import { parse } from 'acorn';
|
|
19
|
+
import { jsChildren, memberName, scopeBinds } from './script-js.js';
|
|
19
20
|
import { checkBpmnExpressions } from './bpmn-expr-check.js';
|
|
20
21
|
import { allNodes, collectSerializerModel, folderCompanionKeys, implicitNodeVars, processId } from './serialize.js';
|
|
21
22
|
import { refreshConnectionDiagnostics } from './refresh-connections.js';
|
|
@@ -1115,92 +1116,6 @@ function readsBareIdentifier(script, name) {
|
|
|
1115
1116
|
}
|
|
1116
1117
|
/** The `result` members a v2+ output may read directly: the wrapper, and the error slot. */
|
|
1117
1118
|
const RESULT_MEMBERS = new Set(['response', 'Error']);
|
|
1118
|
-
const isJsNode = (v) => typeof v === 'object' && v !== null && typeof v.type === 'string';
|
|
1119
|
-
/** The child nodes of `node`, in source order. */
|
|
1120
|
-
function jsChildren(node) {
|
|
1121
|
-
const out = [];
|
|
1122
|
-
for (const [field, v] of Object.entries(node)) {
|
|
1123
|
-
if (field === 'type' || field === 'start' || field === 'end')
|
|
1124
|
-
continue;
|
|
1125
|
-
if (Array.isArray(v))
|
|
1126
|
-
for (const item of v) {
|
|
1127
|
-
if (isJsNode(item))
|
|
1128
|
-
out.push(item);
|
|
1129
|
-
}
|
|
1130
|
-
else if (isJsNode(v))
|
|
1131
|
-
out.push(v);
|
|
1132
|
-
}
|
|
1133
|
-
return out;
|
|
1134
|
-
}
|
|
1135
|
-
/** Whether a binding pattern (`result`, `{ a: result }`, `[result = 1]`, `...result`) declares `name`. */
|
|
1136
|
-
function patternBinds(p, name) {
|
|
1137
|
-
switch (p.type) {
|
|
1138
|
-
case 'Identifier': return p.name === name;
|
|
1139
|
-
case 'AssignmentPattern': return patternBinds(p.left, name);
|
|
1140
|
-
case 'RestElement': return patternBinds(p.argument, name);
|
|
1141
|
-
case 'ArrayPattern': return p.elements.some((e) => e !== null && patternBinds(e, name));
|
|
1142
|
-
// A pattern's computed key or default value is an expression, not a binding.
|
|
1143
|
-
case 'ObjectPattern': return p.properties.some((pr) => patternBinds(pr.type === 'RestElement' ? pr : pr.value, name));
|
|
1144
|
-
default: return false;
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
const isFunction = (n) => /Function/.test(n.type);
|
|
1148
|
-
/** Whether a `let`/`const`/`var` declaration of the given kinds declares `name`. */
|
|
1149
|
-
function declarationBinds(n, name, kinds) {
|
|
1150
|
-
return isJsNode(n) && n.type === 'VariableDeclaration' && kinds(n.kind)
|
|
1151
|
-
&& n.declarations.some((d) => patternBinds(d.id, name));
|
|
1152
|
-
}
|
|
1153
|
-
/** Whether these statements, at the top of one block, declare `name` block-scoped: `let`, `const`, `class` or a function declaration. */
|
|
1154
|
-
function lexicallyBinds(statements, name) {
|
|
1155
|
-
return statements.some((s) => declarationBinds(s, name, (k) => k !== 'var')
|
|
1156
|
-
|| ((s.type === 'ClassDeclaration' || s.type === 'FunctionDeclaration') && isJsNode(s.id) && s.id.name === name));
|
|
1157
|
-
}
|
|
1158
|
-
/** Whether a `var` under `node` declares `name` in the function `node` belongs to: nested functions and static blocks are their own `var` scope and are not walked. */
|
|
1159
|
-
function varBinds(node, name) {
|
|
1160
|
-
if (declarationBinds(node, name, (k) => k === 'var'))
|
|
1161
|
-
return true;
|
|
1162
|
-
return jsChildren(node).some((c) => !isFunction(c) && c.type !== 'StaticBlock' && varBinds(c, name));
|
|
1163
|
-
}
|
|
1164
|
-
/**
|
|
1165
|
-
* Whether `node` opens a scope that declares `name`, so every `name` inside it is that
|
|
1166
|
-
* binding, not the outer one. A function: its own name (an expression's), a parameter,
|
|
1167
|
-
* a `var` anywhere in its body outside a nested function, or a block-scoped declaration
|
|
1168
|
-
* at the top of its body. A block, a `switch`, a `for` head or a `catch` parameter: the
|
|
1169
|
-
* declarations scoped to it. A declaration in a nested function shadows only inside that
|
|
1170
|
-
* function, so it is found when the walk reaches that function, never from outside.
|
|
1171
|
-
*/
|
|
1172
|
-
function scopeBinds(node, name) {
|
|
1173
|
-
if (isFunction(node)) {
|
|
1174
|
-
if (node.type === 'FunctionExpression' && isJsNode(node.id) && node.id.name === name)
|
|
1175
|
-
return true;
|
|
1176
|
-
if (node.params.some((p) => patternBinds(p, name)))
|
|
1177
|
-
return true;
|
|
1178
|
-
const body = node.body;
|
|
1179
|
-
return body.type === 'BlockStatement' && (varBinds(body, name) || lexicallyBinds(body.body, name));
|
|
1180
|
-
}
|
|
1181
|
-
switch (node.type) {
|
|
1182
|
-
case 'BlockStatement': return lexicallyBinds(node.body, name);
|
|
1183
|
-
case 'StaticBlock': return varBinds(node, name) || lexicallyBinds(node.body, name);
|
|
1184
|
-
case 'SwitchStatement': return lexicallyBinds(node.cases.flatMap((c) => c.consequent), name);
|
|
1185
|
-
case 'CatchClause': return isJsNode(node.param) && patternBinds(node.param, name);
|
|
1186
|
-
case 'ForStatement': return declarationBinds(node.init, name, (k) => k !== 'var');
|
|
1187
|
-
case 'ForInStatement':
|
|
1188
|
-
case 'ForOfStatement': return declarationBinds(node.left, name, (k) => k !== 'var');
|
|
1189
|
-
case 'ClassExpression':
|
|
1190
|
-
case 'ClassDeclaration': return isJsNode(node.id) && node.id.name === name;
|
|
1191
|
-
default: return false;
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
/** The string a member selector names: `.response`, `['response']`, `` [`response`] ``; `undefined` for any other. */
|
|
1195
|
-
function memberName(member) {
|
|
1196
|
-
const prop = member.property;
|
|
1197
|
-
if (!member.computed)
|
|
1198
|
-
return prop.type === 'Identifier' ? prop.name : undefined;
|
|
1199
|
-
if (prop.type === 'Literal')
|
|
1200
|
-
return typeof prop.value === 'string' ? prop.value : undefined;
|
|
1201
|
-
const quasis = prop.quasis;
|
|
1202
|
-
return prop.type === 'TemplateLiteral' && quasis?.length === 1 ? quasis[0].value.cooked : undefined;
|
|
1203
|
-
}
|
|
1204
1119
|
/**
|
|
1205
1120
|
* Where `code` reads the variable `result` other than through `result.response` or
|
|
1206
1121
|
* `result.Error`: the span of each such identifier, in source order, and whether it is an object
|
|
@@ -54,6 +54,26 @@ export function typedNodeDeclaredVars(n) {
|
|
|
54
54
|
* @internal
|
|
55
55
|
*/
|
|
56
56
|
export function nodeDeclaredVars(n) {
|
|
57
|
+
return [...ownDeclaredVars(n), ...payloadDeclaredVars(n)];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The variables a node's decorating PAYLOAD writes: each `uipath:output` row's `var`, as
|
|
61
|
+
* on any other node. A start event's `BPMN.Variables` mapping copies an input into a
|
|
62
|
+
* process variable this way, a message start event lands the message in one, and a
|
|
63
|
+
* sub-process's mapping hoists its result into the enclosing scope (`var="fetch.output"`,
|
|
64
|
+
* the shape the Flow converter emits for every HTTP, connector and loop node).
|
|
65
|
+
*/
|
|
66
|
+
function payloadDeclaredVars(n) {
|
|
67
|
+
const payload = 'payload' in n ? n.payload : undefined;
|
|
68
|
+
return (payload?.outputRows ?? []).map((r) => r.var).filter((v) => v !== undefined);
|
|
69
|
+
}
|
|
70
|
+
function ownDeclaredVars(n) {
|
|
71
|
+
// A trigger's payload row writes a variable like any typed node's; serialize declares it
|
|
72
|
+
// (`implicitNodeVars`), so a read of it resolves.
|
|
73
|
+
if (n.kind === 'startEvent' && n.trigger) {
|
|
74
|
+
const v = typedNodeOutputVar(n.id, n.trigger.type, n.trigger.outputVar);
|
|
75
|
+
return v ? [v] : [];
|
|
76
|
+
}
|
|
57
77
|
if (n.kind === 'connector') {
|
|
58
78
|
const { response, error } = connectorOutputVars(n);
|
|
59
79
|
return [response, error, ...Object.keys(n.outputs ?? {})];
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bpmn/expr-fields — every expression-bearing field of a built BPMN process, in one walk.
|
|
3
|
+
*
|
|
4
|
+
* The expression rules (`bpmn-expr-check.ts`) judge what this yields. Each field carries
|
|
5
|
+
* its element id, its path in the built model, and the names in scope where it is
|
|
6
|
+
* evaluated ({@link BpmnExprField}).
|
|
7
|
+
*
|
|
8
|
+
* The walk reads every value of a node, at any depth, and yields each `=`-string. Keys
|
|
9
|
+
* that change that are named here:
|
|
10
|
+
*
|
|
11
|
+
* - keys evaluated in a different scope (`errorMapping`, `loop`, a sub-process's own
|
|
12
|
+
* graph) get their own roots;
|
|
13
|
+
* - a script body is JavaScript, yielded as a `script` field;
|
|
14
|
+
* - {@link LITERAL} keys are written to slots the runtime does not evaluate (a display
|
|
15
|
+
* name, an id, a type tag, a JSON schema), so an `=` there is text;
|
|
16
|
+
* - under {@link DATA} keys the value is the author's data, and every string is read.
|
|
17
|
+
*
|
|
18
|
+
* `tests/bpmn-expr-fields.test.ts` derives the same split from the serializer's output:
|
|
19
|
+
* a field is yielded exactly when the emitted XML evaluates it.
|
|
20
|
+
*/
|
|
21
|
+
import type { BuiltBpmn, BpmnVarDecl } from './bpmn-sdk.js';
|
|
22
|
+
/**
|
|
23
|
+
* The names an expression may read where it is evaluated: the closed namespaces an
|
|
24
|
+
* author declares (`vars.`, `bindings.`).
|
|
25
|
+
*/
|
|
26
|
+
export interface BpmnRoots {
|
|
27
|
+
/**
|
|
28
|
+
* Every readable `vars.<root>`: declared variables by id AND display name, node outputs
|
|
29
|
+
* in scope, and the scoped pseudo-roots a slot adds (`error` in an errorMapping
|
|
30
|
+
* condition, `iterator` in a loop completion).
|
|
31
|
+
*/
|
|
32
|
+
vars: Set<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Declared variable IDS only — no display names, and none of the scoped pseudo-roots
|
|
35
|
+
* (`error`, `iterator`) that `vars` picks up inside a handler or a loop.
|
|
36
|
+
*
|
|
37
|
+
* `vars` is deliberately lenient: it accepts a display name so an author who wrote
|
|
38
|
+
* `vars.<displayName>` gets the reference resolved. That leniency is right for "is this
|
|
39
|
+
* reference declared?" and wrong for "is this a declared variable spelled WITHOUT its
|
|
40
|
+
* namespace?", because a display name is not a spelling of anything — nothing reads
|
|
41
|
+
* `vars.<name>` on the wire.
|
|
42
|
+
*
|
|
43
|
+
* The product writes `source="=Error"` on the error payload of every boundary event,
|
|
44
|
+
* and a variable whose display name is `Error` is exactly what it binds it to. Sharing
|
|
45
|
+
* one set made that pair report `EXPR_BARE_VAR_REF` and refuse to build, on markup the
|
|
46
|
+
* product itself emits.
|
|
47
|
+
*/
|
|
48
|
+
varIds: Set<string>;
|
|
49
|
+
bindings: Set<string>;
|
|
50
|
+
/**
|
|
51
|
+
* The process's public ARGUMENTS that no expression may read: a top-level
|
|
52
|
+
* `uipath:input` or `uipath:output` declaration, keyed by its id and its display
|
|
53
|
+
* name, whose spelling nothing readable shares (no `uipath:inputOutput` and no node
|
|
54
|
+
* output of that name in scope).
|
|
55
|
+
*
|
|
56
|
+
* An input is scoped to its start event and an output to its end event. Studio Web
|
|
57
|
+
* and `validate` resolve a `vars.<id>` read only against `uipath:inputOutput`
|
|
58
|
+
* declarations and node outputs, so a read of an argument from any other element is
|
|
59
|
+
* unresolved there, though the engine runs it (#2138). The readable bridge is the
|
|
60
|
+
* canvas's own shape: the start event's `BPMN.Variables` mapping copies the input into
|
|
61
|
+
* a variable scoped to that start event, and downstream elements read that variable.
|
|
62
|
+
* The element an argument is scoped to may read it: that is the bridge itself.
|
|
63
|
+
*
|
|
64
|
+
* Only an argument scoped to an ELEMENT is listed (see `processArguments`): `validate`
|
|
65
|
+
* treats a declaration scoped to the process as root state, readable everywhere.
|
|
66
|
+
*/
|
|
67
|
+
args: ReadonlyMap<string, ArgumentDecl>;
|
|
68
|
+
}
|
|
69
|
+
/** A process argument and the element it is scoped to. */
|
|
70
|
+
export interface ArgumentDecl {
|
|
71
|
+
decl: BpmnVarDecl;
|
|
72
|
+
scope: string;
|
|
73
|
+
}
|
|
74
|
+
/** One expression-bearing field of a built process. */
|
|
75
|
+
export interface BpmnExprField {
|
|
76
|
+
/**
|
|
77
|
+
* `expression`: an `=`-expression (`=vars.x > 1`, `=js:…`), as the field holds it.
|
|
78
|
+
* `script`: a script task's JavaScript body, which reads variables as `vars.<id>`
|
|
79
|
+
* with no `=` sigil.
|
|
80
|
+
*/
|
|
81
|
+
form: 'expression' | 'script';
|
|
82
|
+
/** The expression or script text. */
|
|
83
|
+
text: string;
|
|
84
|
+
/** The id of the flow or element the field is on. */
|
|
85
|
+
elementId: string;
|
|
86
|
+
/** Where it is, for a message: `flow "F1" condition`, `typed "call" input`. */
|
|
87
|
+
where: string;
|
|
88
|
+
/**
|
|
89
|
+
* The field's path inside its element, from the built model: `condition`,
|
|
90
|
+
* `inputs.url`, `inputRows[2].body.url`, `errorMapping[0].condition`.
|
|
91
|
+
*/
|
|
92
|
+
path: string;
|
|
93
|
+
/** The names in scope where it is evaluated. */
|
|
94
|
+
roots: BpmnRoots;
|
|
95
|
+
/**
|
|
96
|
+
* The field is an output row's `source`, evaluated against the node's own RESULT
|
|
97
|
+
* (`=response.body`, a human task's `=category`, a script's `=result.score`): a bare
|
|
98
|
+
* name there is a field of that result, not a variable spelled without `vars.`.
|
|
99
|
+
*/
|
|
100
|
+
result: boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Every expression-bearing field of `built`, in a stable order (flows of a scope, then its
|
|
104
|
+
* nodes; a sub-process's own graph right after the sub-process).
|
|
105
|
+
*/
|
|
106
|
+
export declare function bpmnExpressionFields(built: BuiltBpmn): BpmnExprField[];
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { nodeDeclaredVars, publicDeclarationScope } from './declared-vars.js';
|
|
2
|
+
import { isExpressionValue } from './expression-value.js';
|
|
3
|
+
import { processId } from './serialize.js';
|
|
4
|
+
import { ownEntry } from '../core/own-entry.js';
|
|
5
|
+
/**
|
|
6
|
+
* Keys whose value is written to a slot the runtime does not evaluate, so an `=` at its
|
|
7
|
+
* front is text: `.task('t', { name: '=vars.x' })` is a task labelled `=vars.x`, and
|
|
8
|
+
* `serialize` writes it to `bpmn:task/@name` as is. By class, with where each lands:
|
|
9
|
+
*
|
|
10
|
+
* - display text: `name` (an element's or a row's `@name`), `description`, `detail`;
|
|
11
|
+
* - ids and references: `id`, `attachedTo` (`@attachedToRef`), `default` (a gateway's
|
|
12
|
+
* default flow), `messageRef`, `errorRef`, `code` (`uipath:error/@errorRef`), `var`,
|
|
13
|
+
* `outputVar`, `errorVar` (`uipath:output/@var`), `itemVar` (`@inputElement`),
|
|
14
|
+
* `entryPointId`, `target` (where a row WRITES, e.g. `target="=aPIOutput1"`), and the
|
|
15
|
+
* binding names `connection`, `folder`, `folderPath` (`serialize` writes the
|
|
16
|
+
* `=bindings.<name>` read itself);
|
|
17
|
+
* - type tags and versions: `kind`, `type`, `tag`, `typeVersion`, `version`, `key`,
|
|
18
|
+
* `action`, `eventName`, `object`, `element`, `family`, `mode`, `subscribe`,
|
|
19
|
+
* `scriptFormat`, `scriptVersion`, `priority`;
|
|
20
|
+
* - literal data: JSON schemas (`schema`, `varSchema`, `inputSchema`), the registry
|
|
21
|
+
* `spec`, `retry`, `tags`, and `filters` (a BPMN event filter compares against the
|
|
22
|
+
* value as written: `contains: '=vars.x'` lowers to `contains(subject,'=vars.x')`).
|
|
23
|
+
*
|
|
24
|
+
* A flow's `source` is an element id too ({@link FLOW_LITERAL}); on an output row it is
|
|
25
|
+
* the expression, so it is not listed here.
|
|
26
|
+
*/
|
|
27
|
+
const LITERAL = new Set([
|
|
28
|
+
'name', 'description', 'detail',
|
|
29
|
+
'id', 'attachedTo', 'default', 'messageRef', 'errorRef', 'code', 'var', 'outputVar', 'errorVar', 'itemVar',
|
|
30
|
+
'entryPointId', 'target', 'connection', 'folder', 'folderPath',
|
|
31
|
+
'kind', 'type', 'tag', 'typeVersion', 'version', 'key', 'action', 'eventName', 'object', 'element', 'family',
|
|
32
|
+
'mode', 'subscribe', 'scriptFormat', 'scriptVersion', 'priority',
|
|
33
|
+
'schema', 'varSchema', 'inputSchema', 'spec', 'retry', 'tags', 'filters',
|
|
34
|
+
]);
|
|
35
|
+
/** A flow's own literal key on top of {@link LITERAL}: `source`, the element it leaves. */
|
|
36
|
+
const FLOW_LITERAL = new Set([...LITERAL, 'source']);
|
|
37
|
+
/** Keys the walk does not descend into: a sub-process's own scope (walked separately) and the script body. */
|
|
38
|
+
const OWN_WALK = new Set(['nodes', 'flows', 'variables', 'script']);
|
|
39
|
+
/** Keys walked with their own scope, below; never by the generic walk. */
|
|
40
|
+
const SCOPED = new Set(['errorMapping', 'loop']);
|
|
41
|
+
/**
|
|
42
|
+
* The word a field's top-level key reads as in a message. The first three are the
|
|
43
|
+
* labels the hand-listed rule sites used, kept so a finding reads as it did.
|
|
44
|
+
*/
|
|
45
|
+
const LABEL = {
|
|
46
|
+
inputs: 'input',
|
|
47
|
+
outputs: 'output',
|
|
48
|
+
set: 'assignment',
|
|
49
|
+
inputRows: 'input',
|
|
50
|
+
outputRows: 'output',
|
|
51
|
+
mappedOutputRows: 'output',
|
|
52
|
+
context: 'context',
|
|
53
|
+
contextRows: 'context',
|
|
54
|
+
skipCondition: 'skip condition',
|
|
55
|
+
payload: 'payload',
|
|
56
|
+
event: 'event definition',
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* A `=<marker>:` value that is not an expression: Studio Web's `=jsonString:` guard on a
|
|
60
|
+
* JSON string it stores in node metadata. `=js:` is an expression and is not one.
|
|
61
|
+
*/
|
|
62
|
+
const NON_EXPRESSION_MARKER = /^=jsonString:/;
|
|
63
|
+
/**
|
|
64
|
+
* Whether `v` is an `=`-expression string: `isExpressionValue`, the rule `serialize`
|
|
65
|
+
* applies to a value-or-literal field (`.task({ set })`, a script input), less the
|
|
66
|
+
* `=jsonString:` marker. Literal text is never a read.
|
|
67
|
+
*/
|
|
68
|
+
function isExpression(v) {
|
|
69
|
+
return typeof v === 'string' && isExpressionValue(v) && !NON_EXPRESSION_MARKER.test(v);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Every expression-bearing field of `built`, in a stable order (flows of a scope, then its
|
|
73
|
+
* nodes; a sub-process's own graph right after the sub-process).
|
|
74
|
+
*/
|
|
75
|
+
export function bpmnExpressionFields(built) {
|
|
76
|
+
const out = [];
|
|
77
|
+
walkScope(built.nodes, built.flows, built.variables, processId(built.id), rootScope(built), out);
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
/** The root scope's declared names: variables (by id and display name) and bindings. */
|
|
81
|
+
function rootScope(built) {
|
|
82
|
+
return {
|
|
83
|
+
// Keyed by ID, which is what an expression reads — `BpmnVarDecl.id` is documented as
|
|
84
|
+
// "what expressions read as `vars.<id>`", and every product-shaped artifact agrees:
|
|
85
|
+
// the fixtures under skills `edit/*/fixture` declare
|
|
86
|
+
// `<uipath:inputOutput id="Var_OrderId" name="OrderId">` and reference
|
|
87
|
+
// `=vars.Var_OrderId`, never the display name.
|
|
88
|
+
//
|
|
89
|
+
// The display name is accepted too. It is not what the wire uses, but an author who
|
|
90
|
+
// wrote `vars.<displayName>` in an existing process should get the reference resolved
|
|
91
|
+
// rather than a spurious error from a stricter check.
|
|
92
|
+
vars: new Set(built.variables.flatMap((v) => [v.id, v.name])),
|
|
93
|
+
varIds: new Set(built.variables.map((v) => v.id)),
|
|
94
|
+
// Author-declared bindings, plus the symbolic connection/folder names a connector
|
|
95
|
+
// turns into bindings at serialize time — the author's own spelling is what they
|
|
96
|
+
// would reference, so both are legitimate roots.
|
|
97
|
+
bindings: new Set([...built.bindings.map((b) => b.id), ...connectorBindingNames(built.nodes)]),
|
|
98
|
+
args: processArguments(built),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The top-level arguments no expression may read — see {@link BpmnRoots.args}.
|
|
103
|
+
*
|
|
104
|
+
* An argument is one only where it is SCOPED TO AN ELEMENT: its `elementId`, or the
|
|
105
|
+
* element `publicDeclarationScope` writes for it (the manual start event for an input,
|
|
106
|
+
* the end event that writes an output). One scoped to the process itself is root state
|
|
107
|
+
* to `validate`, which counts every declaration whose `elementId` is the process as
|
|
108
|
+
* available everywhere, so it is left alone, as is one written with no `elementId` at
|
|
109
|
+
* all (`null`, a legacy import), which `validate` already reports as missing.
|
|
110
|
+
*
|
|
111
|
+
* Keyed by id and by display name, as `vars` is. A spelling an internal variable
|
|
112
|
+
* shares is left out: the canvas resolves the reference to that variable.
|
|
113
|
+
*/
|
|
114
|
+
function processArguments(built) {
|
|
115
|
+
const scopeOf = publicDeclarationScope(built.nodes, built.id);
|
|
116
|
+
const readable = new Set(built.variables.filter((v) => v.direction === 'inputOutput').flatMap((v) => [v.id, v.name]));
|
|
117
|
+
const args = new Map();
|
|
118
|
+
for (const v of built.variables) {
|
|
119
|
+
if (v.direction === 'inputOutput' || v.elementId === null)
|
|
120
|
+
continue;
|
|
121
|
+
const scope = v.elementId ?? scopeOf(v);
|
|
122
|
+
if (scope === built.id)
|
|
123
|
+
continue;
|
|
124
|
+
for (const key of [v.id, v.name])
|
|
125
|
+
if (!readable.has(key) && !args.has(key))
|
|
126
|
+
args.set(key, { decl: v, scope });
|
|
127
|
+
}
|
|
128
|
+
return args;
|
|
129
|
+
}
|
|
130
|
+
/** Every symbolic connection/folder name in a graph, at any nesting depth. */
|
|
131
|
+
function connectorBindingNames(nodes) {
|
|
132
|
+
const out = [];
|
|
133
|
+
for (const n of nodes) {
|
|
134
|
+
if (n.kind === 'connector') {
|
|
135
|
+
if (n.connection)
|
|
136
|
+
out.push(n.connection);
|
|
137
|
+
if (n.folder)
|
|
138
|
+
out.push(n.folder);
|
|
139
|
+
}
|
|
140
|
+
if (n.kind === 'subProcess')
|
|
141
|
+
out.push(...connectorBindingNames(n.nodes));
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* `roots` with more readable `vars` roots; `varIds` and `bindings` are shared. A name that
|
|
147
|
+
* becomes readable (a node writes it, a scope declares it) is no longer an argument read.
|
|
148
|
+
*/
|
|
149
|
+
function withVars(roots, ...names) {
|
|
150
|
+
const vars = new Set(roots.vars);
|
|
151
|
+
const args = new Map(roots.args);
|
|
152
|
+
for (const name of names) {
|
|
153
|
+
vars.add(name);
|
|
154
|
+
args.delete(name);
|
|
155
|
+
}
|
|
156
|
+
return { ...roots, vars, args };
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The variables `nodes` write, which become readable in their scope. A process output
|
|
160
|
+
* that its own end event maps onto is the exception: that row defines the argument
|
|
161
|
+
* (`var="res"` on the end event `res` is scoped to), and the canvas still does not
|
|
162
|
+
* resolve a read of it anywhere else.
|
|
163
|
+
*/
|
|
164
|
+
function writtenVars(nodes, roots) {
|
|
165
|
+
return nodes.flatMap((n) => nodeDeclaredVars(n).filter((name) => roots.args.get(name)?.scope !== n.id));
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* One scope: the process root or a sub-process body. `scopeId` is the element its
|
|
169
|
+
* variable declarations sit on in the XML (the process, or the sub-process).
|
|
170
|
+
*/
|
|
171
|
+
function walkScope(nodes, flows, variables, scopeId, rootsIn, out) {
|
|
172
|
+
// A node's output `var` IS a variable declaration to the platform (its canvas model
|
|
173
|
+
// keys a variable off each output's `var`), so a downstream read of one resolves
|
|
174
|
+
// without any `uipath:variables` entry — a connector's response, a script task's
|
|
175
|
+
// output, a variable task's assignment target. Collect them for the WHOLE scope before
|
|
176
|
+
// walking: a flow condition is checked first but may read a node declared later in
|
|
177
|
+
// authoring order.
|
|
178
|
+
const roots = withVars(rootsIn, ...writtenVars(nodes, rootsIn));
|
|
179
|
+
for (const f of flows) {
|
|
180
|
+
const at = `flow "${f.id}"`;
|
|
181
|
+
for (const key of Object.keys(f)) {
|
|
182
|
+
if (FLOW_LITERAL.has(key))
|
|
183
|
+
continue;
|
|
184
|
+
walkValue(f[key], key, (text, path) => {
|
|
185
|
+
out.push({ form: 'expression', text, elementId: f.id, where: `${at} ${path}`, path, roots, result: false });
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// A variable's default may be an expression too — a decompiled canvas process carries
|
|
190
|
+
// `default="=Newtonsoft.Json.JsonConvert.SerializeObject(vars.response.Output.DocumentData)"`.
|
|
191
|
+
variables.forEach((v, i) => {
|
|
192
|
+
if (isExpression(v.default)) {
|
|
193
|
+
out.push({ form: 'expression', text: v.default, elementId: scopeId, where: `variable "${v.id}" default`, path: `variables[${i}].default`, roots, result: false });
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
for (const n of nodes)
|
|
197
|
+
walkNode(n, roots, out);
|
|
198
|
+
}
|
|
199
|
+
/** The fields on one node; a sub-process recurses into its own scope. */
|
|
200
|
+
function walkNode(n, roots, out) {
|
|
201
|
+
const at = `${n.kind} "${n.id}"`;
|
|
202
|
+
const push = (text, path, label, scope, form = 'expression') => {
|
|
203
|
+
out.push({ form, text, elementId: n.id, where: `${at} ${label}`, path, roots: scope, result: readsResult(path) });
|
|
204
|
+
};
|
|
205
|
+
// A sub-process is its own variable scope: it sees the enclosing variables plus the
|
|
206
|
+
// ones it declares, by ID as well as display name (an expression reads `vars.<id>`).
|
|
207
|
+
let inner;
|
|
208
|
+
// What the sub-process's own fields see: its scope once its body has run. Its mapping
|
|
209
|
+
// payload runs on exit and its loop completion after each pass, so both may read what
|
|
210
|
+
// the body's nodes wrote (`source="=vars.response"`, hoisting an inner task's result).
|
|
211
|
+
let afterBody;
|
|
212
|
+
if (n.kind === 'subProcess') {
|
|
213
|
+
// Only the process's own arguments are reported: a sub-process's declarations,
|
|
214
|
+
// whatever their direction, are left to the platform's own scoping.
|
|
215
|
+
inner = withVars(roots, ...n.variables.flatMap((v) => [v.id, v.name]));
|
|
216
|
+
inner.varIds = new Set([...roots.varIds, ...n.variables.map((v) => v.id)]);
|
|
217
|
+
afterBody = withVars(inner, ...writtenVars(n.nodes, inner));
|
|
218
|
+
}
|
|
219
|
+
// An errorMapping row's `condition` is an expression on EVERY activity kind. The
|
|
220
|
+
// CANVAS treats an undeclared reference in it as a blocking error while
|
|
221
|
+
// `uip maestro bpmn validate` says nothing at all.
|
|
222
|
+
//
|
|
223
|
+
// `error` is a BUILT-IN root here, not an author declaration: the skill's expression
|
|
224
|
+
// reference has a row inspect the built-in error object through `vars.error`
|
|
225
|
+
// (`=vars.error.code == "SERVICE_UNAVAILABLE"`), and requiring `.var('error', …)` first
|
|
226
|
+
// forced authors to declare a DECOY variable that then shipped as a real
|
|
227
|
+
// `uipath:inputOutput` row. Scoped to this one slot: outside an errorMapping condition
|
|
228
|
+
// there is no error object in scope, so `vars.error` there really is undeclared.
|
|
229
|
+
// It joins `vars` but NOT `varIds`: a scoped runtime binding is not a declared
|
|
230
|
+
// variable, so `=error` is not a bare spelling of one.
|
|
231
|
+
if ('errorMapping' in n && n.errorMapping) {
|
|
232
|
+
const errRoots = withVars(roots, 'error');
|
|
233
|
+
n.errorMapping.forEach((row, i) => {
|
|
234
|
+
walkValue(row, `errorMapping[${i}]`, (text, path) => push(text, path, `errorMapping "${row.code}" ${path.slice(path.lastIndexOf('.') + 1)}`, errRoots));
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
// A loop's collection is evaluated in the ENCLOSING scope (before entry). Its
|
|
238
|
+
// completion condition may read the loop's own iterator bindings (`iterator.item`); on
|
|
239
|
+
// a sub-process it sees the sub-process's scope after a pass of its body. The engine honours
|
|
240
|
+
// the completion condition and swallows an unevaluatable one (the loop then runs the
|
|
241
|
+
// whole collection), so this is the gate that reports it.
|
|
242
|
+
if ('loop' in n && n.loop) {
|
|
243
|
+
const completionRoots = afterBody ?? withVars(roots, 'iterator');
|
|
244
|
+
walkValue(n.loop, 'loop', (text, path) => {
|
|
245
|
+
const completion = path === 'loop.completion';
|
|
246
|
+
push(text, path, completion ? 'loop completion' : path === 'loop.collection' ? 'loop collection' : path, completion ? completionRoots : roots);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
// A script body is JavaScript, not an `=`-expression: yielded as its own form, for the
|
|
250
|
+
// rules that can read it (bpmn-expr-check `checkScript`).
|
|
251
|
+
if (n.kind === 'scriptTask' && n.script)
|
|
252
|
+
push(n.script, 'script', 'script', roots, 'script');
|
|
253
|
+
// Everything else, generically. A sub-process's own mapping payload is read with its
|
|
254
|
+
// scope after the body: a row there maps between the two, and that one is the superset.
|
|
255
|
+
const scope = afterBody ?? roots;
|
|
256
|
+
// Keys are filtered before a value is read: a value nothing judges is never touched.
|
|
257
|
+
for (const key of Object.keys(n)) {
|
|
258
|
+
if (OWN_WALK.has(key) || LITERAL.has(key) || SCOPED.has(key))
|
|
259
|
+
continue;
|
|
260
|
+
walkValue(n[key], key, (text, path) => push(text, path, ownEntry(LABEL, key) ?? key, scope), modeUnder(key));
|
|
261
|
+
}
|
|
262
|
+
if (n.kind === 'subProcess' && inner)
|
|
263
|
+
walkScope(n.nodes, n.flows, n.variables, n.id, inner, out);
|
|
264
|
+
}
|
|
265
|
+
/** An output row's source: `outputRows[0].source`, `payload.outputRows[1].source`, `outputs.total`, `outputs.total.source`. */
|
|
266
|
+
const ROW_SOURCE = /^(?:(?:payload\.)?(?:outputRows|mappedOutputRows)\[\d+\]\.source|outputs\.[^.[]+(?:\.source)?)$/;
|
|
267
|
+
/**
|
|
268
|
+
* Whether the field at `path` on `n` is an output row's source — see
|
|
269
|
+
* {@link BpmnExprField.result}. A variable task's `set` is the exception that is not: its
|
|
270
|
+
* rows are assignments computed from the variables, and it keeps them under `set`.
|
|
271
|
+
*
|
|
272
|
+
* `custom="true"` does not decide it: a human task's answer rows carry it and still read
|
|
273
|
+
* the form's answer (`source="=category"`).
|
|
274
|
+
*/
|
|
275
|
+
function readsResult(path) {
|
|
276
|
+
return ROW_SOURCE.test(path);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Keys whose value is the AUTHOR's data rather than the model's structure: everything
|
|
280
|
+
* under them is walked, whatever its keys are called. A connector input named `name`
|
|
281
|
+
* or `schema` is an input like any other, and so is a key inside a JSON body row.
|
|
282
|
+
*/
|
|
283
|
+
const DATA = new Set(['inputs', 'context', 'filter', 'parameters', 'body', 'value']);
|
|
284
|
+
/**
|
|
285
|
+
* Keys whose value maps an author's NAME (the variable a row writes) to a model value:
|
|
286
|
+
* an expression, or a row object such as a connector's `{ source, name, type }`. The
|
|
287
|
+
* names are never filtered (a variable may be called `name`); the values are model
|
|
288
|
+
* values, so a row's `name` and `type` are {@link LITERAL}.
|
|
289
|
+
*/
|
|
290
|
+
const MAP = new Set(['set', 'outputs']);
|
|
291
|
+
/** The mode for the value under model key `k`. */
|
|
292
|
+
function modeUnder(k) {
|
|
293
|
+
if (DATA.has(k))
|
|
294
|
+
return 'data';
|
|
295
|
+
return MAP.has(k) ? 'map' : 'model';
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Call `visit` on every `=`-expression string in `value`, at any depth, with its path.
|
|
299
|
+
* Object KEYS are never visited — in a `field → expression` map (`inputs`, `set`,
|
|
300
|
+
* `outputs`) the key is a target, not an expression. Inside the model's own objects (a
|
|
301
|
+
* row, a payload, an event definition) a {@link LITERAL} key is left out; inside the
|
|
302
|
+
* author's data ({@link DATA}) nothing is.
|
|
303
|
+
*/
|
|
304
|
+
function walkValue(value, path, visit, mode = 'model') {
|
|
305
|
+
if (isExpression(value)) {
|
|
306
|
+
visit(value, path);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (Array.isArray(value)) {
|
|
310
|
+
value.forEach((v, i) => walkValue(v, `${path}[${i}]`, visit, mode));
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (value === null || typeof value !== 'object' || value instanceof Map || value instanceof Set)
|
|
314
|
+
return;
|
|
315
|
+
for (const k of Object.keys(value)) {
|
|
316
|
+
if (mode === 'model' && LITERAL.has(k))
|
|
317
|
+
continue;
|
|
318
|
+
const next = mode === 'data' ? 'data' : mode === 'map' ? 'model' : modeUnder(k);
|
|
319
|
+
walkValue(value[k], path ? `${path}.${k}` : k, visit, next);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ExprRef } from '../core/expr-check.js';
|
|
2
|
+
/** An acorn node, read generically: every node has a `type` and a source span. */
|
|
3
|
+
export interface JsNode {
|
|
4
|
+
type: string;
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
[field: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
export declare const isJsNode: (v: unknown) => v is JsNode;
|
|
10
|
+
/** The child nodes of `node`, in source order. */
|
|
11
|
+
export declare function jsChildren(node: JsNode): JsNode[];
|
|
12
|
+
/** Whether a binding pattern (`result`, `{ a: result }`, `[result = 1]`, `...result`) declares `name`. */
|
|
13
|
+
export declare function patternBinds(p: JsNode, name: string): boolean;
|
|
14
|
+
export declare const isFunction: (n: JsNode) => boolean;
|
|
15
|
+
/** Whether a `let`/`const`/`var` declaration of the given kinds declares `name`. */
|
|
16
|
+
export declare function declarationBinds(n: unknown, name: string, kinds: (k: string) => boolean): boolean;
|
|
17
|
+
/** Whether these statements, at the top of one block, declare `name` block-scoped: `let`, `const`, `class` or a function declaration. */
|
|
18
|
+
export declare function lexicallyBinds(statements: JsNode[], name: string): boolean;
|
|
19
|
+
/** Whether a `var` under `node` declares `name` in the function `node` belongs to: nested functions and static blocks are their own `var` scope and are not walked. */
|
|
20
|
+
export declare function varBinds(node: JsNode, name: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether `node` opens a scope that declares `name`, so every `name` inside it is that
|
|
23
|
+
* binding, not the outer one. A function: its own name (an expression's), a parameter,
|
|
24
|
+
* a `var` anywhere in its body outside a nested function, or a block-scoped declaration
|
|
25
|
+
* at the top of its body. A block, a `switch`, a `for` head or a `catch` parameter: the
|
|
26
|
+
* declarations scoped to it. A declaration in a nested function shadows only inside that
|
|
27
|
+
* function, so it is found when the walk reaches that function, never from outside.
|
|
28
|
+
*/
|
|
29
|
+
export declare function scopeBinds(node: JsNode, name: string): boolean;
|
|
30
|
+
/** The string a member selector names: `.response`, `['response']`, `` [`response`] ``; `undefined` for any other. */
|
|
31
|
+
export declare function memberName(member: JsNode): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Every `vars.<root>` a script BODY reads, with the path after the root, or `undefined`
|
|
34
|
+
* when the body does not parse (nothing is claimed about code that does not run).
|
|
35
|
+
*
|
|
36
|
+
* The platform runs the body as a function (`(function(){<body>})()`, as the local
|
|
37
|
+
* engine does) with `vars` in scope. A read is a member selector on that `vars`: dotted
|
|
38
|
+
* (`vars.amount`), or a quoted key (`vars['amount']`). Not a read:
|
|
39
|
+
*
|
|
40
|
+
* - anything under a scope that binds its own `vars` (a parameter, `let`, `const`,
|
|
41
|
+
* `var`, a function or `catch` binding), which is not the platform's;
|
|
42
|
+
* - a computed key (`vars[name]`), which names no root this can see;
|
|
43
|
+
* - a call through `vars` (`vars.hasOwnProperty('x')`): an `Object.prototype` method,
|
|
44
|
+
* not a variable;
|
|
45
|
+
* - the operand of `typeof`, which a script uses to ask whether a variable exists;
|
|
46
|
+
* - a root the body itself ASSIGNS (`vars.total = …`, `vars.total ??= 0`) or deletes,
|
|
47
|
+
* whose later read is of the body's own value.
|
|
48
|
+
*/
|
|
49
|
+
export declare function scriptVarReads(script: string): ExprRef[] | undefined;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bpmn/script-js — reading a BPMN script task's JavaScript: which names a piece of code
|
|
3
|
+
* binds, and where it reads one.
|
|
4
|
+
*
|
|
5
|
+
* Parsed with acorn, as the Case checks parse JavaScript, so only real references count:
|
|
6
|
+
* a property name, an object key, a string, template text, a regex or a comment is none.
|
|
7
|
+
* Shared by `check` (a script output's `result` reads) and the expression rules (a script
|
|
8
|
+
* body's `vars.<id>` reads, bpmn-expr-check).
|
|
9
|
+
*/
|
|
10
|
+
import { parse } from 'acorn';
|
|
11
|
+
export const isJsNode = (v) => typeof v === 'object' && v !== null && typeof v.type === 'string';
|
|
12
|
+
/** The child nodes of `node`, in source order. */
|
|
13
|
+
export function jsChildren(node) {
|
|
14
|
+
const out = [];
|
|
15
|
+
for (const [field, v] of Object.entries(node)) {
|
|
16
|
+
if (field === 'type' || field === 'start' || field === 'end')
|
|
17
|
+
continue;
|
|
18
|
+
if (Array.isArray(v))
|
|
19
|
+
for (const item of v) {
|
|
20
|
+
if (isJsNode(item))
|
|
21
|
+
out.push(item);
|
|
22
|
+
}
|
|
23
|
+
else if (isJsNode(v))
|
|
24
|
+
out.push(v);
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
/** Whether a binding pattern (`result`, `{ a: result }`, `[result = 1]`, `...result`) declares `name`. */
|
|
29
|
+
export function patternBinds(p, name) {
|
|
30
|
+
switch (p.type) {
|
|
31
|
+
case 'Identifier': return p.name === name;
|
|
32
|
+
case 'AssignmentPattern': return patternBinds(p.left, name);
|
|
33
|
+
case 'RestElement': return patternBinds(p.argument, name);
|
|
34
|
+
case 'ArrayPattern': return p.elements.some((e) => e !== null && patternBinds(e, name));
|
|
35
|
+
// A pattern's computed key or default value is an expression, not a binding.
|
|
36
|
+
case 'ObjectPattern': return p.properties.some((pr) => patternBinds(pr.type === 'RestElement' ? pr : pr.value, name));
|
|
37
|
+
default: return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export const isFunction = (n) => /Function/.test(n.type);
|
|
41
|
+
/** Whether a `let`/`const`/`var` declaration of the given kinds declares `name`. */
|
|
42
|
+
export function declarationBinds(n, name, kinds) {
|
|
43
|
+
return isJsNode(n) && n.type === 'VariableDeclaration' && kinds(n.kind)
|
|
44
|
+
&& n.declarations.some((d) => patternBinds(d.id, name));
|
|
45
|
+
}
|
|
46
|
+
/** Whether these statements, at the top of one block, declare `name` block-scoped: `let`, `const`, `class` or a function declaration. */
|
|
47
|
+
export function lexicallyBinds(statements, name) {
|
|
48
|
+
return statements.some((s) => declarationBinds(s, name, (k) => k !== 'var')
|
|
49
|
+
|| ((s.type === 'ClassDeclaration' || s.type === 'FunctionDeclaration') && isJsNode(s.id) && s.id.name === name));
|
|
50
|
+
}
|
|
51
|
+
/** Whether a `var` under `node` declares `name` in the function `node` belongs to: nested functions and static blocks are their own `var` scope and are not walked. */
|
|
52
|
+
export function varBinds(node, name) {
|
|
53
|
+
if (declarationBinds(node, name, (k) => k === 'var'))
|
|
54
|
+
return true;
|
|
55
|
+
return jsChildren(node).some((c) => !isFunction(c) && c.type !== 'StaticBlock' && varBinds(c, name));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Whether `node` opens a scope that declares `name`, so every `name` inside it is that
|
|
59
|
+
* binding, not the outer one. A function: its own name (an expression's), a parameter,
|
|
60
|
+
* a `var` anywhere in its body outside a nested function, or a block-scoped declaration
|
|
61
|
+
* at the top of its body. A block, a `switch`, a `for` head or a `catch` parameter: the
|
|
62
|
+
* declarations scoped to it. A declaration in a nested function shadows only inside that
|
|
63
|
+
* function, so it is found when the walk reaches that function, never from outside.
|
|
64
|
+
*/
|
|
65
|
+
export function scopeBinds(node, name) {
|
|
66
|
+
if (isFunction(node)) {
|
|
67
|
+
if (node.type === 'FunctionExpression' && isJsNode(node.id) && node.id.name === name)
|
|
68
|
+
return true;
|
|
69
|
+
if (node.params.some((p) => patternBinds(p, name)))
|
|
70
|
+
return true;
|
|
71
|
+
const body = node.body;
|
|
72
|
+
return body.type === 'BlockStatement' && (varBinds(body, name) || lexicallyBinds(body.body, name));
|
|
73
|
+
}
|
|
74
|
+
switch (node.type) {
|
|
75
|
+
case 'BlockStatement': return lexicallyBinds(node.body, name);
|
|
76
|
+
case 'StaticBlock': return varBinds(node, name) || lexicallyBinds(node.body, name);
|
|
77
|
+
case 'SwitchStatement': return lexicallyBinds(node.cases.flatMap((c) => c.consequent), name);
|
|
78
|
+
case 'CatchClause': return isJsNode(node.param) && patternBinds(node.param, name);
|
|
79
|
+
case 'ForStatement': return declarationBinds(node.init, name, (k) => k !== 'var');
|
|
80
|
+
case 'ForInStatement':
|
|
81
|
+
case 'ForOfStatement': return declarationBinds(node.left, name, (k) => k !== 'var');
|
|
82
|
+
case 'ClassExpression':
|
|
83
|
+
case 'ClassDeclaration': return isJsNode(node.id) && node.id.name === name;
|
|
84
|
+
default: return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** The string a member selector names: `.response`, `['response']`, `` [`response`] ``; `undefined` for any other. */
|
|
88
|
+
export function memberName(member) {
|
|
89
|
+
const prop = member.property;
|
|
90
|
+
if (!member.computed)
|
|
91
|
+
return prop.type === 'Identifier' ? prop.name : undefined;
|
|
92
|
+
if (prop.type === 'Literal')
|
|
93
|
+
return typeof prop.value === 'string' ? prop.value : undefined;
|
|
94
|
+
const quasis = prop.quasis;
|
|
95
|
+
return prop.type === 'TemplateLiteral' && quasis?.length === 1 ? quasis[0].value.cooked : undefined;
|
|
96
|
+
}
|
|
97
|
+
/** Whether a `vars.<root>` met under a node is a read. */
|
|
98
|
+
var ReadContext;
|
|
99
|
+
(function (ReadContext) {
|
|
100
|
+
/** It is: the body uses the value. */
|
|
101
|
+
ReadContext[ReadContext["Read"] = 0] = "Read";
|
|
102
|
+
/** Under `typeof`: the body only asks whether it exists. */
|
|
103
|
+
ReadContext[ReadContext["TypeofOperand"] = 1] = "TypeofOperand";
|
|
104
|
+
})(ReadContext || (ReadContext = {}));
|
|
105
|
+
/**
|
|
106
|
+
* Every `vars.<root>` a script BODY reads, with the path after the root, or `undefined`
|
|
107
|
+
* when the body does not parse (nothing is claimed about code that does not run).
|
|
108
|
+
*
|
|
109
|
+
* The platform runs the body as a function (`(function(){<body>})()`, as the local
|
|
110
|
+
* engine does) with `vars` in scope. A read is a member selector on that `vars`: dotted
|
|
111
|
+
* (`vars.amount`), or a quoted key (`vars['amount']`). Not a read:
|
|
112
|
+
*
|
|
113
|
+
* - anything under a scope that binds its own `vars` (a parameter, `let`, `const`,
|
|
114
|
+
* `var`, a function or `catch` binding), which is not the platform's;
|
|
115
|
+
* - a computed key (`vars[name]`), which names no root this can see;
|
|
116
|
+
* - a call through `vars` (`vars.hasOwnProperty('x')`): an `Object.prototype` method,
|
|
117
|
+
* not a variable;
|
|
118
|
+
* - the operand of `typeof`, which a script uses to ask whether a variable exists;
|
|
119
|
+
* - a root the body itself ASSIGNS (`vars.total = …`, `vars.total ??= 0`) or deletes,
|
|
120
|
+
* whose later read is of the body's own value.
|
|
121
|
+
*/
|
|
122
|
+
export function scriptVarReads(script) {
|
|
123
|
+
let program;
|
|
124
|
+
try {
|
|
125
|
+
program = parse(`(function(){${script}\n})`, { ecmaVersion: 'latest', sourceType: 'script' });
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
const reads = [];
|
|
131
|
+
const written = new Set();
|
|
132
|
+
/** `stack` is the ancestors of `node`, nearest last. */
|
|
133
|
+
const visit = (node, stack, context) => {
|
|
134
|
+
if (node.type === 'MemberExpression' && isJsNode(node.object) && node.object.type === 'Identifier' && node.object.name === 'vars') {
|
|
135
|
+
const root = memberName(node);
|
|
136
|
+
const parent = stack[stack.length - 1];
|
|
137
|
+
if (root !== undefined) {
|
|
138
|
+
const target = (parent?.type === 'AssignmentExpression' && parent.left === node)
|
|
139
|
+
|| parent?.type === 'UpdateExpression'
|
|
140
|
+
|| (parent?.type === 'UnaryExpression' && parent.operator === 'delete');
|
|
141
|
+
const callee = parent?.type === 'CallExpression' && parent.callee === node;
|
|
142
|
+
if (target)
|
|
143
|
+
written.add(root);
|
|
144
|
+
else if (!callee && context === ReadContext.Read) {
|
|
145
|
+
// The selectors after the root, outward: `vars.step1.output.ok` → ['output', 'ok'].
|
|
146
|
+
const path = [];
|
|
147
|
+
let inner = node;
|
|
148
|
+
for (let k = stack.length - 1; k >= 0; k--) {
|
|
149
|
+
const outer = stack[k];
|
|
150
|
+
if (outer.type !== 'MemberExpression' || outer.object !== inner)
|
|
151
|
+
break;
|
|
152
|
+
const name = memberName(outer);
|
|
153
|
+
if (name === undefined)
|
|
154
|
+
break;
|
|
155
|
+
path.push(name);
|
|
156
|
+
inner = outer;
|
|
157
|
+
}
|
|
158
|
+
reads.push({ root, path, raw: ['vars', root, ...path].join('.') });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// A computed key is code of its own (`vars[pick(vars.kind)]`).
|
|
162
|
+
if (node.computed)
|
|
163
|
+
visit(node.property, [...stack, node], context);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (scopeBinds(node, 'vars'))
|
|
167
|
+
return;
|
|
168
|
+
const typeofOperand = node.type === 'UnaryExpression' && node.operator === 'typeof';
|
|
169
|
+
for (const child of jsChildren(node)) {
|
|
170
|
+
// A name in a property position is not a reference: `a.vars`, `{ vars: … }`, a label.
|
|
171
|
+
const isName = child === node.key || child === node.property || child === node.label || child === node.meta;
|
|
172
|
+
if (isName && !node.computed)
|
|
173
|
+
continue;
|
|
174
|
+
visit(child, [...stack, node], typeofOperand ? ReadContext.TypeofOperand : context);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
visit(program, [], ReadContext.Read);
|
|
178
|
+
return reads.filter((r) => !written.has(r.root));
|
|
179
|
+
}
|
|
@@ -159,3 +159,10 @@ export declare function quotedOnlyMentions(expr: string, namespace?: string): Qu
|
|
|
159
159
|
* "fully valid"; the `validate` CLI is what proves the rest.
|
|
160
160
|
*/
|
|
161
161
|
export declare function checkExpression(expr: string, scope: ExprScope, escapes?: readonly CookedEscape[]): ExprDiagnostic[];
|
|
162
|
+
/**
|
|
163
|
+
* The resolution half of {@link checkExpression}, for references found some other way
|
|
164
|
+
* than by scanning an expression's text — a BPMN script body's `vars.<id>` reads, which
|
|
165
|
+
* are found by parsing the JavaScript (`bpmn/script-js.ts`). Every reference's root must
|
|
166
|
+
* resolve; one diagnostic per unresolved root.
|
|
167
|
+
*/
|
|
168
|
+
export declare function checkRefs(refs: readonly ExprRef[], scope: ExprScope): ExprDiagnostic[];
|
package/dist/core/expr-check.js
CHANGED
|
@@ -316,9 +316,6 @@ function nearMiss(name, roots) {
|
|
|
316
316
|
*/
|
|
317
317
|
export function checkExpression(expr, scope, escapes = []) {
|
|
318
318
|
const namespace = scope.namespace ?? DEFAULT_NAMESPACE;
|
|
319
|
-
const noun = scope.noun ?? 'input, variable, or step';
|
|
320
|
-
const diags = [];
|
|
321
|
-
const seen = new Set();
|
|
322
319
|
// Syntax first: an expression that does not parse cannot have meaningful
|
|
323
320
|
// references, and reporting both would just be noise on one root cause.
|
|
324
321
|
const syntax = scope.syntax === 'javascript' ? syntaxError(expr) : undefined;
|
|
@@ -340,8 +337,21 @@ export function checkExpression(expr, scope, escapes = []) {
|
|
|
340
337
|
: {}),
|
|
341
338
|
}];
|
|
342
339
|
}
|
|
340
|
+
return checkRefs(extractRefs(expr, namespace), scope);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* The resolution half of {@link checkExpression}, for references found some other way
|
|
344
|
+
* than by scanning an expression's text — a BPMN script body's `vars.<id>` reads, which
|
|
345
|
+
* are found by parsing the JavaScript (`bpmn/script-js.ts`). Every reference's root must
|
|
346
|
+
* resolve; one diagnostic per unresolved root.
|
|
347
|
+
*/
|
|
348
|
+
export function checkRefs(refs, scope) {
|
|
349
|
+
const namespace = scope.namespace ?? DEFAULT_NAMESPACE;
|
|
350
|
+
const noun = scope.noun ?? 'input, variable, or step';
|
|
351
|
+
const diags = [];
|
|
352
|
+
const seen = new Set();
|
|
343
353
|
const dotted = dottedRoots(scope.roots);
|
|
344
|
-
for (const ref of
|
|
354
|
+
for (const ref of refs) {
|
|
345
355
|
if (scope.roots.has(ref.root))
|
|
346
356
|
continue;
|
|
347
357
|
const name = dotted.length ? unresolvedDottedName(ref, dotted) : ref.root;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uipath/maestro-builder-sdk",
|
|
3
|
-
"version": "6.120.
|
|
3
|
+
"version": "6.120.20",
|
|
4
4
|
"description": "Build UiPath Flow, Case, and BPMN artifacts by writing TypeScript.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://docs.uipath.com/maestro",
|
|
@@ -124,5 +124,5 @@
|
|
|
124
124
|
"@types/node": "^22.7.0",
|
|
125
125
|
"esbuild": "^0.28.1"
|
|
126
126
|
},
|
|
127
|
-
"gitref": "
|
|
127
|
+
"gitref": "fba3d99fba6ecd89a4f5b85e8d8c09f202e8a53e"
|
|
128
128
|
}
|