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.
- package/NOTICE +5 -0
- package/README.md +8 -3
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +180 -90
- package/aot/compiler/animations.mjs +568 -317
- package/aot/compiler/boot.mjs +97 -35
- package/aot/compiler/branch-merge.mjs +4 -3
- package/aot/compiler/check.mjs +70 -18
- package/aot/compiler/collect.mjs +787 -288
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +439 -268
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/diagnostics.mjs +22 -25
- package/aot/compiler/elements/activity-indicator.mjs +25 -24
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/dial.mjs +91 -77
- package/aot/compiler/elements/flat-list.mjs +24 -22
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +52 -50
- package/aot/compiler/elements/modal.mjs +31 -30
- package/aot/compiler/elements/props.mjs +61 -26
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/elements/switch.mjs +42 -34
- package/aot/compiler/elements/text-input.mjs +34 -32
- package/aot/compiler/expressions.mjs +1685 -392
- package/aot/compiler/handlers.mjs +2029 -547
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/functions.mjs +11 -1
- package/aot/compiler/ir/nodes.mjs +43 -4
- package/aot/compiler/ir/reads.mjs +223 -22
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +26 -14
- package/aot/compiler/ir/vectors.mjs +5 -1
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/keyboard.mjs +17 -7
- 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 +246 -111
- 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 +195 -172
- package/aot/compiler/options.mjs +37 -31
- package/aot/compiler/out.mjs +32 -23
- package/aot/compiler/package/animations.mjs +779 -0
- package/aot/compiler/package/arena.mjs +252 -0
- package/aot/compiler/package/assemble.mjs +175 -0
- package/aot/compiler/package/bytecode.mjs +315 -0
- package/aot/compiler/package/checks.mjs +1026 -0
- package/aot/compiler/package/codegen.mjs +2168 -0
- package/aot/compiler/package/enums.mjs +148 -0
- package/aot/compiler/package/format.mjs +771 -0
- package/aot/compiler/package/layouts.mjs +136 -0
- package/aot/compiler/package/lower.mjs +2103 -0
- package/aot/compiler/package/props.mjs +118 -0
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +127 -0
- package/aot/compiler/package/vectors.mjs +502 -0
- package/aot/compiler/package/writer.mjs +686 -0
- package/aot/compiler/pan-responder.mjs +69 -61
- package/aot/compiler/parse.mjs +23 -21
- 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/static-eval.mjs +340 -30
- package/aot/compiler/style-text.mjs +178 -174
- package/aot/compiler/svg.mjs +480 -251
- 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 +320 -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/screenshot-smoke.mjs +54 -40
- package/aot/style-map.mjs +152 -92
- 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 +23 -13
- package/cli.mjs +402 -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 +62 -64
- 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 +37 -21
- 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 +113 -94
- package/src/embedded-react/Animated.js +24 -24
- package/src/embedded-react/Dimensions.js +37 -0
- 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 +7 -9
- package/src/embedded-react/StyleSheet.js +4 -3
- package/src/embedded-react/TouchableOpacity.js +13 -8
- package/src/embedded-react/index.d.ts +88 -8
- package/src/embedded-react/index.js +2 -0
- 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/nativeModule.js +462 -0
- 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
package/aot/compiler/nodes.mjs
CHANGED
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
19
|
import { checkNumber } from './check.mjs';
|
|
20
|
-
import { NODE_TYPES } from '../style-map.mjs';
|
|
21
|
-
import { aotError, checkEngineString, constantText, withLoc, } from './diagnostics.mjs';
|
|
20
|
+
import { NODE_TYPES, OPACITY_OPAQUE } from '../style-map.mjs';
|
|
21
|
+
import { aotError, checkEngineString, constantText, currentLoc, withLoc, } from './diagnostics.mjs';
|
|
22
22
|
import { buildValueOf, foldBoot } from './boot.mjs';
|
|
23
23
|
import { evalStaticOrThrow, evalStatic, foldScope } from './static-eval.mjs';
|
|
24
24
|
import { lowerExpr } from './expressions.mjs';
|
|
@@ -27,7 +27,8 @@ import { attrExpr, collectStyleAssigns, lowerNodeText, collectTextSpans, } from
|
|
|
27
27
|
import { at, checkAttributes, checkNoChildren, elementSpec, EVENT_TYPES, withoutPlatformNoOps, } from './elements/props.mjs';
|
|
28
28
|
import { lowerHandler } from './handlers.mjs';
|
|
29
29
|
import { emitPanResponder, panSpreadTarget } from './pan-responder.mjs';
|
|
30
|
-
import { emitComponent, emitChildren } from './control-flow.mjs';
|
|
30
|
+
import { emitComponent, emitChildren, emitProvider } from './control-flow.mjs';
|
|
31
|
+
import { providedContextOf } from './contexts.mjs';
|
|
31
32
|
import { emitSvg } from './svg.mjs';
|
|
32
33
|
import { emitDial } from './elements/dial.mjs';
|
|
33
34
|
import { emitSwitch } from './elements/switch.mjs';
|
|
@@ -35,18 +36,13 @@ import { emitTextInput } from './elements/text-input.mjs';
|
|
|
35
36
|
import { emitActivityIndicator } from './elements/activity-indicator.mjs';
|
|
36
37
|
import { emitModal } from './elements/modal.mjs';
|
|
37
38
|
import { emitFlatList } from './elements/flat-list.mjs';
|
|
39
|
+
import { emitButton } from './elements/button.mjs';
|
|
40
|
+
import { emitImageBackground } from './elements/image-background.mjs';
|
|
41
|
+
import { emitSectionList } from './elements/section-list.mjs';
|
|
38
42
|
import { resolveImageAttrs } from './elements/image.mjs';
|
|
39
43
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
40
44
|
- Constants
|
|
41
45
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
42
|
-
// JS-only wrappers with no lowering yet, mapped to the tree to write by hand; "unknown element" would mislead.
|
|
43
|
-
const FLOW_A_ONLY_COMPONENTS = {
|
|
44
|
-
Button: '<Pressable style={…} onPress={…}><Text style={…}>title</Text></Pressable>.',
|
|
45
|
-
ImageBackground: "<View style={…}><Image source={…} style={{position: 'absolute', top: 0, left: 0, " +
|
|
46
|
-
'right: 0, bottom: 0}} />…children…</View>.',
|
|
47
|
-
SectionList: '<ScrollView> with the header element and a data.map(…) per section (a section is not ' +
|
|
48
|
-
'one .map, which is why it has no lowering).',
|
|
49
|
-
};
|
|
50
46
|
// <TouchableOpacity> press feedback (see touchablePressFades).
|
|
51
47
|
const TOUCHABLE_ACTIVE_OPACITY = 0.2; // RN's default
|
|
52
48
|
const TOUCHABLE_RESTORE_MS = 250; // RN's fade-back; the dim itself lands with no ramp
|
|
@@ -62,6 +58,10 @@ const ELLIPSIZE_MODES = {
|
|
|
62
58
|
tail: 'ER_TEXT_ELLIPSIZE_TAIL',
|
|
63
59
|
clip: 'ER_TEXT_ELLIPSIZE_CLIP',
|
|
64
60
|
};
|
|
61
|
+
/** The most lines a <Text> may keep: the engine counts them in a byte. */
|
|
62
|
+
const MAX_NUMBER_OF_LINES = 255;
|
|
63
|
+
/** The longest long press, in ms: the engine keeps it in 16 bits. */
|
|
64
|
+
const MAX_LONG_PRESS_MS = 65535;
|
|
65
65
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
66
66
|
- Implementation
|
|
67
67
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -86,25 +86,25 @@ function resolveTag(openingElement) {
|
|
|
86
86
|
* The node refs `ref={myRef}` stores the element's handle in (a node ref from useRef), marked used.
|
|
87
87
|
*
|
|
88
88
|
* @param openingElement The element's opening tag.
|
|
89
|
-
* @param
|
|
89
|
+
* @param environment The expression environment.
|
|
90
90
|
*
|
|
91
|
-
* @returns The refs'
|
|
91
|
+
* @returns The refs' slots.
|
|
92
92
|
*/
|
|
93
|
-
export function lowerRefBinds(openingElement,
|
|
93
|
+
export function lowerRefBinds(openingElement, environment) {
|
|
94
94
|
const refs = [];
|
|
95
|
-
for (const
|
|
96
|
-
if (
|
|
97
|
-
|
|
95
|
+
for (const attribute of openingElement.attributes) {
|
|
96
|
+
if (attribute.type !== 'JSXAttribute' ||
|
|
97
|
+
attribute.name.name !== 'ref') {
|
|
98
98
|
continue;
|
|
99
99
|
}
|
|
100
|
-
const
|
|
101
|
-
?
|
|
100
|
+
const refExpression = attribute.value?.type === 'JSXExpressionContainer'
|
|
101
|
+
? attribute.value.expression
|
|
102
102
|
: null;
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
const nodeRef =
|
|
103
|
+
if (refExpression?.type === 'Identifier' &&
|
|
104
|
+
environment.refs?.get(refExpression.name)?.kind === 'node') {
|
|
105
|
+
const nodeRef = environment.refs.get(refExpression.name);
|
|
106
106
|
nodeRef.used = true;
|
|
107
|
-
refs.push(nodeRef.
|
|
107
|
+
refs.push(nodeRef.slotName);
|
|
108
108
|
}
|
|
109
109
|
else {
|
|
110
110
|
throw new Error('AOT: ref={…} must reference a node ref declared with useRef()');
|
|
@@ -121,7 +121,9 @@ export function lowerRefBinds(openingElement, env) {
|
|
|
121
121
|
* @returns The attribute, if the element has it.
|
|
122
122
|
*/
|
|
123
123
|
function namedAttr(openingElement, name) {
|
|
124
|
-
return openingElement.attributes.find((
|
|
124
|
+
return openingElement.attributes.find((attribute) => attribute.type === 'JSXAttribute' &&
|
|
125
|
+
attribute.name &&
|
|
126
|
+
attribute.name.name === name);
|
|
125
127
|
}
|
|
126
128
|
/**
|
|
127
129
|
* True for `<Pressable disabled>` / `<TouchableOpacity disabled={SOME_CONST}>`. Must fold: `disabled`
|
|
@@ -135,10 +137,10 @@ function namedAttr(openingElement, name) {
|
|
|
135
137
|
* @returns Whether it is disabled.
|
|
136
138
|
*/
|
|
137
139
|
function pressableIsDisabled(element, tag, scope) {
|
|
138
|
-
const
|
|
139
|
-
if (!
|
|
140
|
+
const attribute = namedAttr(element.openingElement, 'disabled');
|
|
141
|
+
if (!attribute)
|
|
140
142
|
return false;
|
|
141
|
-
return !!evalStaticOrThrow(attrExpr(
|
|
143
|
+
return !!evalStaticOrThrow(attrExpr(attribute), scope, `AOT: <${tag} disabled> must be a compile-time constant`, 'a disabled one still renders — it lowers to a plain <Pressable>, children, layout ' +
|
|
142
144
|
'and style intact — but its press handlers are not emitted at all, so the ' +
|
|
143
145
|
'AOT has to know at build time. To gate on state, leave it enabled and return early ' +
|
|
144
146
|
'in the handler (`onPress={() => { if (!ready) return; … }}`).');
|
|
@@ -154,26 +156,26 @@ function pressableIsDisabled(element, tag, scope) {
|
|
|
154
156
|
*/
|
|
155
157
|
function lowerTextTruncation(openingElement, scope) {
|
|
156
158
|
const assigns = [];
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
const lines = foldAttr(
|
|
159
|
+
const linesAttribute = namedAttr(openingElement, 'numberOfLines');
|
|
160
|
+
if (linesAttribute) {
|
|
161
|
+
const lines = foldAttr(linesAttribute, scope, 'AOT: <Text numberOfLines> must be a compile-time constant');
|
|
160
162
|
if (typeof lines !== 'number' ||
|
|
161
163
|
!Number.isInteger(lines) ||
|
|
162
164
|
lines < 0 ||
|
|
163
|
-
lines >
|
|
164
|
-
throw at(aotError(`AOT: <Text numberOfLines> must be a whole number from 0 to
|
|
165
|
+
lines > MAX_NUMBER_OF_LINES) {
|
|
166
|
+
throw at(aotError(`AOT: <Text numberOfLines> must be a whole number from 0 to ${MAX_NUMBER_OF_LINES} (got ${String(lines)})`, '0 does not truncate; any other value is the most lines the text wraps to.'), linesAttribute);
|
|
165
167
|
}
|
|
166
|
-
assigns.push({ field: 'number_of_lines',
|
|
168
|
+
assigns.push({ field: 'number_of_lines', value: lines });
|
|
167
169
|
}
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
170
|
-
const mode = foldAttr(
|
|
170
|
+
const modeAttribute = namedAttr(openingElement, 'ellipsizeMode');
|
|
171
|
+
if (modeAttribute) {
|
|
172
|
+
const mode = foldAttr(modeAttribute, scope, 'AOT: <Text ellipsizeMode> must be a compile-time constant');
|
|
171
173
|
if (!Object.hasOwn(ELLIPSIZE_MODES, mode)) {
|
|
172
|
-
throw at(aotError(`AOT: <Text ellipsizeMode> "${String(mode)}" is not drawn by the engine`, "use 'tail' or 'clip'; the engine draws 'head' and 'middle' as 'tail'."),
|
|
174
|
+
throw at(aotError(`AOT: <Text ellipsizeMode> "${String(mode)}" is not drawn by the engine`, "use 'tail' or 'clip'; the engine draws 'head' and 'middle' as 'tail'."), modeAttribute);
|
|
173
175
|
}
|
|
174
176
|
assigns.push({
|
|
175
177
|
field: 'ellipsize_mode',
|
|
176
|
-
|
|
178
|
+
value: ELLIPSIZE_MODES[mode],
|
|
177
179
|
});
|
|
178
180
|
}
|
|
179
181
|
return assigns;
|
|
@@ -181,32 +183,32 @@ function lowerTextTruncation(openingElement, scope) {
|
|
|
181
183
|
/**
|
|
182
184
|
* An attribute's value, which must fold; the error is pinned to the attribute.
|
|
183
185
|
*
|
|
184
|
-
* @param
|
|
186
|
+
* @param attribute The attribute.
|
|
185
187
|
* @param scope Compile-time constants in reach.
|
|
186
188
|
* @param message The error when it does not fold.
|
|
187
189
|
*
|
|
188
190
|
* @returns The folded value.
|
|
189
191
|
*/
|
|
190
|
-
function foldAttr(
|
|
192
|
+
function foldAttr(attribute, scope, message) {
|
|
191
193
|
try {
|
|
192
|
-
return evalStaticOrThrow(attrExpr(
|
|
194
|
+
return evalStaticOrThrow(attrExpr(attribute), scope, message);
|
|
193
195
|
}
|
|
194
196
|
catch (error) {
|
|
195
|
-
throw at(error,
|
|
197
|
+
throw at(error, attribute);
|
|
196
198
|
}
|
|
197
199
|
}
|
|
198
200
|
/**
|
|
199
201
|
* A folded `activeOpacity` as a number in 0..1. Everything else is an error HERE, where the source line
|
|
200
|
-
* is still in reach: it would otherwise reach
|
|
201
|
-
*
|
|
202
|
-
* `activeOpacity` is `true`, so
|
|
202
|
+
* is still in reach: it would otherwise reach floatConstant and land in the package as a value that
|
|
203
|
+
* is not a number, or quietly means something the app never asked for — a bare
|
|
204
|
+
* `activeOpacity` is `true`, so 1, which is not dim at all; `{false}` is an invisible one.
|
|
203
205
|
*
|
|
204
206
|
* @param value The folded value.
|
|
205
|
-
* @param
|
|
207
|
+
* @param attribute The attribute, for the error's location.
|
|
206
208
|
*
|
|
207
209
|
* @returns The opacity.
|
|
208
210
|
*/
|
|
209
|
-
function opacityLiteralOrThrow(value,
|
|
211
|
+
function opacityLiteralOrThrow(value, attribute) {
|
|
210
212
|
if (typeof value !== 'number' ||
|
|
211
213
|
!Number.isFinite(value) ||
|
|
212
214
|
value < 0 ||
|
|
@@ -216,8 +218,8 @@ function opacityLiteralOrThrow(value, attr) {
|
|
|
216
218
|
? String(value)
|
|
217
219
|
: (JSON.stringify(value) ?? String(value));
|
|
218
220
|
const error = aotError(`AOT: <TouchableOpacity activeOpacity> must be a number between 0 and 1 (got ${shown})`, 'it is the opacity the node dims to while held — 0 is invisible, 1 is no dim at all. RN defaults it to 0.2.');
|
|
219
|
-
if (
|
|
220
|
-
error.aotLoc =
|
|
221
|
+
if (attribute.loc) {
|
|
222
|
+
error.aotLoc = attribute.loc.start;
|
|
221
223
|
}
|
|
222
224
|
throw error;
|
|
223
225
|
}
|
|
@@ -233,43 +235,45 @@ function opacityLiteralOrThrow(value, attr) {
|
|
|
233
235
|
* @param element The <TouchableOpacity>.
|
|
234
236
|
* @param nodeId The node's variable.
|
|
235
237
|
* @param staticAssigns The style's constant writes.
|
|
236
|
-
* @param
|
|
238
|
+
* @param dynamicAssigns The style's state-driven writes.
|
|
237
239
|
* @param binds The style's animated-value binds.
|
|
238
|
-
* @param
|
|
240
|
+
* @param output Everything emitted so far.
|
|
239
241
|
* @param scope Compile-time constants in reach.
|
|
240
242
|
*
|
|
241
243
|
* @returns The opacity bind, and the fade to run on onPressIn and the one to run on onPressOut.
|
|
242
244
|
*/
|
|
243
|
-
function touchablePressFades(element, nodeId, staticAssigns,
|
|
245
|
+
function touchablePressFades(element, nodeId, staticAssigns, dynamicAssigns, binds, output, scope) {
|
|
244
246
|
// The press feedback owns the node's opacity, so the style may not animate it or drive it from state.
|
|
245
247
|
const hasAnimatedOpacity = binds.some(bind => bind.prop === 'ER_PROP_OPACITY');
|
|
246
248
|
if (hasAnimatedOpacity ||
|
|
247
|
-
|
|
249
|
+
dynamicAssigns.some(assign => assign.field === 'opacity')) {
|
|
248
250
|
throw aotError(`AOT: <TouchableOpacity> cannot take ${hasAnimatedOpacity ? 'an Animated' : 'a state-driven'} opacity`, "the press feedback owns this node's opacity — a second writer does not blend with " +
|
|
249
251
|
'it, it races it. To animate opacity yourself, use <Pressable>: the dim is just ' +
|
|
250
252
|
'onPressIn/onPressOut driving an Animated.Value (see TouchableOpacity.js for the ' +
|
|
251
253
|
'whole of it).');
|
|
252
254
|
}
|
|
253
|
-
// lowerStyle scaled static opacity to 0–255 (the resting value);
|
|
255
|
+
// lowerStyle scaled static opacity to 0–255 (the resting value); a NaN one is refused later.
|
|
254
256
|
const opacityAssign = staticAssigns.find(assign => assign.field === 'opacity');
|
|
255
|
-
const restingRaw = opacityAssign
|
|
257
|
+
const restingRaw = opacityAssign
|
|
258
|
+
? Number(opacityAssign.value) / OPACITY_OPAQUE
|
|
259
|
+
: 1;
|
|
256
260
|
const restingOpacity = Number.isFinite(restingRaw) ? restingRaw : 1;
|
|
257
261
|
// The dim target: a folded activeOpacity, or RN's default.
|
|
258
|
-
const
|
|
259
|
-
const activeOpacity =
|
|
260
|
-
? opacityLiteralOrThrow(evalStaticOrThrow(attrExpr(
|
|
262
|
+
const activeAttribute = namedAttr(element.openingElement, 'activeOpacity');
|
|
263
|
+
const activeOpacity = activeAttribute
|
|
264
|
+
? opacityLiteralOrThrow(evalStaticOrThrow(attrExpr(activeAttribute), scope, 'AOT: <TouchableOpacity activeOpacity> must be a compile-time constant', 'the dim target is baked into the handler, so it cannot come from state.'), activeAttribute)
|
|
261
265
|
: TOUCHABLE_ACTIVE_OPACITY;
|
|
262
266
|
// Bind a fresh animated value, starting at rest, to the node's opacity.
|
|
263
|
-
const
|
|
267
|
+
const slotName = `anim_press_${nodeId}`;
|
|
264
268
|
checkNumber(restingOpacity);
|
|
265
|
-
|
|
269
|
+
output.childAnimations.push({ slotName, initial: restingOpacity });
|
|
266
270
|
// Each fade is one timing animation of that value.
|
|
267
271
|
return {
|
|
268
|
-
bind: {
|
|
272
|
+
bind: { slotName, prop: 'ER_PROP_OPACITY' },
|
|
269
273
|
fades: {
|
|
270
|
-
onPressIn: { value:
|
|
274
|
+
onPressIn: { value: slotName, opacity: activeOpacity, durationMs: 0 },
|
|
271
275
|
onPressOut: {
|
|
272
|
-
value:
|
|
276
|
+
value: slotName,
|
|
273
277
|
opacity: restingOpacity,
|
|
274
278
|
durationMs: TOUCHABLE_RESTORE_MS,
|
|
275
279
|
},
|
|
@@ -297,7 +301,7 @@ function applyShow(node, show) {
|
|
|
297
301
|
value: {
|
|
298
302
|
kind: 'whileShown',
|
|
299
303
|
show,
|
|
300
|
-
value: { kind: 'constant',
|
|
304
|
+
value: { kind: 'constant', value: visible.value },
|
|
301
305
|
},
|
|
302
306
|
});
|
|
303
307
|
return;
|
|
@@ -309,77 +313,86 @@ function applyShow(node, show) {
|
|
|
309
313
|
* Lowers an event prop's function to a handler: a useCallback compiles once per instance and is shared, a
|
|
310
314
|
* callback prop compiles in its caller's environment, and an inline function compiles where it is.
|
|
311
315
|
*
|
|
312
|
-
* @param
|
|
313
|
-
* @param
|
|
314
|
-
* @param
|
|
316
|
+
* @param attribute The event prop.
|
|
317
|
+
* @param output Everything emitted so far.
|
|
318
|
+
* @param environment The expression environment.
|
|
315
319
|
* @param state The component's state table.
|
|
316
320
|
*
|
|
317
321
|
* @returns The handler's name.
|
|
318
322
|
*/
|
|
319
|
-
export function lowerEventHandler(
|
|
320
|
-
const
|
|
321
|
-
const layout =
|
|
322
|
-
if (
|
|
323
|
+
export function lowerEventHandler(attribute, output, environment, state) {
|
|
324
|
+
const handlerExpression = attrExpr(attribute);
|
|
325
|
+
const layout = attribute.name.name === 'onLayout';
|
|
326
|
+
if (handlerExpression.type === 'Identifier' &&
|
|
327
|
+
environment.callbacks?.has(handlerExpression.name)) {
|
|
323
328
|
// A useCallback compiles to one shared handler, namespaced by cbPrefix so each child instance gets its own.
|
|
324
329
|
// Its onLayout use gets a handler of its own, since only that event carries the layout rect. The key's
|
|
325
|
-
// `layout:` and the name's `
|
|
326
|
-
const callbackKey = `${
|
|
330
|
+
// `layout:` and the name's `layout_callback_` can't come from an identifier, so they never meet another callback.
|
|
331
|
+
const callbackKey = `${environment.callbackPrefix ?? ''}${handlerExpression.name}`;
|
|
327
332
|
const emittedKey = layout ? `layout:${callbackKey}` : callbackKey;
|
|
328
|
-
let handlerName =
|
|
333
|
+
let handlerName = output.emittedCallbacks.get(emittedKey);
|
|
329
334
|
if (!handlerName) {
|
|
330
|
-
handlerName = `${layout ? '
|
|
331
|
-
|
|
332
|
-
|
|
335
|
+
handlerName = `${layout ? 'layout_callback_' : 'callback_'}${callbackKey}`;
|
|
336
|
+
output.emittedCallbacks.set(emittedKey, handlerName);
|
|
337
|
+
output.handlers.push({
|
|
333
338
|
kind: 'callback',
|
|
334
339
|
name: handlerName,
|
|
335
|
-
callback: lowerHandler(
|
|
340
|
+
callback: lowerHandler(environment.callbacks.get(handlerExpression.name), { ...environment, layout }, state, output),
|
|
336
341
|
});
|
|
337
342
|
}
|
|
338
343
|
return handlerName;
|
|
339
344
|
}
|
|
340
|
-
const handlerName = `
|
|
341
|
-
if (
|
|
345
|
+
const handlerName = `handler_${output.handlers.length}`;
|
|
346
|
+
if (handlerExpression.type === 'Identifier' &&
|
|
347
|
+
environment.functionProps?.has(handlerExpression.name)) {
|
|
342
348
|
// Inline a callback prop's function, compiled in the caller's env/state so its setters and locals resolve.
|
|
343
|
-
const callbackProp =
|
|
344
|
-
|
|
349
|
+
const callbackProp = environment.functionProps.get(handlerExpression.name);
|
|
350
|
+
output.handlers.push({
|
|
345
351
|
kind: 'callback',
|
|
346
352
|
name: handlerName,
|
|
347
|
-
callback: lowerHandler(callbackProp.node, { ...callbackProp.
|
|
353
|
+
callback: lowerHandler(callbackProp.node, { ...callbackProp.environment, layout }, callbackProp.state, output),
|
|
348
354
|
});
|
|
349
355
|
}
|
|
350
|
-
else if (isFn(
|
|
351
|
-
|
|
356
|
+
else if (isFn(handlerExpression)) {
|
|
357
|
+
output.handlers.push({
|
|
352
358
|
kind: 'callback',
|
|
353
359
|
name: handlerName,
|
|
354
|
-
callback: lowerHandler(
|
|
360
|
+
callback: lowerHandler(handlerExpression, { ...environment, layout }, state, output),
|
|
355
361
|
});
|
|
356
362
|
}
|
|
357
363
|
else {
|
|
358
|
-
throw aotError(`AOT: ${
|
|
364
|
+
throw aotError(`AOT: ${attribute.name.name} must be an inline function, a useCallback, or a callback prop`, `pass an inline arrow (onPress={() => setX(…)}), a useCallback identifier, or a ` +
|
|
359
365
|
`function prop received by this component.`);
|
|
360
366
|
}
|
|
361
367
|
return handlerName;
|
|
362
368
|
}
|
|
363
369
|
/**
|
|
364
370
|
* Lowers one JSX element to its engine node (see emitNode, the located entry point): dispatches the typed
|
|
365
|
-
* elements (Svg, Switch, Dial, TextInput, ActivityIndicator, Modal,
|
|
366
|
-
* their emitters, and builds a generic host node (View / Text / Pressable / TouchableOpacity / Image /
|
|
371
|
+
* elements (Svg, Switch, Dial, TextInput, ActivityIndicator, Modal), the wrappers (FlatList, SectionList,
|
|
372
|
+
* Button, ImageBackground) and function components to their emitters, and builds a generic host node (View / Text / Pressable / TouchableOpacity / Image /
|
|
367
373
|
* ScrollView) itself: style, text, events, refs, and children.
|
|
368
374
|
*
|
|
369
375
|
* @param element The element.
|
|
370
376
|
* @param scope Compile-time constants in reach.
|
|
371
|
-
* @param
|
|
372
|
-
* @param
|
|
377
|
+
* @param output Everything emitted so far.
|
|
378
|
+
* @param environment The expression environment.
|
|
373
379
|
* @param state The component's state table.
|
|
374
|
-
* @param
|
|
380
|
+
* @param options How the element is placed.
|
|
375
381
|
*
|
|
376
382
|
* @returns What the element lowered to.
|
|
377
383
|
*/
|
|
378
|
-
function emitNodeImpl(element, scope,
|
|
384
|
+
function emitNodeImpl(element, scope, output, environment, state, options = {}) {
|
|
385
|
+
// A context's provider stands for the one element it wraps.
|
|
386
|
+
const context = providedContextOf(element, environment);
|
|
387
|
+
if (context) {
|
|
388
|
+
return emitProvider(element, context, scope, output, environment, state, options);
|
|
389
|
+
}
|
|
379
390
|
// Refuse any prop the element does not declare, whatever its value, then drop the no-ops and the props that
|
|
380
391
|
// fold to undefined before dispatch.
|
|
392
|
+
// A component in this file wins over a built-in that is no host node, as its binding would in JS.
|
|
381
393
|
const tag = resolveTag(element.openingElement);
|
|
382
|
-
const
|
|
394
|
+
const localComponent = !NODE_TYPES[tag] && output.components.has(tag);
|
|
395
|
+
const spec = localComponent ? undefined : elementSpec(tag);
|
|
383
396
|
if (spec) {
|
|
384
397
|
checkAttributes(spec, element.openingElement);
|
|
385
398
|
if (spec.children === 'none') {
|
|
@@ -387,45 +400,48 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
|
|
|
387
400
|
}
|
|
388
401
|
element = withoutPlatformNoOps(spec, element);
|
|
389
402
|
}
|
|
390
|
-
element = omitUndefinedAttrs(element, scope,
|
|
403
|
+
element = omitUndefinedAttrs(element, scope, environment);
|
|
391
404
|
const typed = (node) => {
|
|
392
|
-
if (
|
|
393
|
-
applyShow(node,
|
|
405
|
+
if (options.show) {
|
|
406
|
+
applyShow(node, options.show);
|
|
394
407
|
}
|
|
395
408
|
return { kind: 'node', id: node.id, node };
|
|
396
409
|
};
|
|
410
|
+
if (localComponent) {
|
|
411
|
+
return emitComponent(element, scope, output, environment, state, options);
|
|
412
|
+
}
|
|
397
413
|
if (tag === 'Svg') {
|
|
398
|
-
return typed(emitSvg(element, scope,
|
|
414
|
+
return typed(emitSvg(element, scope, output, environment, state, options));
|
|
399
415
|
}
|
|
400
416
|
if (tag === 'Switch') {
|
|
401
|
-
return typed(emitSwitch(element, scope,
|
|
417
|
+
return typed(emitSwitch(element, scope, output, environment, state));
|
|
402
418
|
}
|
|
403
419
|
if (tag === 'Dial')
|
|
404
|
-
return typed(emitDial(element, scope,
|
|
420
|
+
return typed(emitDial(element, scope, output, environment, state));
|
|
405
421
|
if (tag === 'TextInput') {
|
|
406
|
-
return typed(emitTextInput(element, scope,
|
|
422
|
+
return typed(emitTextInput(element, scope, output, environment, state));
|
|
407
423
|
}
|
|
408
424
|
if (tag === 'ActivityIndicator') {
|
|
409
|
-
return typed(emitActivityIndicator(element, scope,
|
|
425
|
+
return typed(emitActivityIndicator(element, scope, output, environment));
|
|
410
426
|
}
|
|
411
427
|
if (tag === 'Modal') {
|
|
412
|
-
return typed(emitModal(element, scope,
|
|
428
|
+
return typed(emitModal(element, scope, output, environment, state));
|
|
413
429
|
}
|
|
414
430
|
if (tag === 'FlatList') {
|
|
415
|
-
return emitFlatList(element, scope,
|
|
431
|
+
return emitFlatList(element, scope, output, environment, state, options);
|
|
432
|
+
}
|
|
433
|
+
if (tag === 'SectionList') {
|
|
434
|
+
return emitSectionList(element, scope, output, environment, state, options);
|
|
435
|
+
}
|
|
436
|
+
if (tag === 'Button') {
|
|
437
|
+
return emitButton(element, scope, output, environment, state, options);
|
|
416
438
|
}
|
|
417
|
-
|
|
439
|
+
if (tag === 'ImageBackground') {
|
|
440
|
+
return emitImageBackground(element, scope, output, environment, state, options);
|
|
441
|
+
}
|
|
442
|
+
// Anything else must be a host node.
|
|
418
443
|
const nodeType = NODE_TYPES[tag];
|
|
419
444
|
if (!nodeType) {
|
|
420
|
-
if (out.components.has(tag)) {
|
|
421
|
-
return emitComponent(element, scope, out, env, state, opts);
|
|
422
|
-
}
|
|
423
|
-
// A package export with no lowering yet gets its own error; "unknown element" would read like a typo.
|
|
424
|
-
const replacement = FLOW_A_ONLY_COMPONENTS[tag];
|
|
425
|
-
if (replacement) {
|
|
426
|
-
throw aotError(`AOT: <${tag}> is not supported in Flow B yet`, `it renders in Flow A (the simulator and the QuickJS runtime) but the AOT has no ` +
|
|
427
|
-
`lowering for it. Write it out by hand for the device build: ${replacement}`);
|
|
428
|
-
}
|
|
429
445
|
throw aotError(`AOT: unknown element <${tag}> (not a built-in or a component in this file)`, `<${tag}> must be a built-in (View / Text / Pressable / TouchableOpacity / Image / ` +
|
|
430
446
|
`ScrollView / Svg + shapes / Animated.*) or a function component defined in THIS ` +
|
|
431
447
|
`file. Check the import / spelling or define the component here.`);
|
|
@@ -440,7 +456,7 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
|
|
|
440
456
|
continue;
|
|
441
457
|
let panResponder;
|
|
442
458
|
try {
|
|
443
|
-
panResponder = panSpreadTarget(spread.argument,
|
|
459
|
+
panResponder = panSpreadTarget(spread.argument, environment);
|
|
444
460
|
}
|
|
445
461
|
catch (error) {
|
|
446
462
|
if (spread.loc && !error.aotLoc) {
|
|
@@ -462,62 +478,68 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
|
|
|
462
478
|
throw spreadError;
|
|
463
479
|
}
|
|
464
480
|
// Allocate the node and collect its style, text content, and image attributes.
|
|
465
|
-
const nodeId = `n${
|
|
466
|
-
const { staticAssigns,
|
|
481
|
+
const nodeId = `n${output.allocateNodeId()}`;
|
|
482
|
+
const { staticAssigns, dynamicAssigns, binds } = collectStyleAssigns(element.openingElement, scope, environment, spec);
|
|
467
483
|
if (tag === 'Text') {
|
|
468
484
|
staticAssigns.push(...lowerTextTruncation(element.openingElement, scope));
|
|
469
485
|
}
|
|
470
486
|
// A <Text> with a nested <Text> becomes inline SPANS; otherwise a single (possibly dynamic) string.
|
|
471
|
-
const spans = tag === 'Text'
|
|
487
|
+
const spans = tag === 'Text'
|
|
488
|
+
? collectTextSpans(element.children, scope, environment)
|
|
489
|
+
: null;
|
|
472
490
|
const text = tag === 'Text' && !spans
|
|
473
|
-
? lowerNodeText(element.children, scope,
|
|
491
|
+
? lowerNodeText(element.children, scope, environment)
|
|
474
492
|
: null;
|
|
475
493
|
if (text) {
|
|
476
494
|
checkEngineString(constantText(text), 'ER_TEXT_MAX', 'a <Text>');
|
|
477
495
|
}
|
|
478
496
|
// An <Image>'s resize/tint are static, so fold them into staticAssigns for both the static and dynamic paths.
|
|
479
|
-
const image = tag === 'Image' ? resolveImageAttrs(element,
|
|
497
|
+
const image = tag === 'Image' ? resolveImageAttrs(element, environment, output) : null;
|
|
480
498
|
checkEngineString(image?.imageName ?? null, 'ER_IMAGE_NAME_MAX', `image name "${image?.imageName}"`);
|
|
481
499
|
if (image?.resizeMode) {
|
|
482
|
-
staticAssigns.push({ field: 'resize_mode',
|
|
500
|
+
staticAssigns.push({ field: 'resize_mode', value: image.resizeMode });
|
|
483
501
|
}
|
|
484
502
|
if (image?.tintColor) {
|
|
485
|
-
staticAssigns.push({ field: 'tint_color',
|
|
503
|
+
staticAssigns.push({ field: 'tint_color', value: image.tintColor });
|
|
486
504
|
}
|
|
487
505
|
// `visible` is `display` as in Flow A (style `display` wins); not in collectStyleAssigns, which <Modal> shares.
|
|
488
|
-
const
|
|
489
|
-
|
|
506
|
+
const visibleAttribute = element.openingElement.attributes.find((attribute) => attribute.type === 'JSXAttribute' &&
|
|
507
|
+
attribute.name &&
|
|
508
|
+
attribute.name.name === 'visible');
|
|
509
|
+
if (visibleAttribute &&
|
|
490
510
|
!staticAssigns.some(assign => assign.field === 'display') &&
|
|
491
|
-
!
|
|
492
|
-
const
|
|
493
|
-
if (
|
|
494
|
-
staticAssigns.push({ field: 'display',
|
|
511
|
+
!dynamicAssigns.some(assign => assign.field === 'display')) {
|
|
512
|
+
const expression = visibleAttribute.value == null ? null : attrExpr(visibleAttribute); // bare `visible` === true
|
|
513
|
+
if (expression == null) {
|
|
514
|
+
staticAssigns.push({ field: 'display', value: 'ER_DISPLAY_FLEX' });
|
|
495
515
|
}
|
|
496
516
|
else {
|
|
497
517
|
try {
|
|
498
518
|
staticAssigns.push({
|
|
499
519
|
field: 'display',
|
|
500
|
-
|
|
520
|
+
value: evalStatic(expression, scope)
|
|
521
|
+
? 'ER_DISPLAY_FLEX'
|
|
522
|
+
: 'ER_DISPLAY_NONE',
|
|
501
523
|
});
|
|
502
524
|
}
|
|
503
525
|
catch {
|
|
504
|
-
|
|
526
|
+
dynamicAssigns.push({
|
|
505
527
|
field: 'display',
|
|
506
|
-
value: { kind: 'visible', value: lowerExpr(
|
|
528
|
+
value: { kind: 'visible', value: lowerExpr(expression, environment) },
|
|
507
529
|
});
|
|
508
530
|
}
|
|
509
531
|
}
|
|
510
532
|
}
|
|
511
533
|
// delayLongPress must fold since it is baked into props; 0 becomes 1 ms because 0 means "default" to the engine.
|
|
512
|
-
const
|
|
513
|
-
if (
|
|
534
|
+
const delayAttribute = namedAttr(element.openingElement, 'delayLongPress');
|
|
535
|
+
if (delayAttribute) {
|
|
514
536
|
const delayError = aotError(`AOT: <${tag} delayLongPress> must fold to a number`, 'pass a literal or a module-level constant in milliseconds, e.g. delayLongPress={800}.');
|
|
515
|
-
if (
|
|
537
|
+
if (delayAttribute.value == null) {
|
|
516
538
|
throw delayError;
|
|
517
539
|
}
|
|
518
540
|
let delayMs;
|
|
519
541
|
try {
|
|
520
|
-
delayMs = Number(evalStatic(attrExpr(
|
|
542
|
+
delayMs = Number(evalStatic(attrExpr(delayAttribute), scope));
|
|
521
543
|
}
|
|
522
544
|
catch {
|
|
523
545
|
throw delayError;
|
|
@@ -527,19 +549,19 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
|
|
|
527
549
|
}
|
|
528
550
|
staticAssigns.push({
|
|
529
551
|
field: 'long_press_ms',
|
|
530
|
-
|
|
552
|
+
value: Math.min(MAX_LONG_PRESS_MS, Math.max(1, Math.round(delayMs))),
|
|
531
553
|
});
|
|
532
554
|
}
|
|
533
|
-
// A state-driven conditional flips `display` in
|
|
534
|
-
if (
|
|
535
|
-
|
|
555
|
+
// A state-driven conditional flips `display` in the update; pushed last to beat the element's visible/display.
|
|
556
|
+
if (options.show) {
|
|
557
|
+
dynamicAssigns.push({
|
|
536
558
|
field: 'display',
|
|
537
|
-
value: { kind: 'shown', show:
|
|
559
|
+
value: { kind: 'shown', show: options.show },
|
|
538
560
|
});
|
|
539
561
|
}
|
|
540
562
|
// <TouchableOpacity>'s own opacity binding, on top of any the style asked for.
|
|
541
563
|
const press = tag === 'TouchableOpacity' && !isPressDisabled
|
|
542
|
-
? touchablePressFades(element, nodeId, staticAssigns,
|
|
564
|
+
? touchablePressFades(element, nodeId, staticAssigns, dynamicAssigns, binds, output, scope)
|
|
543
565
|
: null;
|
|
544
566
|
// A host node wires its binds (the press feedback's last), then its refs, events and PanResponders.
|
|
545
567
|
const wiring = binds.map((bind, index) => ({
|
|
@@ -550,18 +572,19 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
|
|
|
550
572
|
if (press) {
|
|
551
573
|
wiring.push({ kind: 'bind', bind: press.bind, index: binds.length });
|
|
552
574
|
}
|
|
553
|
-
for (const slot of lowerRefBinds(element.openingElement,
|
|
575
|
+
for (const slot of lowerRefBinds(element.openingElement, environment)) {
|
|
554
576
|
wiring.push({ kind: 'ref', slot });
|
|
555
577
|
}
|
|
556
578
|
const node = {
|
|
557
579
|
id: nodeId,
|
|
580
|
+
location: currentLoc(),
|
|
558
581
|
type: nodeType,
|
|
559
582
|
constantProps: staticAssigns,
|
|
560
|
-
stateProps:
|
|
583
|
+
stateProps: dynamicAssigns,
|
|
561
584
|
placeholder: null,
|
|
562
585
|
text,
|
|
563
|
-
image: image?.
|
|
564
|
-
? { kind: 'value', value: image.
|
|
586
|
+
image: image?.imageNameDynamic != null
|
|
587
|
+
? { kind: 'value', value: image.imageNameDynamic }
|
|
565
588
|
: image?.imageName != null
|
|
566
589
|
? { kind: 'static', name: image.imageName }
|
|
567
590
|
: null,
|
|
@@ -571,29 +594,29 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
|
|
|
571
594
|
};
|
|
572
595
|
// Compile each event prop into a handler; a disabled one drops its press events.
|
|
573
596
|
const fadesWired = new Set();
|
|
574
|
-
for (const
|
|
575
|
-
if (
|
|
597
|
+
for (const attribute of element.openingElement.attributes) {
|
|
598
|
+
if (attribute.type !== 'JSXAttribute')
|
|
576
599
|
continue;
|
|
577
|
-
const eventType = EVENT_TYPES[
|
|
600
|
+
const eventType = EVENT_TYPES[attribute.name.name];
|
|
578
601
|
if (!eventType)
|
|
579
602
|
continue;
|
|
580
603
|
if (isPressDisabled &&
|
|
581
|
-
PRESS_EVENTS.has(
|
|
604
|
+
PRESS_EVENTS.has(attribute.name.name)) {
|
|
582
605
|
continue;
|
|
583
606
|
}
|
|
584
|
-
let handlerName = lowerEventHandler(
|
|
607
|
+
let handlerName = lowerEventHandler(attribute, output, environment, state);
|
|
585
608
|
// Wrap the app's press-in/out with the fade; prepending would dim every other element sharing a useCallback.
|
|
586
|
-
const pressFade = press?.fades[
|
|
609
|
+
const pressFade = press?.fades[attribute.name.name];
|
|
587
610
|
if (pressFade) {
|
|
588
|
-
const wrapperName = `
|
|
589
|
-
|
|
611
|
+
const wrapperName = `handler_${output.handlers.length}`;
|
|
612
|
+
output.handlers.push({
|
|
590
613
|
kind: 'pressFade',
|
|
591
614
|
name: wrapperName,
|
|
592
615
|
fade: pressFade,
|
|
593
616
|
then: handlerName,
|
|
594
617
|
});
|
|
595
618
|
handlerName = wrapperName;
|
|
596
|
-
fadesWired.add(
|
|
619
|
+
fadesWired.add(attribute.name.name);
|
|
597
620
|
}
|
|
598
621
|
wiring.push({ kind: 'event', event: eventType, handler: handlerName });
|
|
599
622
|
}
|
|
@@ -602,8 +625,8 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
|
|
|
602
625
|
for (const eventName of ['onPressIn', 'onPressOut']) {
|
|
603
626
|
if (fadesWired.has(eventName))
|
|
604
627
|
continue;
|
|
605
|
-
const fadeHandlerName = `
|
|
606
|
-
|
|
628
|
+
const fadeHandlerName = `handler_${output.handlers.length}`;
|
|
629
|
+
output.handlers.push({
|
|
607
630
|
kind: 'pressFade',
|
|
608
631
|
name: fadeHandlerName,
|
|
609
632
|
fade: press.fades[eventName],
|
|
@@ -620,13 +643,13 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
|
|
|
620
643
|
for (const panResponder of panSpreads) {
|
|
621
644
|
wiring.push({
|
|
622
645
|
kind: 'responder',
|
|
623
|
-
pan: emitPanResponder(panResponder,
|
|
646
|
+
pan: emitPanResponder(panResponder, output, environment, state),
|
|
624
647
|
});
|
|
625
648
|
}
|
|
626
649
|
checkInterpolations(node);
|
|
627
650
|
// A <Text>'s children are its text, already consumed above.
|
|
628
651
|
if (tag !== 'Text') {
|
|
629
|
-
node.children = emitChildren(element.children, scope,
|
|
652
|
+
node.children = emitChildren(element.children, scope, output, environment, state);
|
|
630
653
|
}
|
|
631
654
|
return { kind: 'node', id: nodeId, node };
|
|
632
655
|
}
|
|
@@ -640,24 +663,24 @@ function emitNodeImpl(element, scope, out, env, state, opts = {}) {
|
|
|
640
663
|
*
|
|
641
664
|
* @param element The element.
|
|
642
665
|
* @param scope Compile-time constants in reach.
|
|
643
|
-
* @param
|
|
666
|
+
* @param environment The expression environment.
|
|
644
667
|
*
|
|
645
668
|
* @returns The element, or a copy of it without those attributes.
|
|
646
669
|
*/
|
|
647
|
-
function omitUndefinedAttrs(element, scope,
|
|
648
|
-
const
|
|
670
|
+
function omitUndefinedAttrs(element, scope, environment) {
|
|
671
|
+
const attributes = element.openingElement.attributes;
|
|
649
672
|
// Built lazily: the runtime-aware scope plus the global `undefined`, so `SHOW ? true : undefined` folds too.
|
|
650
673
|
let foldingScope = null;
|
|
651
|
-
const
|
|
652
|
-
if (
|
|
653
|
-
|
|
674
|
+
const keptAttributes = attributes.filter(attribute => {
|
|
675
|
+
if (attribute.type !== 'JSXAttribute' ||
|
|
676
|
+
attribute.value?.type !== 'JSXExpressionContainer') {
|
|
654
677
|
return true;
|
|
655
678
|
}
|
|
656
|
-
foldingScope ??= Object.assign(Object.create(foldScope(
|
|
679
|
+
foldingScope ??= Object.assign(Object.create(foldScope(environment, scope)), {
|
|
657
680
|
undefined,
|
|
658
681
|
});
|
|
659
682
|
try {
|
|
660
|
-
const value = evalStatic(
|
|
683
|
+
const value = evalStatic(attribute.value.expression, foldingScope, 'boot');
|
|
661
684
|
if (buildValueOf(value) !== undefined)
|
|
662
685
|
return true;
|
|
663
686
|
foldBoot(value); // undefined on this panel only: omitting it assumes the panel
|
|
@@ -667,26 +690,26 @@ function omitUndefinedAttrs(element, scope, env) {
|
|
|
667
690
|
return true; // not a compile-time value — its reader decides
|
|
668
691
|
}
|
|
669
692
|
});
|
|
670
|
-
return
|
|
693
|
+
return keptAttributes.length === attributes.length
|
|
671
694
|
? element
|
|
672
695
|
: {
|
|
673
696
|
...element,
|
|
674
|
-
openingElement: { ...element.openingElement, attributes:
|
|
697
|
+
openingElement: { ...element.openingElement, attributes: keptAttributes },
|
|
675
698
|
};
|
|
676
699
|
}
|
|
677
700
|
/**
|
|
678
|
-
* Refuses an interpolation table holding a number
|
|
701
|
+
* Refuses an interpolation table holding a number that isn't finite, at the element that binds it rather than when
|
|
679
702
|
* its build lines are written.
|
|
680
703
|
*
|
|
681
704
|
* @param node The node.
|
|
682
705
|
*/
|
|
683
706
|
export function checkInterpolations(node) {
|
|
684
707
|
for (const wire of node.wiring) {
|
|
685
|
-
if (wire.kind !== 'bind' || !wire.bind.
|
|
708
|
+
if (wire.kind !== 'bind' || !wire.bind.interpolation)
|
|
686
709
|
continue;
|
|
687
710
|
for (const point of [
|
|
688
|
-
...wire.bind.
|
|
689
|
-
...wire.bind.
|
|
711
|
+
...wire.bind.interpolation.input,
|
|
712
|
+
...wire.bind.interpolation.output,
|
|
690
713
|
]) {
|
|
691
714
|
checkNumber(point);
|
|
692
715
|
}
|