embedded-react 0.19.0 → 0.20.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 (116) hide show
  1. package/README.md +7 -3
  2. package/aot/compile.mjs +178 -58
  3. package/aot/compiler/animations.mjs +290 -281
  4. package/aot/compiler/boot.mjs +70 -33
  5. package/aot/compiler/branch-merge.mjs +4 -3
  6. package/aot/compiler/check.mjs +9 -9
  7. package/aot/compiler/collect.mjs +324 -205
  8. package/aot/compiler/control-flow.mjs +209 -197
  9. package/aot/compiler/diagnostics.mjs +22 -25
  10. package/aot/compiler/elements/activity-indicator.mjs +25 -24
  11. package/aot/compiler/elements/dial.mjs +91 -77
  12. package/aot/compiler/elements/flat-list.mjs +24 -22
  13. package/aot/compiler/elements/image.mjs +51 -50
  14. package/aot/compiler/elements/modal.mjs +31 -30
  15. package/aot/compiler/elements/props.mjs +23 -23
  16. package/aot/compiler/elements/switch.mjs +42 -34
  17. package/aot/compiler/elements/text-input.mjs +34 -32
  18. package/aot/compiler/expressions.mjs +372 -333
  19. package/aot/compiler/handlers.mjs +473 -387
  20. package/aot/compiler/ir/functions.mjs +11 -1
  21. package/aot/compiler/ir/nodes.mjs +4 -4
  22. package/aot/compiler/ir/reads.mjs +19 -19
  23. package/aot/compiler/ir/types.mjs +14 -14
  24. package/aot/compiler/ir/vectors.mjs +5 -1
  25. package/aot/compiler/keyboard.mjs +17 -7
  26. package/aot/compiler/lower.mjs +77 -80
  27. package/aot/compiler/nodes.mjs +169 -152
  28. package/aot/compiler/options.mjs +35 -30
  29. package/aot/compiler/out.mjs +18 -22
  30. package/aot/compiler/package/animations.mjs +669 -0
  31. package/aot/compiler/package/arena.mjs +252 -0
  32. package/aot/compiler/package/assemble.mjs +177 -0
  33. package/aot/compiler/package/bytecode.mjs +286 -0
  34. package/aot/compiler/package/checks.mjs +1022 -0
  35. package/aot/compiler/package/codegen.mjs +1329 -0
  36. package/aot/compiler/package/enums.mjs +138 -0
  37. package/aot/compiler/package/format.mjs +760 -0
  38. package/aot/compiler/package/layouts.mjs +136 -0
  39. package/aot/compiler/package/lower.mjs +1606 -0
  40. package/aot/compiler/package/props.mjs +118 -0
  41. package/aot/compiler/package/tables.mjs +103 -0
  42. package/aot/compiler/package/vectors.mjs +502 -0
  43. package/aot/compiler/package/writer.mjs +664 -0
  44. package/aot/compiler/pan-responder.mjs +69 -61
  45. package/aot/compiler/parse.mjs +21 -21
  46. package/aot/compiler/static-eval.mjs +25 -23
  47. package/aot/compiler/style-text.mjs +161 -172
  48. package/aot/compiler/svg.mjs +477 -251
  49. package/aot/screenshot-smoke.mjs +54 -40
  50. package/aot/style-map.mjs +102 -90
  51. package/assets/bake-font.mjs +123 -77
  52. package/assets/bake-image.mjs +39 -22
  53. package/assets/bake-svg.mjs +361 -262
  54. package/assets/build-builtin-font.mjs +11 -7
  55. package/assets/emit-c.mjs +77 -58
  56. package/assets/emit-container.mjs +123 -37
  57. package/assets/emit-pack.mjs +77 -67
  58. package/assets/font-config.mjs +9 -6
  59. package/assets/font-sizes.mjs +163 -123
  60. package/assets/glyph-coverage.mjs +74 -54
  61. package/assets/index.mjs +31 -9
  62. package/assets/rasterize.mjs +126 -99
  63. package/assets/svg-loader.mjs +8 -8
  64. package/build.mjs +14 -12
  65. package/cli.mjs +359 -172
  66. package/compile-bin.mjs +3 -3
  67. package/flash.mjs +537 -0
  68. package/hotreload/dev-device.mjs +90 -33
  69. package/hotreload/pack-app.mjs +55 -43
  70. package/hotreload/pack-split.mjs +46 -37
  71. package/hotreload/package-transfer.mjs +175 -0
  72. package/hotreload/protocol.mjs +50 -37
  73. package/hotreload/uploader.mjs +38 -27
  74. package/hotreload/watch-tree.mjs +19 -19
  75. package/pack-container.mjs +28 -20
  76. package/package.json +7 -8
  77. package/persist-transform.mjs +34 -28
  78. package/qjsc-wasm.mjs +25 -14
  79. package/sim/embedded-react.cjs +1 -1
  80. package/sim/embedded-react.js +1 -1
  81. package/sim/embedded-react.wasm +0 -0
  82. package/sim/index.html +94 -85
  83. package/sim-server.mjs +101 -82
  84. package/src/embedded-react/Animated.js +24 -24
  85. package/src/embedded-react/Easing.js +1 -1
  86. package/src/embedded-react/FlatList.js +3 -3
  87. package/src/embedded-react/LayoutAnimation.js +8 -5
  88. package/src/embedded-react/PanResponder.js +75 -71
  89. package/src/embedded-react/Pressable.js +2 -8
  90. package/src/embedded-react/SectionList.js +6 -6
  91. package/src/embedded-react/StyleSheet.js +4 -3
  92. package/src/embedded-react/TouchableOpacity.js +13 -8
  93. package/src/embedded-react/index.d.ts +5 -5
  94. package/src/embedded-react/layout-anim-config.js +10 -4
  95. package/src/embedded-react/list-child.js +5 -5
  96. package/src/embedded-react/named-colors.js +1 -1
  97. package/src/embedded-react/split-style.js +11 -11
  98. package/src/embedded-react/svg-ops.js +760 -593
  99. package/src/embedded-react/useHostValue.js +3 -3
  100. package/src/embedded-react/usePersistentState.js +6 -6
  101. package/src/embedded-react/warn-props.js +1 -1
  102. package/src/host-config.js +60 -53
  103. package/src/props.js +49 -41
  104. package/src/renderer.js +7 -4
  105. package/aot/compiler/assemble.mjs +0 -944
  106. package/aot/compiler/c/animations.mjs +0 -436
  107. package/aot/compiler/c/boot.mjs +0 -127
  108. package/aot/compiler/c/expressions.mjs +0 -270
  109. package/aot/compiler/c/functions.mjs +0 -268
  110. package/aot/compiler/c/keyboard.mjs +0 -96
  111. package/aot/compiler/c/nodes.mjs +0 -303
  112. package/aot/compiler/c/pan-responder.mjs +0 -136
  113. package/aot/compiler/c/statements.mjs +0 -319
  114. package/aot/compiler/c/text.mjs +0 -83
  115. package/aot/compiler/c/vectors.mjs +0 -381
  116. package/aot/compiler/c-syntax.mjs +0 -127
