embedded-react 0.19.0 → 0.21.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.
Files changed (148) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +8 -3
  3. package/aot/app-file-loader.mjs +116 -0
  4. package/aot/compile.mjs +180 -90
  5. package/aot/compiler/animations.mjs +568 -317
  6. package/aot/compiler/boot.mjs +97 -35
  7. package/aot/compiler/branch-merge.mjs +4 -3
  8. package/aot/compiler/check.mjs +70 -18
  9. package/aot/compiler/collect.mjs +787 -288
  10. package/aot/compiler/contexts.mjs +391 -0
  11. package/aot/compiler/control-flow.mjs +439 -268
  12. package/aot/compiler/custom-hooks.mjs +686 -0
  13. package/aot/compiler/diagnostics.mjs +22 -25
  14. package/aot/compiler/elements/activity-indicator.mjs +25 -24
  15. package/aot/compiler/elements/button.mjs +182 -0
  16. package/aot/compiler/elements/dial.mjs +91 -77
  17. package/aot/compiler/elements/flat-list.mjs +24 -22
  18. package/aot/compiler/elements/image-background.mjs +76 -0
  19. package/aot/compiler/elements/image.mjs +52 -50
  20. package/aot/compiler/elements/modal.mjs +31 -30
  21. package/aot/compiler/elements/props.mjs +61 -26
  22. package/aot/compiler/elements/rewrite.mjs +118 -0
  23. package/aot/compiler/elements/section-list.mjs +370 -0
  24. package/aot/compiler/elements/switch.mjs +42 -34
  25. package/aot/compiler/elements/text-input.mjs +34 -32
  26. package/aot/compiler/expressions.mjs +1685 -392
  27. package/aot/compiler/handlers.mjs +2029 -547
  28. package/aot/compiler/helper-values.mjs +312 -0
  29. package/aot/compiler/ir/functions.mjs +11 -1
  30. package/aot/compiler/ir/nodes.mjs +43 -4
  31. package/aot/compiler/ir/reads.mjs +223 -22
  32. package/aot/compiler/ir/text.mjs +5 -1
  33. package/aot/compiler/ir/types.mjs +26 -14
  34. package/aot/compiler/ir/vectors.mjs +5 -1
  35. package/aot/compiler/kept-states.mjs +177 -0
  36. package/aot/compiler/keyboard.mjs +17 -7
  37. package/aot/compiler/list-items.mjs +226 -0
  38. package/aot/compiler/list-order.mjs +586 -0
  39. package/aot/compiler/list-split.mjs +259 -0
  40. package/aot/compiler/loops.mjs +582 -0
  41. package/aot/compiler/lower.mjs +246 -111
  42. package/aot/compiler/native-files.mjs +439 -0
  43. package/aot/compiler/native-header.mjs +335 -0
  44. package/aot/compiler/native-modules.mjs +1173 -0
  45. package/aot/compiler/nodes.mjs +195 -172
  46. package/aot/compiler/options.mjs +37 -31
  47. package/aot/compiler/out.mjs +32 -23
  48. package/aot/compiler/package/animations.mjs +779 -0
  49. package/aot/compiler/package/arena.mjs +252 -0
  50. package/aot/compiler/package/assemble.mjs +175 -0
  51. package/aot/compiler/package/bytecode.mjs +315 -0
  52. package/aot/compiler/package/checks.mjs +1026 -0
  53. package/aot/compiler/package/codegen.mjs +2168 -0
  54. package/aot/compiler/package/enums.mjs +148 -0
  55. package/aot/compiler/package/format.mjs +771 -0
  56. package/aot/compiler/package/layouts.mjs +136 -0
  57. package/aot/compiler/package/lower.mjs +2103 -0
  58. package/aot/compiler/package/props.mjs +118 -0
  59. package/aot/compiler/package/string-caps.mjs +515 -0
  60. package/aot/compiler/package/tables.mjs +127 -0
  61. package/aot/compiler/package/vectors.mjs +502 -0
  62. package/aot/compiler/package/writer.mjs +686 -0
  63. package/aot/compiler/pan-responder.mjs +69 -61
  64. package/aot/compiler/parse.mjs +23 -21
  65. package/aot/compiler/record-shapes.mjs +246 -0
  66. package/aot/compiler/records.mjs +654 -0
  67. package/aot/compiler/reducers.mjs +272 -0
  68. package/aot/compiler/static-eval.mjs +340 -30
  69. package/aot/compiler/style-text.mjs +178 -174
  70. package/aot/compiler/svg.mjs +480 -251
  71. package/aot/compiler/switch-cases.mjs +198 -0
  72. package/aot/compiler/tagged-records.mjs +450 -0
  73. package/aot/compiler/typing.mjs +307 -0
  74. package/aot/compiler/updaters.mjs +320 -0
  75. package/aot/compiler/window-dimensions.mjs +94 -0
  76. package/aot/compiler/worked-values.mjs +319 -0
  77. package/aot/demo-file.mjs +30 -0
  78. package/aot/screenshot-smoke.mjs +54 -40
  79. package/aot/style-map.mjs +152 -92
  80. package/assets/bake-font.mjs +123 -77
  81. package/assets/bake-image.mjs +39 -22
  82. package/assets/bake-svg.mjs +361 -262
  83. package/assets/build-builtin-font.mjs +11 -7
  84. package/assets/emit-c.mjs +77 -58
  85. package/assets/emit-container.mjs +123 -37
  86. package/assets/emit-pack.mjs +77 -67
  87. package/assets/font-config.mjs +9 -6
  88. package/assets/font-sizes.mjs +163 -123
  89. package/assets/glyph-coverage.mjs +74 -54
  90. package/assets/index.mjs +31 -9
  91. package/assets/rasterize.mjs +126 -99
  92. package/assets/svg-loader.mjs +8 -8
  93. package/build.mjs +23 -13
  94. package/cli.mjs +402 -172
  95. package/compile-bin.mjs +3 -3
  96. package/flash.mjs +537 -0
  97. package/hotreload/dev-device.mjs +90 -33
  98. package/hotreload/pack-app.mjs +55 -43
  99. package/hotreload/pack-split.mjs +62 -64
  100. package/hotreload/package-transfer.mjs +175 -0
  101. package/hotreload/protocol.mjs +50 -37
  102. package/hotreload/uploader.mjs +38 -27
  103. package/hotreload/watch-tree.mjs +19 -19
  104. package/pack-container.mjs +37 -21
  105. package/package.json +7 -8
  106. package/persist-transform.mjs +34 -28
  107. package/qjsc-wasm.mjs +25 -14
  108. package/sim/embedded-react.cjs +1 -1
  109. package/sim/embedded-react.js +1 -1
  110. package/sim/embedded-react.wasm +0 -0
  111. package/sim/index.html +94 -85
  112. package/sim-server.mjs +113 -94
  113. package/src/embedded-react/Animated.js +24 -24
  114. package/src/embedded-react/Dimensions.js +37 -0
  115. package/src/embedded-react/Easing.js +1 -1
  116. package/src/embedded-react/FlatList.js +3 -3
  117. package/src/embedded-react/LayoutAnimation.js +8 -5
  118. package/src/embedded-react/PanResponder.js +75 -71
  119. package/src/embedded-react/Pressable.js +2 -8
  120. package/src/embedded-react/SectionList.js +7 -9
  121. package/src/embedded-react/StyleSheet.js +4 -3
  122. package/src/embedded-react/TouchableOpacity.js +13 -8
  123. package/src/embedded-react/index.d.ts +88 -8
  124. package/src/embedded-react/index.js +2 -0
  125. package/src/embedded-react/layout-anim-config.js +10 -4
  126. package/src/embedded-react/list-child.js +5 -5
  127. package/src/embedded-react/named-colors.js +1 -1
  128. package/src/embedded-react/nativeModule.js +462 -0
  129. package/src/embedded-react/split-style.js +11 -11
  130. package/src/embedded-react/svg-ops.js +760 -593
  131. package/src/embedded-react/useHostValue.js +3 -3
  132. package/src/embedded-react/usePersistentState.js +6 -6
  133. package/src/embedded-react/warn-props.js +1 -1
  134. package/src/host-config.js +60 -53
  135. package/src/props.js +49 -41
  136. package/src/renderer.js +7 -4
  137. package/aot/compiler/assemble.mjs +0 -944
  138. package/aot/compiler/c/animations.mjs +0 -436
  139. package/aot/compiler/c/boot.mjs +0 -127
  140. package/aot/compiler/c/expressions.mjs +0 -270
  141. package/aot/compiler/c/functions.mjs +0 -268
  142. package/aot/compiler/c/keyboard.mjs +0 -96
  143. package/aot/compiler/c/nodes.mjs +0 -303
  144. package/aot/compiler/c/pan-responder.mjs +0 -136
  145. package/aot/compiler/c/statements.mjs +0 -319
  146. package/aot/compiler/c/text.mjs +0 -83
  147. package/aot/compiler/c/vectors.mjs +0 -381
  148. package/aot/compiler/c-syntax.mjs +0 -127
