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
@@ -17,8 +17,8 @@
17
17
  - Imports
18
18
  ---------------------------------------------------------------------------------------------------------------------*/
19
19
  import { checkNumber } from './check.mjs';
20
- import { NODE_TYPES } from '../style-map.mjs';
21
- import { aotError, checkEngineString, constantText, withLoc, } from './diagnostics.mjs';
20
+ import { NODE_TYPES, OPACITY_OPAQUE } from '../style-map.mjs';
21
+ import { aotError, checkEngineString, constantText, currentLoc, withLoc, } from './diagnostics.mjs';
22
22
  import { buildValueOf, foldBoot } from './boot.mjs';
23
23
  import { evalStaticOrThrow, evalStatic, foldScope } from './static-eval.mjs';
24
24
  import { lowerExpr } from './expressions.mjs';
@@ -62,6 +62,10 @@ const ELLIPSIZE_MODES = {
62
62
  tail: 'ER_TEXT_ELLIPSIZE_TAIL',
63
63
  clip: 'ER_TEXT_ELLIPSIZE_CLIP',
64
64
  };
65
+ /** The most lines a <Text> may keep: the engine counts them in a byte. */
66
+ const MAX_NUMBER_OF_LINES = 255;
67
+ /** The longest long press, in ms: the engine keeps it in 16 bits. */
68
+ const MAX_LONG_PRESS_MS = 65535;
65
69
  /*----------------------------------------------------------------------------------------------------------------------
66
70
  - Implementation
67
71
  ---------------------------------------------------------------------------------------------------------------------*/
