embedded-react 0.18.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 (117) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +8 -4
  3. package/aot/compile.mjs +178 -58
  4. package/aot/compiler/animations.mjs +290 -281
  5. package/aot/compiler/boot.mjs +70 -33
  6. package/aot/compiler/branch-merge.mjs +4 -3
  7. package/aot/compiler/check.mjs +9 -9
  8. package/aot/compiler/collect.mjs +324 -205
  9. package/aot/compiler/control-flow.mjs +209 -197
  10. package/aot/compiler/diagnostics.mjs +22 -25
  11. package/aot/compiler/elements/activity-indicator.mjs +25 -24
  12. package/aot/compiler/elements/dial.mjs +91 -77
  13. package/aot/compiler/elements/flat-list.mjs +24 -22
  14. package/aot/compiler/elements/image.mjs +51 -50
  15. package/aot/compiler/elements/modal.mjs +31 -30
  16. package/aot/compiler/elements/props.mjs +23 -23
  17. package/aot/compiler/elements/switch.mjs +42 -34
  18. package/aot/compiler/elements/text-input.mjs +34 -32
  19. package/aot/compiler/expressions.mjs +372 -333
  20. package/aot/compiler/handlers.mjs +473 -387
  21. package/aot/compiler/ir/functions.mjs +11 -1
  22. package/aot/compiler/ir/nodes.mjs +4 -4
  23. package/aot/compiler/ir/reads.mjs +19 -19
  24. package/aot/compiler/ir/types.mjs +14 -14
  25. package/aot/compiler/ir/vectors.mjs +5 -1
  26. package/aot/compiler/keyboard.mjs +17 -7
  27. package/aot/compiler/lower.mjs +77 -80
  28. package/aot/compiler/nodes.mjs +169 -152
  29. package/aot/compiler/options.mjs +35 -30
  30. package/aot/compiler/out.mjs +18 -22
  31. package/aot/compiler/package/animations.mjs +669 -0
  32. package/aot/compiler/package/arena.mjs +252 -0
  33. package/aot/compiler/package/assemble.mjs +177 -0
  34. package/aot/compiler/package/bytecode.mjs +286 -0
  35. package/aot/compiler/package/checks.mjs +1022 -0
  36. package/aot/compiler/package/codegen.mjs +1329 -0
  37. package/aot/compiler/package/enums.mjs +138 -0
  38. package/aot/compiler/package/format.mjs +760 -0
  39. package/aot/compiler/package/layouts.mjs +136 -0
  40. package/aot/compiler/package/lower.mjs +1606 -0
  41. package/aot/compiler/package/props.mjs +118 -0
  42. package/aot/compiler/package/tables.mjs +103 -0
  43. package/aot/compiler/package/vectors.mjs +502 -0
  44. package/aot/compiler/package/writer.mjs +664 -0
  45. package/aot/compiler/pan-responder.mjs +69 -61
  46. package/aot/compiler/parse.mjs +21 -21
  47. package/aot/compiler/static-eval.mjs +25 -23
  48. package/aot/compiler/style-text.mjs +161 -172
  49. package/aot/compiler/svg.mjs +477 -251
  50. package/aot/screenshot-smoke.mjs +55 -41
  51. package/aot/style-map.mjs +102 -90
  52. package/assets/bake-font.mjs +123 -77
  53. package/assets/bake-image.mjs +39 -22
  54. package/assets/bake-svg.mjs +361 -262
  55. package/assets/build-builtin-font.mjs +14 -10
  56. package/assets/emit-c.mjs +83 -62
  57. package/assets/emit-container.mjs +124 -38
  58. package/assets/emit-pack.mjs +77 -67
  59. package/assets/font-config.mjs +9 -6
  60. package/assets/font-sizes.mjs +163 -123
  61. package/assets/glyph-coverage.mjs +74 -54
  62. package/assets/index.mjs +31 -9
  63. package/assets/rasterize.mjs +126 -99
  64. package/assets/svg-loader.mjs +8 -8
  65. package/build.mjs +16 -14
  66. package/cli.mjs +359 -172
  67. package/compile-bin.mjs +5 -5
  68. package/flash.mjs +537 -0
  69. package/hotreload/dev-device.mjs +90 -33
  70. package/hotreload/pack-app.mjs +55 -43
  71. package/hotreload/pack-split.mjs +46 -37
  72. package/hotreload/package-transfer.mjs +175 -0
  73. package/hotreload/protocol.mjs +51 -38
  74. package/hotreload/uploader.mjs +38 -27
  75. package/hotreload/watch-tree.mjs +19 -19
  76. package/pack-container.mjs +31 -23
  77. package/package.json +11 -12
  78. package/persist-transform.mjs +34 -28
  79. package/qjsc-wasm.mjs +25 -14
  80. package/sim/embedded-react.cjs +1 -1
  81. package/sim/embedded-react.js +1 -1
  82. package/sim/embedded-react.wasm +0 -0
  83. package/sim/index.html +94 -85
  84. package/sim-server.mjs +101 -82
  85. package/src/embedded-react/Animated.js +24 -24
  86. package/src/embedded-react/Easing.js +1 -1
  87. package/src/embedded-react/FlatList.js +4 -4
  88. package/src/embedded-react/LayoutAnimation.js +8 -5
  89. package/src/embedded-react/PanResponder.js +75 -71
  90. package/src/embedded-react/Pressable.js +2 -8
  91. package/src/embedded-react/SectionList.js +6 -6
  92. package/src/embedded-react/StyleSheet.js +4 -3
  93. package/src/embedded-react/TouchableOpacity.js +13 -8
  94. package/src/embedded-react/index.d.ts +5 -5
  95. package/src/embedded-react/layout-anim-config.js +10 -4
  96. package/src/embedded-react/list-child.js +5 -5
  97. package/src/embedded-react/named-colors.js +1 -1
  98. package/src/embedded-react/split-style.js +11 -11
  99. package/src/embedded-react/svg-ops.js +760 -593
  100. package/src/embedded-react/useHostValue.js +3 -3
  101. package/src/embedded-react/usePersistentState.js +6 -6
  102. package/src/embedded-react/warn-props.js +1 -1
  103. package/src/host-config.js +60 -53
  104. package/src/props.js +49 -41
  105. package/src/renderer.js +7 -4
  106. package/aot/compiler/assemble.mjs +0 -944
  107. package/aot/compiler/c/animations.mjs +0 -436
  108. package/aot/compiler/c/boot.mjs +0 -127
  109. package/aot/compiler/c/expressions.mjs +0 -270
  110. package/aot/compiler/c/functions.mjs +0 -268
  111. package/aot/compiler/c/keyboard.mjs +0 -96
  112. package/aot/compiler/c/nodes.mjs +0 -303
  113. package/aot/compiler/c/pan-responder.mjs +0 -136
  114. package/aot/compiler/c/statements.mjs +0 -319
  115. package/aot/compiler/c/text.mjs +0 -83
  116. package/aot/compiler/c/vectors.mjs +0 -381
  117. package/aot/compiler/c-syntax.mjs +0 -127
@@ -28,15 +28,15 @@ import { parseColorValue } from '../style-map.mjs';
28
28
  - Constants
29
29
  ---------------------------------------------------------------------------------------------------------------------*/
30
30
  /** The style keys an animated value drives only through an interpolation onto colors. */
