@unframework.dev/target-angular 0.0.0-stage → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,547 @@
1
+ import { assertedCode, assertedFunction } from "./narrowing.js";
2
+ import { bindingById, formOf, isLoopVariable, resultApi, unreachable } from "./plan.js";
3
+ import { classRules, statementRead, statementRules } from "./rules.js";
4
+ import { bodyStatements, returnsValue } from "./statements.js";
5
+ import { childEvent } from "./composition.js";
6
+ import { angularCode, parameterText, parseExpression, parseStatementsSource, pascalCase, rewriteCode } from "@unframework.dev/codegen";
7
+ import { DOM_EVENTS, walk } from "@unframework.dev/ir";
8
+ /**
9
+ * Plans every listener of a component's template, in document order. A native `v-model`'s write
10
+ * runs first in the template listener of the attribute `writes` gives it (./models.ts).
11
+ */
12
+ function planListeners(plan, nextTick, writes) {
13
+ const { component } = plan;
14
+ const statements = /* @__PURE__ */ new Map();
15
+ const outputs = /* @__PURE__ */ new Map();
16
+ const attributes = /* @__PURE__ */ new Map();
17
+ const methods = [];
18
+ const directives = /* @__PURE__ */ new Map();
19
+ const reads = /* @__PURE__ */ new Set();
20
+ const members = /* @__PURE__ */ new Set();
21
+ const globals = /* @__PURE__ */ new Set();
22
+ const guards = /* @__PURE__ */ new Map();
23
+ let once;
24
+ const collected = {
25
+ reads,
26
+ members,
27
+ globals,
28
+ nextTick,
29
+ tested: /* @__PURE__ */ new Map()
30
+ };
31
+ const { tested } = collected;
32
+ /** Counts the bindings an `If`'s conditions read in or out, as the walk enters and leaves it. */
33
+ const count = (node, step) => {
34
+ for (const { condition } of node.branches) for (const reference of condition?.refs ?? []) {
35
+ if (reference.kind !== "Binding") continue;
36
+ const next = (tested.get(reference.binding) ?? 0) + step;
37
+ if (next === 0) tested.delete(reference.binding);
38
+ else tested.set(reference.binding, next);
39
+ }
40
+ };
41
+ const context = {
42
+ methods,
43
+ collected,
44
+ once: () => once ??= templateMember(plan, "once"),
45
+ guard: (event) => {
46
+ let guard = guards.get(event);
47
+ if (guard === void 0) {
48
+ guard = templateMember(plan, `${event}Once`);
49
+ guards.set(event, guard);
50
+ }
51
+ return guard;
52
+ }
53
+ };
54
+ walk(component.render, {
55
+ leave(node) {
56
+ if (node.kind === "If") count(node, -1);
57
+ },
58
+ enter(node) {
59
+ if (node.kind === "If") count(node, 1);
60
+ const child = node.kind === "Component" ? node.component : node.kind === "Dynamic" ? node.candidates.find((candidate) => candidate.kind === "Component")?.component : void 0;
61
+ if (child !== void 0 && (node.kind === "Component" || node.kind === "Dynamic")) {
62
+ for (const attribute of node.attributes) {
63
+ if (attribute.kind !== "Listener") continue;
64
+ const event = childEvent(plan, child, attribute.event);
65
+ outputs.set(attribute, outputStatement(plan, attribute, event, methods, collected));
66
+ }
67
+ return;
68
+ }
69
+ const element = node.kind === "Element" ? node : node.kind === "Dynamic" && node.candidates[0]?.kind === "Tag" ? {
70
+ kind: "Element",
71
+ tag: node.candidates[0].tag,
72
+ attributes: node.attributes,
73
+ children: node.children,
74
+ span: node.span
75
+ } : void 0;
76
+ if (element === void 0) return;
77
+ onElement(element);
78
+ }
79
+ });
80
+ function onElement(node) {
81
+ const groups = orderedGroups(node, writes);
82
+ for (const attribute of node.attributes) {
83
+ if (attribute.kind !== "Event") continue;
84
+ const group = groups.get(attribute);
85
+ if (group !== void 0) {
86
+ const chained = group[0] === attribute ? groupStatement(plan, node, group, context) : void 0;
87
+ const write = writes.get(attribute);
88
+ const statement = chained === void 0 || write === void 0 ? chained : `${write}; ${chained}`;
89
+ attributes.set(attribute, statement === void 0 ? "" : `(${attribute.event})="${angularCode(statement, "event")}"`);
90
+ continue;
91
+ }
92
+ const name = () => handlerName(plan, node, attribute.event, optionOf(attribute));
93
+ const { code, valued } = listenerStatement(plan, attribute, name, methods, collected);
94
+ const write = writes.get(attribute);
95
+ const statement = `${write === void 0 ? "" : `${write}; `}${valued ? `void ${code}` : code}`;
96
+ const option = optionOf(attribute);
97
+ if (option === void 0) {
98
+ statements.set(attribute, statement);
99
+ continue;
100
+ }
101
+ const output = `uf${pascalCase(attribute.event)}${pascalCase(option)}`;
102
+ let directive = directives.get(output);
103
+ if (!directive) {
104
+ directive = {
105
+ event: attribute.event,
106
+ option,
107
+ output,
108
+ className: plan.imports.claim(`${pascalCase(attribute.event)}${pascalCase(option)}`),
109
+ eventType: DOM_EVENTS.get(attribute.event) ?? "Event"
110
+ };
111
+ directives.set(output, directive);
112
+ }
113
+ attributes.set(attribute, `(${output})="${angularCode(statement, "event")}"`);
114
+ }
115
+ }
116
+ return {
117
+ statements,
118
+ outputs,
119
+ attributes,
120
+ methods,
121
+ directives: [...directives.values()],
122
+ reads,
123
+ members,
124
+ globals,
125
+ guards: [...guards.values()],
126
+ ...once === void 0 ? {} : { once }
127
+ };
128
+ }
129
+ /**
130
+ * What a listener of a child's output passes its handler, by the payload rule (ADR-0047): an
131
+ * output emits one value, nothing for an event without members, the value for one required
132
+ * member, and the tuple of the arguments otherwise.
133
+ */
134
+ function payloadArguments(event) {
135
+ const [only, ...more] = event.parameters;
136
+ if (only === void 0) return [];
137
+ if (more.length === 0 && !only.optional) return ["$event"];
138
+ return event.parameters.map((_, index) => `$event[${index}]`);
139
+ }
140
+ /**
141
+ * The template statement of a listener of a child's output (ADR-0053): a setup function it
142
+ * names, called with as much of the payload as it takes (`clear($event)`); an inline handler that
143
+ * is one call the template can read, its parameters read from the payload
144
+ * (`clear($event.toUpperCase())` would not be one); or any other, moved to a method that takes
145
+ * the payload's members, typed as the child declares them (`onPickedURL($event)`). An output's
146
+ * listener prevents nothing, whatever its value.
147
+ */
148
+ function outputStatement(plan, attribute, event, methods, collected) {
149
+ const payload = payloadArguments(event);
150
+ const { handler } = attribute;
151
+ switch (handler.kind) {
152
+ case "Function": {
153
+ const fn = functionOf(plan.component, handler.binding);
154
+ collected.reads.add(handler.binding);
155
+ return `${bindingById(plan, handler.binding).name}(${payload.slice(0, fn.parameters.length).join(", ")})`;
156
+ }
157
+ case "Inline": {
158
+ const fn = handler.function;
159
+ const statement = templateStatement(plan, fn, collected, payload);
160
+ if (statement !== void 0) return statement.code;
161
+ const name = templateMember(plan, `on${pascalCase(attribute.event)}`);
162
+ const body = bodyStatements(assertedFunction(fn, () => true), plan, classRules(plan, collected.nextTick));
163
+ methods.push({
164
+ name,
165
+ parameters: fn.parameters.map((parameter, index) => parameter.type || event.parameters[index] === void 0 ? parameterText(parameter) : `${parameterText(parameter)}: ${event.parameters[index].type}`),
166
+ async: fn.async === true,
167
+ body
168
+ });
169
+ return `${name}(${payload.slice(0, fn.parameters.length).join(", ")})`;
170
+ }
171
+ default: return unreachable(handler);
172
+ }
173
+ }
174
+ /** A listener's option, or none. */
175
+ function optionOf(attribute) {
176
+ if (attribute.capture) return "capture";
177
+ if (attribute.once) return "once";
178
+ return attribute.passive ? "passive" : void 0;
179
+ }
180
+ /** The template statement a listener runs, moving its handler to a method when it must. */
181
+ function listenerStatement(plan, attribute, methodName, methods, collected) {
182
+ const { reads, nextTick } = collected;
183
+ const { component } = plan;
184
+ const { handler } = attribute;
185
+ switch (handler.kind) {
186
+ case "Function": {
187
+ const binding = bindingById(plan, handler.binding);
188
+ const fn = functionOf(component, handler.binding);
189
+ const takesEvent = fn.parameters[0]?.event !== void 0;
190
+ reads.add(handler.binding);
191
+ return {
192
+ code: `${binding.name}(${takesEvent ? "$event" : ""})`,
193
+ valued: !fn.async && returnsValue(fn)
194
+ };
195
+ }
196
+ case "Inline": {
197
+ const statement = templateStatement(plan, handler.function, collected);
198
+ if (statement !== void 0) return statement;
199
+ const fn = handler.function;
200
+ const [event] = fn.parameters;
201
+ const name = methodName();
202
+ const body = bodyStatements(assertedFunction(fn, () => true), plan, classRules(plan, nextTick));
203
+ methods.push(hoisted(name, fn, attribute.event, body));
204
+ return {
205
+ code: `${name}(${event === void 0 ? "" : "$event"})`,
206
+ valued: false
207
+ };
208
+ }
209
+ default: return unreachable(handler);
210
+ }
211
+ }
212
+ /**
213
+ * The name of the method a handler moves to, `on` and what the element says it is
214
+ * (`elementSubject`), with its option's name for a listener of a group (`onGoOnce`), or, for an
215
+ * element that says nothing, the event and its option (`onClickCapture`).
216
+ */
217
+ function handlerName(plan, element, domEvent, option, optioned = false) {
218
+ const suffix = option === void 0 ? "" : pascalCase(option);
219
+ const subject = elementSubject(element, domEvent);
220
+ return templateMember(plan, subject === void 0 ? `on${pascalCase(domEvent)}${suffix}` : `on${subject}${optioned ? suffix : ""}`);
221
+ }
222
+ /**
223
+ * A name for a member the template reads (a moved handler, a once guard and its set), claimed
224
+ * beside the class's members: never a list's variable's name, which would shadow it in the list.
225
+ */
226
+ function templateMember(plan, base) {
227
+ let name = plan.members.claim(base);
228
+ while (plan.loopNames.has(name)) name = plan.members.claim(base);
229
+ return name;
230
+ }
231
+ /**
232
+ * What an element says it is, for the names of its handlers: its static `aria-label`
233
+ * or its text (`AddOne`, `Reset`), with the event's name but for a click (`QueryKeydown`); or a
234
+ * form control's `name` and the event (`EmailInput`); or `undefined`.
235
+ */
236
+ function elementSubject(element, domEvent) {
237
+ const event = pascalCase(domEvent);
238
+ const label = words(staticValue(element, "aria-label") ?? textOf(element));
239
+ if (label !== void 0) return `${label}${domEvent === "click" ? "" : event}`;
240
+ const control = words(staticValue(element, "name"));
241
+ return control === void 0 ? void 0 : `${control}${event}`;
242
+ }
243
+ /** A handler hoisted to a method, its event parameter typed as its event's DOM interface. */
244
+ function hoisted(name, fn, domEvent, body) {
245
+ const [event] = fn.parameters;
246
+ return {
247
+ name,
248
+ parameters: event === void 0 ? [] : [event.type ? parameterText(event) : `${parameterText(event)}: ${event.event ?? DOM_EVENTS.get(domEvent)}`],
249
+ async: fn.async === true,
250
+ body
251
+ };
252
+ }
253
+ /** An element's static attribute value. */
254
+ function staticValue(element, name) {
255
+ for (const attribute of element.attributes) if (attribute.kind === "Static" && attribute.name === name && attribute.value !== true) return attribute.value;
256
+ }
257
+ /** An element's text, when its children are text alone. */
258
+ function textOf(element) {
259
+ const { children } = element;
260
+ if (!children.length || !children.every((child) => child.kind === "Text")) return void 0;
261
+ return children.map((child) => child.kind === "Text" ? child.value : "").join("");
262
+ }
263
+ /** Up to four ASCII words in PascalCase (`Add one` → `AddOne`), or `undefined`. */
264
+ function words(text) {
265
+ const found = text?.match(/[A-Za-z0-9]+/g);
266
+ if (!found || found.length > 4) return void 0;
267
+ return found.map((word) => `${word[0].toUpperCase()}${word.slice(1).toLowerCase()}`).join("");
268
+ }
269
+ /** The function a setup function's binding names. */
270
+ function functionOf(component, id) {
271
+ for (const item of component.setup) if (item.kind === "Function" && item.binding === id) return item.function;
272
+ throw new Error(`No setup function declares ${id}.`);
273
+ }
274
+ const isAstNode = (value) => typeof value === "object" && value !== null && typeof value.type === "string" && typeof value.start === "number";
275
+ /** Calls `visit` on every node of an AST, parents first; `false` skips a node's children. */
276
+ function visitAst(root, visit) {
277
+ if (Array.isArray(root)) {
278
+ for (const item of root) visitAst(item, visit);
279
+ return;
280
+ }
281
+ if (!isAstNode(root) || visit(root) === false) return;
282
+ for (const [key, value] of Object.entries(root)) if (key !== "type" && typeof value === "object") visitAst(value, visit);
283
+ }
284
+ /**
285
+ * An inline handler as a template statement, when it is one call of a setup function or of
286
+ * `emit` whose arguments the template can read: always for a handler that reads a list's item
287
+ * or index (the analyser keeps those to this form, UF3029); for one that reads a prop a condition
288
+ * around it tests, when Angular's expressions can hold its arguments (the analyser keeps a handler
289
+ * that reads a narrowed prop to this form, UF3029, which the template keeps narrowed, where a
290
+ * method of the class would read the input un-narrowed); otherwise when its arguments are
291
+ * literals, names and members of the inputs, the constants, a list's variables and the event, so
292
+ * that nothing in them reads a state's value from the last render. Otherwise `undefined`.
293
+ */
294
+ function templateStatement(plan, fn, { reads, members, globals, tested }, payload = ["$event"]) {
295
+ const call = singleCall(fn.body, fn.expression === true);
296
+ if (!call) return void 0;
297
+ if (fn.parameters.some((parameter) => parameter.name === void 0)) return void 0;
298
+ const refs = fn.body.refs;
299
+ const readsLoop = refs.some((reference) => reference.kind === "Binding" && isLoopVariable(bindingById(plan, reference.binding).kind));
300
+ const readsTested = refs.some((reference) => reference.kind === "Binding" && tested.has(reference.binding) && formOf(plan, bindingById(plan, reference.binding)) === "input");
301
+ if (!readsLoop && !(readsTested && call.arguments.every(angularReadable)) && !(call.arguments.every(isSimple) && refs.every((ref) => simpleRead(plan, ref)))) return;
302
+ const code = assertedCode({
303
+ code: call.code,
304
+ span: call.span,
305
+ refs: refs.filter((reference) => reference.span.start >= call.span.start && reference.span.end <= call.span.end)
306
+ }, (reference) => formOf(plan, bindingById(plan, reference.binding)) !== "input");
307
+ for (const reference of code.refs) if (reference.kind === "Binding") (statementRead(plan, bindingById(plan, reference.binding)).startsWith("this.") ? members : reads).add(reference.binding);
308
+ else if (reference.kind === "Emit") reads.add(reference.binding);
309
+ else if (reference.kind === "Global") globals.add(reference.name);
310
+ const statement = fn.parameters.reduce((written, parameter, index) => renamed(written, parameter.name, payload[index] ?? "$event"), rewriteCode(code, plan.component, statementRules(plan), "client"));
311
+ if (call.callee === void 0) return {
312
+ code: statement,
313
+ valued: false
314
+ };
315
+ if (bindingById(plan, call.callee).kind === "usedFn") return {
316
+ code: statement,
317
+ valued: resultApi(plan, call.callee).async !== true
318
+ };
319
+ const { kind } = bindingById(plan, call.callee);
320
+ if (kind === "import" || kind === "moduleConst") return {
321
+ code: statement,
322
+ valued: true
323
+ };
324
+ const callee = functionOf(plan.component, call.callee);
325
+ return {
326
+ code: statement,
327
+ valued: !callee.async && returnsValue(callee)
328
+ };
329
+ }
330
+ /** The one call an arrow's body makes, with its code and span in the source. */
331
+ function singleCall(body, expression) {
332
+ let node;
333
+ if (expression) node = parseExpression(body.code);
334
+ else {
335
+ const { statements } = parseStatementsSource(body.code);
336
+ const block = statements[0];
337
+ const inner = statements.length === 1 && block?.type === "BlockStatement" ? block.body : [];
338
+ const [only] = inner;
339
+ if (inner.length !== 1 || only?.type !== "ExpressionStatement") return void 0;
340
+ node = only.expression;
341
+ }
342
+ if (node.type !== "CallExpression" || node.optional) return void 0;
343
+ const callee = node.callee;
344
+ const args = node.arguments;
345
+ if (callee.type !== "Identifier" || args.some((arg) => arg.type === "SpreadElement")) return;
346
+ const offset = body.span.start;
347
+ const start = offset + node.start;
348
+ const end = offset + node.end;
349
+ const callRef = body.refs.find((reference) => reference.span.start === start);
350
+ const callsFunction = callRef?.kind === "Binding" && callRef.call === true && callRef.span.end === offset + callee.end;
351
+ const emits = callRef?.kind === "Emit" && callRef.span.end === end;
352
+ if (!callsFunction && !emits) return void 0;
353
+ return {
354
+ code: body.code.slice(node.start, node.end),
355
+ span: {
356
+ start,
357
+ end
358
+ },
359
+ arguments: args,
360
+ ...callsFunction ? { callee: callRef.binding } : {}
361
+ };
362
+ }
363
+ /** An argument the template reads as the source does: literals, names, members, simple operators. */
364
+ function isSimple(node) {
365
+ switch (node.type) {
366
+ case "Literal": return node.regex === void 0 && node.bigint === void 0;
367
+ case "Identifier": return true;
368
+ case "MemberExpression": return isSimple(node.object) && (!node.computed || isSimple(node.property));
369
+ case "ChainExpression": return isSimple(node.expression);
370
+ case "UnaryExpression": return [
371
+ "!",
372
+ "-",
373
+ "+"
374
+ ].includes(node.operator) && isSimple(node.argument);
375
+ case "ArrayExpression": return node.elements.every((element) => element !== null && element.type !== "SpreadElement" && isSimple(element));
376
+ default: return false;
377
+ }
378
+ }
379
+ /**
380
+ * The syntax JavaScript has and Angular's expressions do not (Angular 22's `parseAction`, which
381
+ * reads spreads in arrays, objects and calls, expression-bodied arrows and regular expressions): a
382
+ * handler's argument holding one stays in the class. The analyser keeps a narrowed or listed
383
+ * handler's arguments to the template subset (UF3029), which none of these is in.
384
+ */
385
+ const NOT_ANGULAR = /* @__PURE__ */ new Set([
386
+ "NewExpression",
387
+ "FunctionExpression",
388
+ "ClassExpression",
389
+ "AssignmentExpression",
390
+ "UpdateExpression",
391
+ "SequenceExpression",
392
+ "AwaitExpression",
393
+ "YieldExpression",
394
+ "TaggedTemplateExpression",
395
+ "ImportExpression",
396
+ "MetaProperty",
397
+ "ThisExpression",
398
+ "Super",
399
+ "TSAsExpression",
400
+ "TSSatisfiesExpression",
401
+ "TSTypeAssertion",
402
+ "TSInstantiationExpression"
403
+ ]);
404
+ /** Whether Angular's expressions can hold an argument as the printer writes it. */
405
+ function angularReadable(node) {
406
+ let readable = true;
407
+ visitAst(node, (each) => {
408
+ if (NOT_ANGULAR.has(each.type) || each.type === "ArrowFunctionExpression" && !each.expression || each.type === "UnaryExpression" && each.operator === "delete" || each.type === "Literal" && each.bigint !== void 0) readable = false;
409
+ return readable;
410
+ });
411
+ return readable;
412
+ }
413
+ /** A reference a template statement reads as the source does (no state's last-render value). */
414
+ function simpleRead(plan, reference) {
415
+ switch (reference.kind) {
416
+ case "Binding": {
417
+ const form = formOf(plan, bindingById(plan, reference.binding));
418
+ switch (form) {
419
+ case "input":
420
+ case "value":
421
+ case "loop":
422
+ case "method":
423
+ case "arrow":
424
+ case "context":
425
+ case "module":
426
+ case "resultValue": return true;
427
+ case "result":
428
+ case "model":
429
+ case "instance":
430
+ case "component":
431
+ case "signal":
432
+ case "linked":
433
+ case "computed":
434
+ case "once":
435
+ case "query":
436
+ case "field":
437
+ case "emit": return false;
438
+ default: return unreachable(form);
439
+ }
440
+ }
441
+ case "Emit":
442
+ case "Event": return true;
443
+ case "Global":
444
+ case "Import":
445
+ case "Slot":
446
+ case "Write":
447
+ case "Api": return false;
448
+ default: return unreachable(reference);
449
+ }
450
+ }
451
+ /** An expression with every read of the name `from` renamed `to`. */
452
+ function renamed(expression, from, to) {
453
+ const edits = [];
454
+ const visit = (value) => {
455
+ if (Array.isArray(value)) {
456
+ for (const item of value) visit(item);
457
+ return;
458
+ }
459
+ if (!isAstNode(value)) return;
460
+ switch (value.type) {
461
+ case "Identifier":
462
+ if (value.name === from) edits.push({
463
+ start: value.start,
464
+ end: value.end,
465
+ text: to
466
+ });
467
+ return;
468
+ case "MemberExpression":
469
+ visit(value.object);
470
+ if (value.computed) visit(value.property);
471
+ return;
472
+ case "Property":
473
+ if (value.shorthand && value.value.type === "Identifier") {
474
+ if (value.value.name === from) edits.push({
475
+ start: value.start,
476
+ end: value.end,
477
+ text: `${from}: ${to}`
478
+ });
479
+ return;
480
+ }
481
+ if (value.computed) visit(value.key);
482
+ visit(value.value);
483
+ return;
484
+ default: for (const [key, child] of Object.entries(value)) if (key !== "type" && typeof child === "object") visit(child);
485
+ }
486
+ };
487
+ visit(parseExpression(expression));
488
+ let result = expression;
489
+ for (const { start, end, text } of edits.toSorted((a, b) => b.start - a.start)) result = `${result.slice(0, start)}${text}${result.slice(end)}`;
490
+ return result;
491
+ }
492
+ /**
493
+ * The listeners of one element that must run in their attributes' order, by attribute: those of
494
+ * one event in the bubble phase, when there are two or three (a plain one beside a `once` or a
495
+ * `passive` one: the analyser allows each once), or a lone `once` or `passive` one a native
496
+ * `v-model`'s write runs before (`writes`). A capture listener is alone in its phase, and at its
497
+ * target it runs before the bubble phase's whatever the order it was added in.
498
+ */
499
+ function orderedGroups(element, writes) {
500
+ const byEvent = /* @__PURE__ */ new Map();
501
+ for (const attribute of element.attributes) {
502
+ if (attribute.kind !== "Event" || attribute.capture) continue;
503
+ const group = byEvent.get(attribute.event) ?? [];
504
+ group.push(attribute);
505
+ byEvent.set(attribute.event, group);
506
+ }
507
+ const groups = /* @__PURE__ */ new Map();
508
+ for (const group of byEvent.values()) {
509
+ const [only] = group;
510
+ const option = only !== void 0 && (only.once || only.passive);
511
+ if (group.length < 2 && !(option && writes.has(only))) continue;
512
+ for (const attribute of group) groups.set(attribute, group);
513
+ }
514
+ return groups;
515
+ }
516
+ /**
517
+ * A group's one template listener: a chain of template statements, one per listener in its
518
+ * attribute's order (ADR-0047), each written as it would be alone (a setup function's call, an
519
+ * inline handler's call, or the call of the method an inline handler moved to), so the template
520
+ * keeps typing and narrowing what each reads (a list's item, a value a condition narrows), and
521
+ * the source's names meet no name the emitter declares. A `once` listener runs under a guard,
522
+ * `once(clickOnce, $event) && …`, whose set remembers each element it ran on, as `{ once: true }`
523
+ * removes a listener from its own element only (a list's rows each run theirs once), marking it
524
+ * before the listener runs, as the browser removes a listener before calling it. A `passive`
525
+ * listener joins the others: the element already has a listener that is not passive, so scrolling
526
+ * waits for it either way (the analyser rejects `preventDefault()` in a passive listener, which
527
+ * never prevents anything: UF3034). Angular prevents the event when the listener's value is
528
+ * `false`, and a chain's value is its last statement's: that one is `void` when it may have one.
529
+ */
530
+ function groupStatement(plan, element, group, context) {
531
+ const parts = group.map((attribute) => {
532
+ const name = () => handlerName(plan, element, attribute.event, optionOf(attribute), true);
533
+ const statement = listenerStatement(plan, attribute, name, context.methods, context.collected);
534
+ if (!attribute.once) return {
535
+ ...statement,
536
+ guarded: false
537
+ };
538
+ return {
539
+ code: `${context.once()}(${context.guard(attribute.event)}, $event) && ${statement.code}`,
540
+ valued: true,
541
+ guarded: true
542
+ };
543
+ });
544
+ const last = parts.length - 1;
545
+ return parts.map(({ code, valued, guarded }, index) => index < last || !valued ? code : `void ${guarded ? `(${code})` : code}`).join("; ");
546
+ }
547
+ export { planListeners };