embedded-react 0.19.0 → 0.21.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 (148) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +8 -3
  3. package/aot/app-file-loader.mjs +116 -0
  4. package/aot/compile.mjs +180 -90
  5. package/aot/compiler/animations.mjs +568 -317
  6. package/aot/compiler/boot.mjs +97 -35
  7. package/aot/compiler/branch-merge.mjs +4 -3
  8. package/aot/compiler/check.mjs +70 -18
  9. package/aot/compiler/collect.mjs +787 -288
  10. package/aot/compiler/contexts.mjs +391 -0
  11. package/aot/compiler/control-flow.mjs +439 -268
  12. package/aot/compiler/custom-hooks.mjs +686 -0
  13. package/aot/compiler/diagnostics.mjs +22 -25
  14. package/aot/compiler/elements/activity-indicator.mjs +25 -24
  15. package/aot/compiler/elements/button.mjs +182 -0
  16. package/aot/compiler/elements/dial.mjs +91 -77
  17. package/aot/compiler/elements/flat-list.mjs +24 -22
  18. package/aot/compiler/elements/image-background.mjs +76 -0
  19. package/aot/compiler/elements/image.mjs +52 -50
  20. package/aot/compiler/elements/modal.mjs +31 -30
  21. package/aot/compiler/elements/props.mjs +61 -26
  22. package/aot/compiler/elements/rewrite.mjs +118 -0
  23. package/aot/compiler/elements/section-list.mjs +370 -0
  24. package/aot/compiler/elements/switch.mjs +42 -34
  25. package/aot/compiler/elements/text-input.mjs +34 -32
  26. package/aot/compiler/expressions.mjs +1685 -392
  27. package/aot/compiler/handlers.mjs +2029 -547
  28. package/aot/compiler/helper-values.mjs +312 -0
  29. package/aot/compiler/ir/functions.mjs +11 -1
  30. package/aot/compiler/ir/nodes.mjs +43 -4
  31. package/aot/compiler/ir/reads.mjs +223 -22
  32. package/aot/compiler/ir/text.mjs +5 -1
  33. package/aot/compiler/ir/types.mjs +26 -14
  34. package/aot/compiler/ir/vectors.mjs +5 -1
  35. package/aot/compiler/kept-states.mjs +177 -0
  36. package/aot/compiler/keyboard.mjs +17 -7
  37. package/aot/compiler/list-items.mjs +226 -0
  38. package/aot/compiler/list-order.mjs +586 -0
  39. package/aot/compiler/list-split.mjs +259 -0
  40. package/aot/compiler/loops.mjs +582 -0
  41. package/aot/compiler/lower.mjs +246 -111
  42. package/aot/compiler/native-files.mjs +439 -0
  43. package/aot/compiler/native-header.mjs +335 -0
  44. package/aot/compiler/native-modules.mjs +1173 -0
  45. package/aot/compiler/nodes.mjs +195 -172
  46. package/aot/compiler/options.mjs +37 -31
  47. package/aot/compiler/out.mjs +32 -23
  48. package/aot/compiler/package/animations.mjs +779 -0
  49. package/aot/compiler/package/arena.mjs +252 -0
  50. package/aot/compiler/package/assemble.mjs +175 -0
  51. package/aot/compiler/package/bytecode.mjs +315 -0
  52. package/aot/compiler/package/checks.mjs +1026 -0
  53. package/aot/compiler/package/codegen.mjs +2168 -0
  54. package/aot/compiler/package/enums.mjs +148 -0
  55. package/aot/compiler/package/format.mjs +771 -0
  56. package/aot/compiler/package/layouts.mjs +136 -0
  57. package/aot/compiler/package/lower.mjs +2103 -0
  58. package/aot/compiler/package/props.mjs +118 -0
  59. package/aot/compiler/package/string-caps.mjs +515 -0
  60. package/aot/compiler/package/tables.mjs +127 -0
  61. package/aot/compiler/package/vectors.mjs +502 -0
  62. package/aot/compiler/package/writer.mjs +686 -0
  63. package/aot/compiler/pan-responder.mjs +69 -61
  64. package/aot/compiler/parse.mjs +23 -21
  65. package/aot/compiler/record-shapes.mjs +246 -0
  66. package/aot/compiler/records.mjs +654 -0
  67. package/aot/compiler/reducers.mjs +272 -0
  68. package/aot/compiler/static-eval.mjs +340 -30
  69. package/aot/compiler/style-text.mjs +178 -174
  70. package/aot/compiler/svg.mjs +480 -251
  71. package/aot/compiler/switch-cases.mjs +198 -0
  72. package/aot/compiler/tagged-records.mjs +450 -0
  73. package/aot/compiler/typing.mjs +307 -0
  74. package/aot/compiler/updaters.mjs +320 -0
  75. package/aot/compiler/window-dimensions.mjs +94 -0
  76. package/aot/compiler/worked-values.mjs +319 -0
  77. package/aot/demo-file.mjs +30 -0
  78. package/aot/screenshot-smoke.mjs +54 -40
  79. package/aot/style-map.mjs +152 -92
  80. package/assets/bake-font.mjs +123 -77
  81. package/assets/bake-image.mjs +39 -22
  82. package/assets/bake-svg.mjs +361 -262
  83. package/assets/build-builtin-font.mjs +11 -7
  84. package/assets/emit-c.mjs +77 -58
  85. package/assets/emit-container.mjs +123 -37
  86. package/assets/emit-pack.mjs +77 -67
  87. package/assets/font-config.mjs +9 -6
  88. package/assets/font-sizes.mjs +163 -123
  89. package/assets/glyph-coverage.mjs +74 -54
  90. package/assets/index.mjs +31 -9
  91. package/assets/rasterize.mjs +126 -99
  92. package/assets/svg-loader.mjs +8 -8
  93. package/build.mjs +23 -13
  94. package/cli.mjs +402 -172
  95. package/compile-bin.mjs +3 -3
  96. package/flash.mjs +537 -0
  97. package/hotreload/dev-device.mjs +90 -33
  98. package/hotreload/pack-app.mjs +55 -43
  99. package/hotreload/pack-split.mjs +62 -64
  100. package/hotreload/package-transfer.mjs +175 -0
  101. package/hotreload/protocol.mjs +50 -37
  102. package/hotreload/uploader.mjs +38 -27
  103. package/hotreload/watch-tree.mjs +19 -19
  104. package/pack-container.mjs +37 -21
  105. package/package.json +7 -8
  106. package/persist-transform.mjs +34 -28
  107. package/qjsc-wasm.mjs +25 -14
  108. package/sim/embedded-react.cjs +1 -1
  109. package/sim/embedded-react.js +1 -1
  110. package/sim/embedded-react.wasm +0 -0
  111. package/sim/index.html +94 -85
  112. package/sim-server.mjs +113 -94
  113. package/src/embedded-react/Animated.js +24 -24
  114. package/src/embedded-react/Dimensions.js +37 -0
  115. package/src/embedded-react/Easing.js +1 -1
  116. package/src/embedded-react/FlatList.js +3 -3
  117. package/src/embedded-react/LayoutAnimation.js +8 -5
  118. package/src/embedded-react/PanResponder.js +75 -71
  119. package/src/embedded-react/Pressable.js +2 -8
  120. package/src/embedded-react/SectionList.js +7 -9
  121. package/src/embedded-react/StyleSheet.js +4 -3
  122. package/src/embedded-react/TouchableOpacity.js +13 -8
  123. package/src/embedded-react/index.d.ts +88 -8
  124. package/src/embedded-react/index.js +2 -0
  125. package/src/embedded-react/layout-anim-config.js +10 -4
  126. package/src/embedded-react/list-child.js +5 -5
  127. package/src/embedded-react/named-colors.js +1 -1
  128. package/src/embedded-react/nativeModule.js +462 -0
  129. package/src/embedded-react/split-style.js +11 -11
  130. package/src/embedded-react/svg-ops.js +760 -593
  131. package/src/embedded-react/useHostValue.js +3 -3
  132. package/src/embedded-react/usePersistentState.js +6 -6
  133. package/src/embedded-react/warn-props.js +1 -1
  134. package/src/host-config.js +60 -53
  135. package/src/props.js +49 -41
  136. package/src/renderer.js +7 -4
  137. package/aot/compiler/assemble.mjs +0 -944
  138. package/aot/compiler/c/animations.mjs +0 -436
  139. package/aot/compiler/c/boot.mjs +0 -127
  140. package/aot/compiler/c/expressions.mjs +0 -270
  141. package/aot/compiler/c/functions.mjs +0 -268
  142. package/aot/compiler/c/keyboard.mjs +0 -96
  143. package/aot/compiler/c/nodes.mjs +0 -303
  144. package/aot/compiler/c/pan-responder.mjs +0 -136
  145. package/aot/compiler/c/statements.mjs +0 -319
  146. package/aot/compiler/c/text.mjs +0 -83
  147. package/aot/compiler/c/vectors.mjs +0 -381
  148. package/aot/compiler/c-syntax.mjs +0 -127
