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