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
@@ -87,7 +87,7 @@ export function lowerGestureField(field, pan) {
87
87
  return {
88
88
  kind: 'gesture',
89
89
  field: field,
90
- statePrefix: pan.cPrefix,
90
+ statePrefix: pan.statePrefix,
91
91
  stateID: pan.stateID,
92
92
  type: field === 'vx' || field === 'vy' ? FLOAT : INT,
93
93
  };
@@ -99,7 +99,7 @@ export function lowerGestureField(field, pan) {
99
99
  *
100
100
  * @param name The JS name the responder is bound to.
101
101
  * @param createCall The `PanResponder.create(…)` call.
102
- * @param prefix The C name prefix: none for the App, `c<n>_` for an inlined instance.
102
+ * @param prefix The name prefix: none for the App, `c<n>_` for an inlined instance.
103
103
  *
104
104
  * @returns The responder.
105
105
  */
@@ -133,7 +133,7 @@ function buildPanDescriptor(name, createCall, prefix) {
133
133
  throw aotError(`AOT: unknown PanResponder config key "${key}"`, `supported: ${[...Object.keys(PAN_QUERIES), ...Object.keys(PAN_EVENTS)].join(', ')}.`);
134
134
  }
135
135
  if (prop.type !== 'ObjectMethod' && !isFn(callback)) {
136
- throw aotError(`AOT: PanResponder "${key}" must be a function`, 'pass an inline arrow — `(e, g) => …` — so it can be compiled into the generated C.');
136
+ throw aotError(`AOT: PanResponder "${key}" must be a function`, 'pass an inline arrow — `(e, g) => …` — so it can be compiled.');
137
137
  }
138
138
  if (query) {
139
139
  queries.set(query, callback);
@@ -144,8 +144,8 @@ function buildPanDescriptor(name, createCall, prefix) {
144
144
  }
145
145
  return {
146
146
  name,
147
- cPrefix: `s_pan_${prefix}${name}`,
148
- fnPrefix: `er_pan_${prefix}${name}`,
147
+ statePrefix: `pan_state_${prefix}${name}`,
148
+ functionPrefix: `pan_${prefix}${name}`,
149
149
  stateID: 0, // assigned when the responder is first wired to a node
150
150
  queries,
151
151
  events,
@@ -157,49 +157,49 @@ function buildPanDescriptor(name, createCall, prefix) {
157
157
  * `useRef(…)` form (read back as `pan.current.panHandlers`) is accepted too; a bare `create(…)` is not,
158
158
  * because it would re-create the recognizer every render in Flow A and the two flows must agree.
159
159
  *
160
- * @param fnBody The component's body.
161
- * @param prefix The C name prefix: none for the App, `c<n>_` for an inlined instance.
160
+ * @param functionBody The component's body.
161
+ * @param prefix The name prefix: none for the App, `c<n>_` for an inlined instance.
162
162
  *
163
163
  * @returns The responders, by name.
164
164
  */
165
- export function collectPanResponders(fnBody, prefix = '') {
165
+ export function collectPanResponders(functionBody, prefix = '') {
166
166
  // Only the component body's own top-level declarations can hold a responder.
167
167
  const pans = new Map();
168
- if (fnBody.type !== 'BlockStatement')
168
+ if (functionBody.type !== 'BlockStatement')
169
169
  return pans;
170
- for (const statement of fnBody.body) {
170
+ for (const statement of functionBody.body) {
171
171
  if (statement.type !== 'VariableDeclaration')
172
172
  continue;
173
- for (const decl of statement.declarations) {
174
- const init = decl.init;
175
- if (decl.id.type !== 'Identifier' || !init)
173
+ for (const declarator of statement.declarations) {
174
+ const initializer = declarator.init;
175
+ if (declarator.id.type !== 'Identifier' || !initializer)
176
176
  continue;
177
177
  // Find the useRef call in either `useRef(…).current` or a bare `useRef(…)`.
178
- const viaCurrent = init.type === 'MemberExpression' &&
179
- !init.computed &&
180
- init.property.name === 'current' &&
181
- init.object.type === 'CallExpression' &&
182
- init.object.callee.name === 'useRef'
183
- ? init.object
178
+ const viaCurrent = initializer.type === 'MemberExpression' &&
179
+ !initializer.computed &&
180
+ initializer.property.name === 'current' &&
181
+ initializer.object.type === 'CallExpression' &&
182
+ initializer.object.callee.name === 'useRef'
183
+ ? initializer.object
184
184
  : null;
185
- const viaRef = init.type === 'CallExpression' &&
186
- init.callee.name === 'useRef'
187
- ? init
185
+ const viaRef = initializer.type === 'CallExpression' &&
186
+ initializer.callee.name === 'useRef'
187
+ ? initializer
188
188
  : null;
189
189
  const useRefCall = viaCurrent || viaRef;
190
190
  // Skip anything that is not a useRef around PanResponder.create(…); an unwrapped create is an error.
191
191
  if (!useRefCall || !isPanCreate(useRefCall.arguments[0])) {
192
- if (isPanCreate(init)) {
193
- throw aotError('AOT: PanResponder.create(...) must be kept in a useRef', `write \`const ${decl.id.name} = useRef(PanResponder.create({…})).current;\` — the ` +
192
+ if (isPanCreate(initializer)) {
193
+ throw aotError('AOT: PanResponder.create(...) must be kept in a useRef', `write \`const ${declarator.id.name} = useRef(PanResponder.create({…})).current;\` — the ` +
194
194
  `recognizer owns the live gesture, so a fresh one per render would throw the drag ` +
195
195
  `away (the same rule Flow A enforces).`);
196
196
  }
197
197
  continue;
198
198
  }
199
199
  // Build the responder's descriptor and record which way the app must spell its spread.
200
- const pan = buildPanDescriptor(decl.id.name, useRefCall.arguments[0], prefix);
200
+ const pan = buildPanDescriptor(declarator.id.name, useRefCall.arguments[0], prefix);
201
201
  pan.viaRefCurrent = !viaCurrent; // how the app spells the spread: pan.current.panHandlers
202
- pans.set(decl.id.name, pan);
202
+ pans.set(declarator.id.name, pan);
203
203
  }
204
204
  }
205
205
  return pans;
@@ -208,64 +208,68 @@ export function collectPanResponders(fnBody, prefix = '') {
208
208
  * Lowers a should-set predicate to a single condition: the engine calls these synchronously inside
209
209
  * hit-testing, before anyone owns the gesture, so they may only READ.
210
210
  *
211
- * @param fnNode The predicate.
212
- * @param env The expression environment.
211
+ * @param functionNode The predicate.
212
+ * @param environment The expression environment.
213
213
  * @param pan The responder it belongs to.
214
214
  *
215
215
  * @returns The condition.
216
216
  */
217
- function lowerPanQuery(fnNode, env, pan) {
217
+ function lowerPanQuery(functionNode, environment, pan) {
218
218
  // The predicate reads the event and gestureState through its own parameter names.
219
- const eventParam = fnNode.params[0]?.type === 'Identifier' ? fnNode.params[0].name : null;
220
- const gestureParam = fnNode.params[1]?.type === 'Identifier' ? fnNode.params[1].name : null;
221
- const queryEnv = { ...env, pan };
222
- if (eventParam) {
223
- queryEnv.event = eventParam;
219
+ const eventParameter = functionNode.params[0]?.type === 'Identifier'
220
+ ? functionNode.params[0].name
221
+ : null;
222
+ const gestureParameter = functionNode.params[1]?.type === 'Identifier'
223
+ ? functionNode.params[1].name
224
+ : null;
225
+ const queryEnvironment = { ...environment, pan };
226
+ if (eventParameter) {
227
+ queryEnvironment.event = eventParameter;
224
228
  }
225
- if (gestureParam) {
226
- queryEnv.gesture = gestureParam;
229
+ if (gestureParameter) {
230
+ queryEnvironment.gesture = gestureParameter;
227
231
  }
228
232
  // Its body must be one expression: an expression body, or a block that only returns one.
229
- const body = fnNode.body;
230
- const expr = body.type === 'BlockStatement'
233
+ const body = functionNode.body;
234
+ const expression = body.type === 'BlockStatement'
231
235
  ? body.body.length === 1 && body.body[0].type === 'ReturnStatement'
232
236
  ? body.body[0].argument
233
237
  : null
234
238
  : body;
235
- if (!expr) {
239
+ if (!expression) {
236
240
  throw aotError('AOT: a PanResponder should-set predicate must be a single boolean expression', 'write it as `() => true` or `(e, g) => Math.abs(g.dx) > 8`. The engine asks these ' +
237
241
  'mid-hit-test, so they may only read (state, event/gesture fields, constants) — never ' +
238
242
  'set state.');
239
243
  }
240
- return lowerExpr(expr, queryEnv);
244
+ return lowerExpr(expression, queryEnvironment);
241
245
  }
242
246
  /**
243
247
  * Lowers a PanResponder onto the engine's responder system, not a transpiled copy of it: the engine already runs
244
- * RN's state machine in C. Capture/bubble negotiation (er_responder_query_set) picks an owner, then GRANT / MOVE /
248
+ * RN's state machine in the engine. Capture/bubble negotiation (er_responder_query_set) picks an owner, then GRANT / MOVE /
245
249
  * RELEASE / TERMINATE fire on the owner alone, carrying cumulative travel and velocity. So the should-set
246
250
  * predicates become QUERIES and the callbacks become responder EVENT handlers: no gesture math is duplicated into
247
- * the generated C, and a granted pan owns the gesture, so a ScrollView ancestor cannot auto-scroll out from under
251
+ * the package, and a granted pan owns the gesture, so a ScrollView ancestor cannot auto-scroll out from under
248
252
  * it.
249
253
  *
250
254
  * The one thing with no engine counterpart is RN's anchor: `g.dx` is measured from the grant, while the engine's
251
255
  * `data->dx` runs from touch-down, so a claim that needed 10 px of slop would otherwise open with a 10 px jump.
252
- * That anchor, plus `x0`/`y0`, is a handful of file-scope ints per responder, kept by the grant, release and
256
+ * That anchor, plus `x0`/`y0`, is a handful of ints per responder, kept by the grant, release and
253
257
  * terminate handlers. Those three are ALWAYS lowered, even with no app callback; move and reject only with one.
254
258
  *
255
259
  * @param pan The responder; its gesture id must be assigned.
256
- * @param env The expression environment.
260
+ * @param environment The expression environment.
257
261
  * @param state The component's state table.
258
- * @param out Everything emitted so far.
262
+ * @param output Everything emitted so far.
259
263
  *
260
264
  * @returns The responder.
261
265
  */
262
- export function lowerPanResponder(pan, env, state, out) {
263
- const panEnv = { ...env, pan };
266
+ export function lowerPanResponder(pan, environment, state, output) {
267
+ const panEnvironment = { ...environment, pan };
264
268
  const event = (name, role) => ({
265
269
  event: name,
266
270
  role,
267
271
  callback: pan.events.has(name)
268
- ? lowerHandler(pan.events.get(name), panEnv, state, out, pan)
272
+ ? lowerHandler(pan.events.get(name), panEnvironment, state, output, pan)
269
273
  : null,
270
274
  });
271
275
  const events = [
@@ -281,13 +285,13 @@ export function lowerPanResponder(pan, env, state, out) {
281
285
  }
282
286
  return {
283
287
  name: pan.name,
284
- statePrefix: pan.cPrefix,
285
- fnPrefix: pan.fnPrefix,
288
+ statePrefix: pan.statePrefix,
289
+ functionPrefix: pan.functionPrefix,
286
290
  stateID: pan.stateID,
287
291
  events,
288
292
  queries: [...pan.queries].map(([query, predicate]) => ({
289
293
  query,
290
- test: lowerPanQuery(predicate, panEnv, pan),
294
+ test: lowerPanQuery(predicate, panEnvironment, pan),
291
295
  })),
292
296
  };
293
297
  }
@@ -296,19 +300,23 @@ export function lowerPanResponder(pan, env, state, out) {
296
300
  * handlers to the output. Each node that spreads it wires them in its own build lines.
297
301
  *
298
302
  * @param pan The responder.
299
- * @param out Everything emitted so far.
300
- * @param env The expression environment.
303
+ * @param output Everything emitted so far.
304
+ * @param environment The expression environment.
301
305
  * @param state The component's state table.
302
306
  *
303
307
  * @returns The lowered responder.
304
308
  */
305
- export function emitPanResponder(pan, out, env, state) {
309
+ export function emitPanResponder(pan, output, environment, state) {
306
310
  if (!pan.lowered) {
307
- pan.stateID = ++out.panN;
308
- pan.lowered = lowerPanResponder(pan, env, state, out);
309
- out.panResponders.push(pan.lowered);
311
+ pan.stateID = ++output.panCount;
312
+ pan.lowered = lowerPanResponder(pan, environment, state, output);
313
+ output.panResponders.push(pan.lowered);
310
314
  for (const panEvent of pan.lowered.events) {
311
- out.handlers.push({ kind: 'panEvent', pan: pan.lowered, event: panEvent });
315
+ output.handlers.push({
316
+ kind: 'panEvent',
317
+ pan: pan.lowered,
318
+ event: panEvent,
319
+ });
312
320
  }
313
321
  }
314
322
  return pan.lowered;
@@ -319,11 +327,11 @@ export function emitPanResponder(pan, out, env, state) {
319
327
  * or vice versa) is an error rather than a silent miss — Flow A would throw at runtime on the same code.
320
328
  *
321
329
  * @param argument The spread's argument.
322
- * @param env The expression environment.
330
+ * @param environment The expression environment.
323
331
  *
324
332
  * @returns The responder, or null when the spread is not `<responder>.panHandlers`.
325
333
  */
326
- export function panSpreadTarget(argument, env) {
334
+ export function panSpreadTarget(argument, environment) {
327
335
  // Only `<name>.panHandlers` or `<name>.current.panHandlers` can spread a responder.
328
336
  if (argument?.type !== 'MemberExpression' ||
329
337
  argument.computed ||
@@ -339,7 +347,7 @@ export function panSpreadTarget(argument, env) {
339
347
  ? handlersOwner.object.name
340
348
  : handlersOwner.name;
341
349
  const pan = handlersOwner.type === 'Identifier' || usesCurrent
342
- ? env.pans?.get(rootName)
350
+ ? environment.pans?.get(rootName)
343
351
  : null;
344
352
  if (!pan)
345
353
  return null;
@@ -23,7 +23,7 @@ import { isUndeclaredAttribute } from './elements/props.mjs';
23
23
  - Constants
24
24
  ---------------------------------------------------------------------------------------------------------------------*/
25
25
  // Type-only expression wrappers: `x as T`, `x satisfies T`, `x!`, `<T>x`, `f<T>` — unwrap to the inner expr.
26
- const TS_EXPR_WRAPPERS = new Set([
26
+ const TS_EXPRESSION_WRAPPERS = new Set([
27
27
  'TSAsExpression',
28
28
  'TSSatisfiesExpression',
29
29
  'TSNonNullExpression',
@@ -31,7 +31,7 @@ const TS_EXPR_WRAPPERS = new Set([
31
31
  'TSInstantiationExpression',
32
32
  ]);
33
33
  // Type-only declarations (no runtime presence) — dropped from any statement/body list.
34
- const TS_TYPE_DECLS = new Set([
34
+ const TS_TYPE_DECLARATIONS = new Set([
35
35
  'TSInterfaceDeclaration',
36
36
  'TSTypeAliasDeclaration',
37
37
  'TSDeclareFunction',
@@ -66,13 +66,13 @@ const TS_SKIP_KEYS = new Set([
66
66
  - Implementation
67
67
  ---------------------------------------------------------------------------------------------------------------------*/
68
68
  /**
69
- * Is this app a TypeScript entry? Driven by the filename extension, or an explicit opts.ts (for tests).
69
+ * Is this app a TypeScript entry? Driven by the filename extension, or an explicit options.ts (for tests).
70
70
  *
71
- * @param opts compileSource's options.
71
+ * @param options compilePackage's options.
72
72
  *
73
73
  * @returns Whether to parse the source as TypeScript.
74
74
  */
75
- const isTsEntry = (opts) => opts.ts ?? /\.[cm]?tsx$/.test(opts.filename || '');
75
+ const isTsEntry = (options) => options.ts ?? /\.[cm]?tsx$/.test(options.filename || '');
76
76
  /**
77
77
  * The Babel parser plugins for an entry.
78
78
  *
@@ -89,7 +89,7 @@ const parserPlugins = (isTypeScript) => isTypeScript ? ['jsx', 'typescript'] : [
89
89
  * @returns Whether it is type-only.
90
90
  */
91
91
  const isTypeOnly = (node) => !!node &&
92
- (TS_TYPE_DECLS.has(node.type) ||
92
+ (TS_TYPE_DECLARATIONS.has(node.type) ||
93
93
  // `import type ... ` / `export type ...`, and per-specifier `import { type X }`.
94
94
  ((node.type === 'ImportDeclaration' || node.type === 'ImportSpecifier') &&
95
95
  node.importKind === 'type') ||
@@ -104,7 +104,7 @@ const isTypeOnly = (node) => !!node &&
104
104
  * @returns The expression under every wrapper.
105
105
  */
106
106
  const unwrapTs = (node) => {
107
- while (node && TS_EXPR_WRAPPERS.has(node.type)) {
107
+ while (node && TS_EXPRESSION_WRAPPERS.has(node.type)) {
108
108
  node = node.expression;
109
109
  }
110
110
  return node;
@@ -139,7 +139,7 @@ function stripTypeScript(root) {
139
139
  for (let item of value) {
140
140
  if (isTypeOnly(item))
141
141
  continue;
142
- if (item && TS_EXPR_WRAPPERS.has(item.type)) {
142
+ if (item && TS_EXPRESSION_WRAPPERS.has(item.type)) {
143
143
  item = unwrapTs(item);
144
144
  }
145
145
  kept.push(item);
@@ -149,7 +149,7 @@ function stripTypeScript(root) {
149
149
  }
150
150
  else if (value && typeof value.type === 'string') {
151
151
  // A single child node: replace a type-only wrapper with the expression under it.
152
- if (TS_EXPR_WRAPPERS.has(value.type)) {
152
+ if (TS_EXPRESSION_WRAPPERS.has(value.type)) {
153
153
  value = unwrapTs(value);
154
154
  node[key] = value;
155
155
  }
@@ -210,10 +210,10 @@ export function normalizeUndefined(ast) {
210
210
  }
211
211
  };
212
212
  // A JSX attribute written as exactly `name={undefined}`.
213
- const isUndefinedAttr = (attr) => attr.type === 'JSXAttribute' &&
214
- attr.value?.type === 'JSXExpressionContainer' &&
215
- attr.value.expression.type === 'Identifier' &&
216
- attr.value.expression.name === 'undefined';
213
+ const isUndefinedAttr = (attribute) => attribute.type === 'JSXAttribute' &&
214
+ attribute.value?.type === 'JSXExpressionContainer' &&
215
+ attribute.value.expression.type === 'Identifier' &&
216
+ attribute.value.expression.name === 'undefined';
217
217
  // Keys that never hold child nodes.
218
218
  const SKIP = new Set([
219
219
  'loc',
@@ -259,8 +259,8 @@ export function normalizeUndefined(ast) {
259
259
  break;
260
260
  case 'JSXOpeningElement':
261
261
  // An undeclared prop stays, so the element refuses it by name whatever its value.
262
- node.attributes = node.attributes.filter((attr) => !isUndefinedAttr(attr) ||
263
- isUndeclaredAttribute(node, attr));
262
+ node.attributes = node.attributes.filter((attribute) => !isUndefinedAttr(attribute) ||
263
+ isUndeclaredAttribute(node, attribute));
264
264
  break;
265
265
  }
266
266
  // Then walk every child node.
@@ -280,16 +280,16 @@ export function normalizeUndefined(ast) {
280
280
  }
281
281
  /**
282
282
  * Parses an app entry to a JS+JSX AST, transparently stripping TypeScript when the entry is .tsx (JSX is not
283
- * allowed in a .ts file). The strip is faithful: an App.tsx compiles to the same C as its untyped App.jsx twin.
283
+ * allowed in a .ts file). The strip is faithful: an App.tsx compiles to the same package as its untyped App.jsx twin.
284
284
  *
285
- * @param src The entry's source.
286
- * @param opts compileSource's options: its filename (or `ts`) decides whether it is TypeScript.
285
+ * @param source The entry's source.
286
+ * @param options compilePackage's options: its filename (or `ts`) decides whether it is TypeScript.
287
287
  *
288
288
  * @returns The parsed file.
289
289
  */
290
- export function parseApp(src, opts = {}) {
291
- const isTypeScript = isTsEntry(opts);
292
- const ast = parse(src, {
290
+ export function parseApp(source, options = {}) {
291
+ const isTypeScript = isTsEntry(options);
292
+ const ast = parse(source, {
293
293
  sourceType: 'module',
294
294
  plugins: parserPlugins(isTypeScript),
295
295
  });
@@ -61,7 +61,7 @@ export function evalStaticOrThrow(node, scope, message, hint) {
61
61
  /**
62
62
  * Folds an expression to the value JS would give it when every name it reads is a compile-time constant.
63
63
  * Styles and state initial values fold through here. A caller that can also handle a runtime value catches
64
- * the error thrown on anything dynamic (a state reference, say) and emits C instead.
64
+ * the error thrown on anything dynamic (a state reference, say) and lowers it instead.
65
65
  *
66
66
  * A value derived from the panel size (see BootValue) folds by `mode`: `fold` takes what it is on the build's
67
67
  * panel and records that as an assumption the panel at boot must meet; `boot` keeps it as a boot value, which
@@ -328,22 +328,24 @@ function evaluate(node, scope, fold) {
328
328
  return evaluate(node.arguments[0], scope, fold);
329
329
  }
330
330
  // Math.min / max / floor / ceil / round / trunc / abs fold as JS works them out; others are dynamic.
331
- const mathFn = callee.type === 'MemberExpression' &&
331
+ const mathFunction = callee.type === 'MemberExpression' &&
332
332
  !callee.computed &&
333
333
  callee.object.type === 'Identifier' &&
334
334
  callee.object.name === 'Math' &&
335
335
  !hasBinding(scope, 'Math')
336
336
  ? callee.property.name
337
337
  : null;
338
- if (mathFn && Object.hasOwn(STATIC_MATH, mathFn)) {
339
- const args = node.arguments.map(arg => {
340
- if (arg.type === 'SpreadElement') {
338
+ if (mathFunction && Object.hasOwn(STATIC_MATH, mathFunction)) {
339
+ const argumentValues = node.arguments.map(argument => {
340
+ if (argument.type === 'SpreadElement') {
341
341
  throw new Error('AOT: cannot statically evaluate a spread');
342
342
  }
343
- return evaluate(arg, scope, fold);
343
+ return evaluate(argument, scope, fold);
344
344
  });
345
- const result = STATIC_MATH[mathFn](...args.map(buildValueOf));
346
- return args.some(isBoot) ? bootOf(node, result, fold) : result;
345
+ const result = STATIC_MATH[mathFunction](...argumentValues.map(buildValueOf));
346
+ return argumentValues.some(isBoot)
347
+ ? bootOf(node, result, fold)
348
+ : result;
347
349
  }
348
350
  throw new Error(`AOT: cannot statically evaluate call expression`);
349
351
  }
@@ -391,29 +393,29 @@ function binary(operator, left, right) {
391
393
  throw new Error('AOT: unsupported expression "BinaryExpression" in static context');
392
394
  }
393
395
  /**
394
- * `scope` minus every name `env` binds at RUNTIME — locals, state, refs, animated values, and the event /
395
- * gesture params of the handler being compiled. emitExpr resolves those before env.consts, so a fold
396
+ * `scope` minus every name `environment` binds at RUNTIME — locals, state, refs, animated values, and the event /
397
+ * gesture params of the handler being compiled. lowerExpr resolves those before environment.constants, so a fold
396
398
  * that consulted the raw scope would silently swap a module const in for the value the code actually
397
399
  * uses. Every env-driven constant fold goes through this; the JSX-side folds keep the same rule by
398
400
  * deleting a name from their scope copy when they bind it (see emitComponent / emitDynamicMap).
399
401
  *
400
- * @param env The expression environment.
402
+ * @param environment The expression environment.
401
403
  * @param scope The constants a fold would otherwise see.
402
404
  *
403
405
  * @returns `scope` itself when nothing shadows it, else a copy without the shadowed names.
404
406
  */
405
- export function foldScope(env, scope) {
407
+ export function foldScope(environment, scope) {
406
408
  const runtimeNames = new Set([
407
- ...(env.locals?.keys() ?? []),
408
- ...(env.state?.keys() ?? []),
409
- ...(env.refs?.keys() ?? []),
410
- ...(env.animations?.keys() ?? []),
409
+ ...(environment.locals?.keys() ?? []),
410
+ ...(environment.state?.keys() ?? []),
411
+ ...(environment.refs?.keys() ?? []),
412
+ ...(environment.animations?.keys() ?? []),
411
413
  ]);
412
- if (env.event) {
413
- runtimeNames.add(env.event);
414
+ if (environment.event) {
415
+ runtimeNames.add(environment.event);
414
416
  }
415
- if (env.gesture) {
416
- runtimeNames.add(env.gesture);
417
+ if (environment.gesture) {
418
+ runtimeNames.add(environment.gesture);
417
419
  }
418
420
  // Copy the scope only when a runtime name actually shadows one of its constants.
419
421
  let hasShadowedName = false;
@@ -469,16 +471,16 @@ export const withUndefined = (scope) => Object.assign(Object.create(scope), { un
469
471
  * evalStatic with a fallback default when the node is absent or not foldable.
470
472
  *
471
473
  * @param node The expression, if there is one.
472
- * @param env The expression environment; its constants are what the fold sees.
474
+ * @param environment The expression environment; its constants are what the fold sees.
473
475
  * @param defaultValue The value to use when the node is absent or does not fold.
474
476
  *
475
477
  * @returns The folded value, or `defaultValue`.
476
478
  */
477
- export function evalStaticOr(node, env, defaultValue) {
479
+ export function evalStaticOr(node, environment, defaultValue) {
478
480
  if (!node)
479
481
  return defaultValue;
480
482
  try {
481
- return evalStatic(node, foldScope(env, env.consts ?? {}));
483
+ return evalStatic(node, foldScope(environment, environment.constants ?? {}));
482
484
  }
483
485
  catch {
484
486
  return defaultValue;