31
- export const ANIM_COLOR_KEYS = new Set(['backgroundColor', 'color']);
32
- /** Style key → the ERAnimProp(s) an animated value binds to. */
33
- export const ANIM_STYLE_PROPS = {
31
+ export const ANIMATED_COLOR_KEYS = new Set(['backgroundColor', 'color']);
32
+ /** Style key → the ERAnimationProp(s) an animated value binds to. */
33
+ export const ANIMATED_STYLE_PROPS = {
34
34
  opacity: ['ER_PROP_OPACITY'],
35
35
  backgroundColor: ['ER_PROP_BACKGROUND_COLOR'],
36
36
  color: ['ER_PROP_COLOR'],
37
37
  };
38
- /** Transform key → the ERAnimProp(s) an animated value binds to. */
39
- export const ANIM_TRANSFORM_PROPS = {
38
+ /** Transform key → the ERAnimationProp(s) an animated value binds to. */
39
+ export const ANIMATED_TRANSFORM_PROPS = {
40
40
  scale: ['ER_PROP_SCALE_X', 'ER_PROP_SCALE_Y'],
41
41
  scaleX: ['ER_PROP_SCALE_X'],
42
42
  scaleY: ['ER_PROP_SCALE_Y'],
@@ -45,7 +45,7 @@ export const ANIM_TRANSFORM_PROPS = {
45
45
  rotate: ['ER_PROP_ROTATE_Z'],
46
46
  rotateZ: ['ER_PROP_ROTATE_Z'],
47
47
  };
48
- const ANIM_KINDS = new Set([
48
+ const ANIMATION_KINDS = new Set([
49
49
  'timing',
50
50
  'spring',
51
51
  'decay',
@@ -55,130 +55,138 @@ const ANIM_KINDS = new Set([
55
55
  'delay',
56
56
  'loop',
57
57
  ]);
58
+ // What an Animated config's field is when the app leaves it out, as React Native has it.
59
+ const DEFAULT_TIMING_DURATION_MS = 250;
60
+ const DEFAULT_SPRING_STIFFNESS = 200;
61
+ const DEFAULT_SPRING_DAMPING = 18;
62
+ const DEFAULT_DECAY_DECELERATION = 0.998;
63
+ /** The numbers Easing.bezier takes: x1, y1, x2, y2. */
64
+ const BEZIER_CONTROL_POINTS = 4;
58
65
  /*----------------------------------------------------------------------------------------------------------------------
59
66
  - Implementation
60
67
  ---------------------------------------------------------------------------------------------------------------------*/
61
68
  /**
62
- * Collects `const x = useAnimatedValue(initial)` → Map (name → {cVar, initial}). `prefix` namespaces the
63
- * C var (`s_av_<prefix><name>`) so each inlined child instance gets its own engine value handle.
69
+ * Collects `const x = useAnimatedValue(initial)` → Map (name → {slotName, initial}). `prefix` namespaces the
70
+ * handle (`anim_<prefix><name>`) so each inlined child instance gets its own engine value handle.
64
71
  *
65
- * @param fnBody The component's body.
72
+ * @param functionBody The component's body.
66
73
  * @param scope Compile-time constants the initial values fold against.
67
- * @param prefix The C name prefix: none for the App, `c<n>_` for an inlined instance.
74
+ * @param prefix The name prefix: none for the App, `c<n>_` for an inlined instance.
68
75
  *
69
76
  * @returns The animated values, by name.
70
77
  */
71
- export function collectAnims(fnBody, scope, prefix = '') {
78
+ export function collectAnims(functionBody, scope, prefix = '') {
72
79
  // Collect animated value records by their JS binding name.
73
- const anims = new Map();
80
+ const animations = new Map();
74
81
  // Only block-bodied functions can contain hook declarations to collect.
75
- if (fnBody.type !== 'BlockStatement')
76
- return anims;
82
+ if (functionBody.type !== 'BlockStatement')
83
+ return animations;
77
84
  // Scan top-level declarations in the function body for useAnimatedValue hooks to allocate animated slots.
78
- for (const stmt of fnBody.body) {
85
+ for (const statement of functionBody.body) {
79
86
  // Only variable declarations can introduce bindings we need to inspect.
80
- if (stmt.type !== 'VariableDeclaration')
87
+ if (statement.type !== 'VariableDeclaration')
81
88
  continue;
82
89
  // Collect useAnimatedValue declarations and register their engine-side animated slots.
83
- for (const decl of stmt.declarations) {
84
- const init = decl.init;
85
- if (init?.type === 'CallExpression' &&
86
- init.callee.name === 'useAnimatedValue' &&
87
- decl.id.type === 'Identifier') {
88
- const initVal = init.arguments[0]
89
- ? evalStaticOrThrow(init.arguments[0], scope, `AOT: the initial value of useAnimatedValue "${decl.id.name}" must be a compile-time constant`, 'give it a finite starting number: useAnimatedValue(0).')
90
+ for (const declarator of statement.declarations) {
91
+ const initializer = declarator.init;
92
+ if (initializer?.type === 'CallExpression' &&
93
+ initializer.callee.name === 'useAnimatedValue' &&
94
+ declarator.id.type === 'Identifier') {
95
+ const initialValue = initializer.arguments[0]
96
+ ? evalStaticOrThrow(initializer.arguments[0], scope, `AOT: the initial value of useAnimatedValue "${declarator.id.name}" must be a compile-time constant`, 'give it a finite starting number: useAnimatedValue(0).')
90
97
  : 0;
91
- // An animated value is a float slot; null or a non-finite number would reach C as `NaNf`.
98
+ // An animated value is a float slot, which null or a non-finite number doesn't fit.
92
99
  // Refuse here, at the declaration, with its location.
93
- if (typeof initVal !== 'number' || !Number.isFinite(initVal)) {
94
- const e = aotError(`AOT: the initial value of useAnimatedValue "${decl.id.name}" is ${initVal === undefined ? 'undefined' : String(initVal)}`, 'give it a finite starting number: useAnimatedValue(0).');
95
- if (init.arguments[0]?.loc) {
96
- e.aotLoc = init.arguments[0].loc.start;
100
+ if (typeof initialValue !== 'number' ||
101
+ !Number.isFinite(initialValue)) {
102
+ const error = aotError(`AOT: the initial value of useAnimatedValue "${declarator.id.name}" is ${initialValue === undefined ? 'undefined' : String(initialValue)}`, 'give it a finite starting number: useAnimatedValue(0).');
103
+ if (initializer.arguments[0]?.loc) {
104
+ error.aotLoc = initializer.arguments[0].loc.start;
97
105
  }
98
- throw e;
106
+ throw error;
99
107
  }
100
- checkNumber(initVal);
101
- anims.set(decl.id.name, {
102
- cVar: `s_av_${prefix}${decl.id.name}`,
103
- initial: initVal,
108
+ checkNumber(initialValue);
109
+ animations.set(declarator.id.name, {
110
+ slotName: `anim_${prefix}${declarator.id.name}`,
111
+ initial: initialValue,
104
112
  });
105
113
  }
106
114
  }
107
115
  }
108
- return anims;
116
+ return animations;
109
117
  }
110
118
  /**
111
- * Collects `const r = useRef(initial)` refs → Map (name → {cVar, cType, initial, kind}). Two kinds:
112
- * - VALUE ref (numeric initial): a mutable C slot (escape-hatch state that does NOT re-render;
119
+ * Collects `const r = useRef(initial)` refs → Map (name → {slotName, slotKind, initial, kind}). Two kinds:
120
+ * - VALUE ref (numeric initial): a mutable slot (escape-hatch state that does NOT re-render;
113
121
  * `.current` reads/writes).
114
- * - NODE ref (`useRef()` / `useRef(null)`): holds an `ERNode*`, captured by `ref={r}` on an element and
122
+ * - NODE ref (`useRef()` / `useRef(null)`): holds an node handle, captured by `ref={r}` on an element and
115
123
  * used as the target of imperative calls like updateVector(r, …). kind === 'node'.
116
124
  *
117
- * @param fnBody The component's body.
125
+ * @param functionBody The component's body.
118
126
  * @param scope Compile-time constants the initial values fold against.
119
- * @param prefix The C name prefix: none for the App, `c<n>_` for an inlined instance.
127
+ * @param prefix The name prefix: none for the App, `c<n>_` for an inlined instance.
120
128
  * @param wide Slots to declare 64-bit (see compileWidened).
121
129
  *
122
130
  * @returns The refs, by name.
123
131
  */
124
- export function collectRefs(fnBody, scope, prefix = '', wide = NO_WIDE) {
132
+ export function collectRefs(functionBody, scope, prefix = '', wide = NO_WIDE) {
125
133
  // Collect ref records by their JS binding name.
126
134
  const refs = new Map();
127
135
  // Only block-bodied functions can contain ref declarations to collect.
128
- if (fnBody.type !== 'BlockStatement')
136
+ if (functionBody.type !== 'BlockStatement')
129
137
  return refs;
130
138
  // Collect useRef declarations, splitting null/empty node refs from numeric value refs.
131
- for (const stmt of fnBody.body) {
139
+ for (const statement of functionBody.body) {
132
140
  // Only variable declarations can introduce bindings we need to inspect.
133
- if (stmt.type !== 'VariableDeclaration')
141
+ if (statement.type !== 'VariableDeclaration')
134
142
  continue;
135
143
  // Find useRef bindings and lower each supported initializer to either a node ref or value ref record.
136
- for (const decl of stmt.declarations) {
137
- const init = decl.init;
138
- if (init?.type === 'CallExpression' &&
139
- init.callee.name === 'useRef' &&
140
- decl.id.type === 'Identifier') {
141
- const arg = init.arguments[0];
144
+ for (const declarator of statement.declarations) {
145
+ const initializer = declarator.init;
146
+ if (initializer?.type === 'CallExpression' &&
147
+ initializer.callee.name === 'useRef' &&
148
+ declarator.id.type === 'Identifier') {
149
+ const argument = initializer.arguments[0];
142
150
  // A PanResponder ref — collectPanResponders owns it
143
- if (isPanCreate(arg))
151
+ if (isPanCreate(argument))
144
152
  continue;
145
153
  // Empty or null useRef values are node refs, initialized to no bound ERNode.
146
- const cVar = `s_ref_${prefix}${decl.id.name}`;
147
- if (!arg || arg.type === 'NullLiteral') {
148
- refs.set(decl.id.name, {
149
- cVar,
150
- cType: 'ERNode*',
154
+ const slotName = `ref_${prefix}${declarator.id.name}`;
155
+ if (!argument || argument.type === 'NullLiteral') {
156
+ refs.set(declarator.id.name, {
157
+ slotName,
158
+ slotKind: 'node',
151
159
  kind: 'node',
152
160
  used: false,
153
161
  });
154
162
  continue;
155
163
  }
156
164
  // Value refs must start from a finite compile-time number.
157
- const value = evalStaticOrThrow(arg, scope, `AOT: useRef initial for "${decl.id.name}" must be a number (value ref) or null/empty (node ref)`, 'a value ref needs a compile-time number: useRef(0).');
165
+ const value = evalStaticOrThrow(argument, scope, `AOT: useRef initial for "${declarator.id.name}" must be a number (value ref) or null/empty (node ref)`, 'a value ref needs a compile-time number: useRef(0).');
158
166
  if (typeof value !== 'number' || !Number.isFinite(value)) {
159
- const error = aotError(`AOT: useRef initial for "${decl.id.name}" must be a number (value ref) or null/empty (node ref)`, `got ${value === undefined ? 'undefined' : String(value)}.`);
160
- if (arg.loc) {
161
- error.aotLoc = arg.loc.start;
167
+ const error = aotError(`AOT: useRef initial for "${declarator.id.name}" must be a number (value ref) or null/empty (node ref)`, `got ${value === undefined ? 'undefined' : String(value)}.`);
168
+ if (argument.loc) {
169
+ error.aotLoc = argument.loc.start;
162
170
  }
163
171
  throw error;
164
172
  }
165
173
  // A ref a timestamp or a number past the int range is written to hold 64 bits (see compileWidened).
166
174
  const initialWidth = wideInitial(value);
167
175
  const widened = Number.isInteger(value) && initialWidth !== 'float'
168
- ? (wide.get(cVar) ??
176
+ ? (wide.get(slotName) ??
169
177
  (initialWidth === 'number' ? 'number' : undefined))
170
178
  : undefined;
171
- const cType = !Number.isInteger(value) || initialWidth === 'float'
179
+ const slotKind = !Number.isInteger(value) || initialWidth === 'float'
172
180
  ? 'float'
173
181
  : widened
174
182
  ? 'i64'
175
183
  : 'int';
176
- if (cType === 'float') {
184
+ if (slotKind === 'float') {
177
185
  checkNumber(value);
178
186
  }
179
- refs.set(decl.id.name, {
180
- cVar,
181
- cType,
187
+ refs.set(declarator.id.name, {
188
+ slotName,
189
+ slotKind,
182
190
  initial: value,
183
191
  kind: 'value',
184
192
  used: false,
@@ -212,11 +220,11 @@ function easingFamily(node) {
212
220
  * Easing.bezier(x1,y1,x2,y2). No easing → ER_EASE_EASE_IN_OUT (RN's timing default); unknown → same.
213
221
  *
214
222
  * @param node The `easing:` expression, if there is one.
215
- * @param env The expression environment for folding bezier control points.
223
+ * @param environment The expression environment for folding bezier control points.
216
224
  *
217
225
  * @returns The engine easing, and its control points when it is a bezier.
218
226
  */
219
- function easingInfo(node, env) {
227
+ function easingInfo(node, environment) {
220
228
  // Use React Native's timing default whenever no easing is supplied (or the expression is unsupported).
221
229
  const FALLBACK = { ease: 'ER_EASE_EASE_IN_OUT', bezier: null };
222
230
  if (!node)
@@ -241,22 +249,24 @@ function easingInfo(node, env) {
241
249
  if (node.type === 'CallExpression' &&
242
250
  node.callee.type === 'MemberExpression' &&
243
251
  node.callee.object?.name === 'Easing') {
244
- const fn = node.callee.property.name;
245
- if (fn === 'bezier') {
246
- const cps = node.arguments
247
- .slice(0, 4)
248
- .map(a => Number(evalStaticOr(a, env, 0)));
249
- return cps.length === 4
250
- ? { ease: 'ER_EASE_BEZIER', bezier: cps }
252
+ const easing = node.callee.property.name;
253
+ if (easing === 'bezier') {
254
+ const controlPoints = node.arguments
255
+ .slice(0, BEZIER_CONTROL_POINTS)
256
+ .map(argument => Number(evalStaticOr(argument, environment, 0)));
257
+ return controlPoints.length === BEZIER_CONTROL_POINTS
258
+ ? { ease: 'ER_EASE_BEZIER', bezier: controlPoints }
251
259
  : FALLBACK;
252
260
  }
253
- if (fn === 'elastic') {
261
+ if (easing === 'elastic') {
254
262
  return { ease: 'ER_EASE_ELASTIC_OUT', bezier: null };
255
263
  }
256
- if (fn === 'in' || fn === 'out' || fn === 'inOut') {
257
- const fam = easingFamily(node.arguments[0]);
258
- const dir = fn === 'in' ? 'IN' : fn === 'out' ? 'OUT' : 'IN_OUT';
259
- return fam ? { ease: `ER_EASE_${fam}_${dir}`, bezier: null } : FALLBACK;
264
+ if (easing === 'in' || easing === 'out' || easing === 'inOut') {
265
+ const family = easingFamily(node.arguments[0]);
266
+ const direction = easing === 'in' ? 'IN' : easing === 'out' ? 'OUT' : 'IN_OUT';
267
+ return family
268
+ ? { ease: `ER_EASE_${family}_${direction}`, bezier: null }
269
+ : FALLBACK;
260
270
  }
261
271
  }
262
272
  return FALLBACK;
@@ -265,42 +275,42 @@ function easingInfo(node, env) {
265
275
  * Parses a `.interpolate({ inputRange, outputRange, extrapolate })` config object → a static
266
276
  * { input, output, exLeft, exRight } descriptor (ranges must be static, equal-length, 2..8 points).
267
277
  *
268
- * @param cfgNode The config argument.
269
- * @param env The expression environment.
278
+ * @param configNode The config argument.
279
+ * @param environment The expression environment.
270
280
  *
271
281
  * @returns The folded interpolation.
272
282
  */
273
- export function parseInterp(cfgNode, env) {
274
- // Interpolation ranges must be known at compile time so the generated C can bake the breakpoints directly.
275
- if (cfgNode?.type !== 'ObjectExpression') {
283
+ export function parseInterp(configNode, environment) {
284
+ // Interpolation ranges must be known at compile time so the package can bake the breakpoints directly.
285
+ if (configNode?.type !== 'ObjectExpression') {
276
286
  throw aotError('AOT: .interpolate() needs a config object literal { inputRange, outputRange }');
277
287
  }
278
288
  // Read a named property from the interpolation config, accepting both identifier and string-literal keys.
279
- const get = (key) => cfgNode.properties.find(property => (property.key.name ??
289
+ const get = (key) => configNode.properties.find(property => (property.key.name ??
280
290
  property.key.value) === key)?.value;
281
291
  // Fold an interpolation range into its breakpoints; ranges must be array literals for AOT emission.
282
292
  const arr = (node, name) => {
283
293
  if (node?.type !== 'ArrayExpression') {
284
294
  throw aotError(`AOT: .interpolate() ${name} must be an array literal`);
285
295
  }
286
- return node.elements.map(e => evalStatic(e, env.consts ?? {}));
296
+ return node.elements.map(element => evalStatic(element, environment.constants ?? {}));
287
297
  };
288
298
  // inputRange and outputRange define the piecewise mapping and must line up point-for-point. An
289
299
  // outputRange of strings maps onto colors.
290
300
  const input = arr(get('inputRange'), 'inputRange').map(Number);
291
301
  const outputValues = arr(get('outputRange'), 'outputRange');
292
302
  // Colors parse as strictly as a static style color, so a typo is an error rather than black.
293
- const colors = outputValues.every(v => typeof v === 'string')
294
- ? outputValues.map(v => {
303
+ const colors = outputValues.every(value => typeof value === 'string')
304
+ ? outputValues.map(color => {
295
305
  try {
296
- return parseColorValue(v);
306
+ return parseColorValue(color);
297
307
  }
298
308
  catch (error) {
299
309
  throw aotError(`AOT: .interpolate() outputRange has an ${error.message}`);
300
310
  }
301
311
  })
302
312
  : undefined;
303
- if (!colors && outputValues.some(v => typeof v !== 'number')) {
313
+ if (!colors && outputValues.some(value => typeof value !== 'number')) {
304
314
  throw aotError('AOT: .interpolate() outputRange must be all numbers or all colors');
305
315
  }
306
316
  const output = colors ? [] : outputValues;
@@ -311,7 +321,7 @@ export function parseInterp(cfgNode, env) {
311
321
  // Convert RN extrapolation strings to engine enum names, defaulting to extend like React Native.
312
322
  const ex = (node) => {
313
323
  const extrapolateMode = node
314
- ? String(evalStaticOr(node, env, 'extend'))
324
+ ? String(evalStaticOr(node, environment, 'extend'))
315
325
  : 'extend';
316
326
  return extrapolateMode === 'clamp'
317
327
  ? 'ER_EXTRAPOLATE_CLAMP'
@@ -325,23 +335,23 @@ export function parseInterp(cfgNode, env) {
325
335
  input,
326
336
  output,
327
337
  ...(colors && { colors }),
328
- exLeft: ex(get('extrapolateLeft') ?? both),
329
- exRight: ex(get('extrapolateRight') ?? both),
338
+ extrapolateLeft: ex(get('extrapolateLeft') ?? both),
339
+ extrapolateRight: ex(get('extrapolateRight') ?? both),
330
340
  };
331
341
  }
332
342
  /**
333
343
  * Builds a `get(key)` accessor over an `Animated.*(value, config)` call's config object literal.
334
344
  *
335
- * @param cfgObj The config argument, if there is one.
345
+ * @param configObject The config argument, if there is one.
336
346
  *
337
347
  * @returns The accessor; it reads undefined for every key when there is no config.
338
348
  */
339
- function animConfigGetter(cfgObj) {
340
- return key => cfgObj?.properties?.find(property => (property.key.name ??
349
+ function animConfigGetter(configObject) {
350
+ return key => configObject?.properties?.find(property => (property.key.name ??
341
351
  property.key.value) === key)?.value;
342
352
  }
343
353
  /**
344
- * A folded config number that will be printed as a float, checked now so a value with no C form is reported
354
+ * A folded config number that will be printed as a float, checked now so a value a float can't hold is reported
345
355
  * where the animation is lowered.
346
356
  *
347
357
  * @param rawValue The folded value.
@@ -353,17 +363,17 @@ function configFloat(rawValue) {
353
363
  return Number(rawValue);
354
364
  }
355
365
  /**
356
- * A folded config time in whole milliseconds, checked so a time C cannot hold is reported at the field.
366
+ * A folded config time in whole milliseconds, checked so a time too long to hold is reported at the field.
357
367
  *
358
368
  * @param node The field's value, if the app wrote one.
359
- * @param env The expression environment.
369
+ * @param environment The expression environment.
360
370
  * @param defaultValue The time when the field is left out or not known at build time.
361
371
  * @param field What the time is, for the error.
362
372
  *
363
373
  * @returns The time.
364
374
  */
365
- function configMs(node, env, defaultValue, field) {
366
- const rawValue = evalStaticOr(node, env, defaultValue);
375
+ function configMs(node, environment, defaultValue, field) {
376
+ const rawValue = evalStaticOr(node, environment, defaultValue);
367
377
  check({ kind: 'milliseconds', field, value: rawValue }, node?.loc?.start);
368
378
  return Math.round(Number(rawValue));
369
379
  }
@@ -371,21 +381,21 @@ function configMs(node, env, defaultValue, field) {
371
381
  * A timing's folded duration (250 ms when it is left out, as in React Native).
372
382
  *
373
383
  * @param get The timing's config.
374
- * @param env The expression environment.
384
+ * @param environment The expression environment.
375
385
  *
376
386
  * @returns The duration.
377
387
  */
378
- const timingDuration = (get, env) => configMs(get('duration'), env, 250, `Animated.timing's "duration"`);
388
+ const timingDuration = (get, environment) => configMs(get('duration'), environment, DEFAULT_TIMING_DURATION_MS, `Animated.timing's "duration"`);
379
389
  /**
380
390
  * An animation's own delay (0 when it is left out).
381
391
  *
382
392
  * @param kind timing, spring or decay.
383
393
  * @param get The animation's config.
384
- * @param env The expression environment.
394
+ * @param environment The expression environment.
385
395
  *
386
396
  * @returns The delay.
387
397
  */
388
- const ownDelayMs = (kind, get, env) => configMs(get('delay'), env, 0, `Animated.${kind}'s "delay"`);
398
+ const ownDelayMs = (kind, get, environment) => configMs(get('delay'), environment, 0, `Animated.${kind}'s "delay"`);
389
399
  /**
390
400
  * A time added up from a composition's times, checked like them: each fits an int, but a sum of them need not.
391
401
  *
@@ -402,32 +412,32 @@ function totalMs(value) {
402
412
  * offsets are realized) and `loop` repeats a timing on the engine's own loop.
403
413
  *
404
414
  * @param entry The animation.
405
- * @param env The expression environment.
415
+ * @param environment The expression environment.
406
416
  *
407
417
  * @returns The animation.
408
418
  */
409
- function lowerAnimation(entry, env) {
410
- const { cVar, kind, get, delayMs, loop } = entry;
419
+ function lowerAnimation(entry, environment) {
420
+ const { slotName, kind, get, delayMs, loop } = entry;
411
421
  // Fold the curve's fields, using RN-like defaults when the app leaves one out.
412
422
  let curve;
413
423
  if (kind === 'spring') {
414
424
  curve = {
415
425
  kind: 'spring',
416
- stiffness: configFloat(evalStaticOr(get('stiffness'), env, 200)),
417
- damping: configFloat(evalStaticOr(get('damping'), env, 18)),
418
- mass: configFloat(evalStaticOr(get('mass'), env, 1)),
426
+ stiffness: configFloat(evalStaticOr(get('stiffness'), environment, DEFAULT_SPRING_STIFFNESS)),
427
+ damping: configFloat(evalStaticOr(get('damping'), environment, DEFAULT_SPRING_DAMPING)),
428
+ mass: configFloat(evalStaticOr(get('mass'), environment, 1)),
419
429
  };
420
430
  }
421
431
  else if (kind === 'decay') {
422
432
  curve = {
423
433
  kind: 'decay',
424
- deceleration: configFloat(evalStaticOr(get('deceleration'), env, 0.998)),
425
- velocity: configFloat(evalStaticOr(get('velocity'), env, 0)),
434
+ deceleration: configFloat(evalStaticOr(get('deceleration'), environment, DEFAULT_DECAY_DECELERATION)),
435
+ velocity: configFloat(evalStaticOr(get('velocity'), environment, 0)),
426
436
  };
427
437
  }
428
438
  else {
429
- const durationMs = timingDuration(get, env);
430
- const { ease, bezier } = easingInfo(get('easing'), env);
439
+ const durationMs = timingDuration(get, environment);
440
+ const { ease, bezier } = easingInfo(get('easing'), environment);
431
441
  curve = {
432
442
  kind: 'timing',
433
443
  durationMs,
@@ -441,9 +451,9 @@ function lowerAnimation(entry, env) {
441
451
  throw aotError(`AOT: Animated.${kind}() config needs a toValue`);
442
452
  }
443
453
  return {
444
- handle: cVar,
454
+ handle: slotName,
445
455
  curve,
446
- to: toNode ? lowerExpr(toNode, env) : null,
456
+ to: toNode ? lowerExpr(toNode, environment) : null,
447
457
  delayMs: totalMs(delayMs),
448
458
  isLooping: loop,
449
459
  };
@@ -456,32 +466,33 @@ function lowerAnimation(entry, env) {
456
466
  * null = unknown (spring/decay/loop), which is illegal to sequence anything after.
457
467
  *
458
468
  * @param node The composition.
459
- * @param env The expression environment.
469
+ * @param environment The expression environment.
460
470
  * @param baseDelay When the composition starts, in ms.
461
471
  * @param loop The composition repeats forever (inside an Animated.loop).
462
472
  *
463
473
  * @returns Its atomic entries and its run length.
464
474
  */
465
- function flattenAnim(node, env, baseDelay, loop) {
475
+ function flattenAnim(node, environment, baseDelay, loop) {
466
476
  // Resolve a named animation handle, then require one of the supported Animated.* calls.
467
- node = resolveAnim(node, env);
477
+ node = resolveAnim(node, environment);
468
478
  if (!isAnimatedCall(node)) {
469
479
  throw aotError('AOT: an animation must be Animated.timing/spring/decay/sequence/parallel/stagger/delay/loop(...)');
470
480
  }
471
481
  // Atomic animations drive one useAnimatedValue directly; timing has a known length, spring/decay do not.
472
482
  const kind = node.callee.property.name;
473
- const args = node.arguments;
483
+ const callArguments = node.arguments;
474
484
  if (kind === 'timing' || kind === 'spring' || kind === 'decay') {
475
- const valRef = args[0];
476
- if (valRef?.type !== 'Identifier' || !env.animations?.has(valRef.name)) {
485
+ const valueRef = callArguments[0];
486
+ if (valueRef?.type !== 'Identifier' ||
487
+ !environment.animations?.has(valueRef.name)) {
477
488
  throw aotError(`AOT: Animated.${kind}() first argument must be a useAnimatedValue`);
478
489
  }
479
- const cVar = env.animations.get(valRef.name).cVar;
480
- const get = animConfigGetter(args[1]);
481
- const ownDelay = ownDelayMs(kind, get, env);
482
- const duration = kind === 'timing' ? ownDelay + timingDuration(get, env) : null;
490
+ const slotName = environment.animations.get(valueRef.name).slotName;
491
+ const get = animConfigGetter(callArguments[1]);
492
+ const ownDelay = ownDelayMs(kind, get, environment);
493
+ const duration = kind === 'timing' ? ownDelay + timingDuration(get, environment) : null;
483
494
  return {
484
- entries: [{ cVar, kind, get, delayMs: baseDelay + ownDelay, loop }],
495
+ entries: [{ slotName, kind, get, delayMs: baseDelay + ownDelay, loop }],
485
496
  duration,
486
497
  };
487
498
  }
@@ -489,65 +500,65 @@ function flattenAnim(node, env, baseDelay, loop) {
489
500
  if (kind === 'delay') {
490
501
  return {
491
502
  entries: [],
492
- duration: configMs(args[0], env, 0, "Animated.delay's time"),
503
+ duration: configMs(callArguments[0], environment, 0, "Animated.delay's time"),
493
504
  };
494
505
  }
495
506
  // Composition nodes flatten into atomic animations with absolute delay_ms offsets.
496
507
  if (kind === 'sequence' || kind === 'parallel' || kind === 'stagger') {
497
- const list = kind === 'stagger' ? args[1] : args[0];
508
+ const list = kind === 'stagger' ? callArguments[1] : callArguments[0];
498
509
  const staggerMs = kind === 'stagger'
499
- ? configMs(args[0], env, 0, "Animated.stagger's interval")
510
+ ? configMs(callArguments[0], environment, 0, "Animated.stagger's interval")
500
511
  : 0;
501
512
  if (list?.type !== 'ArrayExpression') {
502
513
  throw aotError(`AOT: Animated.${kind}(...) needs an array of animations`);
503
514
  }
504
515
  // Sequence advances its running offset; parallel/stagger start children from the same base with offsets.
505
516
  const entries = [];
506
- let off = baseDelay; // running offset (sequence)
507
- let groupDur = 0; // max end-time relative to baseDelay (parallel/stagger)
517
+ let offset = baseDelay; // running offset (sequence)
518
+ let groupDuration = 0; // max end-time relative to baseDelay (parallel/stagger)
508
519
  let index = 0;
509
520
  for (const child of list.elements) {
510
521
  if (!child)
511
522
  continue;
512
- const start = kind === 'sequence' ? off : baseDelay + index * staggerMs;
513
- const flatAnim = flattenAnim(child, env, start, loop);
514
- entries.push(...flatAnim.entries);
523
+ const start = kind === 'sequence' ? offset : baseDelay + index * staggerMs;
524
+ const flatAnimation = flattenAnim(child, environment, start, loop);
525
+ entries.push(...flatAnimation.entries);
515
526
  if (kind === 'sequence') {
516
- if (flatAnim.duration == null) {
527
+ if (flatAnimation.duration == null) {
517
528
  throw aotError('AOT: an Animated.sequence entry needs a known duration — use Animated.timing / Animated.delay (a spring/decay/loop inside a sequence is not supported; it has no fixed length to offset the next entry by)');
518
529
  }
519
- off += flatAnim.duration;
530
+ offset += flatAnimation.duration;
520
531
  }
521
532
  else {
522
- const end = start - baseDelay + (flatAnim.duration ?? 0);
523
- if (end > groupDur) {
524
- groupDur = end;
533
+ const end = start - baseDelay + (flatAnimation.duration ?? 0);
534
+ if (end > groupDuration) {
535
+ groupDuration = end;
525
536
  }
526
537
  }
527
538
  index++;
528
539
  }
529
- // The same value can't appear twice in a flat (delay_ms) composition: er_anim_value_animate cancels the
540
+ // The same value can't appear twice in a flat (delay_ms) composition: er_animation_value_animate cancels the
530
541
  // running anim on a value, so concurrent/flat-sequenced same-value steps cancel each other. (A
531
542
  // top-level Animated.sequence is handled separately via on_complete chaining, which does support this.)
532
543
  const seen = new Set();
533
544
  for (const entry of entries) {
534
- if (seen.has(entry.cVar)) {
545
+ if (seen.has(entry.slotName)) {
535
546
  throw aotError('AOT: the same animated value is driven more than once in this composition — concurrent/flat same-value steps cancel each other. Use a top-level Animated.sequence(...) for multi-step animation of one value.');
536
547
  }
537
- seen.add(entry.cVar);
548
+ seen.add(entry.slotName);
538
549
  }
539
550
  return {
540
551
  entries,
541
- duration: kind === 'sequence' ? off - baseDelay : groupDur,
552
+ duration: kind === 'sequence' ? offset - baseDelay : groupDuration,
542
553
  };
543
554
  }
544
555
  // A nested loop can flatten only when it wraps a single atomic animation; complex loops need start-time chaining.
545
556
  if (kind === 'loop') {
546
- const flatAnim = flattenAnim(args[0], env, baseDelay, true);
547
- if (flatAnim.entries.length !== 1) {
557
+ const flatAnimation = flattenAnim(callArguments[0], environment, baseDelay, true);
558
+ if (flatAnimation.entries.length !== 1) {
548
559
  throw aotError('AOT: an Animated.loop inside another composition can only wrap a single Animated.timing/spring/decay', 'a loop around a sequence works when the loop is the animation you start: Animated.loop(Animated.sequence([...])).start().');
549
560
  }
550
- return { entries: flatAnim.entries, duration: null };
561
+ return { entries: flatAnimation.entries, duration: null };
551
562
  }
552
563
  throw aotError(`AOT: Animated.${kind}(...) is not a supported animation`);
553
564
  }
@@ -561,39 +572,40 @@ function flattenAnim(node, env, baseDelay, loop) {
561
572
  export const isAnimatedCall = (node) => node?.type === 'CallExpression' &&
562
573
  node.callee.type === 'MemberExpression' &&
563
574
  node.callee.object?.name === 'Animated' &&
564
- ANIM_KINDS.has(node.callee.property?.name);
575
+ ANIMATION_KINDS.has(node.callee.property?.name);
565
576
  /**
566
577
  * An animation handle (`anim` after `const anim = Animated.loop(…)`) resolved to the call it names.
567
578
  *
568
579
  * @param node An animation, or a handler local bound to one.
569
- * @param env The expression environment.
580
+ * @param environment The expression environment.
570
581
  *
571
582
  * @returns The animation the node stands for.
572
583
  */
573
- export const resolveAnim = (node, env) => node?.type === 'Identifier' && env.animLocals?.has(node.name)
574
- ? env.animLocals.get(node.name)
584
+ export const resolveAnim = (node, environment) => node?.type === 'Identifier' && environment.animationLocals?.has(node.name)
585
+ ? environment.animationLocals.get(node.name)
575
586
  : node;
576
587
  /**
577
588
  * One Animated.timing/spring/decay call as a chain step, started `extraDelay` ms later than its own delay.
578
589
  *
579
590
  * @param node The call.
580
- * @param env The expression environment.
591
+ * @param environment The expression environment.
581
592
  * @param extraDelay Milliseconds added to its own delay.
582
593
  *
583
594
  * @returns The step.
584
595
  */
585
- function animStep(node, env, extraDelay) {
596
+ function animStep(node, environment, extraDelay) {
586
597
  const kind = node.callee.property.name;
587
598
  // A chain step must drive one collected useAnimatedValue.
588
- const valRef = node.arguments[0];
589
- if (valRef?.type !== 'Identifier' || !env.animations?.has(valRef.name)) {
599
+ const valueRef = node.arguments[0];
600
+ if (valueRef?.type !== 'Identifier' ||
601
+ !environment.animations?.has(valueRef.name)) {
590
602
  throw aotError(`AOT: Animated.${kind}() first argument must be a useAnimatedValue`);
591
603
  }
592
604
  // Fold this step's own delay and add any delay inherited from an enclosing sequence/delay.
593
605
  const get = animConfigGetter(node.arguments[1]);
594
- const ownDelay = ownDelayMs(kind, get, env);
606
+ const ownDelay = ownDelayMs(kind, get, environment);
595
607
  return {
596
- cVar: env.animations.get(valRef.name).cVar,
608
+ slotName: environment.animations.get(valueRef.name).slotName,
597
609
  kind,
598
610
  get,
599
611
  delayMs: extraDelay + ownDelay,
@@ -601,35 +613,35 @@ function animStep(node, env, extraDelay) {
601
613
  };
602
614
  }
603
615
  /**
604
- * The C handle of every value an animation drives.
616
+ * The handle of every value an animation drives.
605
617
  *
606
618
  * @param node The animation.
607
- * @param env The expression environment.
619
+ * @param environment The expression environment.
608
620
  * @param accumulator Collects the handles.
609
621
  *
610
622
  * @returns `accumulator`.
611
623
  */
612
- export function animValues(node, env, accumulator = new Set()) {
613
- node = resolveAnim(node, env);
624
+ export function animValues(node, environment, accumulator = new Set()) {
625
+ node = resolveAnim(node, environment);
614
626
  // Reject props that the FlatList-to-ScrollView rewrite cannot preserve.
615
627
  if (!isAnimatedCall(node)) {
616
628
  throw aotError('AOT: an animation must be Animated.timing/spring/decay/sequence/parallel/stagger/delay/loop(...)');
617
629
  }
618
630
  // Recurse into composed animations, skipping delay nodes because they drive no animated value.
619
631
  const kind = node.callee.property.name;
620
- const args = node.arguments;
632
+ const callArguments = node.arguments;
621
633
  if (kind === 'timing' || kind === 'spring' || kind === 'decay') {
622
- accumulator.add(animStep(node, env, 0).cVar);
634
+ accumulator.add(animStep(node, environment, 0).slotName);
623
635
  }
624
636
  else if (kind === 'loop') {
625
- animValues(args[0], env, accumulator);
637
+ animValues(callArguments[0], environment, accumulator);
626
638
  }
627
639
  else if (kind !== 'delay') {
628
- const list = kind === 'stagger' ? args[1] : args[0];
640
+ const list = kind === 'stagger' ? callArguments[1] : callArguments[0];
629
641
  for (const child of list?.elements ??
630
642
  []) {
631
643
  if (child) {
632
- animValues(child, env, accumulator);
644
+ animValues(child, environment, accumulator);
633
645
  }
634
646
  }
635
647
  }
@@ -639,13 +651,13 @@ export function animValues(node, env, accumulator = new Set()) {
639
651
  * The steps of an `Animated.sequence([...])` for an on_complete chain. A delay() folds into the next step's
640
652
  * delay_ms; `trailingDelay` is what follows the last step. A nested parallel/stagger/loop throws.
641
653
  *
642
- * @param seqNode The sequence call.
643
- * @param env The expression environment.
654
+ * @param sequenceNode The sequence call.
655
+ * @param environment The expression environment.
644
656
  *
645
657
  * @returns The steps, and the delay after the last one.
646
658
  */
647
- function sequenceSteps(seqNode, env) {
648
- const list = seqNode.arguments[0];
659
+ function sequenceSteps(sequenceNode, environment) {
660
+ const list = sequenceNode.arguments[0];
649
661
  // Sequence composition is lowered at build time, so its children must be an array literal.
650
662
  if (list?.type !== 'ArrayExpression') {
651
663
  throw aotError('AOT: Animated.sequence(...) needs an array of animations');
@@ -656,7 +668,7 @@ function sequenceSteps(seqNode, env) {
656
668
  for (const element of list.elements) {
657
669
  if (!element)
658
670
  continue;
659
- const child = resolveAnim(element, env);
671
+ const child = resolveAnim(element, environment);
660
672
  // Reject non-animation entries in the sequence.
661
673
  if (!isAnimatedCall(child)) {
662
674
  throw aotError('AOT: Animated.sequence entries must be Animated.timing/spring/decay/delay(...)');
@@ -664,7 +676,7 @@ function sequenceSteps(seqNode, env) {
664
676
  // Fold delay-only entries into the following animation step.
665
677
  const kind = child.callee.property.name;
666
678
  if (kind === 'delay') {
667
- pendingDelay += configMs(child.arguments[0], env, 0, "Animated.delay's time");
679
+ pendingDelay += configMs(child.arguments[0], environment, 0, "Animated.delay's time");
668
680
  continue;
669
681
  }
670
682
  // Keep sequence chains flat: delay plus timing/spring/decay only.
@@ -672,14 +684,14 @@ function sequenceSteps(seqNode, env) {
672
684
  throw aotError('AOT: Animated.sequence entries must be Animated.timing/spring/decay/delay (a nested ' +
673
685
  'parallel/stagger/loop inside a sequence is not yet supported — keep the sequence flat)');
674
686
  }
675
- steps.push(animStep(child, env, pendingDelay));
687
+ steps.push(animStep(child, environment, pendingDelay));
676
688
  pendingDelay = 0;
677
689
  }
678
690
  return { steps, trailingDelay: pendingDelay };
679
691
  }
680
692
  /**
681
693
  * Lowers steps to an on_complete CHAIN: step 0 starts inline, and each step's completion callback starts the
682
- * next. Unlike the flat delay_ms path, this is correct when steps share a value — er_anim_value_animate
694
+ * next. Unlike the flat delay_ms path, this is correct when steps share a value — er_animation_value_animate
683
695
  * cancels the running anim on a value, so starting them together would cancel all but the last — and needs
684
696
  * no fixed duration. A step that is interrupted (finished == false) ends the chain, as it does in JS. The
685
697
  * chain's callbacks and loop slots are added to the output here.
@@ -688,21 +700,21 @@ function sequenceSteps(seqNode, env) {
688
700
  * put back where it started before each repeat, or null), trailingDelay (ms before each repeat)}.
689
701
  *
690
702
  * @param steps The chain's steps.
691
- * @param env The expression environment.
692
- * @param ctx The statement compiler's context.
703
+ * @param environment The expression environment.
704
+ * @param context The statement compiler's context.
693
705
  * @param completion The completion callback to run when the chain ends, if any.
694
706
  * @param loop How the chain repeats, or null for once.
695
707
  * @param trailing For a chain that runs once: the composition's key and the wait after its last step.
696
708
  *
697
709
  * @returns The chain.
698
710
  */
699
- function lowerChain(steps, env, ctx, completion, loop = null, trailing = null) {
700
- // GLOBAL: callback names are file-scope, so must be unique across handlers
701
- const id = ctx.out.seqN++;
711
+ function lowerChain(steps, environment, context, completion, loop = null, trailing = null) {
712
+ // GLOBAL: callback names must be unique across handlers
713
+ const id = context.output.sequenceCount++;
702
714
  // Lowered from the tail, the order the callbacks are emitted in.
703
715
  const lowered = new Array(steps.length);
704
716
  for (let index = steps.length - 1; index >= 0; index--) {
705
- lowered[index] = lowerAnimation(steps[index], env);
717
+ lowered[index] = lowerAnimation(steps[index], environment);
706
718
  }
707
719
  // A repeat restarts step 0 after any trailing sequence delay.
708
720
  const chain = {
@@ -713,36 +725,35 @@ function lowerChain(steps, env, ctx, completion, loop = null, trailing = null) {
713
725
  ? {
714
726
  iterations: loop.iterations,
715
727
  resetHandle: loop.resetTo,
716
- restart: lowerAnimation({ ...steps[0], delayMs: steps[0].delayMs + loop.trailingDelay }, env),
728
+ restart: lowerAnimation({ ...steps[0], delayMs: steps[0].delayMs + loop.trailingDelay }, environment),
717
729
  finalWait: loop.iterations >= 0 && completion && loop.trailingDelay > 0
718
730
  ? {
719
731
  delayMs: totalMs(loop.trailingDelay),
720
- owner: waitOwner(ctx, loop.key, true),
732
+ owner: waitOwner(context, loop.key, true),
721
733
  }
722
734
  : null,
723
735
  }
724
736
  : null,
725
737
  completion,
726
738
  completionWait: !loop && completion && trailing && trailing.delayMs > 0
727
- ? completionWait(ctx, trailing.key, trailing.delayMs, `er_seqcb_${id}_${steps.length}`)
739
+ ? completionWait(context, trailing.key, trailing.delayMs, `chain_${id}_${steps.length}`)
728
740
  : null,
729
741
  };
730
- ctx.out.animCbs.push({ kind: 'chain', chain });
731
- ctx.out.effectDecls.push({ kind: 'chain', chain });
742
+ context.output.animationCallbacks.push({ kind: 'chain', chain });
743
+ context.output.effectDeclarations.push({ kind: 'chain', chain });
732
744
  return chain;
733
745
  }
734
746
  /**
735
747
  * A start with nothing to run.
736
748
  *
737
- * @param ctx The statement compiler's context.
749
+ * @param context The statement compiler's context.
738
750
  * @param completion The completion callback, if any; it never runs.
739
751
  *
740
752
  * @returns The start.
741
753
  */
742
- const emptyStart = (ctx, completion) => ({
754
+ const emptyStart = (context, completion) => ({
743
755
  kind: 'startAnimations',
744
756
  animations: [],
745
- firstConfig: ctx.animIdx,
746
757
  completion,
747
758
  completionWait: null,
748
759
  completionJoin: null,
@@ -757,32 +768,32 @@ let nextCompositionId = 0;
757
768
  * … pulse.stop()`) reach the same node.
758
769
  *
759
770
  * @param node The composition, resolved.
760
- * @param env The expression environment.
771
+ * @param environment The expression environment.
761
772
  *
762
773
  * @returns The key.
763
774
  */
764
- function compositionKey(node, env) {
775
+ function compositionKey(node, environment) {
765
776
  let id = node ? compositionIds.get(node) : -1;
766
777
  if (id === undefined) {
767
778
  id = nextCompositionId++;
768
779
  compositionIds.set(node, id);
769
780
  }
770
- return `${env.cbPrefix ?? ''}|${id}`;
781
+ return `${environment.callbackPrefix ?? ''}|${id}`;
771
782
  }
772
783
  /**
773
784
  * The owner number completion waits of a composition carry, so a stop can end them; numbered on first use.
774
785
  *
775
- * @param ctx The statement compiler's context.
786
+ * @param context The statement compiler's context.
776
787
  * @param key The composition's key.
777
788
  * @param isStart A start is asking, so the waits are real (a stop alone leaves nothing to end).
778
789
  *
779
790
  * @returns The owner.
780
791
  */
781
- function waitOwner(ctx, key, isStart) {
782
- let record = ctx.out.animWaits.get(key);
792
+ function waitOwner(context, key, isStart) {
793
+ let record = context.output.animationWaits.get(key);
783
794
  if (!record) {
784
- record = { owner: ctx.out.animWaits.size, isStarted: false };
785
- ctx.out.animWaits.set(key, record);
795
+ record = { owner: context.output.animationWaits.size, isStarted: false };
796
+ context.output.animationWaits.set(key, record);
786
797
  }
787
798
  if (isStart) {
788
799
  record.isStarted = true;
@@ -793,25 +804,25 @@ function waitOwner(ctx, key, isStart) {
793
804
  * True when a composition has an Animated.delay anywhere, the only thing a completion can wait on.
794
805
  *
795
806
  * @param node The composition.
796
- * @param env The expression environment.
807
+ * @param environment The expression environment.
797
808
  *
798
809
  * @returns Whether it does.
799
810
  */
800
- function hasDelay(node, env) {
801
- node = resolveAnim(node, env);
811
+ function hasDelay(node, environment) {
812
+ node = resolveAnim(node, environment);
802
813
  if (!isAnimatedCall(node))
803
814
  return false;
804
815
  // Look through compositions; a timing, spring or decay waits on nothing beyond itself.
805
816
  const kind = node.callee.property.name;
806
- const args = node.arguments;
817
+ const callArguments = node.arguments;
807
818
  if (kind === 'delay')
808
819
  return true;
809
820
  if (kind === 'loop')
810
- return hasDelay(args[0], env);
821
+ return hasDelay(callArguments[0], environment);
811
822
  if (kind === 'sequence' || kind === 'parallel' || kind === 'stagger') {
812
- const list = kind === 'stagger' ? args[1] : args[0];
823
+ const list = kind === 'stagger' ? callArguments[1] : callArguments[0];
813
824
  return (list?.type === 'ArrayExpression' &&
814
- list.elements.some(child => child && hasDelay(child, env)));
825
+ list.elements.some(child => child && hasDelay(child, environment)));
815
826
  }
816
827
  return false;
817
828
  }
@@ -819,46 +830,46 @@ function hasDelay(node, env) {
819
830
  * The composition whose completion waits `anim.stop()` ends, when it has a delay to wait on.
820
831
  *
821
832
  * @param node The composition being stopped.
822
- * @param env The expression environment.
823
- * @param ctx The statement compiler's context.
833
+ * @param environment The expression environment.
834
+ * @param context The statement compiler's context.
824
835
  *
825
836
  * @returns The owner, or null.
826
837
  */
827
- export function stopWaitOwner(node, env, ctx) {
828
- const resolved = resolveAnim(node, env);
829
- return hasDelay(resolved, env)
830
- ? waitOwner(ctx, compositionKey(resolved, env), false)
838
+ export function stopWaitOwner(node, environment, context) {
839
+ const resolved = resolveAnim(node, environment);
840
+ return hasDelay(resolved, environment)
841
+ ? waitOwner(context, compositionKey(resolved, environment), false)
831
842
  : null;
832
843
  }
833
844
  /**
834
845
  * The wait between a composition's last animation finishing and its completion running.
835
846
  *
836
- * @param ctx The statement compiler's context.
847
+ * @param context The statement compiler's context.
837
848
  * @param key The composition's key.
838
849
  * @param delayMs The wait.
839
850
  * @param callback The name of the on_complete callback that starts it.
840
851
  *
841
852
  * @returns The wait.
842
853
  */
843
- const completionWait = (ctx, key, delayMs, callback) => ({
854
+ const completionWait = (context, key, delayMs, callback) => ({
844
855
  delayMs: totalMs(delayMs),
845
856
  callback,
846
- owner: waitOwner(ctx, key, true),
857
+ owner: waitOwner(context, key, true),
847
858
  });
848
859
  /**
849
860
  * A start that drives no value. As in JS, its completion still runs as finished once the composition's delays
850
861
  * have passed, counted down in a completion wait of its own.
851
862
  *
852
- * @param ctx The statement compiler's context.
863
+ * @param context The statement compiler's context.
853
864
  * @param completion The completion callback, if any.
854
865
  * @param delayMs How long the composition takes.
855
866
  * @param key The composition's key.
856
867
  *
857
868
  * @returns The start.
858
869
  */
859
- function startNothing(ctx, completion, delayMs, key) {
870
+ function startNothing(context, completion, delayMs, key) {
860
871
  if (!completion) {
861
- return emptyStart(ctx, completion);
872
+ return emptyStart(context, completion);
862
873
  }
863
874
  const start = {
864
875
  kind: 'completeAfter',
@@ -867,7 +878,7 @@ function startNothing(ctx, completion, delayMs, key) {
867
878
  owner: null,
868
879
  };
869
880
  if (delayMs > 0) {
870
- start.owner = waitOwner(ctx, key, true);
881
+ start.owner = waitOwner(context, key, true);
871
882
  }
872
883
  return start;
873
884
  }
@@ -878,23 +889,23 @@ function startNothing(ctx, completion, delayMs, key) {
878
889
  * started before each repeat (resetBeforeIteration), and a looped sequence carries on from where it ended.
879
890
  *
880
891
  * @param loopNode The `Animated.loop(…)` call.
881
- * @param env The expression environment.
882
- * @param ctx The statement compiler's context.
892
+ * @param environment The expression environment.
893
+ * @param context The statement compiler's context.
883
894
  * @param completion The completion callback to run when the loop ends, if any.
884
895
  * @param key The loop's composition key.
885
896
  *
886
897
  * @returns The start, or null when the flat path (the engine's own cfg.loop) handles it.
887
898
  */
888
- function lowerLoopStart(loopNode, env, ctx, completion, key) {
899
+ function lowerLoopStart(loopNode, environment, context, completion, key) {
889
900
  // Fold the loop count at build time; absent or noninteger iterations mean repeat forever.
890
- const inner = resolveAnim(loopNode.arguments[0], env);
901
+ const inner = resolveAnim(loopNode.arguments[0], environment);
891
902
  const kind = isAnimatedCall(inner) ? inner.callee.property.name : null;
892
903
  const get = animConfigGetter(loopNode.arguments[1]);
893
904
  let iterations = -1;
894
905
  if (get('iterations')) {
895
906
  let value;
896
907
  try {
897
- value = evalStatic(get('iterations'), foldScope(env, env.consts ?? {}));
908
+ value = evalStatic(get('iterations'), foldScope(environment, environment.constants ?? {}));
898
909
  }
899
910
  catch {
900
911
  throw aotError('AOT: Animated.loop iterations must be known at build time', 'use a number or a module-level constant.');
@@ -905,19 +916,19 @@ function lowerLoopStart(loopNode, env, ctx, completion, key) {
905
916
  : -1;
906
917
  }
907
918
  // Use the engine's native loop only for endless reset timing loops; other loop shapes need callback chaining.
908
- const reset = evalStaticOr(get('resetBeforeIteration'), env, true) !== false;
919
+ const reset = evalStaticOr(get('resetBeforeIteration'), environment, true) !== false;
909
920
  let steps;
910
921
  let trailingDelay = 0;
911
922
  let resetTo = null;
912
923
  if (kind === 'sequence') {
913
- ({ steps, trailingDelay } = sequenceSteps(inner, env));
924
+ ({ steps, trailingDelay } = sequenceSteps(inner, environment));
914
925
  }
915
926
  else if (kind === 'timing' || kind === 'spring' || kind === 'decay') {
916
927
  if (kind === 'timing' && iterations < 0 && reset)
917
928
  return null;
918
- steps = [animStep(inner, env, 0)];
929
+ steps = [animStep(inner, environment, 0)];
919
930
  if (reset) {
920
- resetTo = steps[0].cVar;
931
+ resetTo = steps[0].slotName;
921
932
  }
922
933
  }
923
934
  else {
@@ -925,23 +936,23 @@ function lowerLoopStart(loopNode, env, ctx, completion, key) {
925
936
  }
926
937
  // A zero-iteration loop starts nothing but still reports successful completion.
927
938
  if (iterations === 0) {
928
- return startNothing(ctx, completion, 0, key);
939
+ return startNothing(context, completion, 0, key);
929
940
  }
930
941
  // A loop of delays alone completes after its passes; an endless one never does.
931
942
  if (!steps.length) {
932
943
  return iterations < 0
933
- ? emptyStart(ctx, completion)
934
- : startNothing(ctx, completion, iterations * trailingDelay, key);
944
+ ? emptyStart(context, completion)
945
+ : startNothing(context, completion, iterations * trailingDelay, key);
935
946
  }
936
- // A timing with no duration and no delay completes inside er_anim_value_animate, so a loop made only of
947
+ // A timing with no duration and no delay completes inside er_animation_value_animate, so a loop made only of
937
948
  // those would restart itself forever without returning.
938
- const instant = (animEntry) => animEntry.kind === 'timing' &&
939
- animEntry.delayMs === 0 &&
940
- timingDuration(animEntry.get, env) === 0;
949
+ const instant = (animationEntry) => animationEntry.kind === 'timing' &&
950
+ animationEntry.delayMs === 0 &&
951
+ timingDuration(animationEntry.get, environment) === 0;
941
952
  if (trailingDelay === 0 && steps.every(instant)) {
942
953
  throw aotError('AOT: every step of this Animated.loop finishes instantly, so it would never stop repeating', 'give a step a duration or a delay.');
943
954
  }
944
- return lowerChain(steps, env, ctx, completion, {
955
+ return lowerChain(steps, environment, context, completion, {
945
956
  iterations,
946
957
  resetTo,
947
958
  trailingDelay,
@@ -949,47 +960,46 @@ function lowerLoopStart(loopNode, env, ctx, completion, key) {
949
960
  });
950
961
  }
951
962
  /**
952
- * Lowers a `.start(onComplete)` completion callback to a file-scope C fn (ERAnimCompleteFn) set as the
963
+ * Lowers a `.start(onComplete)` completion callback to a function (ERAnimationCompleteFn) set as the
953
964
  * animation's on_complete, and adds it to the output; its body runs setters/refs/etc. and re-applies state via
954
- * app_update if needed.
965
+ * the update if needed.
955
966
  *
956
- * @param fnNode The callback.
957
- * @param env The expression environment.
967
+ * @param functionNode The callback.
968
+ * @param environment The expression environment.
958
969
  * @param state The component's state table.
959
- * @param ctx The statement compiler's context.
970
+ * @param context The statement compiler's context.
960
971
  *
961
972
  * @returns The completion.
962
973
  */
963
- function lowerCompletion(fnNode, env, state, ctx) {
964
- // Generate a file-scope completion callback and expose start(({finished}) => ...) as a local C int.
965
- const id = ctx.out.seqN++;
966
- const name = `er_donecb_${id}`;
967
- const locals = new Map(env.locals);
968
- const param = fnNode.params[0];
969
- if (param?.type === 'ObjectPattern') {
970
- for (const property of param.properties) {
974
+ function lowerCompletion(functionNode, environment, state, context) {
975
+ // Generate a completion callback and expose start(({finished}) => ...) as a local int.
976
+ const id = context.output.sequenceCount++;
977
+ const name = `done_${id}`;
978
+ const locals = new Map(environment.locals);
979
+ const parameter = functionNode.params[0];
980
+ if (parameter?.type === 'ObjectPattern') {
981
+ for (const property of parameter.properties) {
971
982
  if ((property.key?.name ??
972
983
  property.key?.value) === 'finished') {
973
984
  locals.set(property.value?.name ?? 'finished', {
974
- code: 'finished',
975
- cType: 'int',
985
+ name: 'finished',
986
+ slotKind: 'int',
976
987
  });
977
988
  }
978
989
  }
979
990
  }
980
991
  // Lower the callback body as statements; it re-renders if it changed React state.
981
- const fnBody = fnNode.body;
982
- const list = fnBody.type === 'BlockStatement'
983
- ? fnBody.body
984
- : [{ type: 'ExpressionStatement', expression: fnBody }];
985
- const cctx = {
992
+ const functionBody = functionNode.body;
993
+ const list = functionBody.type === 'BlockStatement'
994
+ ? functionBody.body
995
+ : [{ type: 'ExpressionStatement', expression: functionBody }];
996
+ const completionContext = {
986
997
  stateChanged: false,
987
- animIdx: 0,
988
- out: ctx.out,
998
+ output: context.output,
989
999
  };
990
- const body = lowerStmts(list, { ...env, locals }, state, cctx);
991
- const completion = { name, body, updatesState: cctx.stateChanged };
992
- ctx.out.animCbs.push({ kind: 'completion', completion });
1000
+ const body = lowerStmts(list, { ...environment, locals }, state, completionContext);
1001
+ const completion = { name, body, updatesState: completionContext.stateChanged };
1002
+ context.output.animationCallbacks.push({ kind: 'completion', completion });
993
1003
  return completion;
994
1004
  }
995
1005
  /**
@@ -998,48 +1008,47 @@ function lowerCompletion(fnNode, env, state, ctx) {
998
1008
  * an on_complete chain (lowerChain); everything else flattens to one animation per atomic entry, composition
999
1009
  * expressed through per-entry delay_ms. Native-driven; sets no React state.
1000
1010
  *
1001
- * @param expr The `.start(…)` call.
1002
- * @param env The expression environment.
1011
+ * @param expression The `.start(…)` call.
1012
+ * @param environment The expression environment.
1003
1013
  * @param state The component's state table.
1004
- * @param ctx The statement compiler's context.
1014
+ * @param context The statement compiler's context.
1005
1015
  *
1006
1016
  * @returns The start.
1007
1017
  */
1008
- export function lowerAnimateStart(expr, env, state, ctx) {
1018
+ export function lowerAnimateStart(expression, environment, state, context) {
1009
1019
  // Resolve the animation being started and handle cases that need callback chaining before falling back to flat emission.
1010
- const completion = isFn(expr.arguments[0])
1011
- ? lowerCompletion(expr.arguments[0], env, state, ctx)
1020
+ const completion = isFn(expression.arguments[0])
1021
+ ? lowerCompletion(expression.arguments[0], environment, state, context)
1012
1022
  : null;
1013
- const receiver = resolveAnim(expr.callee.object, env);
1023
+ const receiver = resolveAnim(expression.callee.object, environment);
1014
1024
  const kind = isAnimatedCall(receiver) ? receiver.callee.property.name : null;
1015
- const key = compositionKey(receiver, env);
1025
+ const key = compositionKey(receiver, environment);
1016
1026
  if (kind === 'sequence') {
1017
- const { steps, trailingDelay } = sequenceSteps(receiver, env);
1027
+ const { steps, trailingDelay } = sequenceSteps(receiver, environment);
1018
1028
  return steps.length
1019
- ? lowerChain(steps, env, ctx, completion, null, {
1029
+ ? lowerChain(steps, environment, context, completion, null, {
1020
1030
  key,
1021
1031
  delayMs: trailingDelay,
1022
1032
  })
1023
- : startNothing(ctx, completion, trailingDelay, key);
1033
+ : startNothing(context, completion, trailingDelay, key);
1024
1034
  }
1025
1035
  if (kind === 'loop') {
1026
- const start = lowerLoopStart(receiver, env, ctx, completion, key);
1036
+ const start = lowerLoopStart(receiver, environment, context, completion, key);
1027
1037
  if (start)
1028
1038
  return start;
1029
1039
  }
1030
1040
  // The flat path has no "after all entries finish" join point, so completion callbacks are limited to one entry.
1031
- const { entries, duration } = flattenAnim(receiver, env, 0, false);
1041
+ const { entries, duration } = flattenAnim(receiver, environment, 0, false);
1032
1042
  if (!entries.length) {
1033
- return startNothing(ctx, completion, duration ?? 0, key);
1043
+ return startNothing(context, completion, duration ?? 0, key);
1034
1044
  }
1035
1045
  if (completion && entries.length > 1) {
1036
1046
  throw aotError('AOT: a .start(onComplete) callback on a parallel/stagger animation is not yet supported', 'attach the completion callback to a single animation or an Animated.sequence(...). For "after all parallel anims", restructure as a sequence.');
1037
1047
  }
1038
1048
  // Each entry starts on its own, numbered after the configs already in this body.
1039
- const start = emptyStart(ctx, completion);
1040
- for (const animEntry of entries) {
1041
- start.animations.push(lowerAnimation(animEntry, env));
1042
- ctx.animIdx++;
1049
+ const start = emptyStart(context, completion);
1050
+ for (const animationEntry of entries) {
1051
+ start.animations.push(lowerAnimation(animationEntry, environment));
1043
1052
  }
1044
1053
  // A spring or decay has no fixed end, so a delay beside it that runs past its start is joined at run time.
1045
1054
  const [only] = entries;
@@ -1050,15 +1059,15 @@ export function lowerAnimateStart(expr, env, state, ctx) {
1050
1059
  duration > only.delayMs) {
1051
1060
  start.completionJoin = {
1052
1061
  delayMs: totalMs(duration),
1053
- owner: waitOwner(ctx, key, true),
1062
+ owner: waitOwner(context, key, true),
1054
1063
  };
1055
1064
  }
1056
1065
  // A delay beside the one timing that outlasts it holds the completion back until the composition ends.
1057
1066
  if (completion && only.kind === 'timing' && !only.loop && duration != null) {
1058
- const end = only.delayMs + timingDuration(only.get, env);
1067
+ const end = only.delayMs + timingDuration(only.get, environment);
1059
1068
  if (duration > end) {
1060
- start.completionWait = completionWait(ctx, key, duration - end, `er_waitcb_${ctx.out.seqN++}`);
1061
- ctx.out.animCbs.push({
1069
+ start.completionWait = completionWait(context, key, duration - end, `wait_${context.output.sequenceCount++}`);
1070
+ context.output.animationCallbacks.push({
1062
1071
  kind: 'completionWait',
1063
1072
  completion,
1064
1073
  wait: start.completionWait,