@@ -0,0 +1,312 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /*----------------------------------------------------------------------------------------------------------------------
17
+ - Imports
18
+ ---------------------------------------------------------------------------------------------------------------------*/
19
+ import { aotError } from './diagnostics.mjs';
20
+ import { listValueOf, lowerLocal, lowerSource } from './expressions.mjs';
21
+ import { objectTreeOf } from './records.mjs';
22
+ import { evalStatic, foldScope } from './static-eval.mjs';
23
+ import { switchAsIf } from './switch-cases.mjs';
24
+ import { narrowOn, narrowed } from './tagged-records.mjs';
25
+ import { runsAsStatements, workedValueOf } from './worked-values.mjs';
26
+ /*----------------------------------------------------------------------------------------------------------------------
27
+ - Implementation
28
+ ---------------------------------------------------------------------------------------------------------------------*/
29
+ /**
30
+ * The statements a branch runs.
31
+ *
32
+ * @param node The branch.
33
+ *
34
+ * @returns The statements.
35
+ */
36
+ export const statementsOf = (node) => node.type === 'BlockStatement' ? node.body : [node];
37
+ /**
38
+ * The statements a helper's body runs. An expression body returns its value.
39
+ *
40
+ * @param helper The helper.
41
+ *
42
+ * @returns The statements.
43
+ */
44
+ const bodyOf = ({ body }) => body.type === 'BlockStatement'
45
+ ? body.body
46
+ : [{ type: 'ReturnStatement', argument: body, loc: body.loc }];
47
+ /**
48
+ * Whether statements always end in a `return`, so nothing after them runs. A switch does when each case and
49
+ * its default do.
50
+ *
51
+ * @param statements The statements.
52
+ * @param inLoop In a loop's body, where a `break` or `continue` leaves too.
53
+ *
54
+ * @returns Whether they do.
55
+ */
56
+ export function exits(statements, inLoop = false) {
57
+ const last = statements.at(-1);
58
+ if (!last)
59
+ return false;
60
+ if (last.type === 'ReturnStatement')
61
+ return true;
62
+ if (inLoop &&
63
+ (last.type === 'BreakStatement' || last.type === 'ContinueStatement') &&
64
+ !last.label) {
65
+ return true;
66
+ }
67
+ if (last.type === 'BlockStatement')
68
+ return exits(last.body, inLoop);
69
+ if (last.type === 'SwitchStatement')
70
+ return exits([switchAsIf(last)], inLoop);
71
+ return (last.type === 'IfStatement' &&
72
+ last.alternate !== null &&
73
+ last.alternate !== undefined &&
74
+ exits(statementsOf(last.consequent), inLoop) &&
75
+ exits(statementsOf(last.alternate), inLoop));
76
+ }
77
+ /**
78
+ * What a value-giving body is, for messages: a helper used as a value, or a block-bodied memo.
79
+ *
80
+ * @param name The helper's name.
81
+ *
82
+ * @returns The phrase.
83
+ */
84
+ function valueGiver(name) {
85
+ const memo = /^useMemo\((.*)\)$/.exec(name);
86
+ return memo
87
+ ? `the useMemo for "${memo[1]}" works out a value`
88
+ : `helper "${name}" is used as a value`;
89
+ }
90
+ /**
91
+ * The helper a call names, if it is one: a plain function or a useCallback, and not a name a local or a state
92
+ * hides.
93
+ *
94
+ * @param node The call.
95
+ * @param environment The expression environment.
96
+ *
97
+ * @returns The helper's name and function, or null.
98
+ */
99
+ export function helperOf(node, environment) {
100
+ if (node.type !== 'CallExpression' || node.callee.type !== 'Identifier') {
101
+ return null;
102
+ }
103
+ const { name } = node.callee;
104
+ if (environment.locals.has(name) || environment.state.has(name))
105
+ return null;
106
+ const helper = environment.helpers?.get(name) ?? environment.callbacks?.get(name);
107
+ return helper ? { name, helper } : null;
108
+ }
109
+ /**
110
+ * The environment a helper's body is inlined in: each parameter bound to what the call passes. A constant is
111
+ * bound as a constant, so it folds; an object as the object; anything else as a local holding the value. A helper
112
+ * already being inlined further up is recursive, and refused.
113
+ *
114
+ * @param name The helper's name.
115
+ * @param helper The helper.
116
+ * @param callArguments The call's arguments.
117
+ * @param environment The caller's environment.
118
+ *
119
+ * @returns The body's environment.
120
+ */
121
+ export function helperEnvironment(name, helper, callArguments, environment) {
122
+ if (environment.inlining?.has(name)) {
123
+ throw aotError(`AOT: helper "${name}" is recursive — can't be inlined`, 'each call to a helper is compiled in place, so a helper that calls itself (directly ' +
124
+ 'or through another helper) never ends. Write the steps out, or precompute the value.');
125
+ }
126
+ const locals = new Map(environment.locals);
127
+ const state = new Map(environment.state);
128
+ const constants = { ...environment.constants };
129
+ const scope = foldScope(environment, environment.constants ?? {});
130
+ helper.params.forEach((parameter, index) => {
131
+ if (parameter.type !== 'Identifier') {
132
+ throw aotError(`AOT: helper "${name}" must take simple (identifier) params to be inlined`, 'a helper must use plain positional params (e.g. `(a, b) => …`) — destructuring or ' +
133
+ 'default params in the signature are not supported.');
134
+ }
135
+ const argument = callArguments[index];
136
+ if (!argument || argument.type === 'SpreadElement') {
137
+ throw aotError(`AOT: helper "${name}" must be passed each of its params`, `pass a value for "${parameter.name}".`);
138
+ }
139
+ // The parameter hides any name it shares with the caller's.
140
+ locals.delete(parameter.name);
141
+ state.delete(parameter.name);
142
+ delete constants[parameter.name];
143
+ let folded;
144
+ try {
145
+ folded = evalStatic(argument, scope, 'strict');
146
+ }
147
+ catch {
148
+ folded = undefined;
149
+ }
150
+ if (['number', 'string', 'boolean'].includes(typeof folded)) {
151
+ constants[parameter.name] = folded;
152
+ return;
153
+ }
154
+ const object = objectTreeOf(argument, environment);
155
+ if (object) {
156
+ constants[parameter.name] = object;
157
+ return;
158
+ }
159
+ // A constant array folds where it is read; a list is the list.
160
+ if (Array.isArray(folded)) {
161
+ constants[parameter.name] = folded;
162
+ return;
163
+ }
164
+ const list = listValueOf(argument, environment);
165
+ if (list) {
166
+ state.set(parameter.name, list);
167
+ return;
168
+ }
169
+ locals.set(parameter.name, lowerLocal(argument, environment));
170
+ });
171
+ return {
172
+ ...environment,
173
+ locals,
174
+ state,
175
+ constants,
176
+ inlining: new Set([...(environment.inlining ?? []), name]),
177
+ };
178
+ }
179
+ /**
180
+ * Binds a helper's `const x = …` as a local holding the value.
181
+ *
182
+ * @param declaration The declaration.
183
+ * @param name The helper's name.
184
+ * @param environment The environment before it.
185
+ *
186
+ * @returns The environment after it.
187
+ */
188
+ function bindConst(declaration, name, environment) {
189
+ const locals = new Map(environment.locals);
190
+ for (const declarator of declaration.declarations) {
191
+ if (declaration.kind !== 'const' ||
192
+ declarator.id.type !== 'Identifier' ||
193
+ !declarator.init) {
194
+ throw aotError(`AOT: ${valueGiver(name)}, so its locals must be \`const x = …\``, 'declare each local once with const and a value.');
195
+ }
196
+ locals.set(declarator.id.name, lowerLocal(declarator.init, { ...environment, locals }));
197
+ }
198
+ return { ...environment, locals };
199
+ }
200
+ /**
201
+ * The value statements give: each `if` a ternary over what each branch gives, and a branch that does not return
202
+ * goes on to the statements after it.
203
+ *
204
+ * @param statements The statements.
205
+ * @param name The helper's name.
206
+ * @param bodyEnvironment The environment they run in.
207
+ * @param fallThrough The value when they end without a `return`.
208
+ *
209
+ * @returns The value.
210
+ */
211
+ function valueOf(statements, name, bodyEnvironment, fallThrough) {
212
+ let environment = bodyEnvironment;
213
+ for (let index = 0; index < statements.length; index++) {
214
+ let statement = statements[index];
215
+ const rest = statements.slice(index + 1);
216
+ if (statement.type === 'SwitchStatement')
217
+ statement = switchAsIf(statement);
218
+ switch (statement.type) {
219
+ case 'VariableDeclaration':
220
+ environment = bindConst(statement, name, environment);
221
+ continue;
222
+ case 'ReturnStatement':
223
+ if (!statement.argument)
224
+ break;
225
+ return lowerSource(statement.argument, environment).source;
226
+ case 'BlockStatement': {
227
+ const after = environment;
228
+ return valueOf(statement.body, name, environment, () => valueOf(rest, name, after, fallThrough));
229
+ }
230
+ case 'IfStatement': {
231
+ // The statements after a branch that returns read what the other branch's test leaves.
232
+ const { whenTrue, whenFalse } = narrowOn(statement.test, environment);
233
+ const consequent = statementsOf(statement.consequent);
234
+ const alternate = statement.alternate
235
+ ? statementsOf(statement.alternate)
236
+ : [];
237
+ const after = exits(consequent)
238
+ ? narrowed(environment, whenFalse)
239
+ : exits(alternate)
240
+ ? narrowed(environment, whenTrue)
241
+ : environment;
242
+ const afterwards = () => valueOf(rest, name, after, fallThrough);
243
+ return {
244
+ kind: 'conditional',
245
+ test: lowerSource(statement.test, environment).source,
246
+ consequent: valueOf(consequent, name, narrowed(environment, whenTrue), afterwards),
247
+ alternate: valueOf(alternate, name, narrowed(environment, whenFalse), afterwards),
248
+ location: statement.test.loc?.start,
249
+ };
250
+ }
251
+ }
252
+ const error = aotError(statement.type === 'ReturnStatement'
253
+ ? `AOT: ${valueGiver(name)}, so each \`return\` must give one`
254
+ : `AOT: ${valueGiver(name)}, so it can only declare locals, branch, loop and return`, name.startsWith('useMemo(')
255
+ ? 'a memo works out a value without side effects. Set state in a handler or an effect.'
256
+ : 'a helper whose result is used works out a value without side effects. Call one that sets ' +
257
+ 'state as a statement of its own.');
258
+ if (statement.loc)
259
+ error.aotLoc = statement.loc.start;
260
+ throw error;
261
+ }
262
+ return fallThrough();
263
+ }
264
+ /**
265
+ * A helper call used as a value: the helper's body worked out as one expression, with a ternary for each branch.
266
+ *
267
+ * @param node The call.
268
+ * @param environment The expression environment.
269
+ *
270
+ * @returns The value, or null when the call is not to a helper.
271
+ */
272
+ export function helperValueOf(node, environment) {
273
+ const called = helperOf(node, environment);
274
+ if (!called)
275
+ return null;
276
+ const { name, helper } = called;
277
+ if (runsAsStatements(helper)) {
278
+ return workedValueOf(node, name, helper, environment);
279
+ }
280
+ return valueOf(bodyOf(helper), name, helperEnvironment(name, helper, node.arguments, environment), () => {
281
+ throw aotError(`AOT: ${valueGiver(name)}, but can end without returning one`, `return a value at the end of the ${name.startsWith('useMemo(') ? 'memo' : 'helper'}, and from each branch ` +
282
+ 'that ends it.');
283
+ });
284
+ }
285
+ /**
286
+ * The expression a helper call returns when the helper returns it on its only path, after any consts, and the
287
+ * environment it is read in. Text a helper builds lowers through this.
288
+ *
289
+ * @param node The call.
290
+ * @param environment The expression environment.
291
+ *
292
+ * @returns The expression and its environment, or null when the call is not to such a helper.
293
+ */
294
+ export function returnedExpression(node, environment) {
295
+ const called = helperOf(node, environment);
296
+ if (!called)
297
+ return null;
298
+ const statements = bodyOf(called.helper);
299
+ const last = statements.at(-1);
300
+ if (last?.type !== 'ReturnStatement' ||
301
+ !last.argument ||
302
+ statements
303
+ .slice(0, -1)
304
+ .some(statement => statement.type !== 'VariableDeclaration')) {
305
+ return null;
306
+ }
307
+ let bodyEnvironment = helperEnvironment(called.name, called.helper, node.arguments, environment);
308
+ for (const statement of statements.slice(0, -1)) {
309
+ bodyEnvironment = bindConst(statement, called.name, bodyEnvironment);
310
+ }
311
+ return { node: last.argument, environment: bodyEnvironment };
312
+ }
@@ -13,4 +13,14 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export {};
16
+ /*----------------------------------------------------------------------------------------------------------------------
17
+ - Implementation
18
+ ---------------------------------------------------------------------------------------------------------------------*/
19
+ /**
20
+ * The name of the slot that says an effect's cleanup is due.
21
+ *
22
+ * @param effectId The effect's number.
23
+ *
24
+ * @returns The slot's name.
25
+ */
26
+ export const armedFlag = (effectId) => `effect${effectId}_armed`;
@@ -31,8 +31,8 @@ export const hasRuntimeProps = (node) => (node.text?.parts.some(part => part.kin
31
31
  node.stateProps.length > 0 ||
32
32
  node.image?.kind === 'value';
33
33
  /**
34
- * Whether state drives any of a node's props, text or image, so it keeps a handle and app_update() sets its
35
- * props again. Props that read-only values worked out at boot are set once, by er_app_build().
34
+ * Whether state drives any of a node's props, text or image, so it keeps a handle and the update sets its
35
+ * props again. Props that read-only values worked out at boot are set once, by the build.
36
36
  *
37
37
  * @param node The node.
38
38
  *
@@ -41,7 +41,7 @@ export const hasRuntimeProps = (node) => (node.text?.parts.some(part => part.kin
41
41
  export const isStateDriven = (node) => hasRuntimeProps(node) && !isBootOnlyNode(node);
42
42
  /**
43
43
  * The drawing state drives on a node if it has one: a drawing that reads only values worked out at boot is
44
- * built once, by er_app_build().
44
+ * built once, by the build.
45
45
  *
46
46
  * @param node The node.
47
47
  *
@@ -67,7 +67,7 @@ export function stateDrivenVectorOf(node) {
67
67
  return null;
68
68
  }
69
69
  /**
70
- * Every node under an element, each before its children, in the order er_app_build() creates them.
70
+ * Every node under an element, each before its children, every branch of a conditional included.
71
71
  *
72
72
  * @param element The element.
73
73
  *
@@ -105,3 +105,42 @@ export function branchElements(conditional) {
105
105
  ? branchElements(branch)
106
106
  : [branch]);
107
107
  }
108
+ /**
109
+ * Every conditional under an element, each before those in its branches. A conditional that is another's branch
110
+ * is listed too.
111
+ *
112
+ * @param element The element.
113
+ *
114
+ * @returns The conditionals.
115
+ */
116
+ export function conditionalsOf(element) {
117
+ const found = [];
118
+ const visit = (branch) => {
119
+ if (branch == null) {
120
+ return;
121
+ }
122
+ if (branch.kind === 'conditional') {
123
+ found.push(branch);
124
+ visit(branch.whenTrue);
125
+ visit(branch.whenFalse);
126
+ return;
127
+ }
128
+ if (branch.kind === 'component') {
129
+ visit(branch.root);
130
+ return;
131
+ }
132
+ for (const child of branch.node.children) {
133
+ if (child.kind === 'element') {
134
+ visit(child.element);
135
+ }
136
+ else if (child.kind === 'conditional') {
137
+ visit(child);
138
+ }
139
+ else {
140
+ child.rows.forEach(visit);
141
+ }
142
+ }
143
+ };
144
+ visit(element);
145
+ return found;
146
+ }