@@ -16,11 +16,12 @@
16
16
  /*----------------------------------------------------------------------------------------------------------------------
17
17
  - Imports
18
18
  ---------------------------------------------------------------------------------------------------------------------*/
19
+ import { shapeOf } from '../typing.mjs';
19
20
  import { aotError } from '../diagnostics.mjs';
20
21
  import { at } from './props.mjs';
21
22
  import { evalStatic, evalStaticOr } from '../static-eval.mjs';
22
23
  import { lowerExpr } from '../expressions.mjs';
23
- import { attrExpr, argbLiteral } from '../style-text.mjs';
24
+ import { attrExpr, argbValue } from '../style-text.mjs';
24
25
  /*----------------------------------------------------------------------------------------------------------------------
25
26
  - Constants
26
27
  ---------------------------------------------------------------------------------------------------------------------*/
@@ -40,18 +41,18 @@ const RESIZE_MODES = {
40
41
  * the const scope as their asset-name string, so this folds `wxSun`, `item.icon` (unrolled map), and static
41
42
  * ternaries; `{ uri }` is the explicit remote-shape escape.
42
43
  *
43
- * @param expr The source expression, if there is one.
44
- * @param env The expression environment.
44
+ * @param expression The source expression, if there is one.
45
+ * @param environment The expression environment.
45
46
  *
46
47
  * @returns The asset's name, or null when the source does not fold.
47
48
  */
48
- export function imageNameFromSource(expr, env) {
49
+ export function imageNameFromSource(expression, environment) {
49
50
  // No source expression was provided.
50
- if (!expr)
51
+ if (!expression)
51
52
  return null;
52
53
  // Try to resolve the source as a compile-time constant.
53
54
  try {
54
- const value = evalStatic(expr, env.consts ?? {});
55
+ const value = evalStatic(expression, environment.constants ?? {});
55
56
  if (typeof value === 'string')
56
57
  return value;
57
58
  }
@@ -59,8 +60,8 @@ export function imageNameFromSource(expr, env) {
59
60
  /* not a compile-time constant — fall through to {uri}, else dynamic */
60
61
  }
61
62
  // Handle React Native-style object sources: source={{ uri: 'asset_name' }}.
62
- if (expr.type === 'ObjectExpression') {
63
- const uri = expr.properties.find((property) => property.type === 'ObjectProperty' &&
63
+ if (expression.type === 'ObjectExpression') {
64
+ const uri = expression.properties.find((property) => property.type === 'ObjectProperty' &&
64
65
  (property.key.name === 'uri' ||
65
66
  property.key.value === 'uri'));
66
67
  if (uri?.value?.type === 'StringLiteral')
@@ -70,82 +71,83 @@ export function imageNameFromSource(expr, env) {
70
71
  }
71
72
  /**
72
73
  * Resolves an <Image>'s source/imageName/resizeMode/tintColor for the node props (static name, a dynamic
73
- * name expr, resize mode, tint). Records baking intent in `out`: a static name that matches an import is
74
- * marked used (out.images); a dynamic source flips out.bakeAllImages (its asset can't be enumerated). So
74
+ * name expr, resize mode, tint). Records baking intent in `output`: a static name that matches an import is
75
+ * marked used (output.images); a dynamic source flips output.bakeAllImages (its asset can't be enumerated). So
75
76
  * only REACHED images are baked — an import used solely in a folded-away branch costs no flash.
76
77
  *
77
78
  * @param element The <Image>.
78
- * @param env The expression environment.
79
- * @param out Everything emitted so far.
79
+ * @param environment The expression environment.
80
+ * @param output Everything emitted so far.
80
81
  *
81
82
  * @returns The resolved props.
82
83
  */
83
- export function resolveImageAttrs(element, env, out) {
84
+ export function resolveImageAttrs(element, environment, output) {
84
85
  // Find the image source prop, preferring imageName over source.
85
- const attrs = element.openingElement.attributes;
86
- const find = (attrName) => attrs.find((attr) => attr.type === 'JSXAttribute' && attr.name.name === attrName);
87
- const imAttr = find('imageName');
88
- const srcAttr = find('source');
89
- const srcExpr = imAttr
90
- ? attrExpr(imAttr)
91
- : srcAttr
92
- ? attrExpr(srcAttr)
86
+ const attributes = element.openingElement.attributes;
87
+ const find = (attributeName) => attributes.find((attribute) => attribute.type === 'JSXAttribute' &&
88
+ attribute.name.name === attributeName);
89
+ const imageAttribute = find('imageName');
90
+ const sourceAttribute = find('source');
91
+ const sourceExpression = imageAttribute
92
+ ? attrExpr(imageAttribute)
93
+ : sourceAttribute
94
+ ? attrExpr(sourceAttribute)
93
95
  : null;
94
96
  let imageName = null; // static asset name (a literal), OR …
95
- let imageNameDyn = null; // … a runtime string (a list-item field / state) set in app_update.
97
+ let imageNameDynamic = null; // … a runtime string (a list-item field / state) set in the update.
96
98
  // Resolve static sources immediately and mark imported assets for baking.
97
- if (srcExpr) {
98
- imageName = imageNameFromSource(srcExpr, env);
99
+ if (sourceExpression) {
100
+ imageName = imageNameFromSource(sourceExpression, environment);
99
101
  if (imageName != null) {
100
- const path = env.imageNames?.get(imageName); // a baked import (vs. a bare {uri} name the app supplies)
102
+ const path = environment.imageNames?.get(imageName); // a baked import (vs. a bare {uri} name the app supplies)
101
103
  if (path) {
102
- out.images.set(imageName, path);
104
+ output.images.set(imageName, path);
103
105
  }
104
106
  }
105
107
  else {
106
108
  // Fall back to a dynamic runtime image name when the source cannot be folded.
107
109
  // Emits it as a runtime string. The engine resolves it against the image registry by name each frame,
108
- // so the candidate assets must be baked. They can't be enumerated, so bake them ALL (out.bakeAllImages).
110
+ // so the candidate assets must be baked. They can't be enumerated, so bake them ALL (output.bakeAllImages).
109
111
  // Only triggered when a dynamic source is actually REACHED.
110
- out.bakeAllImages = true;
111
- const nameExpr = lowerExpr(srcExpr, env);
112
- if (nameExpr.type.kind !== 'string') {
113
- const err = aotError('AOT: an <Image source> must resolve to an asset NAME (a string)', "use an imported image (`import logo from './logo.png'` → source={logo}), " +
112
+ output.bakeAllImages = true;
113
+ const nameExpression = lowerExpr(sourceExpression, environment);
114
+ if (shapeOf(nameExpression) !== 'string') {
115
+ const error = aotError('AOT: an <Image source> must resolve to an asset NAME (a string)', "use an imported image (`import logo from './logo.png'` → source={logo}), " +
114
116
  "a string asset name, source={{ uri: 'name' }}, or a string-valued " +
115
117
  'state / list-item field for a dynamic source.');
116
- if (srcExpr.loc) {
117
- err.aotLoc = srcExpr.loc.start;
118
+ if (sourceExpression.loc) {
119
+ error.aotLoc = sourceExpression.loc.start;
118
120
  }
119
121
  {
120
- throw err;
122
+ throw error;
121
123
  }
122
124
  }
123
- imageNameDyn = nameExpr;
125
+ imageNameDynamic = nameExpression;
124
126
  }
125
127
  }
126
128
  // Resolve the optional resize mode and validate it against the supported engine modes.
127
129
  let resizeMode = null;
128
- const rmAttr = find('resizeMode');
129
- if (rmAttr) {
130
- const rm = evalStaticOr(attrExpr(rmAttr), env, null);
131
- resizeMode = RESIZE_MODES[rm];
130
+ const resizeModeAttribute = find('resizeMode');
131
+ if (resizeModeAttribute) {
132
+ const resizeModeValue = evalStaticOr(attrExpr(resizeModeAttribute), environment, null);
133
+ resizeMode = RESIZE_MODES[resizeModeValue];
132
134
  if (!resizeMode) {
133
- const e = aotError(`AOT: unsupported <Image resizeMode> "${rm}"`, `resizeMode must be one of: ${Object.keys(RESIZE_MODES).join(' / ')}.`);
134
- if (rmAttr.loc) {
135
- e.aotLoc = rmAttr.loc.start;
135
+ const error = aotError(`AOT: unsupported <Image resizeMode> "${resizeModeValue}"`, `resizeMode must be one of: ${Object.keys(RESIZE_MODES).join(' / ')}.`);
136
+ if (resizeModeAttribute.loc) {
137
+ error.aotLoc = resizeModeAttribute.loc.start;
136
138
  }
137
- throw e;
139
+ throw error;
138
140
  }
139
141
  }
140
142
  // Resolve the optional tint color into the ARGB literal expected by the engine.
141
143
  let tintColor = null;
142
- const tcAttr = find('tintColor');
143
- if (tcAttr) {
144
- const tc = evalStaticOr(attrExpr(tcAttr), env, null);
145
- if (typeof tc !== 'string' && typeof tc !== 'number') {
146
- throw at(aotError('AOT: <Image tintColor> must be a constant color', 'the tint is baked into the node when it is built; a state-driven one is not lowered yet.'), tcAttr);
144
+ const tintColorAttribute = find('tintColor');
145
+ if (tintColorAttribute) {
146
+ const tintValue = evalStaticOr(attrExpr(tintColorAttribute), environment, null);
147
+ if (typeof tintValue !== 'string' && typeof tintValue !== 'number') {
148
+ throw at(aotError('AOT: <Image tintColor> must be a constant color', 'the tint is baked into the node when it is built; a state-driven one is not lowered yet.'), tintColorAttribute);
147
149
  }
148
- tintColor = argbLiteral(tc);
150
+ tintColor = argbValue(tintValue);
149
151
  }
150
- return { imageName, imageNameDyn, resizeMode, tintColor };
152
+ return { imageName, imageNameDynamic, resizeMode, tintColor };
151
153
  }
@@ -16,8 +16,8 @@
16
16
  /*----------------------------------------------------------------------------------------------------------------------
17
17
  - Imports
18
18
  ---------------------------------------------------------------------------------------------------------------------*/
19
- import { colorLiteral } from '../../style-map.mjs';
20
- import { aotError } from '../diagnostics.mjs';
19
+ import { parseColorValue } from '../../style-map.mjs';
20
+ import { aotError, currentLoc } from '../diagnostics.mjs';
21
21
  import { evalStatic } from '../static-eval.mjs';
22
22
  import { lowerExpr } from '../expressions.mjs';
23
23
  import { attrExpr, styleWrites, collectStyleAssigns } from '../style-text.mjs';
@@ -30,13 +30,13 @@ import { at, elementSpec } from './props.mjs';
30
30
  // Overlay defaults: absolute, fill the parent via four 0 insets (the robust "stretch" for an absolute
31
31
  // node), center the content. The user's style overrides any of these.
32
32
  const DEFAULTS = [
33
- ['position', 'ER_POS_ABSOLUTE'],
34
- ['left', '0'],
35
- ['top', '0'],
36
- ['right', '0'],
37
- ['bottom', '0'],
38
- ['align_items', 'ER_ALIGN_CENTER'],
39
- ['justify_content', 'ER_JUSTIFY_CENTER'],
33
+ { field: 'position', value: 'ER_POSITION_ABSOLUTE' },
34
+ { field: 'left', value: 0 },
35
+ { field: 'top', value: 0 },
36
+ { field: 'right', value: 0 },
37
+ { field: 'bottom', value: 0 },
38
+ { field: 'align_items', value: 'ER_ALIGN_CENTER' },
39
+ { field: 'justify_content', value: 'ER_JUSTIFY_CENTER' },
40
40
  ];
41
41
  /*----------------------------------------------------------------------------------------------------------------------
42
42
  - Implementation
@@ -50,45 +50,45 @@ const DEFAULTS = [
50
50
  *
51
51
  * @param element The <Modal>.
52
52
  * @param scope Compile-time constants in reach.
53
- * @param out Everything emitted so far.
54
- * @param env The expression environment.
53
+ * @param output Everything emitted so far.
54
+ * @param environment The expression environment.
55
55
  * @param state The component's state table.
56
56
  *
57
57
  * @returns The node's variable.
58
58
  */
59
- export function emitModal(element, scope, out, env, state) {
59
+ export function emitModal(element, scope, output, environment, state) {
60
60
  // get node id
61
- const nodeId = `n${out.allocateNodeId()}`;
61
+ const nodeId = `n${output.allocateNodeId()}`;
62
62
  // collect style assignments
63
- const { staticAssigns, dynAssigns, binds } = collectStyleAssigns(element.openingElement, scope, env, elementSpec('Modal'));
64
- const hasField = (f) => styleWrites(staticAssigns, dynAssigns, f);
63
+ const { staticAssigns, dynamicAssigns, binds } = collectStyleAssigns(element.openingElement, scope, environment, elementSpec('Modal'));
64
+ const hasField = (field) => styleWrites(staticAssigns, dynamicAssigns, field);
65
65
  // Apply modal overlay defaults only for fields the user's style has not already set.
66
- for (const [field, expr] of DEFAULTS) {
67
- if (!hasField(field)) {
68
- staticAssigns.push({ field: field, expr });
66
+ for (const assign of DEFAULTS) {
67
+ if (!hasField(assign.field)) {
68
+ staticAssigns.push({ ...assign });
69
69
  }
70
70
  }
71
71
  // process element attributes
72
72
  let visibleNode = null;
73
- for (const attr of element.openingElement.attributes) {
73
+ for (const attribute of element.openingElement.attributes) {
74
74
  // Ensure all props are explicit named attributes.
75
75
  // Spread props cannot be analyzed statically
76
- if (attr.type !== 'JSXAttribute') {
76
+ if (attribute.type !== 'JSXAttribute') {
77
77
  throw aotError('AOT: spread props on <Modal> are not supported');
78
78
  }
79
79
  // skip non-props
80
- const name = attr.name.name;
80
+ const name = attribute.name.name;
81
81
  if (name === 'style' || name === 'ref' || name === 'key')
82
82
  continue;
83
83
  // process props
84
- const node = attrExpr(attr);
84
+ const node = attrExpr(attribute);
85
85
  if (name === 'visible') {
86
86
  visibleNode = node;
87
87
  }
88
88
  else if (name === 'backdropColor') {
89
89
  staticAssigns.push({
90
90
  field: 'backdrop_color',
91
- expr: colorLiteral(String(evalStatic(node, scope))),
91
+ value: parseColorValue(String(evalStatic(node, scope))),
92
92
  });
93
93
  }
94
94
  else if (name === 'animationType') {
@@ -101,7 +101,7 @@ export function emitModal(element, scope, out, env, state) {
101
101
  /* state-driven: refused below */
102
102
  }
103
103
  if (animationType !== 'none') {
104
- throw at(aotError(`AOT: <Modal animationType> ${typeof animationType === 'string' ? `"${animationType}"` : 'from state'} is not supported`, 'the engine shows and hides a Modal at once; use animationType="none", or drop the prop.'), attr);
104
+ throw at(aotError(`AOT: <Modal animationType> ${typeof animationType === 'string' ? `"${animationType}"` : 'from state'} is not supported`, 'the engine shows and hides a Modal at once; use animationType="none", or drop the prop.'), attribute);
105
105
  }
106
106
  }
107
107
  else if (name === 'onRequestClose' || name === 'statusBarTranslucent') {
@@ -118,15 +118,15 @@ export function emitModal(element, scope, out, env, state) {
118
118
  try {
119
119
  staticAssigns.push({
120
120
  field: 'modal_visible',
121
- expr: evalStatic(visibleNode, scope) ? '1' : '0',
121
+ value: evalStatic(visibleNode, scope) ? 1 : 0,
122
122
  });
123
123
  }
124
124
  catch {
125
- dynAssigns.push({
125
+ dynamicAssigns.push({
126
126
  field: 'modal_visible',
127
127
  value: {
128
128
  kind: 'flag',
129
- test: lowerExpr(visibleNode, env),
129
+ test: lowerExpr(visibleNode, environment),
130
130
  truthiness: 'value',
131
131
  negate: false,
132
132
  whenTrue: 1,
@@ -135,9 +135,10 @@ export function emitModal(element, scope, out, env, state) {
135
135
  }
136
136
  const node = {
137
137
  id: nodeId,
138
+ location: currentLoc(),
138
139
  type: 'ER_NODE_MODAL',
139
140
  constantProps: staticAssigns,
140
- stateProps: dynAssigns,
141
+ stateProps: dynamicAssigns,
141
142
  placeholder: null,
142
143
  text: null,
143
144
  image: null,
@@ -145,7 +146,7 @@ export function emitModal(element, scope, out, env, state) {
145
146
  children: [],
146
147
  wiring: [
147
148
  ...binds.map((bind, index) => ({ kind: 'bind', bind, index })),
148
- ...lowerRefBinds(element.openingElement, env).map(slot => ({
149
+ ...lowerRefBinds(element.openingElement, environment).map(slot => ({
149
150
  kind: 'ref',
150
151
  slot,
151
152
  })),
@@ -153,6 +154,6 @@ export function emitModal(element, scope, out, env, state) {
153
154
  };
154
155
  checkInterpolations(node);
155
156
  // The modal's content, shown and hidden with the modal.
156
- node.children = emitChildren(element.children, scope, out, env, state);
157
+ node.children = emitChildren(element.children, scope, output, environment, state);
157
158
  return node;
158
159
  }
@@ -75,8 +75,17 @@ const LAYOUT_STYLE = [
75
75
  'zIndex',
76
76
  'transform',
77
77
  ];
78
+ /** The shadow a View, ScrollView, Pressable or Modal casts. */
79
+ const SHADOW_STYLE = [
80
+ 'shadowColor',
81
+ 'shadowOffset',
82
+ 'shadowOpacity',
83
+ 'shadowRadius',
84
+ 'elevation',
85
+ ];
78
86
  /** What the engine draws a View, ScrollView or Pressable with. */
79
87
  const VIEW_STYLE = [
88
+ ...SHADOW_STYLE,
80
89
  'backgroundColor',
81
90
  'borderRadius',
82
91
  'borderTopLeftRadius',
@@ -105,16 +114,18 @@ const TEXT_STYLE = [
105
114
  'letterSpacing',
106
115
  'opacity',
107
116
  ];
108
- /** What the engine draws a Modal's own box with. */
109
- const MODAL_STYLE = [
117
+ /** What the engine draws a box with: a TextInput's, and a Modal's own. */
118
+ const BOX_STYLE = [
110
119
  'backgroundColor',
111
120
  'borderRadius',
112
121
  'borderWidth',
113
122
  'borderColor',
114
123
  'opacity',
115
124
  ];
125
+ /** What the engine draws a Modal's own box with. */
126
+ const MODAL_STYLE = [...BOX_STYLE, ...SHADOW_STYLE];
116
127
  /** What the engine draws a TextInput with. */
117
- const TEXT_INPUT_STYLE = [...MODAL_STYLE, 'color', 'fontSize'];
128
+ const TEXT_INPUT_STYLE = [...BOX_STYLE, 'color', 'fontSize'];
118
129
  /** The style keys the engine animates on a View, ScrollView, Pressable or Modal; `transform` animates anywhere. */
119
130
  const VIEW_ANIMATED = ['opacity', 'backgroundColor', 'transform'];
120
131
  /** The style keys the engine animates on a Text. */
@@ -132,8 +143,8 @@ const SVG_PAINT = [
132
143
  'strokeLinejoin',
133
144
  'strokeMiterlimit',
134
145
  'fillRule',
135
- 'fillGrad',
136
- 'strokeGrad',
146
+ 'fillGradient',
147
+ 'strokeGradient',
137
148
  ];
138
149
  /** The attributes every host node lowers: style, visibility, a node ref, and its events. */
139
150
  const HOST_PROPS = [
@@ -237,8 +248,32 @@ const ELEMENTS = {
237
248
  ref: 'Flow A cannot pass a ref through <FlatList> either; use <ScrollView ref={…}> with .map.',
238
249
  }),
239
250
  // The Flow A wrapper warns about these too, so a list that runs in the simulator also compiles.
240
- platformNoOps: false,
251
+ takesPlatformProps: false,
241
252
  },
253
+ SectionList: element('SectionList', [
254
+ 'sections',
255
+ 'renderItem',
256
+ 'renderSectionHeader',
257
+ 'renderSectionFooter',
258
+ 'keyExtractor',
259
+ 'style',
260
+ ], [...LAYOUT_STYLE, ...VIEW_STYLE], 'none', {
261
+ ref: 'Flow A cannot pass a ref through <SectionList> either; use <ScrollView ref={…}> with .map.',
262
+ }),
263
+ Button: element('Button', ['title', 'onPress', 'color', 'disabled'], [], 'none', {
264
+ style: 'a Button takes no style, as in React Native. Build the same tree yourself to style it: ' +
265
+ '<Pressable style={…} onPress={…}><Text style={…}>title</Text></Pressable>.',
266
+ }),
267
+ // Its style and ref go to the View; every other prop goes to the Image, as in Flow A.
268
+ ImageBackground: element('ImageBackground', [
269
+ ...HOST_PROPS,
270
+ 'source',
271
+ 'imageName',
272
+ 'resizeMode',
273
+ 'tintColor',
274
+ 'imageStyle',
275
+ 'imageRef',
276
+ ], [...LAYOUT_STYLE, ...VIEW_STYLE], 'nodes', {}, VIEW_ANIMATED),
242
277
  Svg: element('Svg', ['style', 'ref', 'width', 'height', 'viewBox', 'source', ...SVG_PAINT], LAYOUT_STYLE, 'shapes', {
243
278
  visible: 'wrap it: <View visible={…}><Svg …/></View> — the View carries the hide and the whole subtree goes with it.',
244
279
  ...Object.fromEntries(Object.keys(EVENT_TYPES).map(name => [name, SVG_EVENT])),
@@ -279,7 +314,7 @@ function element(tag, props, styleKeys, children, refused = {}, animatedStyleKey
279
314
  tag,
280
315
  props: new Set(props),
281
316
  refused,
282
- platformNoOps: true,
317
+ takesPlatformProps: true,
283
318
  styleKeys: new Set(styleKeys),
284
319
  animatedStyleKeys: new Set(animatedStyleKeys),
285
320
  children,
@@ -298,7 +333,7 @@ function shape(tag, geometry) {
298
333
  tag,
299
334
  props: new Set([...geometry, ...SVG_PAINT]),
300
335
  refused: {},
301
- platformNoOps: false,
336
+ takesPlatformProps: false,
302
337
  styleKeys: null,
303
338
  animatedStyleKeys: new Set(),
304
339
  children: 'none',
@@ -327,13 +362,13 @@ export const svgShapeSpec = (tag) => Object.hasOwn(SVG_SHAPES, tag) ? SVG_SHAPES
327
362
  /**
328
363
  * An attribute's name as written, a namespaced one (`xlink:href`) included.
329
364
  *
330
- * @param attr The attribute.
365
+ * @param attribute The attribute.
331
366
  *
332
367
  * @returns Its name.
333
368
  */
334
- export const attrName = (attr) => attr.name.type === 'JSXNamespacedName'
335
- ? `${attr.name.namespace.name}:${attr.name.name.name}`
336
- : attr.name.name;
369
+ export const attrName = (attribute) => attribute.name.type === 'JSXNamespacedName'
370
+ ? `${attribute.name.namespace.name}:${attribute.name.name.name}`
371
+ : attribute.name.name;
337
372
  /**
338
373
  * Pins an error to a construct's location.
339
374
  *
@@ -358,17 +393,17 @@ export function at(error, node) {
358
393
  */
359
394
  const declares = (spec, name) => name === 'key' ||
360
395
  spec.props.has(name) ||
361
- (spec.platformNoOps && RN_PLATFORM_NO_OPS.includes(name));
396
+ (spec.takesPlatformProps && RN_PLATFORM_NO_OPS.includes(name));
362
397
  /**
363
- * Whether `attr` sits on a built-in element or shape that does not declare it. A component's props are its own,
398
+ * Whether `attribute` sits on a built-in element or shape that does not declare it. A component's props are its own,
364
399
  * so an attribute on one is never undeclared.
365
400
  *
366
401
  * @param openingElement The element's opening tag.
367
- * @param attr One of its attributes.
402
+ * @param attribute One of its attributes.
368
403
  *
369
404
  * @returns Whether the element would refuse it.
370
405
  */
371
- export function isUndeclaredAttribute(openingElement, attr) {
406
+ export function isUndeclaredAttribute(openingElement, attribute) {
372
407
  const nameNode = openingElement.name;
373
408
  const tag = nameNode.type === 'JSXIdentifier'
374
409
  ? nameNode.name
@@ -378,7 +413,7 @@ export function isUndeclaredAttribute(openingElement, attr) {
378
413
  ? nameNode.property.name
379
414
  : null;
380
415
  const spec = tag == null ? undefined : (elementSpec(tag) ?? svgShapeSpec(tag));
381
- return spec != null && !declares(spec, attrName(attr));
416
+ return spec != null && !declares(spec, attrName(attribute));
382
417
  }
383
418
  /**
384
419
  * Refuses every attribute `spec` does not declare, at the attribute. Spreads are left to the element's
@@ -388,16 +423,16 @@ export function isUndeclaredAttribute(openingElement, attr) {
388
423
  * @param openingElement Its opening tag.
389
424
  */
390
425
  export function checkAttributes(spec, openingElement) {
391
- for (const attr of openingElement.attributes) {
392
- if (attr.type !== 'JSXAttribute')
426
+ for (const attribute of openingElement.attributes) {
427
+ if (attribute.type !== 'JSXAttribute')
393
428
  continue;
394
- const name = attrName(attr);
429
+ const name = attrName(attribute);
395
430
  if (declares(spec, name))
396
431
  continue;
397
432
  const refusal = Object.hasOwn(spec.refused, name)
398
433
  ? spec.refused[name]
399
434
  : undefined;
400
- throw at(aotError(`AOT: <${spec.tag}> prop "${name}" is not supported`, refusal ?? `supported props: ${[...spec.props].join(', ')}.`), attr);
435
+ throw at(aotError(`AOT: <${spec.tag}> prop "${name}" is not supported`, refusal ?? `supported props: ${[...spec.props].join(', ')}.`), attribute);
401
436
  }
402
437
  }
403
438
  /**
@@ -410,12 +445,12 @@ export function checkAttributes(spec, openingElement) {
410
445
  * @returns The element, or a copy of it without those attributes.
411
446
  */
412
447
  export function withoutPlatformNoOps(spec, element) {
413
- if (!spec.platformNoOps)
448
+ if (!spec.takesPlatformProps)
414
449
  return element;
415
- const attrs = element.openingElement.attributes;
416
- const kept = attrs.filter(attr => attr.type !== 'JSXAttribute' ||
417
- !RN_PLATFORM_NO_OPS.includes(attrName(attr)));
418
- return kept.length === attrs.length
450
+ const attributes = element.openingElement.attributes;
451
+ const kept = attributes.filter(attribute => attribute.type !== 'JSXAttribute' ||
452
+ !RN_PLATFORM_NO_OPS.includes(attrName(attribute)));
453
+ return kept.length === attributes.length
419
454
  ? element
420
455
  : {
421
456
  ...element,
@@ -0,0 +1,118 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ // Builders for the JSX the wrapper components (Button, ImageBackground, SectionList) are rewritten to.
17
+ /*----------------------------------------------------------------------------------------------------------------------
18
+ - Imports
19
+ ---------------------------------------------------------------------------------------------------------------------*/
20
+ import { aotError } from '../diagnostics.mjs';
21
+ import { at } from './props.mjs';
22
+ /*----------------------------------------------------------------------------------------------------------------------
23
+ - Implementation
24
+ ---------------------------------------------------------------------------------------------------------------------*/
25
+ /**
26
+ * Refuses a spread on a wrapper, whose props are split by name.
27
+ *
28
+ * @param element The wrapper.
29
+ * @param tag Its tag, for the error.
30
+ */
31
+ export function refuseSpreads(element, tag) {
32
+ const spread = element.openingElement.attributes.find(attribute => attribute.type === 'JSXSpreadAttribute');
33
+ if (spread) {
34
+ throw at(aotError(`AOT: a spread {...} on <${tag}> is not supported`, 'list each prop explicitly.'), spread);
35
+ }
36
+ }
37
+ /**
38
+ * A JSX element, located at the wrapper it stands for so its errors point there.
39
+ *
40
+ * @param tag The tag.
41
+ * @param attributes Its attributes.
42
+ * @param children Its children.
43
+ * @param from The wrapper.
44
+ *
45
+ * @returns The element.
46
+ */
47
+ export function elementOf(tag, attributes, children, from) {
48
+ const name = { type: 'JSXIdentifier', name: tag };
49
+ return {
50
+ type: 'JSXElement',
51
+ openingElement: {
52
+ type: 'JSXOpeningElement',
53
+ name,
54
+ attributes,
55
+ selfClosing: children.length === 0,
56
+ },
57
+ closingElement: children.length === 0 ? null : { type: 'JSXClosingElement', name },
58
+ children,
59
+ loc: from.loc,
60
+ };
61
+ }
62
+ /**
63
+ * A `name={value}` attribute.
64
+ *
65
+ * @param name The name.
66
+ * @param value The value.
67
+ *
68
+ * @returns The attribute.
69
+ */
70
+ export function attributeOf(name, value) {
71
+ return {
72
+ type: 'JSXAttribute',
73
+ name: { type: 'JSXIdentifier', name },
74
+ value: { type: 'JSXExpressionContainer', expression: value },
75
+ };
76
+ }
77
+ /**
78
+ * An attribute under another name, keeping its value and location.
79
+ *
80
+ * @param attribute The attribute.
81
+ * @param name The new name.
82
+ *
83
+ * @returns The renamed attribute.
84
+ */
85
+ export function renamed(attribute, name) {
86
+ return { ...attribute, name: { type: 'JSXIdentifier', name } };
87
+ }
88
+ /**
89
+ * A `{value}` child.
90
+ *
91
+ * @param value The expression.
92
+ *
93
+ * @returns The child.
94
+ */
95
+ export function expressionChild(value) {
96
+ return { type: 'JSXExpressionContainer', expression: value };
97
+ }
98
+ /**
99
+ * An object literal of strings and numbers.
100
+ *
101
+ * @param fields The fields.
102
+ *
103
+ * @returns The literal.
104
+ */
105
+ export function literalObject(fields) {
106
+ return {
107
+ type: 'ObjectExpression',
108
+ properties: Object.entries(fields).map(([key, value]) => ({
109
+ type: 'ObjectProperty',
110
+ key: { type: 'Identifier', name: key },
111
+ value: typeof value === 'number'
112
+ ? { type: 'NumericLiteral', value }
113
+ : { type: 'StringLiteral', value },
114
+ computed: false,
115
+ shorthand: false,
116
+ })),
117
+ };
118
+ }