embedded-react 0.20.0 → 0.22.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 (140) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +3 -2
  3. package/aot/app-file-loader.mjs +116 -0
  4. package/aot/compile.mjs +17 -47
  5. package/aot/compiler/alerts.mjs +604 -0
  6. package/aot/compiler/animations.mjs +299 -57
  7. package/aot/compiler/boot.mjs +27 -2
  8. package/aot/compiler/check.mjs +62 -10
  9. package/aot/compiler/collect.mjs +517 -137
  10. package/aot/compiler/contexts.mjs +391 -0
  11. package/aot/compiler/control-flow.mjs +276 -117
  12. package/aot/compiler/custom-hooks.mjs +686 -0
  13. package/aot/compiler/elements/button.mjs +182 -0
  14. package/aot/compiler/elements/image-background.mjs +76 -0
  15. package/aot/compiler/elements/image.mjs +2 -1
  16. package/aot/compiler/elements/props.mjs +47 -8
  17. package/aot/compiler/elements/rewrite.mjs +118 -0
  18. package/aot/compiler/elements/section-list.mjs +370 -0
  19. package/aot/compiler/expressions.mjs +1378 -97
  20. package/aot/compiler/handlers.mjs +1807 -354
  21. package/aot/compiler/helper-values.mjs +312 -0
  22. package/aot/compiler/ir/nodes.mjs +40 -1
  23. package/aot/compiler/ir/reads.mjs +206 -5
  24. package/aot/compiler/ir/text.mjs +5 -1
  25. package/aot/compiler/ir/types.mjs +12 -0
  26. package/aot/compiler/kept-states.mjs +177 -0
  27. package/aot/compiler/keyboard-dismiss.mjs +99 -0
  28. package/aot/compiler/keyboard.mjs +1 -1
  29. package/aot/compiler/list-items.mjs +226 -0
  30. package/aot/compiler/list-order.mjs +586 -0
  31. package/aot/compiler/list-split.mjs +259 -0
  32. package/aot/compiler/loops.mjs +582 -0
  33. package/aot/compiler/lower.mjs +203 -53
  34. package/aot/compiler/native-files.mjs +439 -0
  35. package/aot/compiler/native-header.mjs +335 -0
  36. package/aot/compiler/native-modules.mjs +1173 -0
  37. package/aot/compiler/nodes.mjs +45 -31
  38. package/aot/compiler/options.mjs +3 -2
  39. package/aot/compiler/out.mjs +18 -1
  40. package/aot/compiler/package/animations.mjs +133 -23
  41. package/aot/compiler/package/assemble.mjs +2 -4
  42. package/aot/compiler/package/bytecode.mjs +37 -8
  43. package/aot/compiler/package/checks.mjs +4 -0
  44. package/aot/compiler/package/codegen.mjs +906 -33
  45. package/aot/compiler/package/enums.mjs +10 -0
  46. package/aot/compiler/package/format.mjs +16 -3
  47. package/aot/compiler/package/lower.mjs +707 -176
  48. package/aot/compiler/package/string-caps.mjs +515 -0
  49. package/aot/compiler/package/tables.mjs +24 -0
  50. package/aot/compiler/package/writer.mjs +22 -0
  51. package/aot/compiler/parse.mjs +3 -1
  52. package/aot/compiler/record-shapes.mjs +246 -0
  53. package/aot/compiler/records.mjs +654 -0
  54. package/aot/compiler/reducers.mjs +272 -0
  55. package/aot/compiler/scroll-to.mjs +112 -0
  56. package/aot/compiler/static-eval.mjs +315 -7
  57. package/aot/compiler/style-text.mjs +20 -5
  58. package/aot/compiler/svg.mjs +13 -7
  59. package/aot/compiler/switch-cases.mjs +198 -0
  60. package/aot/compiler/tagged-records.mjs +450 -0
  61. package/aot/compiler/typing.mjs +307 -0
  62. package/aot/compiler/updaters.mjs +321 -0
  63. package/aot/compiler/window-dimensions.mjs +94 -0
  64. package/aot/compiler/worked-values.mjs +319 -0
  65. package/aot/demo-file.mjs +30 -0
  66. package/aot/style-map.mjs +94 -3
  67. package/assets/bake-font.mjs +187 -244
  68. package/assets/bake-image.mjs +47 -71
  69. package/assets/bake-svg.mjs +465 -533
  70. package/assets/build-builtin-font.mjs +14 -27
  71. package/assets/emit-c.mjs +124 -204
  72. package/assets/emit-container.mjs +129 -197
  73. package/assets/emit-pack.mjs +92 -136
  74. package/assets/font-config.mjs +19 -27
  75. package/assets/font-sizes.mjs +432 -507
  76. package/assets/glyph-coverage.mjs +170 -214
  77. package/assets/index.mjs +52 -97
  78. package/assets/rasterize.mjs +173 -194
  79. package/assets/svg-loader.mjs +42 -48
  80. package/build.mjs +85 -94
  81. package/cli.mjs +490 -586
  82. package/compile-bin.mjs +24 -36
  83. package/flash.mjs +297 -401
  84. package/hotreload/dev-device.mjs +229 -270
  85. package/hotreload/pack-app.mjs +118 -159
  86. package/hotreload/pack-split.mjs +146 -213
  87. package/hotreload/package-transfer.mjs +128 -131
  88. package/hotreload/protocol.mjs +118 -118
  89. package/hotreload/uploader.mjs +132 -159
  90. package/hotreload/watch-tree.mjs +56 -65
  91. package/pack-container.mjs +94 -116
  92. package/package.json +19 -16
  93. package/persist-transform.mjs +89 -105
  94. package/qjsc-wasm.mjs +47 -72
  95. package/sim/embedded-react.wasm +0 -0
  96. package/sim/index.html +1 -1
  97. package/sim-server.mjs +260 -354
  98. package/src/embedded-react/Alert.mjs +112 -0
  99. package/src/embedded-react/Animated.mjs +412 -0
  100. package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
  101. package/src/embedded-react/{Button.js → Button.mjs} +29 -53
  102. package/src/embedded-react/Dimensions.mjs +32 -0
  103. package/src/embedded-react/Easing.mjs +34 -0
  104. package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
  105. package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
  106. package/src/embedded-react/Keyboard.mjs +82 -0
  107. package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
  108. package/src/embedded-react/PanResponder.mjs +256 -0
  109. package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
  110. package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
  111. package/src/embedded-react/SectionList.mjs +103 -0
  112. package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
  113. package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
  114. package/src/embedded-react/background-image.mjs +321 -0
  115. package/src/embedded-react/{components.js → components.mjs} +1 -3
  116. package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
  117. package/src/embedded-react/index.d.ts +238 -5
  118. package/src/embedded-react/index.js +26 -17
  119. package/src/embedded-react/layout-anim-config.mjs +85 -0
  120. package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
  121. package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
  122. package/src/embedded-react/nativeModule.mjs +371 -0
  123. package/src/embedded-react/split-style.mjs +57 -0
  124. package/src/embedded-react/svg-ops.mjs +1075 -0
  125. package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
  126. package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
  127. package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
  128. package/src/host-config.mjs +512 -0
  129. package/src/{native-ui.js → native-ui.mjs} +1 -8
  130. package/src/props.mjs +341 -0
  131. package/src/{renderer.js → renderer.mjs} +30 -44
  132. package/src/embedded-react/Animated.js +0 -440
  133. package/src/embedded-react/Easing.js +0 -39
  134. package/src/embedded-react/PanResponder.js +0 -330
  135. package/src/embedded-react/SectionList.js +0 -148
  136. package/src/embedded-react/layout-anim-config.js +0 -101
  137. package/src/embedded-react/split-style.js +0 -58
  138. package/src/embedded-react/svg-ops.js +0 -1295
  139. package/src/host-config.js +0 -548
  140. package/src/props.js +0 -306
