@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.
@@ -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,9 +40,23 @@ 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
  }
46
+ /**
47
+ * Codes that advise how NEW expression text should be written. `check --baseline` drops
48
+ * them on an element the edit did not change (check-baseline.ts): an untouched
49
+ * expression is the original's, and an edit is not asked to rewrite it.
50
+ */
51
+ export declare const AUTHORING_ADVICE_CODES: ReadonlySet<string>;
40
52
  /** Every first-level expression problem in a built BPMN process, stamped with its location. */
41
53
  export declare function checkBpmnExpressions(built: BuiltBpmn): BpmnLocatedDiagnostic[];
54
+ /**
55
+ * Every expression in a built BPMN process that the platform reads as C# while the
56
+ * author most likely meant JavaScript (#2137): `EXPR_BARE_PREFIX` and
57
+ * `EXPR_BARE_PREFIX_JS_SYNTAX`, on the same fields as {@link checkBpmnExpressions}.
58
+ */
59
+ export declare function checkBpmnExpressionLanguage(built: BuiltBpmn): BpmnLocatedDiagnostic[];
42
60
  /**
43
61
  * Was thrown by `BpmnBuilder.build()` when the first-level expression check found an
44
62
  * undeclared `vars.<name>` reference. `message` lists every problem; `diagnostics`
@@ -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 { nodeDeclaredVars, publicDeclarationScope } from './declared-vars.js';
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
- function checkExpr(expr, where, roots, out) {
41
- if (!expr)
42
- return;
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, where, roots, out);
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
- if (bare && roots.varIds.has(bare)) {
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
- * Report each read of a process argument — see {@link BpmnRoots.args}. One finding
67
- * per argument per expression, naming the form that IS readable: the start-event
68
- * mapping into a process variable for an input, the variable the end event maps from
69
- * for an output.
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(expr, where, roots, out) {
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 extractRefs(expr, NAMESPACE)) {
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,189 @@ 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
- /** What a field's string values are, which decides which of them `checkExprValues` checks. */
102
- var FieldValues;
103
- (function (FieldValues) {
104
- /** Every string is an expression and is checked: a script task's `outputs`, expressions against the result. */
105
- FieldValues[FieldValues["Expressions"] = 0] = "Expressions";
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 = {}));
129
+ // Expression language (#2137): Studio Web and the Maestro runtime read a bare `=` as
130
+ // C# and only `=js:` as JavaScript. compile keeps the authored text, since a bare `=`
131
+ // may be deliberate C#, so check reports it instead.
132
+ /** A value the platform reads as a JavaScript expression. */
133
+ const JS_EXPR_PREFIX = '=js:';
134
+ /** Another `=<marker>:` prefix (`=jsonString:` in node metadata) — not a bare-`=` expression. */
135
+ const OTHER_PREFIX = /^=[A-Za-z]+:/;
113
136
  /**
114
- * Check every expression VALUE of a `field → value` map (keys are targets), as `kind` says.
137
+ * A Data Fabric lookup, which the runtime resolves itself rather than as C# or JavaScript:
138
+ * `=datafabric[bindings.<entity>?folderPath=bindings.<folder>]["qes:{...}"]` or
139
+ * `=datafabric.<Entity>["qes:{...}"]` (Studio Web `DataFabricEditorUtils`). Its query
140
+ * tail is JSON with unescaped quotes, so it is not an expression in either language.
141
+ */
142
+ const DATA_FABRIC_LOOKUP = /^=\s*datafabric\s*[.[]/;
143
+ /**
144
+ * One dotted / indexed path (`vars.a.b`, `vars.items[0].id`, `response`, `out_合計`): the
145
+ * same read in C# and JavaScript, both of which take Unicode letters in a name.
146
+ */
147
+ const PLAIN_PATH = /^[\p{L}_$][\p{L}\p{N}_$]*(?:\s*\.\s*[\p{L}_$][\p{L}\p{N}_$]*|\s*\[\s*(?:\d+|"[^"\\]*")\s*\])*$/u;
148
+ /** A literal that is the same value in C# and JavaScript. */
149
+ const PLAIN_LITERAL = /^(?:-?\d+(?:\.\d+)?|true|false|null|"[^"\\]*")$/;
150
+ /**
151
+ * JavaScript that C# (DynamicExpresso) does not have, each with how the message names it.
152
+ * `definite: false` marks one that is also legal C# in some processes (a JSON property
153
+ * named `length`), so it is a warning, not an error.
154
+ */
155
+ const JS_ONLY = [
156
+ { re: /`/, named: 'a template literal', definite: true },
157
+ { re: /===|!==/, named: '`===` / `!==`', definite: true },
158
+ { re: /\bJSON\s*\./, named: '`JSON`', definite: true },
159
+ { re: /\.\s*[a-z_$][\w$]*\s*\(/, named: 'a lower-case (JavaScript) method call', definite: true },
160
+ { re: /\bundefined\b/, named: '`undefined`', definite: true },
161
+ { re: /\bfunction\b/, named: '`function`', definite: true },
162
+ { re: /\.\s*length\b(?!\s*\()/, named: '`.length`', definite: false },
163
+ ];
164
+ /**
165
+ * C# that JavaScript does not have: a .NET member call (`.Contains(`, `.ToString(`), a
166
+ * collection's `.Count` / `.Length`, a .NET type (`String.IsNullOrEmpty`), an interpolated
167
+ * or verbatim string. A body with one is C#, so `=js:` + the same text is no fix.
168
+ */
169
+ const CSHARP_ONLY = [
170
+ /\.\s*[A-Z]\w*\s*\(/,
171
+ /\.\s*(?:Count|Length)\b/,
172
+ /\b(?:String|string|Convert|DateTime|TimeSpan|Guid|Math|double|int|long|decimal|bool|Enumerable|Newtonsoft)\s*\./,
173
+ /[$@]"/,
174
+ ];
175
+ /**
176
+ * `body` with the contents of every string literal emptied, so text inside one
177
+ * (`"a.length"`, `"`"`) is not read as code. Reads C# regular strings and chars
178
+ * (backslash escapes, also JavaScript's `'...'`), C# verbatim strings (`@"..."`, `$@"..."`,
179
+ * where `""` is the only escape) and JavaScript template literals. A template literal
180
+ * keeps its backticks, so it is still reported as JavaScript, and a verbatim string its
181
+ * `@`, so it is still read as C#.
115
182
  *
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.
183
+ * `undefined` when `body` does not read as an expression in either language: a string
184
+ * that never closes, or one followed directly by a word or another quote (`"a"b`).
121
185
  */
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);
186
+ function maskStrings(body) {
187
+ let out = '';
188
+ let i = 0;
189
+ while (i < body.length) {
190
+ const c = body[i];
191
+ const verbatim = /^(?:@\$?|\$@)"/.exec(body.slice(i, i + 3));
192
+ if (verbatim || c === '"' || c === "'" || c === '`') {
193
+ const quote = verbatim ? '"' : c;
194
+ i += verbatim ? verbatim[0].length : 1;
195
+ if (verbatim)
196
+ while (i < body.length && !(body[i] === '"' && body[i + 1] !== '"'))
197
+ i += body[i] === '"' ? 2 : 1;
198
+ else
199
+ while (i < body.length && body[i] !== quote)
200
+ i += body[i] === '\\' ? 2 : 1;
201
+ if (i >= body.length || /[\w$"'`]/.test(body[i + 1] ?? ''))
202
+ return undefined;
203
+ // A verbatim string keeps its `@`/`$@`, so CSHARP_ONLY still sees it is C#.
204
+ out += `${verbatim ? verbatim[0].slice(0, -1) : ''}${quote}${quote}`;
205
+ i++;
206
+ }
207
+ else {
208
+ out += c;
209
+ i++;
127
210
  }
128
- else
129
- deepExprStrings(v, where, roots, out);
130
211
  }
212
+ return out;
213
+ }
214
+ /** `text` for a message, cut to a readable length. */
215
+ function shownExpr(text) {
216
+ return JSON.stringify(text.length > 80 ? `${text.slice(0, 77)}...` : text);
131
217
  }
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);
218
+ /** Report one `=`-expression whose bare `=` prefix makes it C#. */
219
+ function checkLanguagePrefix(expr, where, out) {
220
+ if (!expr || !expr.startsWith('=') || expr.startsWith(JS_EXPR_PREFIX) || OTHER_PREFIX.test(expr))
137
221
  return;
138
- }
139
- if (Array.isArray(val)) {
140
- for (const v of val)
141
- deepExprStrings(v, where, roots, out);
222
+ if (DATA_FABRIC_LOOKUP.test(expr))
223
+ return;
224
+ const body = expr.slice(1).trim();
225
+ if (body === '' || PLAIN_PATH.test(body) || PLAIN_LITERAL.test(body))
226
+ return;
227
+ const code = maskStrings(body);
228
+ if (code === undefined)
229
+ return;
230
+ const shown = shownExpr(expr);
231
+ const csharp = CSHARP_ONLY.some((re) => re.test(code));
232
+ // `=js:` + the same text is a fix only when the body has no C# of its own.
233
+ const suggestion = csharp ? {} : { suggestion: `${JS_EXPR_PREFIX}${body}` };
234
+ const fix = csharp ? 'Rewrite it in JavaScript and prefix it with `=js:`.' : 'Prefix it with `=js:`.';
235
+ const jsOnly = JS_ONLY.find(({ re }) => re.test(code));
236
+ if (jsOnly?.definite) {
237
+ out.push({
238
+ level: 'error',
239
+ code: 'EXPR_BARE_PREFIX_JS_SYNTAX',
240
+ message: `Expression ${shown} starts with a bare \`=\`, which Studio Web and the Maestro runtime read as C#, `
241
+ + `but it uses ${jsOnly.named}, which is JavaScript. The run faults or the condition reads false, `
242
+ + `while validate passes. ${fix}`,
243
+ ...suggestion,
244
+ where,
245
+ });
142
246
  return;
143
247
  }
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
- }
248
+ const uses = jsOnly ? ` It uses ${jsOnly.named}, which C# has only as a member of that name.` : '';
249
+ out.push({
250
+ level: 'warning',
251
+ code: 'EXPR_BARE_PREFIX',
252
+ message: `Expression ${shown} starts with a bare \`=\`, which Studio Web and the Maestro runtime read as C#; `
253
+ + `only \`=js:\` marks JavaScript.${uses} Studio Web opens it in its C# editor. `
254
+ + (csharp
255
+ ? 'It uses C#, so keep it if the C# is meant; otherwise rewrite it in JavaScript and prefix it with `=js:`.'
256
+ : 'Prefix it with `=js:`, unless the C# is meant (an expression decompiled from the canvas, say).'),
257
+ ...suggestion,
258
+ where,
259
+ });
172
260
  }
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();
261
+ /**
262
+ * Codes that advise how NEW expression text should be written. `check --baseline` drops
263
+ * them on an element the edit did not change (check-baseline.ts): an untouched
264
+ * expression is the original's, and an edit is not asked to rewrite it.
265
+ */
266
+ export const AUTHORING_ADVICE_CODES = new Set(['EXPR_BARE_PREFIX']);
267
+ /** Every finding on one field. */
268
+ function checkField(f, out) {
269
+ if (f.form === 'script')
270
+ checkScript(f, out);
271
+ else
272
+ checkExpr(f, out);
257
273
  }
258
274
  /** Every first-level expression problem in a built BPMN process, stamped with its location. */
259
275
  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
276
  const out = [];
286
- walk(built.nodes, built.flows, roots, out);
277
+ for (const f of bpmnExpressionFields(built)) {
278
+ const found = [];
279
+ checkField(f, found);
280
+ for (const d of found)
281
+ out.push({ ...d, elementId: f.elementId, path: f.path });
282
+ }
287
283
  return out;
288
284
  }
289
285
  /**
290
- * The top-level arguments no expression may read — see {@link BpmnRoots.args}.
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.
286
+ * Every expression in a built BPMN process that the platform reads as C# while the
287
+ * author most likely meant JavaScript (#2137): `EXPR_BARE_PREFIX` and
288
+ * `EXPR_BARE_PREFIX_JS_SYNTAX`, on the same fields as {@link checkBpmnExpressions}.
301
289
  */
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) {
290
+ export function checkBpmnExpressionLanguage(built) {
320
291
  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));
292
+ for (const f of bpmnExpressionFields(built)) {
293
+ if (f.form !== 'expression')
294
+ continue;
295
+ const found = [];
296
+ checkLanguagePrefix(f.text, f.where, found);
297
+ for (const d of found)
298
+ out.push({ ...d, elementId: f.elementId, path: f.path });
330
299
  }
331
300
  return out;
332
301
  }
@@ -377,7 +377,12 @@ export interface BpmnFlow {
377
377
  target: string;
378
378
  /** Edge label the designer shows. */
379
379
  name?: string;
380
- /** `=`-expression gating this flow (exclusive/inclusive gateway outgoing). Read a declared process variable as `=vars.<id>`. */
380
+ /**
381
+ * `=`-expression gating this flow (exclusive/inclusive gateway outgoing), e.g.
382
+ * `'=js:vars.status == "ok"'`. Read a declared process variable as `vars.<id>`. Write
383
+ * `=js:` for JavaScript: Studio Web and the runtime read a bare `=` as C#, and
384
+ * `check` says so (`EXPR_BARE_PREFIX`).
385
+ */
381
386
  condition?: string;
382
387
  /**
383
388
  * Set on a flow the builder wrote by implication — an arm's chain, a handler's path,
@@ -2065,7 +2070,7 @@ export interface MessageHandlerOpts extends HandlerOpts {
2065
2070
  * arm nobody gave a condition cannot be written.
2066
2071
  */
2067
2072
  export type ChooseArm = {
2068
- /** `=`-expression selecting this arm, e.g. `'=vars.action == "Approved"'`. */
2073
+ /** `=`-expression selecting this arm, e.g. `'=js:vars.action == "Approved"'`. */
2069
2074
  when: string;
2070
2075
  /** Not on a conditioned arm. */
2071
2076
  otherwise?: never;
@@ -3363,7 +3368,7 @@ declare abstract class ScopeBuilder {
3363
3368
  * .startEvent('start')
3364
3369
  * .task('decide', { set: { action: 'Approved' } })
3365
3370
  * .choose('approved', [
3366
- * { when: '=vars.action == "Approved"', label: 'Yes', body: (b) => b.task('post', { set: { status: 'posted' } }) },
3371
+ * { when: '=js:vars.action == "Approved"', label: 'Yes', body: (b) => b.task('post', { set: { status: 'posted' } }) },
3367
3372
  * { otherwise: true, label: 'No', body: (b) => b.task('reject', { set: { status: 'rejected' } }) },
3368
3373
  * ])
3369
3374
  * .endEvent('done')
@@ -3468,7 +3473,7 @@ declare abstract class ScopeBuilder {
3468
3473
  * ])
3469
3474
  * .startEvent('Start_1')
3470
3475
  * .choose('Gw_1', [
3471
- * { when: '=vars.total > 1000', body: (b) => b.task('Review').goto('Done') },
3476
+ * { when: '=js:vars.total > 1000', body: (b) => b.task('Review').goto('Done') },
3472
3477
  * { otherwise: true, body: (b) => b.task('Pay').goto('Done') },
3473
3478
  * ])
3474
3479
  * .endEvent('Done')
@@ -3679,7 +3684,7 @@ export declare class PathBuilder extends ScopeBuilder {
3679
3684
  * .startEvent('start')
3680
3685
  * .scriptTask('attempt', { script: 'return { ok: true };', outputs: { ok: '=result.response.ok' } })
3681
3686
  * .choose('worked', [
3682
- * { when: '=vars.ok == true', body: (b) => b.endEvent('done') },
3687
+ * { when: '=js:vars.ok == true', body: (b) => b.endEvent('done') },
3683
3688
  * { otherwise: true, body: (b) => b.goto('attempt') },
3684
3689
  * ])
3685
3690
  * .sequenceFlow('start', 'attempt')
@@ -2263,7 +2263,7 @@ class ScopeBuilder {
2263
2263
  * .startEvent('start')
2264
2264
  * .task('decide', { set: { action: 'Approved' } })
2265
2265
  * .choose('approved', [
2266
- * { when: '=vars.action == "Approved"', label: 'Yes', body: (b) => b.task('post', { set: { status: 'posted' } }) },
2266
+ * { when: '=js:vars.action == "Approved"', label: 'Yes', body: (b) => b.task('post', { set: { status: 'posted' } }) },
2267
2267
  * { otherwise: true, label: 'No', body: (b) => b.task('reject', { set: { status: 'rejected' } }) },
2268
2268
  * ])
2269
2269
  * .endEvent('done')
@@ -2399,7 +2399,7 @@ class ScopeBuilder {
2399
2399
  * ])
2400
2400
  * .startEvent('Start_1')
2401
2401
  * .choose('Gw_1', [
2402
- * { when: '=vars.total > 1000', body: (b) => b.task('Review').goto('Done') },
2402
+ * { when: '=js:vars.total > 1000', body: (b) => b.task('Review').goto('Done') },
2403
2403
  * { otherwise: true, body: (b) => b.task('Pay').goto('Done') },
2404
2404
  * ])
2405
2405
  * .endEvent('Done')
@@ -2711,7 +2711,7 @@ export class PathBuilder extends ScopeBuilder {
2711
2711
  * .startEvent('start')
2712
2712
  * .scriptTask('attempt', { script: 'return { ok: true };', outputs: { ok: '=result.response.ok' } })
2713
2713
  * .choose('worked', [
2714
- * { when: '=vars.ok == true', body: (b) => b.endEvent('done') },
2714
+ * { when: '=js:vars.ok == true', body: (b) => b.endEvent('done') },
2715
2715
  * { otherwise: true, body: (b) => b.goto('attempt') },
2716
2716
  * ])
2717
2717
  * .sequenceFlow('start', 'attempt')