@@ -20,8 +20,8 @@ import { aotError } from './diagnostics.mjs';
20
20
  import { foldBoot, isBoot } from './boot.mjs';
21
21
  import { mergeBranchElements } from './branch-merge.mjs';
22
22
  import { evalStatic, setBinding, withUndefined } from './static-eval.mjs';
23
- import { emitSourcedWide, lowerExpr } from './expressions.mjs';
24
- import { isFn, declaredNames, collectState, componentReturnJSX, collectHelpers, collectCallbacks, collectMemos, collectEffects, usesState, bindConst, } from './collect.mjs';
23
+ import { lowerExpr, lowerSourcedWide } from './expressions.mjs';
24
+ import { isFn, declaredNames, collectState, componentReturnJSX, collectHelpers, collectCallbacks, collectMemos, collectEffects, usesState, bindConst, settleBootInitials, } from './collect.mjs';
25
25
  import { collectAnims, collectRefs } from './animations.mjs';
26
26
  import { attrExpr } from './style-text.mjs';
27
27
  import { inlineFragments } from './elements/props.mjs';
@@ -33,29 +33,29 @@ import { emitNode } from './nodes.mjs';
33
33
  ---------------------------------------------------------------------------------------------------------------------*/
34
34
  /**
35
35
  * Reads a component's props as descriptors: `{static:true,value}` (folded),
36
- * `{static:false,code, cType, struct}` (a runtime C expression — e.g., a list row's `item.field`), or
36
+ * `{static:false, slotKind, struct}` (a runtime expression — e.g., a list row's `item.field`), or
37
37
  * `{fn:true,node}` (a callback).
38
38
  *
39
39
  * @param openingElement The component instance's opening tag.
40
40
  * @param scope Compile-time constants in reach at the call site.
41
- * @param env The caller's expression environment.
41
+ * @param environment The caller's expression environment.
42
42
  *
43
43
  * @returns The props, by name.
44
44
  */