@@ -86,25 +90,25 @@ function resolveTag(openingElement) {
86
90
  * The node refs `ref={myRef}` stores the element's handle in (a node ref from useRef), marked used.
87
91
  *
88
92
  * @param openingElement The element's opening tag.
89
- * @param env The expression environment.
93
+ * @param environment The expression environment.
90
94
  *
91
- * @returns The refs' C slots.
95
+ * @returns The refs' slots.
92
96
  */
93
- export function lowerRefBinds(openingElement, env) {
97
+ export function lowerRefBinds(openingElement, environment) {
94
98
  const refs = [];
95
- for (const attr of openingElement.attributes) {
96
- if (attr.type !== 'JSXAttribute' ||
97
- attr.name.name !== 'ref') {
99
+ for (const attribute of openingElement.attributes) {
100
+ if (attribute.type !== 'JSXAttribute' ||
101
+ attribute.name.name !== 'ref') {
98
102
  continue;
99
103
  }
100
- const refExpr = attr.value?.type === 'JSXExpressionContainer'
101
- ? attr.value.expression
104
+ const refExpression = attribute.value?.type === 'JSXExpressionContainer'
105
+ ? attribute.value.expression
102
106
  : null;
103
- if (refExpr?.type === 'Identifier' &&
104
- env.refs?.get(refExpr.name)?.kind === 'node') {
105
- const nodeRef = env.refs.get(refExpr.name);
107
+ if (refExpression?.type === 'Identifier' &&
108
+ environment.refs?.get(refExpression.name)?.kind === 'node') {
109
+ const nodeRef = environment.refs.get(refExpression.name);
106
110
  nodeRef.used = true;
107
- refs.push(nodeRef.cVar);
111
+ refs.push(nodeRef.slotName);
108
112
  }
109
113
  else {
110
114
  throw new Error('AOT: ref={…} must reference a node ref declared with useRef()');
@@ -121,7 +125,9 @@ export function lowerRefBinds(openingElement, env) {
121
125
  * @returns The attribute, if the element has it.
122
126
  */
123
127
  function namedAttr(openingElement, name) {
124
- return openingElement.attributes.find((attr) => attr.type === 'JSXAttribute' && attr.name && attr.name.name === name);
128
+ return openingElement.attributes.find((attribute) => attribute.type === 'JSXAttribute' &&
129
+ attribute.name &&
130
+ attribute.name.name === name);
125
131
  }
126
132
  /**
127
133
  * True for `<Pressable disabled>` / `<TouchableOpacity disabled={SOME_CONST}>`. Must fold: `disabled`
@@ -135,10 +141,10 @@ function namedAttr(openingElement, name) {
135
141
  * @returns Whether it is disabled.
136
142
  */
137
143
  function pressableIsDisabled(element, tag, scope) {
138
- const attr = namedAttr(element.openingElement, 'disabled');
139
- if (!attr)
144
+ const attribute = namedAttr(element.openingElement, 'disabled');
145
+ if (!attribute)
140
146
  return false;
141
- return !!evalStaticOrThrow(attrExpr(attr), scope, `AOT: <${tag} disabled> must be a compile-time constant`, 'a disabled one still renders — it lowers to a plain <Pressable>, children, layout ' +
147
+ return !!evalStaticOrThrow(attrExpr(attribute), scope, `AOT: <${tag} disabled> must be a compile-time constant`, 'a disabled one still renders — it lowers to a plain <Pressable>, children, layout ' +
142
148
  'and style intact — but its press handlers are not emitted at all, so the ' +
143
149
  'AOT has to know at build time. To gate on state, leave it enabled and return early ' +
144
150
  'in the handler (`onPress={() => { if (!ready) return; … }}`).');
@@ -154,26 +160,26 @@ function pressableIsDisabled(element, tag, scope) {
154
160
  */
155
161
  function lowerTextTruncation(openingElement, scope) {
156
162
  const assigns = [];
157
- const linesAttr = namedAttr(openingElement, 'numberOfLines');
158
- if (linesAttr) {
159
- const lines = foldAttr(linesAttr, scope, 'AOT: <Text numberOfLines> must be a compile-time constant');
163
+ const linesAttribute = namedAttr(openingElement, 'numberOfLines');
164
+ if (linesAttribute) {
165
+ const lines = foldAttr(linesAttribute, scope, 'AOT: <Text numberOfLines> must be a compile-time constant');
160
166
  if (typeof lines !== 'number' ||
161
167
  !Number.isInteger(lines) ||
162
168
  lines < 0 ||
163
- lines > 255) {
164
- throw at(aotError(`AOT: <Text numberOfLines> must be a whole number from 0 to 255 (got ${String(lines)})`, '0 does not truncate; any other value is the most lines the text wraps to.'), linesAttr);
169
+ lines > MAX_NUMBER_OF_LINES) {
170
+ throw at(aotError(`AOT: <Text numberOfLines> must be a whole number from 0 to ${MAX_NUMBER_OF_LINES} (got ${String(lines)})`, '0 does not truncate; any other value is the most lines the text wraps to.'), linesAttribute);
165
171
  }
166
- assigns.push({ field: 'number_of_lines', expr: String(lines) });
172
+ assigns.push({ field: 'number_of_lines', value: lines });
167
173
  }
168
- const modeAttr = namedAttr(openingElement, 'ellipsizeMode');
169
- if (modeAttr) {
170
- const mode = foldAttr(modeAttr, scope, 'AOT: <Text ellipsizeMode> must be a compile-time constant');
174
+ const modeAttribute = namedAttr(openingElement, 'ellipsizeMode');
175
+ if (modeAttribute) {
176
+ const mode = foldAttr(modeAttribute, scope, 'AOT: <Text ellipsizeMode> must be a compile-time constant');
171
177
  if (!Object.hasOwn(ELLIPSIZE_MODES, mode)) {
172
- throw at(aotError(`AOT: <Text ellipsizeMode> "${String(mode)}" is not drawn by the engine`, "use 'tail' or 'clip'; the engine draws 'head' and 'middle' as 'tail'."), modeAttr);
178
+ throw at(aotError(`AOT: <Text ellipsizeMode> "${String(mode)}" is not drawn by the engine`, "use 'tail' or 'clip'; the engine draws 'head' and 'middle' as 'tail'."), modeAttribute);
173
179
  }
174
180
  assigns.push({
175
181
  field: 'ellipsize_mode',
176
- expr: ELLIPSIZE_MODES[mode],
182
+ value: ELLIPSIZE_MODES[mode],
177
183
  });
178
184
  }
179
185
  return assigns;
@@ -181,32 +187,32 @@ function lowerTextTruncation(openingElement, scope) {
181
187
  /**
182
188
  * An attribute's value, which must fold; the error is pinned to the attribute.
183
189
  *
184
- * @param attr The attribute.
190
+ * @param attribute The attribute.
185
191
  * @param scope Compile-time constants in reach.
186
192
  * @param message The error when it does not fold.
187
193
  *
188
194
  * @returns The folded value.
189
195
  */
190
- function foldAttr(attr, scope, message) {
196
+ function foldAttr(attribute, scope, message) {
191
197
  try {
192
- return evalStaticOrThrow(attrExpr(attr), scope, message);
198
+ return evalStaticOrThrow(attrExpr(attribute), scope, message);
193
199
  }
194
200
  catch (error) {
195
- throw at(error, attr);
201
+ throw at(error, attribute);
196
202
  }
197
203
  }
198
204
  /**
199
205
  * A folded `activeOpacity` as a number in 0..1. Everything else is an error HERE, where the source line
200
- * is still in reach: it would otherwise reach floatLit and land in the generated C as a literal that
201
- * either does not compile (`NaNf`) or quietly means something the app never asked for — a bare
202
- * `activeOpacity` is `true`, so `1.0f`, which is not dim at all; `{false}` is an invisible one.
206
+ * is still in reach: it would otherwise reach floatConstant and land in the package as a value that
207
+ * is not a number, or quietly means something the app never asked for — a bare
208
+ * `activeOpacity` is `true`, so 1, which is not dim at all; `{false}` is an invisible one.
203
209
  *
204
210
  * @param value The folded value.
205
- * @param attr The attribute, for the error's location.
211
+ * @param attribute The attribute, for the error's location.
206
212
  *
207
213
  * @returns The opacity.
208
214
  */
209
- function opacityLiteralOrThrow(value, attr) {
215
+ function opacityLiteralOrThrow(value, attribute) {
210
216
  if (typeof value !== 'number' ||
211
217
  !Number.isFinite(value) ||
212
218
  value < 0 ||
@@ -216,8 +222,8 @@ function opacityLiteralOrThrow(value, attr) {
216
222
  ? String(value)
217
223
  : (JSON.stringify(value) ?? String(value));
218
224
  const error = aotError(`AOT: <TouchableOpacity activeOpacity> must be a number between 0 and 1 (got ${shown})`, 'it is the opacity the node dims to while held — 0 is invisible, 1 is no dim at all. RN defaults it to 0.2.');
219
- if (attr.loc) {
220
- error.aotLoc = attr.loc.start;
225
+ if (attribute.loc) {
226
+ error.aotLoc = attribute.loc.start;
221
227
  }
222
228
  throw error;
223
229
  }
@@ -233,43 +239,45 @@ function opacityLiteralOrThrow(value, attr) {
233
239
  * @param element The <TouchableOpacity>.
234
240
  * @param nodeId The node's variable.
235
241
  * @param staticAssigns The style's constant writes.
236
- * @param dynAssigns The style's state-driven writes.
242
+ * @param dynamicAssigns The style's state-driven writes.
237
243
  * @param binds The style's animated-value binds.
238
- * @param out Everything emitted so far.
244
+ * @param output Everything emitted so far.
239
245
  * @param scope Compile-time constants in reach.
240
246
  *
241
247
  * @returns The opacity bind, and the fade to run on onPressIn and the one to run on onPressOut.
242
248
  */
243
- function touchablePressFades(element, nodeId, staticAssigns, dynAssigns, binds, out, scope) {
249
+ function touchablePressFades(element, nodeId, staticAssigns, dynamicAssigns, binds, output, scope) {
244
250
  // The press feedback owns the node's opacity, so the style may not animate it or drive it from state.
245
251
  const hasAnimatedOpacity = binds.some(bind => bind.prop === 'ER_PROP_OPACITY');
246
252
  if (hasAnimatedOpacity ||
247
- dynAssigns.some(assign => assign.field === 'opacity')) {
253
+ dynamicAssigns.some(assign => assign.field === 'opacity')) {
248
254
  throw aotError(`AOT: <TouchableOpacity> cannot take ${hasAnimatedOpacity ? 'an Animated' : 'a state-driven'} opacity`, "the press feedback owns this node's opacity — a second writer does not blend with " +
249
255
  'it, it races it. To animate opacity yourself, use <Pressable>: the dim is just ' +
250
256
  'onPressIn/onPressOut driving an Animated.Value (see TouchableOpacity.js for the ' +
251
257
  'whole of it).');
252
258
  }
253
- // lowerStyle scaled static opacity to 0–255 (the resting value); leave a NaN one for the C compiler to reject.
259
+ // lowerStyle scaled static opacity to 0–255 (the resting value); a NaN one is refused later.
254
260
  const opacityAssign = staticAssigns.find(assign => assign.field === 'opacity');
255
- const restingRaw = opacityAssign ? Number(opacityAssign.expr) / 255 : 1;
261
+ const restingRaw = opacityAssign
262
+ ? Number(opacityAssign.value) / OPACITY_OPAQUE
263
+ : 1;
256
264
  const restingOpacity = Number.isFinite(restingRaw) ? restingRaw : 1;
257
265
  // The dim target: a folded activeOpacity, or RN's default.
258
- const activeAttr = namedAttr(element.openingElement, 'activeOpacity');
259
- const activeOpacity = activeAttr
260
- ? opacityLiteralOrThrow(evalStaticOrThrow(attrExpr(activeAttr), scope, 'AOT: <TouchableOpacity activeOpacity> must be a compile-time constant', 'the dim target is baked into the generated handler, so it cannot come from state.'), activeAttr)
266
+ const activeAttribute = namedAttr(element.openingElement, 'activeOpacity');
267
+ const activeOpacity = activeAttribute
268
+ ? opacityLiteralOrThrow(evalStaticOrThrow(attrExpr(activeAttribute), scope, 'AOT: <TouchableOpacity activeOpacity> must be a compile-time constant', 'the dim target is baked into the handler, so it cannot come from state.'), activeAttribute)
261
269
  : TOUCHABLE_ACTIVE_OPACITY;
262
270
  // Bind a fresh animated value, starting at rest, to the node's opacity.
263
- const cVar = `s_av_press_${nodeId}`;
271
+ const slotName = `anim_press_${nodeId}`;
264
272
  checkNumber(restingOpacity);
265
- out.childAnimations.push({ cVar, initial: restingOpacity });
273
+ output.childAnimations.push({ slotName, initial: restingOpacity });
266
274
  // Each fade is one timing animation of that value.
267
275
  return {
268
- bind: { cVar, prop: 'ER_PROP_OPACITY' },
276
+ bind: { slotName, prop: 'ER_PROP_OPACITY' },
269
277
  fades: {
270
- onPressIn: { value: cVar, opacity: activeOpacity, durationMs: 0 },
278
+ onPressIn: { value: slotName, opacity: activeOpacity, durationMs: 0 },
271
279
  onPressOut: {
272
- value: cVar,
280
+ value: slotName,
273
281
  opacity: restingOpacity,
274
282
  durationMs: TOUCHABLE_RESTORE_MS,
275
283
  },
@@ -297,7 +305,7 @@ function applyShow(node, show) {
297
305
  value: {
298
306
  kind: 'whileShown',
299
307
  show,
300
- value: { kind: 'constant', code: visible.expr },
308
+ value: { kind: 'constant', value: visible.value },
301
309
  },
302
310
  });
303
311
  return;
@@ -309,53 +317,55 @@ function applyShow(node, show) {
309
317
  * Lowers an event prop's function to a handler: a useCallback compiles once per instance and is shared, a
310
318
  * callback prop compiles in its caller's environment, and an inline function compiles where it is.
311
319
  *
312
- * @param attr The event prop.
313
- * @param out Everything emitted so far.
314
- * @param env The expression environment.
320
+ * @param attribute The event prop.
321
+ * @param output Everything emitted so far.
322
+ * @param environment The expression environment.
315
323
  * @param state The component's state table.
316
324
  *
317
325
  * @returns The handler's name.
318
326
  */
319
- export function lowerEventHandler(attr, out, env, state) {
320
- const fn = attrExpr(attr);
321
- const layout = attr.name.name === 'onLayout';
322
- if (fn.type === 'Identifier' && env.callbacks?.has(fn.name)) {
327
+ export function lowerEventHandler(attribute, output, environment, state) {
328
+ const handlerExpression = attrExpr(attribute);
329
+ const layout = attribute.name.name === 'onLayout';
330
+ if (handlerExpression.type === 'Identifier' &&
331
+ environment.callbacks?.has(handlerExpression.name)) {
323
332
  // A useCallback compiles to one shared handler, namespaced by cbPrefix so each child instance gets its own.
324
333
  // Its onLayout use gets a handler of its own, since only that event carries the layout rect. The key's
325
- // `layout:` and the name's `er_cbl_` can't come from an identifier, so they never meet another callback.
326
- const callbackKey = `${env.cbPrefix ?? ''}${fn.name}`;
334
+ // `layout:` and the name's `layout_callback_` can't come from an identifier, so they never meet another callback.
335
+ const callbackKey = `${environment.callbackPrefix ?? ''}${handlerExpression.name}`;
327
336
  const emittedKey = layout ? `layout:${callbackKey}` : callbackKey;
328
- let handlerName = out.cbEmitted.get(emittedKey);
337
+ let handlerName = output.emittedCallbacks.get(emittedKey);
329
338
  if (!handlerName) {
330
- handlerName = `${layout ? 'er_cbl_' : 'er_cb_'}${callbackKey}`;
331
- out.cbEmitted.set(emittedKey, handlerName);
332
- out.handlers.push({
339
+ handlerName = `${layout ? 'layout_callback_' : 'callback_'}${callbackKey}`;
340
+ output.emittedCallbacks.set(emittedKey, handlerName);
341
+ output.handlers.push({
333
342
  kind: 'callback',
334
343
  name: handlerName,
335
- callback: lowerHandler(env.callbacks.get(fn.name), { ...env, layout }, state, out),
344
+ callback: lowerHandler(environment.callbacks.get(handlerExpression.name), { ...environment, layout }, state, output),
336
345
  });
337
346
  }
338
347
  return handlerName;
339
348
  }
340
- const handlerName = `er_handler_${out.handlers.length}`;
341
- if (fn.type === 'Identifier' && env.fnProps?.has(fn.name)) {
349
+ const handlerName = `handler_${output.handlers.length}`;
350
+ if (handlerExpression.type === 'Identifier' &&
351
+ environment.functionProps?.has(handlerExpression.name)) {
342
352
  // Inline a callback prop's function, compiled in the caller's env/state so its setters and locals resolve.
343
- const callbackProp = env.fnProps.get(fn.name);
344
- out.handlers.push({
353
+ const callbackProp = environment.functionProps.get(handlerExpression.name);
354
+ output.handlers.push({
345
355
  kind: 'callback',
346
356
  name: handlerName,
347
- callback: lowerHandler(callbackProp.node, { ...callbackProp.env, layout }, callbackProp.state, out),
357
+ callback: lowerHandler(callbackProp.node, { ...callbackProp.environment, layout }, callbackProp.state, output),
348
358
  });
349
359
  }
350
- else if (isFn(fn)) {
351
- out.handlers.push({
360
+ else if (isFn(handlerExpression)) {
361
+ output.handlers.push({
352
362
  kind: 'callback',
353
363
  name: handlerName,
354
- callback: lowerHandler(fn, { ...env, layout }, state, out),
364
+ callback: lowerHandler(handlerExpression, { ...environment, layout }, state, output),
355
365
  });
356
366
  }
357
367
  else {
358
- throw aotError(`AOT: ${attr.name.name} must be an inline function, a useCallback, or a callback prop`, `pass an inline arrow (onPress={() => setX(…)}), a useCallback identifier, or a ` +
368
+ throw aotError(`AOT: ${attribute.name.name} must be an inline function, a useCallback, or a callback prop`, `pass an inline arrow (onPress={() => setX(…)}), a useCallback identifier, or a ` +
359
369
  `function prop received by this component.`);
360
370
  }
361
371
  return handlerName;
@@ -368,14 +378,14 @@ export function lowerEventHandler(attr, out, env, state) {
368
378
  *
369
379
  * @param element The element.
370
380
  * @param scope Compile-time constants in reach.
371
- * @param out Everything emitted so far.
372
- * @param env The expression environment.
381
+ * @param output Everything emitted so far.
382
+ * @param environment The expression environment.
373
383
  * @param state The component's state table.
374
- * @param opts How the element is placed.
384
+ * @param options How the element is placed.
375
385
  *
376
386
  * @returns What the element lowered to.
377
387
  */
378
- function emitNodeImpl(element, scope, out, env, state, opts = {}) {
388
+ function emitNodeImpl(element, scope, output, environment, state, options = {}) {
379
389
  // Refuse any prop the element does not declare, whatever its value, then drop the no-ops and the props that
380
390
  // fold to undefined before dispatch.
381
391
  const tag = resolveTag(element.openingElement);
@@ -387,38 +397,38 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
387
397
  }
388
398
  element = withoutPlatformNoOps(spec, element);
389
399
  }
390
- element = omitUndefinedAttrs(element, scope, env);
400
+ element = omitUndefinedAttrs(element, scope, environment);
391
401
  const typed = (node) => {
392
- if (opts.show) {
393
- applyShow(node, opts.show);
402
+ if (options.show) {
403
+ applyShow(node, options.show);
394
404
  }
395
405
  return { kind: 'node', id: node.id, node };
396
406
  };
397
407
  if (tag === 'Svg') {
398
- return typed(emitSvg(element, scope, out, env, state, opts));
408
+ return typed(emitSvg(element, scope, output, environment, state, options));
399
409
  }
400
410
  if (tag === 'Switch') {
401
- return typed(emitSwitch(element, scope, out, env, state));
411
+ return typed(emitSwitch(element, scope, output, environment, state));
402
412
  }
403
413
  if (tag === 'Dial')
404
- return typed(emitDial(element, scope, out, env, state));
414
+ return typed(emitDial(element, scope, output, environment, state));
405
415
  if (tag === 'TextInput') {
406
- return typed(emitTextInput(element, scope, out, env, state));
416
+ return typed(emitTextInput(element, scope, output, environment, state));
407
417
  }
408
418
  if (tag === 'ActivityIndicator') {
409
- return typed(emitActivityIndicator(element, scope, out, env));
419
+ return typed(emitActivityIndicator(element, scope, output, environment));
410
420
  }
411
421
  if (tag === 'Modal') {
412
- return typed(emitModal(element, scope, out, env, state));
422
+ return typed(emitModal(element, scope, output, environment, state));
413
423
  }
414
424
  if (tag === 'FlatList') {
415
- return emitFlatList(element, scope, out, env, state, opts);
425
+ return emitFlatList(element, scope, output, environment, state, options);
416
426
  }
417
427
  // Anything else must be a host node or a function component defined in this file.
418
428
  const nodeType = NODE_TYPES[tag];
419
429
  if (!nodeType) {
420
- if (out.components.has(tag)) {
421
- return emitComponent(element, scope, out, env, state, opts);
430
+ if (output.components.has(tag)) {
431
+ return emitComponent(element, scope, output, environment, state, options);
422
432
  }
423
433
  // A package export with no lowering yet gets its own error; "unknown element" would read like a typo.
424
434
  const replacement = FLOW_A_ONLY_COMPONENTS[tag];
@@ -440,7 +450,7 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
440
450
  continue;
441
451
  let panResponder;
442
452
  try {
443
- panResponder = panSpreadTarget(spread.argument, env);
453
+ panResponder = panSpreadTarget(spread.argument, environment);
444
454
  }
445
455
  catch (error) {
446
456
  if (spread.loc && !error.aotLoc) {
@@ -462,62 +472,68 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
462
472
  throw spreadError;
463
473
  }
464
474
  // Allocate the node and collect its style, text content, and image attributes.
465
- const nodeId = `n${out.allocateNodeId()}`;
466
- const { staticAssigns, dynAssigns, binds } = collectStyleAssigns(element.openingElement, scope, env, spec);
475
+ const nodeId = `n${output.allocateNodeId()}`;
476
+ const { staticAssigns, dynamicAssigns, binds } = collectStyleAssigns(element.openingElement, scope, environment, spec);
467
477
  if (tag === 'Text') {
468
478
  staticAssigns.push(...lowerTextTruncation(element.openingElement, scope));
469
479
  }
470
480
  // A <Text> with a nested <Text> becomes inline SPANS; otherwise a single (possibly dynamic) string.
471
- const spans = tag === 'Text' ? collectTextSpans(element.children, scope, env) : null;
481
+ const spans = tag === 'Text'
482
+ ? collectTextSpans(element.children, scope, environment)
483
+ : null;
472
484
  const text = tag === 'Text' && !spans
473
- ? lowerNodeText(element.children, scope, env)
485
+ ? lowerNodeText(element.children, scope, environment)
474
486
  : null;
475
487
  if (text) {
476
488
  checkEngineString(constantText(text), 'ER_TEXT_MAX', 'a <Text>');
477
489
  }
478
490
  // An <Image>'s resize/tint are static, so fold them into staticAssigns for both the static and dynamic paths.
479
- const image = tag === 'Image' ? resolveImageAttrs(element, env, out) : null;
491
+ const image = tag === 'Image' ? resolveImageAttrs(element, environment, output) : null;
480
492
  checkEngineString(image?.imageName ?? null, 'ER_IMAGE_NAME_MAX', `image name "${image?.imageName}"`);
481
493
  if (image?.resizeMode) {
482
- staticAssigns.push({ field: 'resize_mode', expr: image.resizeMode });
494
+ staticAssigns.push({ field: 'resize_mode', value: image.resizeMode });
483
495
  }
484
496
  if (image?.tintColor) {
485
- staticAssigns.push({ field: 'tint_color', expr: image.tintColor });
497
+ staticAssigns.push({ field: 'tint_color', value: image.tintColor });
486
498
  }
487
499
  // `visible` is `display` as in Flow A (style `display` wins); not in collectStyleAssigns, which <Modal> shares.
488
- const visibleAttr = element.openingElement.attributes.find((attr) => attr.type === 'JSXAttribute' && attr.name && attr.name.name === 'visible');
489
- if (visibleAttr &&
500
+ const visibleAttribute = element.openingElement.attributes.find((attribute) => attribute.type === 'JSXAttribute' &&
501
+ attribute.name &&
502
+ attribute.name.name === 'visible');
503
+ if (visibleAttribute &&
490
504
  !staticAssigns.some(assign => assign.field === 'display') &&
491
- !dynAssigns.some(assign => assign.field === 'display')) {
492
- const expr = visibleAttr.value == null ? null : attrExpr(visibleAttr); // bare `visible` === true
493
- if (expr == null) {
494
- staticAssigns.push({ field: 'display', expr: 'ER_DISPLAY_FLEX' });
505
+ !dynamicAssigns.some(assign => assign.field === 'display')) {
506
+ const expression = visibleAttribute.value == null ? null : attrExpr(visibleAttribute); // bare `visible` === true
507
+ if (expression == null) {
508
+ staticAssigns.push({ field: 'display', value: 'ER_DISPLAY_FLEX' });
495
509
  }
496
510
  else {
497
511
  try {
498
512
  staticAssigns.push({
499
513
  field: 'display',
500
- expr: evalStatic(expr, scope) ? 'ER_DISPLAY_FLEX' : 'ER_DISPLAY_NONE',
514
+ value: evalStatic(expression, scope)
515
+ ? 'ER_DISPLAY_FLEX'
516
+ : 'ER_DISPLAY_NONE',
501
517
  });
502
518
  }
503
519
  catch {
504
- dynAssigns.push({
520
+ dynamicAssigns.push({
505
521
  field: 'display',
506
- value: { kind: 'visible', value: lowerExpr(expr, env) },
522
+ value: { kind: 'visible', value: lowerExpr(expression, environment) },
507
523
  });
508
524
  }
509
525
  }
510
526
  }
511
527
  // delayLongPress must fold since it is baked into props; 0 becomes 1 ms because 0 means "default" to the engine.
512
- const delayAttr = namedAttr(element.openingElement, 'delayLongPress');
513
- if (delayAttr) {
528
+ const delayAttribute = namedAttr(element.openingElement, 'delayLongPress');
529
+ if (delayAttribute) {
514
530
  const delayError = aotError(`AOT: <${tag} delayLongPress> must fold to a number`, 'pass a literal or a module-level constant in milliseconds, e.g. delayLongPress={800}.');
515
- if (delayAttr.value == null) {
531
+ if (delayAttribute.value == null) {
516
532
  throw delayError;
517
533
  }
518
534
  let delayMs;
519
535
  try {
520
- delayMs = Number(evalStatic(attrExpr(delayAttr), scope));
536
+ delayMs = Number(evalStatic(attrExpr(delayAttribute), scope));
521
537
  }
522
538
  catch {
523
539
  throw delayError;
@@ -527,19 +543,19 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
527
543
  }
528
544
  staticAssigns.push({
529
545
  field: 'long_press_ms',
530
- expr: String(Math.min(65535, Math.max(1, Math.round(delayMs)))),
546
+ value: Math.min(MAX_LONG_PRESS_MS, Math.max(1, Math.round(delayMs))),
531
547
  });
532
548
  }
533
- // A state-driven conditional flips `display` in app_update; pushed last to beat the element's visible/display.
534
- if (opts.show) {
535
- dynAssigns.push({
549
+ // A state-driven conditional flips `display` in the update; pushed last to beat the element's visible/display.
550
+ if (options.show) {
551
+ dynamicAssigns.push({
536
552
  field: 'display',
537
- value: { kind: 'shown', show: opts.show },
553
+ value: { kind: 'shown', show: options.show },
538
554
  });
539
555
  }
540
556
  // <TouchableOpacity>'s own opacity binding, on top of any the style asked for.
541
557
  const press = tag === 'TouchableOpacity' && !isPressDisabled
542
- ? touchablePressFades(element, nodeId, staticAssigns, dynAssigns, binds, out, scope)
558
+ ? touchablePressFades(element, nodeId, staticAssigns, dynamicAssigns, binds, output, scope)
543
559
  : null;
544
560
  // A host node wires its binds (the press feedback's last), then its refs, events and PanResponders.
545
561
  const wiring = binds.map((bind, index) => ({
@@ -550,18 +566,19 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
550
566
  if (press) {
551
567
  wiring.push({ kind: 'bind', bind: press.bind, index: binds.length });
552
568
  }
553
- for (const slot of lowerRefBinds(element.openingElement, env)) {
569
+ for (const slot of lowerRefBinds(element.openingElement, environment)) {
554
570
  wiring.push({ kind: 'ref', slot });
555
571
  }
556
572
  const node = {
557
573
  id: nodeId,
574
+ location: currentLoc(),
558
575
  type: nodeType,
559
576
  constantProps: staticAssigns,
560
- stateProps: dynAssigns,
577
+ stateProps: dynamicAssigns,
561
578
  placeholder: null,
562
579
  text,
563
- image: image?.imageNameDyn != null
564
- ? { kind: 'value', value: image.imageNameDyn }
580
+ image: image?.imageNameDynamic != null
581
+ ? { kind: 'value', value: image.imageNameDynamic }
565
582
  : image?.imageName != null
566
583
  ? { kind: 'static', name: image.imageName }
567
584
  : null,
@@ -571,29 +588,29 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
571
588
  };
572
589
  // Compile each event prop into a handler; a disabled one drops its press events.
573
590
  const fadesWired = new Set();
574
- for (const attr of element.openingElement.attributes) {
575
- if (attr.type !== 'JSXAttribute')
591
+ for (const attribute of element.openingElement.attributes) {
592
+ if (attribute.type !== 'JSXAttribute')
576
593
  continue;
577
- const eventType = EVENT_TYPES[attr.name.name];
594
+ const eventType = EVENT_TYPES[attribute.name.name];
578
595
  if (!eventType)
579
596
  continue;
580
597
  if (isPressDisabled &&
581
- PRESS_EVENTS.has(attr.name.name)) {
598
+ PRESS_EVENTS.has(attribute.name.name)) {
582
599
  continue;
583
600
  }
584
- let handlerName = lowerEventHandler(attr, out, env, state);
601
+ let handlerName = lowerEventHandler(attribute, output, environment, state);
585
602
  // Wrap the app's press-in/out with the fade; prepending would dim every other element sharing a useCallback.
586
- const pressFade = press?.fades[attr.name.name];
603
+ const pressFade = press?.fades[attribute.name.name];
587
604
  if (pressFade) {
588
- const wrapperName = `er_handler_${out.handlers.length}`;
589
- out.handlers.push({
605
+ const wrapperName = `handler_${output.handlers.length}`;
606
+ output.handlers.push({
590
607
  kind: 'pressFade',
591
608
  name: wrapperName,
592
609
  fade: pressFade,
593
610
  then: handlerName,
594
611
  });
595
612
  handlerName = wrapperName;
596
- fadesWired.add(attr.name.name);
613
+ fadesWired.add(attribute.name.name);
597
614
  }
598
615
  wiring.push({ kind: 'event', event: eventType, handler: handlerName });
599
616
  }
@@ -602,8 +619,8 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
602
619
  for (const eventName of ['onPressIn', 'onPressOut']) {
603
620
  if (fadesWired.has(eventName))
604
621
  continue;
605
- const fadeHandlerName = `er_handler_${out.handlers.length}`;
606
- out.handlers.push({
622
+ const fadeHandlerName = `handler_${output.handlers.length}`;
623
+ output.handlers.push({
607
624
  kind: 'pressFade',
608
625
  name: fadeHandlerName,
609
626
  fade: press.fades[eventName],
@@ -620,13 +637,13 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
620
637
  for (const panResponder of panSpreads) {
621
638
  wiring.push({
622
639
  kind: 'responder',
623
- pan: emitPanResponder(panResponder, out, env, state),
640
+ pan: emitPanResponder(panResponder, output, environment, state),
624
641
  });
625
642
  }
626
643
  checkInterpolations(node);
627
644
  // A <Text>'s children are its text, already consumed above.
628
645
  if (tag !== 'Text') {
629
- node.children = emitChildren(element.children, scope, out, env, state);
646
+ node.children = emitChildren(element.children, scope, output, environment, state);
630
647
  }
631
648
  return { kind: 'node', id: nodeId, node };
632
649
  }
@@ -640,24 +657,24 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
640
657
  *
641
658
  * @param element The element.
642
659
  * @param scope Compile-time constants in reach.
643
- * @param env The expression environment.
660
+ * @param environment The expression environment.
644
661
  *
645
662
  * @returns The element, or a copy of it without those attributes.
646
663
  */
647
- function omitUndefinedAttrs(element, scope, env) {
648
- const attrs = element.openingElement.attributes;
664
+ function omitUndefinedAttrs(element, scope, environment) {
665
+ const attributes = element.openingElement.attributes;
649
666
  // Built lazily: the runtime-aware scope plus the global `undefined`, so `SHOW ? true : undefined` folds too.
650
667
  let foldingScope = null;
651
- const keptAttrs = attrs.filter(attr => {
652
- if (attr.type !== 'JSXAttribute' ||
653
- attr.value?.type !== 'JSXExpressionContainer') {
668
+ const keptAttributes = attributes.filter(attribute => {
669
+ if (attribute.type !== 'JSXAttribute' ||
670
+ attribute.value?.type !== 'JSXExpressionContainer') {
654
671
  return true;
655
672
  }
656
- foldingScope ??= Object.assign(Object.create(foldScope(env, scope)), {
673
+ foldingScope ??= Object.assign(Object.create(foldScope(environment, scope)), {
657
674
  undefined,
658
675
  });
659
676
  try {
660
- const value = evalStatic(attr.value.expression, foldingScope, 'boot');
677
+ const value = evalStatic(attribute.value.expression, foldingScope, 'boot');
661
678
  if (buildValueOf(value) !== undefined)
662
679
  return true;
663
680
  foldBoot(value); // undefined on this panel only: omitting it assumes the panel
@@ -667,26 +684,26 @@ function omitUndefinedAttrs(element, scope, env) {
667
684
  return true; // not a compile-time value — its reader decides
668
685
  }
669
686
  });
670
- return keptAttrs.length === attrs.length
687
+ return keptAttributes.length === attributes.length
671
688
  ? element
672
689
  : {
673
690
  ...element,
674
- openingElement: { ...element.openingElement, attributes: keptAttrs },
691
+ openingElement: { ...element.openingElement, attributes: keptAttributes },
675
692
  };
676
693
  }
677
694
  /**
678
- * Refuses an interpolation table holding a number C cannot write, at the element that binds it rather than when
695
+ * Refuses an interpolation table holding a number that isn't finite, at the element that binds it rather than when
679
696
  * its build lines are written.
680
697
  *
681
698
  * @param node The node.
682
699
  */
683
700
  export function checkInterpolations(node) {
684
701
  for (const wire of node.wiring) {
685
- if (wire.kind !== 'bind' || !wire.bind.interp)
702
+ if (wire.kind !== 'bind' || !wire.bind.interpolation)
686
703
  continue;
687
704
  for (const point of [
688
- ...wire.bind.interp.input,
689
- ...wire.bind.interp.output,
705
+ ...wire.bind.interpolation.input,
706
+ ...wire.bind.interpolation.output,
690
707
  ]) {
691
708
  checkNumber(point);
692
709
  }