@uipath/maestro-builder-sdk 6.120.19 → 6.120.21

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.
@@ -18,6 +18,9 @@
18
18
  * - `edited` otherwise: an element the edit changed or added, or an untouched element
19
19
  * the original does not have the finding on (an edit elsewhere broke it).
20
20
  *
21
+ * A pre-existing finding of a code in `AUTHORING_ADVICE_CODES` (advice on how to write a
22
+ * new expression, such as `EXPR_BARE_PREFIX`) is dropped: the edit did not write that text.
23
+ *
21
24
  * An element is unchanged when the edited build and the original's build hold the same
22
25
  * element under its id: the same node (kind, name, type, inputs, outputs, extension
23
26
  * payload, every field the builder carries), the same sequence flow (source, target,
@@ -34,6 +37,7 @@
34
37
  */
35
38
  import { baselineSummary, preExistingFindings, scopeFindings } from '../core/baseline-scope.js';
36
39
  import { refusalClass } from '../core/refusals.js';
40
+ import { AUTHORING_ADVICE_CODES } from './bpmn-expr-check.js';
37
41
  import { checkModel } from './check.js';
38
42
  import { readStamp, sourceDigest } from './decompile-stamp.js';
39
43
  import { stableJson } from './lift-verify.js';
@@ -116,7 +120,8 @@ export function scopeToEdit(edited, baseline) {
116
120
  const place = placeOf(d, editedIndex);
117
121
  return { ...d, ...(place !== '' ? { nodeId: place } : {}), ...(cls !== undefined ? { class: cls } : {}) };
118
122
  });
119
- const out = scopeFindings(classed, preExisting, PRE_EXISTING_LOWERING_NOTE);
123
+ const out = scopeFindings(classed, preExisting, PRE_EXISTING_LOWERING_NOTE)
124
+ .filter((d) => !(d.origin === 'pre-existing' && AUTHORING_ADVICE_CODES.has(d.code)));
120
125
  const stop = edited.checked.stoppedAt;
121
126
  if (stop) {
122
127
  const at = stop.code !== undefined ? `[${stop.code}] ` : '';
@@ -16,7 +16,8 @@
16
16
  * platform rule it corresponds to and how the two differ.
17
17
  */
18
18
  import { parse } from 'acorn';
19
- import { checkBpmnExpressions } from './bpmn-expr-check.js';
19
+ import { jsChildren, memberName, scopeBinds } from './script-js.js';
20
+ import { checkBpmnExpressionLanguage, 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';
22
23
  import { KNOWN_METHOD_SET } from './known-methods.js';
@@ -206,7 +207,8 @@ function refreshConnections(built, definitions, stoodIn, diags) {
206
207
  }
207
208
  /**
208
209
  * The first-level expression check (bpmn-expr-check): an undeclared `vars.<name>` or
209
- * `bindings.<name>` read, or a declared variable read without `vars.`.
210
+ * `bindings.<name>` read, a declared variable read without `vars.`, or an expression
211
+ * whose bare `=` prefix makes it C# when JavaScript was meant (#2137).
210
212
  *
211
213
  * Both codes are `lint` (decided on #1712): the serializer writes the read exactly as
212
214
  * authored, so `compile` writes it and `check` is where it is reported. It ran in
@@ -216,7 +218,7 @@ function refreshConnections(built, definitions, stoodIn, diags) {
216
218
  */
217
219
  function checkExpressions(built, diags) {
218
220
  const nodeIds = new Set(allNodes(built.nodes).map((n) => n.id));
219
- for (const d of checkBpmnExpressions(built)) {
221
+ for (const d of [...checkBpmnExpressions(built), ...checkBpmnExpressionLanguage(built)]) {
220
222
  diags.push({
221
223
  level: d.level,
222
224
  code: d.code,
@@ -1115,92 +1117,6 @@ function readsBareIdentifier(script, name) {
1115
1117
  }
1116
1118
  /** The `result` members a v2+ output may read directly: the wrapper, and the error slot. */
1117
1119
  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
1120
  /**
1205
1121
  * Where `code` reads the variable `result` other than through `result.response` or
1206
1122
  * `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;