45
- function extractProps(openingElement, scope, env) {
45
+ function extractProps(openingElement, scope, environment) {
46
46
  const props = {};
47
- for (const attr of openingElement.attributes) {
47
+ for (const attribute of openingElement.attributes) {
48
48
  // Static spread: {...obj} where obj folds to a compile-time object → merge its keys as props.
49
- if (attr.type === 'JSXSpreadAttribute') {
49
+ if (attribute.type === 'JSXSpreadAttribute') {
50
50
  // A PanResponder's handlers need a real scene node, which a component instance is not.
51
- if (panSpreadTarget(attr.argument, env)) {
51
+ if (panSpreadTarget(attribute.argument, environment)) {
52
52
  throw aotError('AOT: a PanResponder can only be spread onto a host element', 'spread `{...pan.panHandlers}` onto the <View> (or <Pressable>/<ScrollView>) that ' +
53
53
  'should own the gesture, not onto a component instance — the AOT wires the responder ' +
54
54
  'to a real scene node.');
55
55
  }
56
56
  let spreadObject;
57
57
  try {
58
- spreadObject = evalStatic(attr.argument, scope);
58
+ spreadObject = evalStatic(attribute.argument, scope);
59
59
  }
60
60
  catch {
61
61
  throw new Error('AOT: only a compile-time-constant object can be spread to a component ({...obj})');
@@ -69,42 +69,46 @@ function extractProps(openingElement, scope, env) {
69
69
  continue;
70
70
  }
71
71
  // `key` is React's, not the component's.
72
- if (attr.type !== 'JSXAttribute' ||
73
- attr.name.name === 'key') {
72
+ if (attribute.type !== 'JSXAttribute' ||
73
+ attribute.name.name === 'key') {
74
74
  continue;
75
75
  }
76
76
  // A callback prop (inline arrow, caller's useCallback or forwarded prop) is an ` fn `, resolved at its handler.
77
- const node = attrExpr(attr);
77
+ const node = attrExpr(attribute);
78
78
  if (isFn(node)) {
79
- props[attr.name.name] = { fn: true, node };
79
+ props[attribute.name.name] = {
80
+ isCallback: true,
81
+ node,
82
+ };
80
83
  continue;
81
84
  }
82
- if (node.type === 'Identifier' && env.callbacks?.has(node.name)) {
83
- props[attr.name.name] = {
84
- fn: true,
85
- node: env.callbacks.get(node.name),
85
+ if (node.type === 'Identifier' && environment.callbacks?.has(node.name)) {
86
+ props[attribute.name.name] = {
87
+ isCallback: true,
88
+ node: environment.callbacks.get(node.name),
86
89
  };
87
90
  continue;
88
91
  }
89
- if (node.type === 'Identifier' && env.fnProps?.has(node.name)) {
90
- props[attr.name.name] = {
91
- fn: true,
92
- ...env.fnProps.get(node.name),
92
+ if (node.type === 'Identifier' &&
93
+ environment.functionProps?.has(node.name)) {
94
+ props[attribute.name.name] = {
95
+ isCallback: true,
96
+ ...environment.functionProps.get(node.name),
93
97
  }; // forward original {node, env, state}
94
98
  continue;
95
99
  }
96
- // Any other prop folds to a constant when it can, else becomes a runtime C expression.
100
+ // Any other prop folds to a constant when it can, else becomes a runtime expression.
97
101
  try {
98
- const propName = attr.name.name;
102
+ const propName = attribute.name.name;
99
103
  props[propName] = {
100
104
  static: true,
101
105
  value: bindConst(propName, evalStatic(node, scope, 'boot')),
102
106
  };
103
107
  }
104
108
  catch {
105
- props[attr.name.name] = {
109
+ props[attribute.name.name] = {
106
110
  static: false,
107
- ...emitSourcedWide(node, env),
111
+ ...lowerSourcedWide(node, environment),
108
112
  };
109
113
  }
110
114
  }
@@ -113,19 +117,19 @@ function extractProps(openingElement, scope, env) {
113
117
  /**
114
118
  * Maps a component's parameter to its prop descriptors (handles destructure rename and defaults).
115
119
  *
116
- * @param fn The component.
120
+ * @param functionNode The component.
117
121
  * @param props The props the instance was given.
118
122
  * @param scope Module constants a default can refer to.
119
123
  *
120
124
  * @returns The descriptor each name in the component's body is bound to.
121
125
  */
122
- function bindParams(fn, props, scope) {
126
+ function bindParams(functionNode, props, scope) {
123
127
  const bindings = new Map();
124
- const param = fn.params[0];
125
- if (!param)
128
+ const parameter = functionNode.params[0];
129
+ if (!parameter)
126
130
  return bindings;
127
131
  // `function C(props)`: the whole props object is one constant, so every prop must fold.
128
- if (param.type === 'Identifier') {
132
+ if (parameter.type === 'Identifier') {
129
133
  const propsObject = {};
130
134
  for (const [propName, descriptor] of Object.entries(props)) {
131
135
  if (!descriptor.static) {
@@ -133,11 +137,11 @@ function bindParams(fn, props, scope) {
133
137
  }
134
138
  propsObject[propName] = descriptor.value;
135
139
  }
136
- bindings.set(param.name, { static: true, value: propsObject });
140
+ bindings.set(parameter.name, { static: true, value: propsObject });
137
141
  }
138
- else if (param.type === 'ObjectPattern') {
142
+ else if (parameter.type === 'ObjectPattern') {
139
143
  // `function C({x, y: renamed, z = 1})`: bind each name to its prop, else to its folded default.
140
- const properties = param.properties.map(property => {
144
+ const properties = parameter.properties.map(property => {
141
145
  if (property.type === 'RestElement') {
142
146
  throw new Error('AOT: rest props (...rest) in a component param not supported');
143
147
  }
@@ -175,25 +179,25 @@ function bindParams(fn, props, scope) {
175
179
  return bindings;
176
180
  }
177
181
  /**
178
- * True if `expr` is how a component body refers to its children (destructured {children} or props.children).
182
+ * True if `expression` is how a component body refers to its children (destructured {children} or props.children).
179
183
  *
180
- * @param expr A child expression.
181
- * @param env The expression environment.
184
+ * @param expression A child expression.
185
+ * @param environment The expression environment.
182
186
  *
183
187
  * @returns Whether it names the children slot.
184
188
  */
185
- function isChildrenRef(expr, env) {
186
- const childrenRef = env.children?.ref;
189
+ function isChildrenRef(expression, environment) {
190
+ const childrenRef = environment.children?.ref;
187
191
  if (!childrenRef)
188
192
  return false;
189
193
  if (childrenRef.kind === 'local') {
190
- return expr.type === 'Identifier' && expr.name === childrenRef.name;
194
+ return (expression.type === 'Identifier' && expression.name === childrenRef.name);
191
195
  }
192
- return (expr.type === 'MemberExpression' &&
193
- !expr.computed &&
194
- expr.object.type === 'Identifier' &&
195
- expr.object.name === childrenRef.name &&
196
- expr.property.name === 'children');
196
+ return (expression.type === 'MemberExpression' &&
197
+ !expression.computed &&
198
+ expression.object.type === 'Identifier' &&
199
+ expression.object.name === childrenRef.name &&
200
+ expression.property.name === 'children');
197
201
  }
198
202
  /**
199
203
  * Inlines a function component instance: bind props (static → scope, dynamic → locals), emit its JSX.
@@ -201,25 +205,25 @@ function isChildrenRef(expr, env) {
201
205
  *
202
206
  * @param element The component instance.
203
207
  * @param scope Compile-time constants in reach at the call site.
204
- * @param out Everything emitted so far.
205
- * @param env The caller's expression environment.
208
+ * @param output Everything emitted so far.
209
+ * @param environment The caller's expression environment.
206
210
  * @param state The caller's state table.
207
- * @param opts How the instance is placed.
211
+ * @param options How the instance is placed.
208
212
  *
209
213
  * @returns The instance, wrapping the element the component's JSX lowered to.
210
214
  */
211
- export function emitComponent(element, scope, out, env, state, opts) {
215
+ export function emitComponent(element, scope, output, environment, state, options) {
212
216
  // Look up the component and keep the call-site children that render something.
213
217
  const componentName = element.openingElement.name.name;
214
- const fn = out.components.get(componentName);
218
+ const functionNode = output.components.get(componentName);
215
219
  const childNodes = inlineFragments(element.children).filter(child => !(child.type === 'JSXText' && !child.value.trim()) &&
216
220
  !(child.type === 'JSXExpressionContainer' &&
217
221
  child.expression.type === 'JSXEmptyExpression'));
218
222
  // How the body refers to children: destructured `{ children }` (a local) or whole `props` → props.children.
219
- const param = fn.params[0];
223
+ const parameter = functionNode.params[0];
220
224
  let childrenRef = null;
221
- if (param?.type === 'ObjectPattern') {
222
- for (const property of param.properties) {
225
+ if (parameter?.type === 'ObjectPattern') {
226
+ for (const property of parameter.properties) {
223
227
  if ((property.key?.name ??
224
228
  property.key?.value) === 'children') {
225
229
  childrenRef = {
@@ -229,24 +233,24 @@ export function emitComponent(element, scope, out, env, state, opts) {
229
233
  }
230
234
  }
231
235
  }
232
- else if (param?.type === 'Identifier') {
233
- childrenRef = { kind: 'props', name: param.name };
236
+ else if (parameter?.type === 'Identifier') {
237
+ childrenRef = { kind: 'props', name: parameter.name };
234
238
  }
235
239
  // A child sees only module scope: start from module consts with no locals, so caller bindings cannot leak in.
236
- const moduleScope = env.moduleConsts ?? scope;
240
+ const moduleScope = environment.moduleConstants ?? scope;
237
241
  const childScope = { ...moduleScope };
238
242
  const childLocals = new Map();
239
243
  // Callback props resolve to the caller's function, env and state; inherit the caller's own so they forward.
240
- const fnProps = new Map(env.fnProps);
244
+ const functionProps = new Map(environment.functionProps);
241
245
  // Bind each prop: a callback to fnProps, a constant to the child's scope, a runtime value to its locals.
242
- for (const [name, descriptor] of bindParams(fn, extractProps(element.openingElement, scope, env), moduleScope)) {
246
+ for (const [name, descriptor] of bindParams(functionNode, extractProps(element.openingElement, scope, environment), moduleScope)) {
243
247
  // The children binding comes from the slot, not from a value prop.
244
248
  if (childrenRef?.kind === 'local' && name === childrenRef?.name)
245
249
  continue;
246
- if (descriptor.fn) {
247
- fnProps.set(name, {
250
+ if (descriptor.isCallback) {
251
+ functionProps.set(name, {
248
252
  node: descriptor.node,
249
- env: descriptor.env ?? env,
253
+ environment: descriptor.environment ?? environment,
250
254
  state: descriptor.state ?? state,
251
255
  });
252
256
  }
@@ -255,13 +259,14 @@ export function emitComponent(element, scope, out, env, state, opts) {
255
259
  }
256
260
  else {
257
261
  childLocals.set(name, {
258
- code: descriptor.code,
259
- cType: descriptor.cType,
262
+ name: descriptor.name,
263
+ slotKind: descriptor.slotKind,
260
264
  struct: descriptor.struct,
261
- isBool: descriptor.isBool, // keep boolean-ness across the prop boundary (extractProps supplies it)
262
- lit: descriptor.lit,
265
+ isBoolean: descriptor.isBoolean, // keep boolean-ness across the prop boundary (extractProps supplies it)
266
+ isLiteral: descriptor.isLiteral,
263
267
  wide: descriptor.wide,
264
268
  source: descriptor.source,
269
+ expression: descriptor.expression,
265
270
  });
266
271
  // A dynamic prop is a runtime binding; drop any same-named module const so no fold emits it instead.
267
272
  delete childScope[name];
@@ -271,126 +276,128 @@ export function emitComponent(element, scope, out, env, state, opts) {
271
276
  const children = {
272
277
  nodes: childNodes,
273
278
  scope,
274
- env,
279
+ environment,
275
280
  ref: childrenRef,
276
281
  };
277
282
  // Each inlined instance namespaces its own hooks under a unique `c<N>_` prefix so instances stay independent.
278
- const prefix = `c${out.instN++}_`;
283
+ const prefix = `c${output.instanceCount++}_`;
279
284
  // Fold the child body's static consts as lowerApp does for App; they shadow same-named module consts.
280
- if (fn.body.type === 'BlockStatement') {
285
+ if (functionNode.body.type === 'BlockStatement') {
281
286
  // As in App: the body's own names, hook bindings included, shadow module ones before anything folds.
282
- for (const name of declaredNames(fn.body.body)) {
287
+ for (const name of declaredNames(functionNode.body.body)) {
283
288
  delete childScope[name];
284
289
  }
285
- for (const stmt of fn.body.body) {
286
- if (stmt.type !== 'VariableDeclaration' || stmt.kind !== 'const') {
290
+ for (const statement of functionNode.body.body) {
291
+ if (statement.type !== 'VariableDeclaration' ||
292
+ statement.kind !== 'const') {
287
293
  continue;
288
294
  }
289
- for (const decl of stmt.declarations) {
290
- if (decl.id.type !== 'Identifier' || !decl.init)
295
+ for (const declarator of statement.declarations) {
296
+ if (declarator.id.type !== 'Identifier' || !declarator.init)
291
297
  continue;
292
- if (childLocals.has(decl.id.name))
298
+ if (childLocals.has(declarator.id.name))
293
299
  continue; // a dynamic prop of that name is already bound
294
300
  try {
295
- setBinding(childScope, decl.id.name, bindConst(decl.id.name, evalStatic(decl.init, withUndefined(childScope), 'boot')));
301
+ setBinding(childScope, declarator.id.name, bindConst(declarator.id.name, evalStatic(declarator.init, withUndefined(childScope), 'boot')));
296
302
  }
297
303
  catch {
298
304
  // A dynamic const hides any same-named module const; a memo re-binds it below, else it stays unresolved.
299
- delete childScope[decl.id.name];
305
+ delete childScope[declarator.id.name];
300
306
  }
301
307
  }
302
308
  }
303
309
  }
304
310
  // Collect the child's own hooks under its prefix; its state slots are runtime bindings, so they leave the scope.
305
- const childAnims = collectAnims(fn.body, childScope, prefix);
306
- const childRefs = collectRefs(fn.body, childScope, prefix, env.wide);
307
- const childPans = collectPanResponders(fn.body, prefix);
308
- const childCallbacks = collectCallbacks(fn.body);
309
- const childMemos = collectMemos(fn.body);
311
+ const childAnimations = collectAnims(functionNode.body, childScope, prefix);
312
+ const childRefs = collectRefs(functionNode.body, childScope, prefix, environment.wide);
313
+ const childPans = collectPanResponders(functionNode.body, prefix);
314
+ const childCallbacks = collectCallbacks(functionNode.body);
315
+ const childMemos = collectMemos(functionNode.body);
310
316
  let childState = state;
311
- if (usesState(fn)) {
312
- childState = collectState(fn.body, childScope, env.caps, prefix, env.wide);
313
- out.childStateRecords.push(...childState.byName.values());
317
+ if (usesState(functionNode)) {
318
+ childState = collectState(functionNode.body, childScope, environment.caps, prefix, environment.wide);
319
+ settleBootInitials(childState.byName.values());
320
+ output.childStateRecords.push(...childState.byName.values());
314
321
  for (const name of childState.byName.keys()) {
315
322
  delete childScope[name];
316
323
  }
317
324
  }
318
325
  // The child's own refs and animated values are runtime bindings too (see lowerApp).
319
- for (const name of [...childAnims.keys(), ...childRefs.keys()]) {
326
+ for (const name of [...childAnimations.keys(), ...childRefs.keys()]) {
320
327
  delete childScope[name];
321
328
  }
322
- out.childRefs.push(...childRefs.values());
323
- out.childAnimations.push(...childAnims.values());
329
+ output.childRefs.push(...childRefs.values());
330
+ output.childAnimations.push(...childAnimations.values());
324
331
  // The child's expression environment: the caller's, with every name-keyed table replaced by the child's.
325
- const childEnv = {
326
- ...env,
327
- consts: childScope,
332
+ const childEnvironment = {
333
+ ...environment,
334
+ constants: childScope,
328
335
  locals: childLocals,
329
336
  children,
330
- fnProps,
337
+ functionProps,
331
338
  state: childState.byName,
332
- animations: childAnims,
339
+ animations: childAnimations,
333
340
  refs: childRefs,
334
341
  pans: childPans,
335
342
  callbacks: childCallbacks,
336
- helpers: collectHelpers(fn.body, out.program),
337
- cbPrefix: prefix,
343
+ helpers: collectHelpers(functionNode.body, output.program),
344
+ callbackPrefix: prefix,
338
345
  };
339
- // Resolve memos in order (fold, else a local C expr), then compile its effects, all in the child's env/state.
340
- for (const [name, expr] of childMemos) {
346
+ // Resolve memos in order (fold, else a local expression), then compile its effects, all in the child's env/state.
347
+ for (const [name, expression] of childMemos) {
341
348
  try {
342
- setBinding(childScope, name, bindConst(name, evalStatic(expr, childScope, 'boot')));
349
+ setBinding(childScope, name, bindConst(name, evalStatic(expression, childScope, 'boot')));
343
350
  }
344
351
  catch {
345
- const cExpr = emitSourcedWide(expr, childEnv);
352
+ const memo = lowerSourcedWide(expression, childEnvironment);
346
353
  childLocals.set(name, {
347
- code: `(${cExpr.code})`,
348
- cType: cExpr.cType,
349
- isBool: cExpr.isBool,
350
- lit: cExpr.lit,
351
- wide: cExpr.wide,
352
- source: cExpr.source,
354
+ slotKind: memo.slotKind,
355
+ isBoolean: memo.isBoolean,
356
+ isLiteral: memo.isLiteral,
357
+ wide: memo.wide,
358
+ source: memo.source,
359
+ expression: memo.expression,
353
360
  });
354
361
  delete childScope[name]; // a runtime binding beats a module const of its name in every fold
355
362
  }
356
363
  }
357
- for (const effect of collectEffects(fn.body)) {
358
- lowerEffect(effect, childEnv, childState, out);
364
+ for (const effect of collectEffects(functionNode.body)) {
365
+ lowerEffect(effect, childEnvironment, childState, output);
359
366
  }
360
367
  // Emit the JSX the component returns, in the child's own scope.
361
- const root = emitNode(componentReturnJSX(fn, childScope), childScope, out, childEnv, childState, opts);
368
+ const root = emitNode(componentReturnJSX(functionNode, childScope), childScope, output, childEnvironment, childState, options);
362
369
  return { kind: 'component', id: root.id, name: componentName, prefix, root };
363
370
  }
364
371
  /**
365
- * Emits an element / component child. opts.show toggles its display.
372
+ * Emits an element / component child. options.show toggles its display.
366
373
  *
367
374
  * @param node The child; anything but a JSX element is refused.
368
375
  * @param scope Compile-time constants in reach.
369
- * @param out Everything emitted so far.
370
- * @param env The expression environment.
376
+ * @param output Everything emitted so far.
377
+ * @param environment The expression environment.
371
378
  * @param state The component's state table.
372
- * @param opts How the child is placed.
379
+ * @param options How the child is placed.
373
380
  *
374
381
  * @returns The child.
375
382
  */
376
- function emitElementInto(node, scope, out, env, state, opts) {
383
+ function emitElementInto(node, scope, output, environment, state, options) {
377
384
  if (node.type !== 'JSXElement') {
378
385
  throw new Error(`AOT: expected a JSX element here, got ${node.type}`);
379
386
  }
380
- return emitNode(node, scope, out, env, state, opts);
387
+ return emitNode(node, scope, output, environment, state, options);
381
388
  }
382
389
  /**
383
390
  * Unrolls `arr.map((item, i) => <JSX/>)` over a COMPILE-TIME-CONSTANT array.
384
391
  *
385
392
  * @param call The `.map(…)` call.
386
393
  * @param scope Compile-time constants in reach.
387
- * @param out Everything emitted so far.
388
- * @param env The expression environment.
394
+ * @param output Everything emitted so far.
395
+ * @param environment The expression environment.
389
396
  * @param state The component's state table.
390
397
  *
391
398
  * @returns The rows.
392
399
  */
393
- function emitMap(call, scope, out, env, state) {
400
+ function emitMap(call, scope, output, environment, state) {
394
401
  // The array must fold at compile time and the callback must be inline.
395
402
  let items;
396
403
  try {
@@ -402,13 +409,13 @@ function emitMap(call, scope, out, env, state) {
402
409
  if (!Array.isArray(items)) {
403
410
  throw new Error('AOT: .map target did not resolve to an array');
404
411
  }
405
- const mapFn = call.arguments[0];
406
- if (!isFn(mapFn)) {
412
+ const mapFunction = call.arguments[0];
413
+ if (!isFn(mapFunction)) {
407
414
  throw new Error('AOT: .map argument must be an inline function');
408
415
  }
409
- const itemName = mapFn.params[0]?.name;
410
- const indexName = mapFn.params[1]?.name;
411
- const rowJSX = componentReturnJSX(mapFn);
416
+ const itemName = mapFunction.params[0]?.name;
417
+ const indexName = mapFunction.params[1]?.name;
418
+ const rowJSX = componentReturnJSX(mapFunction);
412
419
  // Emit one row per element, with its item and index bound as compile-time constants.
413
420
  return items.map((item, index) => {
414
421
  const rowScope = { ...scope };
@@ -418,25 +425,25 @@ function emitMap(call, scope, out, env, state) {
418
425
  if (indexName) {
419
426
  setBinding(rowScope, indexName, index);
420
427
  }
421
- return emitElementInto(rowJSX, rowScope, out, rowEnv(env, [itemName, indexName], rowScope), state);
428
+ return emitElementInto(rowJSX, rowScope, output, rowEnv(environment, [itemName, indexName], rowScope), state);
422
429
  });
423
430
  }
424
431
  /**
425
432
  * The env for one `.map` row. Its callback params (item, index) shadow every outer binding of the same
426
433
  * name — a JS arrow parameter always does — so those names leave every name-keyed map (state, locals,
427
- * callbacks, helpers, …), and the row's own binding wins: in `consts`, or in `ownLocals` for a pooled
434
+ * callbacks, helpers, …), and the row's own binding wins: in `constants`, or in `ownLocals` for a pooled
428
435
  * row's struct item.
429
436
  *
430
- * @param env The expression environment around the `.map`.
431
- * @param params The callback's parameter names (item, index), where present.
432
- * @param consts The row's compile-time scope.
437
+ * @param environment The expression environment around the `.map`.
438
+ * @param parameters The callback's parameter names (item, index), where present.
439
+ * @param constants The row's compile-time scope.
433
440
  * @param ownLocals The row's runtime bindings, when its item is one (a pooled row).
434
441
  *
435
442
  * @returns The row's environment.
436
443
  */
437
- function rowEnv(env, params, consts, ownLocals = null) {
444
+ function rowEnv(environment, parameters, constants, ownLocals = null) {
438
445
  // Copy a table without the row's names; one that binds none of them is shared as is.
439
- const names = params.filter(Boolean);
446
+ const names = parameters.filter(Boolean);
440
447
  const drop = (bindings) => {
441
448
  if (!bindings || !names.some(name => bindings.has(name)))
442
449
  return bindings;
@@ -448,48 +455,48 @@ function rowEnv(env, params, consts, ownLocals = null) {
448
455
  };
449
456
  // A row param named like the children reference (`children` or `props`) shadows it, leaving no children slot.
450
457
  return {
451
- ...env,
452
- consts,
453
- state: drop(env.state),
454
- refs: drop(env.refs),
455
- animations: drop(env.animations),
456
- locals: ownLocals ?? drop(env.locals),
457
- callbacks: drop(env.callbacks),
458
- fnProps: drop(env.fnProps),
459
- pans: drop(env.pans),
460
- helpers: drop(env.helpers),
461
- svgImports: drop(env.svgImports),
462
- children: names.includes(env.children?.ref?.name)
458
+ ...environment,
459
+ constants,
460
+ state: drop(environment.state),
461
+ refs: drop(environment.refs),
462
+ animations: drop(environment.animations),
463
+ locals: ownLocals ?? drop(environment.locals),
464
+ callbacks: drop(environment.callbacks),
465
+ functionProps: drop(environment.functionProps),
466
+ pans: drop(environment.pans),
467
+ helpers: drop(environment.helpers),
468
+ svgImports: drop(environment.svgImports),
469
+ children: names.includes(environment.children?.ref?.name)
463
470
  ? null
464
- : env.children,
471
+ : environment.children,
465
472
  };
466
473
  }
467
474
  /**
468
475
  * `{listState.map((item, i) => <Row/>)}` over a STATE array of variable length. Pre-allocates a fixed
469
- * pool of `cap` rows (no runtime malloc); the row at index `row` binds `item` to `s_<name>[row]` (a struct
470
- * local) and is shown only while `row < count` (display toggle). app_update then drives every row's content
476
+ * pool of `capacity` rows (no runtime malloc); the row at index `row` binds `item` to `s_<name>[row]` (a struct
477
+ * local) and is shown only while `row < count` (display toggle). the update then drives every row's content
471
478
  * and show.
472
479
  *
473
480
  * @param call The `.map(…)` call.
474
481
  * @param listState The list state it maps over.
475
482
  * @param scope Compile-time constants in reach.
476
- * @param out Everything emitted so far.
477
- * @param env The expression environment.
483
+ * @param output Everything emitted so far.
484
+ * @param environment The expression environment.
478
485
  * @param state The component's state table.
479
486
  *
480
487
  * @returns The pool.
481
488
  */
482
- function emitDynamicMap(call, listState, scope, out, env, state) {
483
- const mapFn = call.arguments[0];
484
- if (!isFn(mapFn)) {
489
+ function emitDynamicMap(call, listState, scope, output, environment, state) {
490
+ const mapFunction = call.arguments[0];
491
+ if (!isFn(mapFunction)) {
485
492
  throw new Error('AOT: .map argument must be an inline function');
486
493
  }
487
- const itemName = mapFn.params[0]?.name;
488
- const indexName = mapFn.params[1]?.name;
489
- const rowJSX = componentReturnJSX(mapFn);
494
+ const itemName = mapFunction.params[0]?.name;
495
+ const indexName = mapFunction.params[1]?.name;
496
+ const rowJSX = componentReturnJSX(mapFunction);
490
497
  // Build every row of the pool; each row's display is tied to the list's current count.
491
498
  const rows = [];
492
- for (let rowIndex = 0; rowIndex < listState.cap; rowIndex++) {
499
+ for (let rowIndex = 0; rowIndex < listState.capacity; rowIndex++) {
493
500
  // The item is a runtime struct slot, so drop any same-named const from the row scope, as emitComponent does.
494
501
  const rowScope = { ...scope };
495
502
  if (itemName) {
@@ -498,19 +505,20 @@ function emitDynamicMap(call, listState, scope, out, env, state) {
498
505
  if (indexName) {
499
506
  setBinding(rowScope, indexName, rowIndex); // the index is a compile-time literal per pooled row
500
507
  }
501
- const rowLocals = new Map(env.locals);
508
+ const rowLocals = new Map(environment.locals);
502
509
  if (indexName) {
503
510
  rowLocals.delete(indexName); // the index is a per-row literal in rowScope
504
511
  }
505
- // A row's item has no C type of its own: only its fields are read, through `struct`.
512
+ // A row's item has no slot of its own: only its fields are read, through `struct`.
506
513
  if (itemName) {
507
514
  rowLocals.set(itemName, {
508
- code: `${listState.arrayName}[${rowIndex}]`,
515
+ name: itemName,
509
516
  struct: listState.struct,
510
517
  list: listState,
518
+ row: rowIndex,
511
519
  });
512
520
  }
513
- rows.push(emitElementInto(rowJSX, rowScope, out, rowEnv(env, [itemName, indexName], rowScope, rowLocals), state, { show: { kind: 'rowInUse', row: rowIndex, list: listState } }));
521
+ rows.push(emitElementInto(rowJSX, rowScope, output, rowEnv(environment, [itemName, indexName], rowScope, rowLocals), state, { show: { kind: 'rowInUse', row: rowIndex, list: listState } }));
514
522
  }
515
523
  return { kind: 'pool', list: listState, rows };
516
524
  }
@@ -527,20 +535,20 @@ const rendersNothing = (value) => value === false || value == null || value ===
527
535
  /**
528
536
  * The error for a child expression that is not lowered; `what` describes it when it folded to a value.
529
537
  *
530
- * @param expr The child expression.
538
+ * @param expression The child expression.
531
539
  * @param what Its folded value, described, or null when it does not fold.
532
540
  *
533
541
  * @returns The error, for the caller to throw.
534
542
  */
535
- function unsupportedChild(expr, what) {
543
+ function unsupportedChild(expression, what) {
536
544
  const error = what == null
537
- ? aotError(`AOT: unsupported expression child "${expr.type}" in a container`, 'a child expression must be a JSX element, `cond && <El/>` / a ternary of elements, ' +
545
+ ? aotError(`AOT: unsupported expression child "${expression.type}" in a container`, 'a child expression must be a JSX element, `cond && <El/>` / a ternary of elements, ' +
538
546
  "or `list.map(item => <El/>)`. A bare variable holding JSX isn't inlined — write the " +
539
547
  'element directly. (If this is a responsive Flow-A-only branch, compile at the target ' +
540
548
  'board size via ER_AOT_SCREEN_W/H so the AOT folds the supported branch.)')
541
549
  : aotError(`AOT: a non-element expression child (${what}) cannot render here`, 'only JSX elements render as children; wrap text in a <Text>{…}</Text>.');
542
- if (expr.loc) {
543
- error.aotLoc = expr.loc.start;
550
+ if (expression.loc) {
551
+ error.aotLoc = expression.loc.start;
544
552
  }
545
553
  return error;
546
554
  }
@@ -549,28 +557,30 @@ function unsupportedChild(expr, what) {
549
557
  * nothing. A condition that folds picks its branch now; a state-driven one builds every branch and shows each
550
558
  * only while it is chosen, `within` the branch it sits in.
551
559
  *
552
- * @param expr The branch.
560
+ * @param expression The branch.
553
561
  * @param scope Compile-time constants in reach.
554
- * @param out Everything emitted so far.
555
- * @param env The expression environment.
562
+ * @param output Everything emitted so far.
563
+ * @param environment The expression environment.
556
564
  * @param state The component's state table.
557
565
  * @param within When the branch it sits in shows, or null at the top.
558
566
  *
559
567
  * @returns The branch.
560
568
  */
561
- function lowerBranch(expr, scope, out, env, state, within) {
562
- if (expr.type === 'JSXElement') {
563
- return emitElementInto(expr, scope, out, env, state, within ? { show: within } : {});
569
+ function lowerBranch(expression, scope, output, environment, state, within) {
570
+ if (expression.type === 'JSXElement') {
571
+ return emitElementInto(expression, scope, output, environment, state, within ? { show: within } : {});
564
572
  }
565
- const isAnd = expr.type === 'LogicalExpression' && expr.operator === '&&';
566
- if (isAnd || expr.type === 'ConditionalExpression') {
567
- const testNode = isAnd ? expr.left : expr.test;
573
+ const isAnd = expression.type === 'LogicalExpression' && expression.operator === '&&';
574
+ if (isAnd || expression.type === 'ConditionalExpression') {
575
+ const testNode = isAnd
576
+ ? expression.left
577
+ : expression.test;
568
578
  const whenTrue = isAnd
569
- ? expr.right
570
- : expr.consequent;
579
+ ? expression.right
580
+ : expression.consequent;
571
581
  const whenFalse = isAnd
572
582
  ? null
573
- : expr.alternate;
583
+ : expression.alternate;
574
584
  // A test that folds picks its branch at build time; `&&` with a false test renders nothing.
575
585
  let folded;
576
586
  try {
@@ -585,21 +595,21 @@ function lowerBranch(expr, scope, out, env, state, within) {
585
595
  ? mergeBranchElements(testNode, whenTrue, whenFalse)
586
596
  : null;
587
597
  if (merged)
588
- return lowerBranch(merged, scope, out, env, state, within);
598
+ return lowerBranch(merged, scope, output, environment, state, within);
589
599
  folded = { value: foldBoot(folded.value) };
590
600
  }
591
601
  if (folded) {
592
602
  // A false `&&` yields its left value, which must be one React renders as nothing (`0` is text).
593
603
  if (isAnd && !folded.value && !rendersNothing(folded.value)) {
594
- throw unsupportedChild(expr, JSON.stringify(folded.value) ?? String(folded.value));
604
+ throw unsupportedChild(expression, JSON.stringify(folded.value) ?? String(folded.value));
595
605
  }
596
606
  const chosen = folded.value ? whenTrue : whenFalse;
597
607
  return chosen
598
- ? lowerBranch(chosen, scope, out, env, state, within)
608
+ ? lowerBranch(chosen, scope, output, environment, state, within)
599
609
  : null;
600
610
  }
601
611
  // A state-driven test builds every branch; each shows while the test picks it.
602
- const test = lowerExpr(testNode, env);
612
+ const test = lowerExpr(testNode, environment);
603
613
  if (isAnd && NUMERIC_KINDS.has(test.type.kind)) {
604
614
  const error = aotError('AOT: a number on the left of `&&` renders 0 as text when it is 0', 'React draws the 0 itself, and text needs a <Text>. Test it as a condition: `count > 0 && <El/>`.');
605
615
  if (testNode.loc) {
@@ -616,22 +626,22 @@ function lowerBranch(expr, scope, out, env, state, within) {
616
626
  return {
617
627
  kind: 'conditional',
618
628
  test,
619
- whenTrue: lowerBranch(whenTrue, scope, out, env, state, shown(false)),
629
+ whenTrue: lowerBranch(whenTrue, scope, output, environment, state, shown(false)),
620
630
  whenFalse: whenFalse
621
- ? lowerBranch(whenFalse, scope, out, env, state, shown(true))
631
+ ? lowerBranch(whenFalse, scope, output, environment, state, shown(true))
622
632
  : null,
623
633
  };
624
634
  }
625
635
  // Anything else must be a constant that renders nothing.
626
636
  let value;
627
637
  try {
628
- value = evalStatic(expr, withUndefined(scope));
638
+ value = evalStatic(expression, withUndefined(scope));
629
639
  }
630
640
  catch {
631
- throw unsupportedChild(expr, null);
641
+ throw unsupportedChild(expression, null);
632
642
  }
633
643
  if (!rendersNothing(value)) {
634
- throw unsupportedChild(expr, JSON.stringify(value) ?? String(value));
644
+ throw unsupportedChild(expression, JSON.stringify(value) ?? String(value));
635
645
  }
636
646
  return null;
637
647
  }
@@ -644,19 +654,19 @@ function lowerBranch(expr, scope, out, env, state, within) {
644
654
  *
645
655
  * @param children The container's children.
646
656
  * @param scope Compile-time constants in reach.
647
- * @param out Everything emitted so far.
648
- * @param env The expression environment.
657
+ * @param output Everything emitted so far.
658
+ * @param environment The expression environment.
649
659
  * @param state The component's state table.
650
660
  *
651
661
  * @returns The container's children.
652
662
  */
653
- export function emitChildren(children, scope, out, env, state) {
663
+ export function emitChildren(children, scope, output, environment, state) {
654
664
  const lowered = [];
655
665
  const element = (built) => lowered.push({ kind: 'element', element: built });
656
666
  for (const child of inlineFragments(children)) {
657
667
  // An element child is emitted as it is; an {expression} child is lowered by its shape below.
658
668
  if (child.type === 'JSXElement') {
659
- element(emitElementInto(child, scope, out, env, state));
669
+ element(emitElementInto(child, scope, output, environment, state));
660
670
  continue;
661
671
  }
662
672
  // Text needs a <Text>; the whitespace between tags is not a child.
@@ -673,30 +683,32 @@ export function emitChildren(children, scope, out, env, state) {
673
683
  if (child.type === 'JSXSpreadChild') {
674
684
  throw unsupportedChild(child, null);
675
685
  }
676
- const expr = child.expression;
677
- if (expr.type === 'JSXEmptyExpression')
686
+ const expression = child.expression;
687
+ if (expression.type === 'JSXEmptyExpression')
678
688
  continue;
679
- if (isChildrenRef(expr, env)) {
689
+ if (isChildrenRef(expression, environment)) {
680
690
  // {children} / {props.children}: emit the captured call-site children, in the caller's scope/env.
681
- lowered.push(...emitChildren(env.children.nodes, env.children.scope, out, env.children.env, state));
691
+ lowered.push(...emitChildren(environment.children.nodes, environment.children.scope, output, environment.children.environment, state));
682
692
  continue;
683
693
  }
684
- if (expr.type === 'CallExpression' &&
685
- expr.callee.type === 'MemberExpression' &&
686
- expr.callee.property.name === 'map') {
694
+ if (expression.type === 'CallExpression' &&
695
+ expression.callee.type === 'MemberExpression' &&
696
+ expression.callee.property.name === 'map') {
687
697
  // `{items.map(item => <X/>)}`: a pool of rows over list state, else unrolled over a constant array.
688
- const mapTarget = expr.callee.object;
689
- const stateRecord = mapTarget.type === 'Identifier' ? env.state.get(mapTarget.name) : null;
698
+ const mapTarget = expression.callee.object;
699
+ const stateRecord = mapTarget.type === 'Identifier'
700
+ ? environment.state.get(mapTarget.name)
701
+ : null;
690
702
  if (stateRecord?.kind === 'list') {
691
- lowered.push(emitDynamicMap(expr, stateRecord, scope, out, env, state));
703
+ lowered.push(emitDynamicMap(expression, stateRecord, scope, output, environment, state));
692
704
  }
693
705
  else {
694
- emitMap(expr, scope, out, env, state).forEach(element);
706
+ emitMap(expression, scope, output, environment, state).forEach(element);
695
707
  }
696
708
  continue;
697
709
  }
698
710
  // An element, `cond && <X/>`, a ternary of them (nested too), or a constant that renders nothing.
699
- const branch = lowerBranch(expr, scope, out, env, state, null);
711
+ const branch = lowerBranch(expression, scope, output, environment, state, null);
700
712
  if (branch?.kind === 'conditional') {
701
713
  lowered.push(branch);
702
714
  }