embedded-react 0.20.0 → 0.22.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/NOTICE +5 -0
- package/README.md +3 -2
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +17 -47
- package/aot/compiler/alerts.mjs +604 -0
- package/aot/compiler/animations.mjs +299 -57
- package/aot/compiler/boot.mjs +27 -2
- package/aot/compiler/check.mjs +62 -10
- package/aot/compiler/collect.mjs +517 -137
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +276 -117
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +2 -1
- package/aot/compiler/elements/props.mjs +47 -8
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/expressions.mjs +1378 -97
- package/aot/compiler/handlers.mjs +1807 -354
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/nodes.mjs +40 -1
- package/aot/compiler/ir/reads.mjs +206 -5
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +12 -0
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/keyboard-dismiss.mjs +99 -0
- package/aot/compiler/keyboard.mjs +1 -1
- package/aot/compiler/list-items.mjs +226 -0
- package/aot/compiler/list-order.mjs +586 -0
- package/aot/compiler/list-split.mjs +259 -0
- package/aot/compiler/loops.mjs +582 -0
- package/aot/compiler/lower.mjs +203 -53
- package/aot/compiler/native-files.mjs +439 -0
- package/aot/compiler/native-header.mjs +335 -0
- package/aot/compiler/native-modules.mjs +1173 -0
- package/aot/compiler/nodes.mjs +45 -31
- package/aot/compiler/options.mjs +3 -2
- package/aot/compiler/out.mjs +18 -1
- package/aot/compiler/package/animations.mjs +133 -23
- package/aot/compiler/package/assemble.mjs +2 -4
- package/aot/compiler/package/bytecode.mjs +37 -8
- package/aot/compiler/package/checks.mjs +4 -0
- package/aot/compiler/package/codegen.mjs +906 -33
- package/aot/compiler/package/enums.mjs +10 -0
- package/aot/compiler/package/format.mjs +16 -3
- package/aot/compiler/package/lower.mjs +707 -176
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +24 -0
- package/aot/compiler/package/writer.mjs +22 -0
- package/aot/compiler/parse.mjs +3 -1
- package/aot/compiler/record-shapes.mjs +246 -0
- package/aot/compiler/records.mjs +654 -0
- package/aot/compiler/reducers.mjs +272 -0
- package/aot/compiler/scroll-to.mjs +112 -0
- package/aot/compiler/static-eval.mjs +315 -7
- package/aot/compiler/style-text.mjs +20 -5
- package/aot/compiler/svg.mjs +13 -7
- package/aot/compiler/switch-cases.mjs +198 -0
- package/aot/compiler/tagged-records.mjs +450 -0
- package/aot/compiler/typing.mjs +307 -0
- package/aot/compiler/updaters.mjs +321 -0
- package/aot/compiler/window-dimensions.mjs +94 -0
- package/aot/compiler/worked-values.mjs +319 -0
- package/aot/demo-file.mjs +30 -0
- package/aot/style-map.mjs +94 -3
- package/assets/bake-font.mjs +187 -244
- package/assets/bake-image.mjs +47 -71
- package/assets/bake-svg.mjs +465 -533
- package/assets/build-builtin-font.mjs +14 -27
- package/assets/emit-c.mjs +124 -204
- package/assets/emit-container.mjs +129 -197
- package/assets/emit-pack.mjs +92 -136
- package/assets/font-config.mjs +19 -27
- package/assets/font-sizes.mjs +432 -507
- package/assets/glyph-coverage.mjs +170 -214
- package/assets/index.mjs +52 -97
- package/assets/rasterize.mjs +173 -194
- package/assets/svg-loader.mjs +42 -48
- package/build.mjs +85 -94
- package/cli.mjs +490 -586
- package/compile-bin.mjs +24 -36
- package/flash.mjs +297 -401
- package/hotreload/dev-device.mjs +229 -270
- package/hotreload/pack-app.mjs +118 -159
- package/hotreload/pack-split.mjs +146 -213
- package/hotreload/package-transfer.mjs +128 -131
- package/hotreload/protocol.mjs +118 -118
- package/hotreload/uploader.mjs +132 -159
- package/hotreload/watch-tree.mjs +56 -65
- package/pack-container.mjs +94 -116
- package/package.json +19 -16
- package/persist-transform.mjs +89 -105
- package/qjsc-wasm.mjs +47 -72
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +1 -1
- package/sim-server.mjs +260 -354
- package/src/embedded-react/Alert.mjs +112 -0
- package/src/embedded-react/Animated.mjs +412 -0
- package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
- package/src/embedded-react/{Button.js → Button.mjs} +29 -53
- package/src/embedded-react/Dimensions.mjs +32 -0
- package/src/embedded-react/Easing.mjs +34 -0
- package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
- package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
- package/src/embedded-react/Keyboard.mjs +82 -0
- package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
- package/src/embedded-react/PanResponder.mjs +256 -0
- package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
- package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
- package/src/embedded-react/SectionList.mjs +103 -0
- package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
- package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
- package/src/embedded-react/background-image.mjs +321 -0
- package/src/embedded-react/{components.js → components.mjs} +1 -3
- package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
- package/src/embedded-react/index.d.ts +238 -5
- package/src/embedded-react/index.js +26 -17
- package/src/embedded-react/layout-anim-config.mjs +85 -0
- package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
- package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
- package/src/embedded-react/nativeModule.mjs +371 -0
- package/src/embedded-react/split-style.mjs +57 -0
- package/src/embedded-react/svg-ops.mjs +1075 -0
- package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
- package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
- package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
- package/src/host-config.mjs +512 -0
- package/src/{native-ui.js → native-ui.mjs} +1 -8
- package/src/props.mjs +341 -0
- package/src/{renderer.js → renderer.mjs} +30 -44
- package/src/embedded-react/Animated.js +0 -440
- package/src/embedded-react/Easing.js +0 -39
- package/src/embedded-react/PanResponder.js +0 -330
- package/src/embedded-react/SectionList.js +0 -148
- package/src/embedded-react/layout-anim-config.js +0 -101
- package/src/embedded-react/split-style.js +0 -58
- package/src/embedded-react/svg-ops.js +0 -1295
- package/src/host-config.js +0 -548
- package/src/props.js +0 -306
package/aot/compiler/lower.mjs
CHANGED
|
@@ -16,20 +16,29 @@
|
|
|
16
16
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
-
import { checkNumber, lowerWithChecks, runChecks } from './check.mjs';
|
|
20
|
-
import { evalStatic, setBinding, withUndefined } from './static-eval.mjs';
|
|
19
|
+
import { checkNumber, lowerWithChecks, runChecks, whenTyped } from './check.mjs';
|
|
20
|
+
import { evalStatic, rethrowFoldLimit, setBinding, withUndefined, } from './static-eval.mjs';
|
|
21
21
|
import { abandonBoot, beginBoot, endBoot, setBootLowering } from './boot.mjs';
|
|
22
|
-
import { findShadowedClockCalls,
|
|
23
|
-
import { findComponent, declaredNames, moduleScope, collectState, settleBootInitials, findReturnJSX, collectComponents, collectHelpers, collectImageImports, collectSvgImports, collectCallbacks, collectMemos, collectEffects, bindConst, } from './collect.mjs';
|
|
22
|
+
import { bindBuiltValues, findShadowedClockCalls, foldRuntime, inferWideSlots, lowerLocal, lowerExpr, } from './expressions.mjs';
|
|
23
|
+
import { findComponent, bindFoldedPattern, declaredNames, moduleScope, collectState, settleBootInitials, findReturnJSX, collectComponents, collectHelpers, collectImageImports, collectSvgImports, collectCallbacks, collectMemos, collectEffects, collectNativeEvents, bindConst, } from './collect.mjs';
|
|
24
24
|
import { collectAnims, collectRefs } from './animations.mjs';
|
|
25
|
-
import { lowerEffect } from './handlers.mjs';
|
|
25
|
+
import { lowerEffect, lowerNativeEvent } from './handlers.mjs';
|
|
26
26
|
import { collectPanResponders } from './pan-responder.mjs';
|
|
27
27
|
import { emitNode } from './nodes.mjs';
|
|
28
28
|
import { lowerKeyboardConfig } from './keyboard.mjs';
|
|
29
|
+
import { itemValueAt } from './list-items.mjs';
|
|
29
30
|
import { normalizeUndefined, parseApp } from './parse.mjs';
|
|
31
|
+
import { collectNativeModules, optionalModulesOf } from './native-modules.mjs';
|
|
32
|
+
import { inlineCustomHooks } from './custom-hooks.mjs';
|
|
33
|
+
import { rewriteWindowDimensions } from './window-dimensions.mjs';
|
|
34
|
+
import { alertState, emitAlertDialogs, rewriteAlerts } from './alerts.mjs';
|
|
35
|
+
import { rewriteKeyboardDismiss } from './keyboard-dismiss.mjs';
|
|
30
36
|
import { Out } from './out.mjs';
|
|
31
|
-
import { isStateDriven, nodesOf, updatedVectorOf } from './ir/nodes.mjs';
|
|
32
|
-
import { nodeReads, vectorReads } from './ir/reads.mjs';
|
|
37
|
+
import { conditionalsOf, isStateDriven, nodesOf, updatedVectorOf, } from './ir/nodes.mjs';
|
|
38
|
+
import { expressionReads, listStates, nodeReads, vectorReads, workedStates, } from './ir/reads.mjs';
|
|
39
|
+
import { wideSlotOf } from './ir/types.mjs';
|
|
40
|
+
import { bindDerivedList, renderBindings } from './list-order.mjs';
|
|
41
|
+
import { bindContextUses, contextsOf, refuseHiddenContexts, } from './contexts.mjs';
|
|
33
42
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
34
43
|
- Implementation
|
|
35
44
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -56,6 +65,9 @@ function settleFunctions(output, hasUpdate) {
|
|
|
56
65
|
settleStmts(statement.consequent);
|
|
57
66
|
settleStmts(statement.alternate ?? []);
|
|
58
67
|
}
|
|
68
|
+
else if (statement.kind === 'block' || statement.kind === 'loop') {
|
|
69
|
+
settleStmts(statement.body);
|
|
70
|
+
}
|
|
59
71
|
}
|
|
60
72
|
};
|
|
61
73
|
const settle = (callback) => {
|
|
@@ -77,6 +89,9 @@ function settleFunctions(output, hasUpdate) {
|
|
|
77
89
|
for (const timer of output.timerFunctions) {
|
|
78
90
|
settle(timer.callback);
|
|
79
91
|
}
|
|
92
|
+
for (const handler of output.nativeEventHandlers) {
|
|
93
|
+
settle(handler.callback);
|
|
94
|
+
}
|
|
80
95
|
for (const animationCallback of output.animationCallbacks) {
|
|
81
96
|
if (animationCallback.kind === 'completion') {
|
|
82
97
|
settle(animationCallback.completion);
|
|
@@ -103,19 +118,29 @@ function settleFunctions(output, hasUpdate) {
|
|
|
103
118
|
}
|
|
104
119
|
}
|
|
105
120
|
/**
|
|
106
|
-
* Flags each state a node or
|
|
107
|
-
*
|
|
121
|
+
* Flags each state a node, drawing, or conditional reads, so a write to it marks it changed and the update sets
|
|
122
|
+
* them again. One that also reads something untracked is set on every update, so its reads need no flag.
|
|
108
123
|
*
|
|
109
|
-
* @param
|
|
124
|
+
* @param root The app's tree.
|
|
125
|
+
* @param derivedLists The lists filtered, sorted or split in render.
|
|
126
|
+
* @param workedValues The values memos and helpers loop for in render.
|
|
110
127
|
*/
|
|
111
|
-
function watchState(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
128
|
+
function watchState(root, derivedLists, workedValues) {
|
|
129
|
+
const reads = [
|
|
130
|
+
...nodesOf(root).flatMap(node => {
|
|
131
|
+
const vector = updatedVectorOf(node);
|
|
132
|
+
return [nodeReads(node), vector && vectorReads(vector)];
|
|
133
|
+
}),
|
|
134
|
+
...conditionalsOf(root).map(conditional => expressionReads(conditional.test)),
|
|
135
|
+
// A handler can read a filtered or sorted list that nothing draws, which must still be rebuilt.
|
|
136
|
+
...derivedLists.map(listStates),
|
|
137
|
+
// So can a value a memo or a helper loops for.
|
|
138
|
+
...workedValues.map(workedStates),
|
|
139
|
+
];
|
|
140
|
+
for (const read of reads) {
|
|
141
|
+
read?.forEach(record => {
|
|
142
|
+
record.isWatched = true;
|
|
143
|
+
});
|
|
119
144
|
}
|
|
120
145
|
}
|
|
121
146
|
/**
|
|
@@ -130,9 +155,10 @@ function checkStateRecords(stateRecords) {
|
|
|
130
155
|
continue;
|
|
131
156
|
for (const item of record.items) {
|
|
132
157
|
for (const field of record.struct.fields) {
|
|
133
|
-
const value = item
|
|
134
|
-
if (field.kind === 'string' ||
|
|
158
|
+
const { present, value } = itemValueAt(item, field);
|
|
159
|
+
if (field.kind === 'string' || field.kind === 'bool' || !present) {
|
|
135
160
|
continue;
|
|
161
|
+
}
|
|
136
162
|
const number = Number(value);
|
|
137
163
|
if (field.kind === 'float' || !Number.isFinite(number)) {
|
|
138
164
|
checkNumber(number);
|
|
@@ -142,20 +168,40 @@ function checkStateRecords(stateRecords) {
|
|
|
142
168
|
}
|
|
143
169
|
}
|
|
144
170
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
171
|
+
* Widens each int slot that has to hold 64 bits. A state or ref slot is typed from its initial value, so
|
|
172
|
+
* `useState(0)` is an int until a setter stores Date.now() in it; the values lowering stored into the int slots
|
|
173
|
+
* say which hold a timestamp or a number past the int range, following one through every slot it reaches.
|
|
174
|
+
*
|
|
175
|
+
* @param wide Takes the slots widened, and what each holds.
|
|
176
|
+
* @param stores Every value lowering stored into an int slot.
|
|
177
|
+
*/
|
|
178
|
+
function widenSlots(wide, stores) {
|
|
179
|
+
for (const [slot, width] of inferWideSlots(stores, new Map())) {
|
|
180
|
+
wide.set(slot, width);
|
|
181
|
+
}
|
|
182
|
+
for (const { slot, target } of stores) {
|
|
183
|
+
const width = wideSlotOf(wide, slot);
|
|
184
|
+
if (target && width) {
|
|
185
|
+
target.slotKind = 'i64';
|
|
186
|
+
target.widened = width;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Lowers a Flow B app's JSX (or TSX) source, widens the slots that hold 64 bits, then runs the typing pass and
|
|
192
|
+
* the check pass over what lowering recorded. Pure (no I/O); the package backend (package/) writes the result.
|
|
147
193
|
*
|
|
148
194
|
* @param source The App.jsx/App.tsx source text.
|
|
149
195
|
* @param options compilePackage's options, resolved (see resolveOptions).
|
|
150
|
-
* @param wide State/ref slots to declare 64-bit (see compileWidened).
|
|
151
|
-
* @param stores Collects every value stored into an int slot.
|
|
152
196
|
*
|
|
153
197
|
* @returns The lowered app.
|
|
154
198
|
*/
|
|
155
|
-
export function lowerApp(source, options
|
|
199
|
+
export function lowerApp(source, options) {
|
|
156
200
|
beginBoot(source);
|
|
157
201
|
try {
|
|
158
|
-
const
|
|
202
|
+
const wide = new Map();
|
|
203
|
+
const stores = [];
|
|
204
|
+
const { result, checks } = lowerWithChecks(() => lowerProgram(source, options, wide, stores), () => widenSlots(wide, stores));
|
|
159
205
|
const app = { ...result, boot: endBoot(), checks };
|
|
160
206
|
runChecks(app.checks);
|
|
161
207
|
return app;
|
|
@@ -170,15 +216,23 @@ export function lowerApp(source, options, wide, stores) {
|
|
|
170
216
|
*
|
|
171
217
|
* @param source The App.jsx/App.tsx source text.
|
|
172
218
|
* @param options compilePackage's options, resolved (see resolveOptions).
|
|
173
|
-
* @param wide
|
|
219
|
+
* @param wide Takes the slots the typing pass widens.
|
|
174
220
|
* @param stores Collects every value stored into an int slot.
|
|
175
221
|
*
|
|
176
222
|
* @returns The lowered app, without its checks.
|
|
177
223
|
*/
|
|
178
224
|
function lowerProgram(source, options, wide, stores) {
|
|
179
225
|
// Parse the app and prepare the AST for the passes below.
|
|
180
|
-
|
|
226
|
+
let nativeModules = new Map();
|
|
227
|
+
const ast = parseApp(source, options, typed => {
|
|
228
|
+
nativeModules = collectNativeModules(typed.program, options.nativeFiles);
|
|
229
|
+
});
|
|
181
230
|
normalizeUndefined(ast);
|
|
231
|
+
rewriteWindowDimensions(ast);
|
|
232
|
+
const raisesAlerts = rewriteAlerts(ast);
|
|
233
|
+
rewriteKeyboardDismiss(ast);
|
|
234
|
+
inlineCustomHooks(ast);
|
|
235
|
+
refuseHiddenContexts(ast);
|
|
182
236
|
const shadowedClock = findShadowedClockCalls(ast);
|
|
183
237
|
// Seed the module scope with image imports (each is its baked-name string) so consts that use them can fold.
|
|
184
238
|
const { screen } = options;
|
|
@@ -193,32 +247,92 @@ function lowerProgram(source, options, wide, stores) {
|
|
|
193
247
|
for (const name of declaredNames(component.body.body)) {
|
|
194
248
|
delete scope[name];
|
|
195
249
|
}
|
|
250
|
+
// What the module itself can read, where a context's default is worked out.
|
|
251
|
+
const imageNames = new Map([...imageImports].map(([, imageImport]) => [
|
|
252
|
+
imageImport.name,
|
|
253
|
+
imageImport.importPath,
|
|
254
|
+
])); // asset name → path
|
|
255
|
+
const moduleEnvironment = {
|
|
256
|
+
state: new Map(),
|
|
257
|
+
locals: new Map(),
|
|
258
|
+
constants: moduleConstants,
|
|
259
|
+
moduleConstants,
|
|
260
|
+
animations: new Map(),
|
|
261
|
+
refs: new Map(),
|
|
262
|
+
pans: new Map(),
|
|
263
|
+
callbacks: new Map(),
|
|
264
|
+
helpers: collectHelpers({ type: 'BlockStatement', body: [], directives: [] }, ast.program),
|
|
265
|
+
imageNames,
|
|
266
|
+
svgImports,
|
|
267
|
+
svgArtifacts: options.svgArtifacts || {},
|
|
268
|
+
caps: options.caps,
|
|
269
|
+
wide,
|
|
270
|
+
stores,
|
|
271
|
+
shadowedClock,
|
|
272
|
+
constantLists: new Map(),
|
|
273
|
+
derivedLists: new Map(),
|
|
274
|
+
workedValues: new Map(),
|
|
275
|
+
splitLists: new Map(),
|
|
276
|
+
functionProps: new Map(),
|
|
277
|
+
children: null,
|
|
278
|
+
nativeModules,
|
|
279
|
+
};
|
|
280
|
+
moduleEnvironment.contexts = {
|
|
281
|
+
records: contextsOf(ast.program),
|
|
282
|
+
defaults: moduleEnvironment,
|
|
283
|
+
};
|
|
284
|
+
// The App has no provider above it, so a context it reads is the default.
|
|
285
|
+
const appLocals = new Map();
|
|
286
|
+
const appFunctionProps = new Map();
|
|
287
|
+
const contextNames = bindContextUses(component.body, moduleEnvironment, {
|
|
288
|
+
scope,
|
|
289
|
+
locals: appLocals,
|
|
290
|
+
functionProps: appFunctionProps,
|
|
291
|
+
lists: new Map(),
|
|
292
|
+
});
|
|
196
293
|
for (const statement of component.body.body) {
|
|
197
294
|
if (statement.type !== 'VariableDeclaration' ||
|
|
198
295
|
statement.kind !== 'const') {
|
|
199
296
|
continue;
|
|
200
297
|
}
|
|
201
298
|
for (const declarator of statement.declarations) {
|
|
299
|
+
if (declarator.id.type === 'ObjectPattern' && declarator.init) {
|
|
300
|
+
try {
|
|
301
|
+
bindFoldedPattern(scope, declarator.id, declarator.init);
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
rethrowFoldLimit(error); // not a fold, so bindBuiltValues binds it
|
|
305
|
+
}
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
202
308
|
if (declarator.id.type !== 'Identifier' || !declarator.init)
|
|
203
309
|
continue;
|
|
310
|
+
if (contextNames.has(declarator.id.name))
|
|
311
|
+
continue;
|
|
204
312
|
try {
|
|
205
313
|
setBinding(scope, declarator.id.name, bindConst(declarator.id.name, evalStatic(declarator.init, withUndefined(scope), 'boot')));
|
|
206
314
|
}
|
|
207
|
-
catch {
|
|
315
|
+
catch (error) {
|
|
316
|
+
rethrowFoldLimit(error);
|
|
208
317
|
// A dynamic const must hide a same-named module const, or the JSX quietly renders the module value.
|
|
209
318
|
delete scope[declarator.id.name];
|
|
210
319
|
}
|
|
211
320
|
}
|
|
212
321
|
}
|
|
213
322
|
// Collect the component's state; a state name hides any module const of the same name from the folds.
|
|
214
|
-
const state = collectState(component.body, scope, options.caps, '',
|
|
323
|
+
const state = collectState(component.body, scope, options.caps, '', ast.program);
|
|
215
324
|
for (const name of state.byName.keys()) {
|
|
216
325
|
delete scope[name];
|
|
217
326
|
}
|
|
327
|
+
const activeAlert = raisesAlerts ? alertState() : null;
|
|
328
|
+
if (activeAlert) {
|
|
329
|
+
state.byName.set(activeAlert.name, activeAlert);
|
|
330
|
+
state.bySetter.set(activeAlert.setter, activeAlert);
|
|
331
|
+
}
|
|
218
332
|
// Collect the component's other hooks, plus the file's helpers and child components.
|
|
219
333
|
const rootJSX = findReturnJSX(component.body, scope);
|
|
220
334
|
const animations = collectAnims(component.body, scope);
|
|
221
|
-
const refs = collectRefs(component.body, scope
|
|
335
|
+
const refs = collectRefs(component.body, scope);
|
|
222
336
|
for (const name of [...animations.keys(), ...refs.keys()]) {
|
|
223
337
|
delete scope[name];
|
|
224
338
|
}
|
|
@@ -227,14 +341,10 @@ function lowerProgram(source, options, wide, stores) {
|
|
|
227
341
|
const memos = collectMemos(component.body);
|
|
228
342
|
const helpers = collectHelpers(component.body, ast.program);
|
|
229
343
|
const components = collectComponents(ast.program);
|
|
230
|
-
const imageNames = new Map([...imageImports].map(([, imageImport]) => [
|
|
231
|
-
imageImport.name,
|
|
232
|
-
imageImport.importPath,
|
|
233
|
-
])); // asset name → path
|
|
234
344
|
// The expression environment every emitter compiles against.
|
|
235
345
|
const environment = {
|
|
236
346
|
state: state.byName,
|
|
237
|
-
locals:
|
|
347
|
+
locals: appLocals,
|
|
238
348
|
constants: scope,
|
|
239
349
|
moduleConstants, // what an inlined child component sees (see emitComponent)
|
|
240
350
|
animations: animations,
|
|
@@ -249,30 +359,46 @@ function lowerProgram(source, options, wide, stores) {
|
|
|
249
359
|
wide,
|
|
250
360
|
stores,
|
|
251
361
|
shadowedClock,
|
|
362
|
+
constantLists: moduleEnvironment.constantLists,
|
|
363
|
+
derivedLists: moduleEnvironment.derivedLists,
|
|
364
|
+
workedValues: moduleEnvironment.workedValues,
|
|
365
|
+
splitLists: moduleEnvironment.splitLists,
|
|
366
|
+
functionProps: appFunctionProps,
|
|
367
|
+
contexts: moduleEnvironment.contexts,
|
|
368
|
+
nativeModules,
|
|
252
369
|
};
|
|
253
370
|
// A value worked out at boot lowers its slot against the app's environment.
|
|
254
371
|
setBootLowering(environment, lowerExpr);
|
|
255
372
|
settleBootInitials(state.byName.values());
|
|
256
373
|
// Before emit, fold each memo or inline its expression at each use (no cache needed: dep tracking re-applies).
|
|
257
|
-
for (const
|
|
374
|
+
for (const { name, expression, isMemo } of renderBindings(component.body, memos)) {
|
|
375
|
+
if (!isMemo) {
|
|
376
|
+
bindDerivedList(name, expression, environment);
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
258
379
|
try {
|
|
259
380
|
setBinding(scope, name, bindConst(name, evalStatic(expression, scope, 'boot')));
|
|
260
381
|
}
|
|
261
|
-
catch {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
rethrowFoldLimit(error);
|
|
384
|
+
if (bindDerivedList(name, expression, environment)) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
if (expression.type === 'ArrayExpression' ||
|
|
388
|
+
expression.type === 'ObjectExpression') {
|
|
389
|
+
setBinding(scope, name, foldRuntime(expression, environment));
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
environment.locals.set(name, lowerLocal(expression, environment));
|
|
271
393
|
delete scope[name]; // a runtime binding beats a module const of its name in every fold
|
|
272
394
|
}
|
|
273
395
|
}
|
|
396
|
+
bindBuiltValues(component.body.body, environment);
|
|
274
397
|
// Emit the scene graph from the root JSX; `output` collects everything else it lowers.
|
|
275
398
|
const output = new Out(components, ast.program);
|
|
399
|
+
output.release = Boolean(options.release);
|
|
400
|
+
output.optionalModules = optionalModulesOf(nativeModules);
|
|
401
|
+
output.alertState = activeAlert;
|
|
276
402
|
const keyboard = lowerKeyboardConfig(ast.program); // a module-level setKeyboardConfig({...})
|
|
277
403
|
const root = emitNode(rootJSX, scope, output, environment, state);
|
|
278
404
|
// Emit registered only the images it reached; a dynamic source can't be enumerated, so bake every import.
|
|
@@ -285,13 +411,37 @@ function lowerProgram(source, options, wide, stores) {
|
|
|
285
411
|
for (const effect of collectEffects(component.body)) {
|
|
286
412
|
lowerEffect(effect, environment, state, output);
|
|
287
413
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
settleFunctions(output, hasUpdate);
|
|
291
|
-
if (hasUpdate) {
|
|
292
|
-
watchState(nodesOf(root));
|
|
414
|
+
for (const call of collectNativeEvents(component.body)) {
|
|
415
|
+
lowerNativeEvent(call, environment, state, output);
|
|
293
416
|
}
|
|
294
|
-
|
|
417
|
+
// Every alert raised is known by now, so their dialogs go under the root, after everything else.
|
|
418
|
+
emitAlertDialogs(root, output);
|
|
419
|
+
// An update exists only when something has to be re-applied after a state change, or a list filtered or sorted
|
|
420
|
+
// in render rebuilt.
|
|
421
|
+
const derivedLists = [...environment.derivedLists.values()].flatMap(lists => [...lists.values()]);
|
|
422
|
+
const workedValues = [...environment.workedValues.values()].flatMap(values => [...values.values()]);
|
|
423
|
+
// What the tree reads is known once it is typed.
|
|
424
|
+
whenTyped(() => {
|
|
425
|
+
const hasUpdate = nodesOf(root).some(node => isStateDriven(node) || updatedVectorOf(node) !== null) ||
|
|
426
|
+
conditionalsOf(root).some(conditional => !conditional.toggle) ||
|
|
427
|
+
output.dependencyEffects.length > 0 ||
|
|
428
|
+
derivedLists.length > 0 ||
|
|
429
|
+
workedValues.length > 0;
|
|
430
|
+
settleFunctions(output, hasUpdate);
|
|
431
|
+
if (hasUpdate) {
|
|
432
|
+
watchState(root, derivedLists, workedValues);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
const stateRecords = [
|
|
436
|
+
...state.byName.values(),
|
|
437
|
+
...output.childStateRecords,
|
|
438
|
+
...environment.constantLists.values(),
|
|
439
|
+
...derivedLists,
|
|
440
|
+
...workedValues,
|
|
441
|
+
...[...environment.splitLists.values()].flatMap(lists => [
|
|
442
|
+
...lists.values(),
|
|
443
|
+
]),
|
|
444
|
+
];
|
|
295
445
|
checkStateRecords(stateRecords);
|
|
296
446
|
return {
|
|
297
447
|
state: stateRecords,
|