@@ -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
+ }
@@ -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 the 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
+ }
@@ -24,8 +24,16 @@
24
24
  * @param found What the walk has found.
25
25
  */
26
26
  function readLocal(local, found) {
27
+ if (local.visit || (local.name && found.internal?.has(local.name)))
28
+ return;
27
29
  if (local.list) {
28
- found.states.add(local.list);
30
+ readList(local.list, found);
31
+ if (local.through) {
32
+ readList(local.through, found);
33
+ }
34
+ if (local.index) {
35
+ readExpr(local.index, found);
36
+ }
29
37
  }
30
38
  else if (local.source) {
31
39
  readSource(local.source, found);
@@ -34,6 +42,119 @@ function readLocal(local, found) {
34
42
  found.untracked = true;
35
43
  }
36
44
  }
45
+ /**
46
+ * Records what reading a list depends on. A constant array's rows never change; a list worked out in render is
47
+ * rebuilt from what its source, if it has one, and its tests read, which a state write flags.
48
+ *
49
+ * @param list The list.
50
+ * @param found What the walk has found.
51
+ */
52
+ function readList(list, found) {
53
+ if (list.derived) {
54
+ found.derived ??= new Set();
55
+ if (found.derived.has(list))
56
+ return;
57
+ found.derived.add(list);
58
+ if (list.derived.source) {
59
+ readList(list.derived.source, found);
60
+ }
61
+ list.derived.tests.forEach(test => readExpr(test, found));
62
+ return;
63
+ }
64
+ if (!list.constant) {
65
+ found.states.add(list);
66
+ }
67
+ }
68
+ /**
69
+ * Records what reading a state depends on: a value worked out with a loop is worked out again from what its
70
+ * statements read, which a state write flags.
71
+ *
72
+ * @param state The state.
73
+ * @param found What the walk has found.
74
+ */
75
+ function readState(state, found) {
76
+ if (state.kind === 'list' || !state.worked) {
77
+ found.states.add(state);
78
+ return;
79
+ }
80
+ found.worked ??= new Set();
81
+ if (found.worked.has(state))
82
+ return;
83
+ found.worked.add(state);
84
+ const { rebuild } = state.worked;
85
+ found.internal ??= new Set();
86
+ declaredLocals(rebuild, found.internal);
87
+ readStatements(rebuild, found);
88
+ }
89
+ /**
90
+ * Collects the names of the locals statements declare, at any depth, loops' visit numbers included.
91
+ *
92
+ * @param statements The statements.
93
+ * @param names Collects the names.
94
+ */
95
+ function declaredLocals(statements, names) {
96
+ for (const statement of statements) {
97
+ if (statement.kind === 'declareLocal') {
98
+ names.add(statement.name);
99
+ }
100
+ else if (statement.kind === 'if') {
101
+ declaredLocals(statement.consequent, names);
102
+ declaredLocals(statement.alternate ?? [], names);
103
+ }
104
+ else if (statement.kind === 'block') {
105
+ declaredLocals(statement.body, names);
106
+ }
107
+ else if (statement.kind === 'loop') {
108
+ if (statement.visit?.name)
109
+ names.add(statement.visit.name);
110
+ declaredLocals(statement.body, names);
111
+ declaredLocals(statement.step, names);
112
+ }
113
+ }
114
+ }
115
+ /**
116
+ * Records what the statements a value is worked out with read.
117
+ *
118
+ * @param statements The statements.
119
+ * @param found What the walk has found.
120
+ */
121
+ function readStatements(statements, found) {
122
+ for (const statement of statements) {
123
+ switch (statement.kind) {
124
+ case 'declareLocal':
125
+ readExpr(statement.initializer, found);
126
+ if (statement.text)
127
+ readText(statement.text, found);
128
+ break;
129
+ case 'assignLocal':
130
+ readExpr(statement.value, found);
131
+ if (statement.text)
132
+ readText(statement.text, found);
133
+ break;
134
+ case 'setState':
135
+ readExpr(statement.value, found);
136
+ break;
137
+ case 'setStateText':
138
+ case 'log':
139
+ readText(statement.text, found);
140
+ break;
141
+ case 'if':
142
+ readExpr(statement.test, found);
143
+ readStatements(statement.consequent, found);
144
+ readStatements(statement.alternate ?? [], found);
145
+ break;
146
+ case 'block':
147
+ readStatements(statement.body, found);
148
+ break;
149
+ case 'loop':
150
+ if (statement.test)
151
+ readExpr(statement.test, found);
152
+ readStatements(statement.body, found);
153
+ readStatements(statement.step, found);
154
+ break;
155
+ }
156
+ }
157
+ }
37
158
  /**
38
159
  * Records what an expression, before typing, reads.
39
160
  *
@@ -47,7 +168,7 @@ function readSource(source, found) {
47
168
  case 'boolean':
48
169
  return;
49
170
  case 'state':
50
- found.states.add(source.state);
171
+ readState(source.state, found);
51
172
  return;
52
173
  case 'local':
53
174
  readLocal(source.local, found);
@@ -90,7 +211,7 @@ function readExpr(expression, found) {
90
211
  case 'pi':
91
212
  return;
92
213
  case 'state':
93
- found.states.add(expression.state);
214
+ readState(expression.state, found);
94
215
  return;
95
216
  case 'boot':
96
217
  found.boot = true;
@@ -99,9 +220,10 @@ function readExpr(expression, found) {
99
220
  readLocal(expression.local, found);
100
221
  return;
101
222
  case 'listLength':
102
- found.states.add(expression.list);
223
+ readList(expression.list, found);
103
224
  return;
104
225
  case 'itemField':
226
+ case 'itemPresent':
105
227
  readLocal(expression.item, found);
106
228
  return;
107
229
  case 'ref':
@@ -122,6 +244,10 @@ function readExpr(expression, found) {
122
244
  case 'floatMath':
123
245
  expression.callArguments.forEach(argument => readExpr(argument, found));
124
246
  return;
247
+ case 'native':
248
+ found.untracked = true;
249
+ expression.call.callArguments.forEach(argument => readExpr(argument, found));
250
+ return;
125
251
  case 'arithmetic':
126
252
  case 'floatDivide':
127
253
  case 'narrowRemainder':
@@ -132,6 +258,14 @@ function readExpr(expression, found) {
132
258
  readExpr(expression.left, found);
133
259
  readExpr(expression.right, found);
134
260
  return;
261
+ case 'stringOrder':
262
+ readExpr(expression.left, found);
263
+ readExpr(expression.right, found);
264
+ return;
265
+ case 'stringIncludes':
266
+ readExpr(expression.haystack, found);
267
+ readExpr(expression.needle, found);
268
+ return;
135
269
  case 'conditional':
136
270
  readExpr(expression.test, found);
137
271
  readExpr(expression.consequent, found);
@@ -147,7 +281,7 @@ function readExpr(expression, found) {
147
281
  */
148
282
  function readShow(show, found) {
149
283
  if (show.kind === 'rowInUse') {
150
- found.states.add(show.list);
284
+ readList(show.list, found);
151
285
  return;
152
286
  }
153
287
  readExpr(show.test, found);
@@ -201,6 +335,12 @@ function readText(text, found) {
201
335
  for (const part of text.parts) {
202
336
  if (part.kind !== 'literal') {
203
337
  readExpr(part.value, found);
338
+ for (const edit of part.edits ?? []) {
339
+ if (edit.kind === 'slice') {
340
+ readExpr(edit.start, found);
341
+ readExpr(edit.end, found);
342
+ }
343
+ }
204
344
  }
205
345
  }
206
346
  }
@@ -261,6 +401,67 @@ const readsOf = (found) => found.untracked ? null : found.states;
261
401
  * @returns Its reads.
262
402
  */
263
403
  export const nodeReads = (node) => readsOf(nodeFound(node));
404
+ /**
405
+ * The state an expression reads.
406
+ *
407
+ * @param expression The expression.
408
+ *
409
+ * @returns Its reads.
410
+ */
411
+ export function expressionReads(expression) {
412
+ const found = { states: new Set(), untracked: false };
413
+ readExpr(expression, found);
414
+ return readsOf(found);
415
+ }
416
+ /**
417
+ * What a filtered or sorted list's rebuild reads.
418
+ *
419
+ * @param list The list.
420
+ *
421
+ * @returns Its reads.
422
+ */
423
+ export function listReads(list) {
424
+ const found = { states: new Set(), untracked: false };
425
+ readList(list, found);
426
+ return readsOf(found);
427
+ }
428
+ /**
429
+ * The state a filtered or sorted list's rebuild reads, even beside something untracked.
430
+ *
431
+ * @param list The list.
432
+ *
433
+ * @returns The state.
434
+ */
435
+ export function listStates(list) {
436
+ const found = { states: new Set(), untracked: false };
437
+ readList(list, found);
438
+ return found.states;
439
+ }
440
+ /**
441
+ * What the update reads to work out a value a memo or a helper loops for in render.
442
+ *
443
+ * @param state The value's state.
444
+ *
445
+ * @returns Its reads.
446
+ */
447
+ export function workedReads(state) {
448
+ const found = { states: new Set(), untracked: false };
449
+ readState(state, found);
450
+ return readsOf(found);
451
+ }
452
+ /**
453
+ * The state the update reads to work out a value a memo or a helper loops for in render, even beside something
454
+ * untracked.
455
+ *
456
+ * @param state The value's state.
457
+ *
458
+ * @returns The state.
459
+ */
460
+ export function workedStates(state) {
461
+ const found = { states: new Set(), untracked: false };
462
+ readState(state, found);
463
+ return found.states;
464
+ }
264
465
  /**
265
466
  * Whether a node's runtime props read only values worked out at boot, so the build sets them once.
266
467
  *
@@ -13,4 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export {};
16
+ /*----------------------------------------------------------------------------------------------------------------------
17
+ - Constants
18
+ ---------------------------------------------------------------------------------------------------------------------*/
19
+ /** slice's end when the call leaves it out: past any text, so the cut runs to the end. LOADI's largest immediate. */
20
+ export const TEXT_END = 0x7fff;
@@ -13,6 +13,18 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ /**
17
+ * What a slot was widened to hold in 64 bits, if it was.
18
+ *
19
+ * @param widths The widths.
20
+ * @param slot The slot's name.
21
+ *
22
+ * @returns What it holds, or undefined for a slot not widened to 64 bits.
23
+ */
24
+ export function wideSlotOf(widths, slot) {
25
+ const width = widths?.get(slot);
26
+ return width === 'float' ? undefined : width;
27
+ }
16
28
  /*----------------------------------------------------------------------------------------------------------------------
17
29
  - Constants
18
30
  ---------------------------------------------------------------------------------------------------------------------*/