embedded-react 0.18.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/NOTICE +1 -1
- package/README.md +8 -4
- 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 +55 -41
- 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 +14 -10
- package/assets/emit-c.mjs +83 -62
- package/assets/emit-container.mjs +124 -38
- 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 +16 -14
- package/cli.mjs +359 -172
- package/compile-bin.mjs +5 -5
- 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 +51 -38
- package/hotreload/uploader.mjs +38 -27
- package/hotreload/watch-tree.mjs +19 -19
- package/pack-container.mjs +31 -23
- package/package.json +11 -12
- 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 +4 -4
- 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
|
@@ -31,37 +31,37 @@ import { emitNode } from '../nodes.mjs';
|
|
|
31
31
|
*
|
|
32
32
|
* @param element The <FlatList>.
|
|
33
33
|
* @param scope Compile-time constants in reach.
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
34
|
+
* @param output Everything emitted so far.
|
|
35
|
+
* @param environment The expression environment.
|
|
36
36
|
* @param state The component's state table.
|
|
37
|
-
* @param
|
|
37
|
+
* @param options How the element is placed.
|
|
38
38
|
*
|
|
39
39
|
* @returns The variable of the <ScrollView> node it lowers to.
|
|
40
40
|
*/
|
|
41
|
-
export function emitFlatList(element, scope,
|
|
41
|
+
export function emitFlatList(element, scope, output, environment, state, options) {
|
|
42
42
|
// Collect the supported <FlatList> props, rejecting anything the AOT rewrite cannot statically lower.
|
|
43
43
|
let dataNode = null;
|
|
44
44
|
let renderItem = null;
|
|
45
|
-
let
|
|
46
|
-
for (const
|
|
45
|
+
let styleAttribute = null;
|
|
46
|
+
for (const attribute of element.openingElement.attributes) {
|
|
47
47
|
// Ensure all props are explicit named attributes.
|
|
48
48
|
// Spread props cannot be analyzed statically
|
|
49
|
-
if (
|
|
49
|
+
if (attribute.type !== 'JSXAttribute') {
|
|
50
50
|
throw aotError('AOT: spread props on <FlatList> are not supported');
|
|
51
51
|
}
|
|
52
52
|
// skip non-props
|
|
53
|
-
const name =
|
|
53
|
+
const name = attribute.name.name;
|
|
54
54
|
if (name === 'keyExtractor' || name === 'key')
|
|
55
55
|
continue;
|
|
56
56
|
// process props
|
|
57
57
|
if (name === 'data') {
|
|
58
|
-
dataNode = attrExpr(
|
|
58
|
+
dataNode = attrExpr(attribute);
|
|
59
59
|
}
|
|
60
60
|
else if (name === 'renderItem') {
|
|
61
|
-
renderItem = attrExpr(
|
|
61
|
+
renderItem = attrExpr(attribute);
|
|
62
62
|
}
|
|
63
63
|
else if (name === 'style') {
|
|
64
|
-
|
|
64
|
+
styleAttribute = attribute;
|
|
65
65
|
}
|
|
66
66
|
else {
|
|
67
67
|
throw aotError(`AOT: <FlatList> prop "${name}" is not supported`, 'supported: data, renderItem, keyExtractor, style. For headers/footers/horizontal/onEndReached etc., use <ScrollView> + .map directly.');
|
|
@@ -74,14 +74,14 @@ export function emitFlatList(element, scope, out, env, state, opts) {
|
|
|
74
74
|
if (!renderItem || !isFn(renderItem)) {
|
|
75
75
|
throw aotError('AOT: <FlatList> needs a renderItem function', 'renderItem={({ item, index }) => <Row item={item} />}');
|
|
76
76
|
}
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
77
|
+
const parameter = renderItem.params[0];
|
|
78
|
+
if (!parameter || parameter.type !== 'ObjectPattern') {
|
|
79
79
|
throw aotError('AOT: FlatList renderItem must destructure ({ item, index })', 'renderItem={({ item }) => <Row item={item} />}');
|
|
80
80
|
}
|
|
81
81
|
// Extract the local item/index names from renderItem's destructured parameter, rejecting any unsupported row fields or patterns.
|
|
82
82
|
let itemName = null;
|
|
83
83
|
let indexName = null;
|
|
84
|
-
for (const prop of
|
|
84
|
+
for (const prop of parameter.properties) {
|
|
85
85
|
if (prop.type !== 'ObjectProperty' || prop.value.type !== 'Identifier') {
|
|
86
86
|
throw aotError('AOT: FlatList renderItem may destructure only item / index (to plain names)');
|
|
87
87
|
}
|
|
@@ -95,18 +95,20 @@ export function emitFlatList(element, scope, out, env, state, opts) {
|
|
|
95
95
|
throw aotError(`AOT: FlatList renderItem cannot destructure "${prop.key.name}" (only item / index)`);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
// Ensure renderItem binds the required item value; index is optional for the
|
|
98
|
+
// Ensure renderItem binds the required item value; index is optional for the map callback.
|
|
99
99
|
if (!itemName) {
|
|
100
100
|
throw aotError('AOT: FlatList renderItem must destructure item', 'renderItem={({ item }) => …}');
|
|
101
101
|
}
|
|
102
102
|
// Rewrite renderItem `({ item, index }) => BODY` → a positional `.map` callback `(item, index) => BODY`.
|
|
103
|
-
const
|
|
103
|
+
const callbackParameters = [
|
|
104
|
+
{ type: 'Identifier', name: itemName },
|
|
105
|
+
];
|
|
104
106
|
if (indexName) {
|
|
105
|
-
|
|
107
|
+
callbackParameters.push({ type: 'Identifier', name: indexName });
|
|
106
108
|
}
|
|
107
|
-
const
|
|
109
|
+
const callback = {
|
|
108
110
|
type: 'ArrowFunctionExpression',
|
|
109
|
-
params:
|
|
111
|
+
params: callbackParameters,
|
|
110
112
|
body: renderItem.body,
|
|
111
113
|
async: false,
|
|
112
114
|
expression: renderItem.body.type !== 'BlockStatement',
|
|
@@ -119,14 +121,14 @@ export function emitFlatList(element, scope, out, env, state, opts) {
|
|
|
119
121
|
property: { type: 'Identifier', name: 'map' },
|
|
120
122
|
computed: false,
|
|
121
123
|
},
|
|
122
|
-
arguments: [
|
|
124
|
+
arguments: [callback],
|
|
123
125
|
};
|
|
124
126
|
const scrollView = {
|
|
125
127
|
type: 'JSXElement',
|
|
126
128
|
openingElement: {
|
|
127
129
|
type: 'JSXOpeningElement',
|
|
128
130
|
name: { type: 'JSXIdentifier', name: 'ScrollView' },
|
|
129
|
-
attributes:
|
|
131
|
+
attributes: styleAttribute ? [styleAttribute] : [],
|
|
130
132
|
selfClosing: false,
|
|
131
133
|
},
|
|
132
134
|
closingElement: {
|
|
@@ -135,5 +137,5 @@ export function emitFlatList(element, scope, out, env, state, opts) {
|
|
|
135
137
|
},
|
|
136
138
|
children: [{ type: 'JSXExpressionContainer', expression: mapCall }],
|
|
137
139
|
};
|
|
138
|
-
return emitNode(scrollView, scope,
|
|
140
|
+
return emitNode(scrollView, scope, output, environment, state, options);
|
|
139
141
|
}
|
|
@@ -20,7 +20,7 @@ import { aotError } from '../diagnostics.mjs';
|
|
|
20
20
|
import { at } from './props.mjs';
|
|
21
21
|
import { evalStatic, evalStaticOr } from '../static-eval.mjs';
|
|
22
22
|
import { lowerExpr } from '../expressions.mjs';
|
|
23
|
-
import { attrExpr,
|
|
23
|
+
import { attrExpr, argbValue } from '../style-text.mjs';
|
|
24
24
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
25
25
|
- Constants
|
|
26
26
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -40,18 +40,18 @@ const RESIZE_MODES = {
|
|
|
40
40
|
* the const scope as their asset-name string, so this folds `wxSun`, `item.icon` (unrolled map), and static
|
|
41
41
|
* ternaries; `{ uri }` is the explicit remote-shape escape.
|
|
42
42
|
*
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
43
|
+
* @param expression The source expression, if there is one.
|
|
44
|
+
* @param environment The expression environment.
|
|
45
45
|
*
|
|
46
46
|
* @returns The asset's name, or null when the source does not fold.
|
|
47
47
|
*/
|
|
48
|
-
export function imageNameFromSource(
|
|
48
|
+
export function imageNameFromSource(expression, environment) {
|
|
49
49
|
// No source expression was provided.
|
|
50
|
-
if (!
|
|
50
|
+
if (!expression)
|
|
51
51
|
return null;
|
|
52
52
|
// Try to resolve the source as a compile-time constant.
|
|
53
53
|
try {
|
|
54
|
-
const value = evalStatic(
|
|
54
|
+
const value = evalStatic(expression, environment.constants ?? {});
|
|
55
55
|
if (typeof value === 'string')
|
|
56
56
|
return value;
|
|
57
57
|
}
|
|
@@ -59,8 +59,8 @@ export function imageNameFromSource(expr, env) {
|
|
|
59
59
|
/* not a compile-time constant — fall through to {uri}, else dynamic */
|
|
60
60
|
}
|
|
61
61
|
// Handle React Native-style object sources: source={{ uri: 'asset_name' }}.
|
|
62
|
-
if (
|
|
63
|
-
const uri =
|
|
62
|
+
if (expression.type === 'ObjectExpression') {
|
|
63
|
+
const uri = expression.properties.find((property) => property.type === 'ObjectProperty' &&
|
|
64
64
|
(property.key.name === 'uri' ||
|
|
65
65
|
property.key.value === 'uri'));
|
|
66
66
|
if (uri?.value?.type === 'StringLiteral')
|
|
@@ -70,82 +70,83 @@ export function imageNameFromSource(expr, env) {
|
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Resolves an <Image>'s source/imageName/resizeMode/tintColor for the node props (static name, a dynamic
|
|
73
|
-
* name expr, resize mode, tint). Records baking intent in `
|
|
74
|
-
* marked used (
|
|
73
|
+
* name expr, resize mode, tint). Records baking intent in `output`: a static name that matches an import is
|
|
74
|
+
* marked used (output.images); a dynamic source flips output.bakeAllImages (its asset can't be enumerated). So
|
|
75
75
|
* only REACHED images are baked — an import used solely in a folded-away branch costs no flash.
|
|
76
76
|
*
|
|
77
77
|
* @param element The <Image>.
|
|
78
|
-
* @param
|
|
79
|
-
* @param
|
|
78
|
+
* @param environment The expression environment.
|
|
79
|
+
* @param output Everything emitted so far.
|
|
80
80
|
*
|
|
81
81
|
* @returns The resolved props.
|
|
82
82
|
*/
|
|
83
|
-
export function resolveImageAttrs(element,
|
|
83
|
+
export function resolveImageAttrs(element, environment, output) {
|
|
84
84
|
// Find the image source prop, preferring imageName over source.
|
|
85
|
-
const
|
|
86
|
-
const find = (
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
const attributes = element.openingElement.attributes;
|
|
86
|
+
const find = (attributeName) => attributes.find((attribute) => attribute.type === 'JSXAttribute' &&
|
|
87
|
+
attribute.name.name === attributeName);
|
|
88
|
+
const imageAttribute = find('imageName');
|
|
89
|
+
const sourceAttribute = find('source');
|
|
90
|
+
const sourceExpression = imageAttribute
|
|
91
|
+
? attrExpr(imageAttribute)
|
|
92
|
+
: sourceAttribute
|
|
93
|
+
? attrExpr(sourceAttribute)
|
|
93
94
|
: null;
|
|
94
95
|
let imageName = null; // static asset name (a literal), OR …
|
|
95
|
-
let
|
|
96
|
+
let imageNameDynamic = null; // … a runtime string (a list-item field / state) set in the update.
|
|
96
97
|
// Resolve static sources immediately and mark imported assets for baking.
|
|
97
|
-
if (
|
|
98
|
-
imageName = imageNameFromSource(
|
|
98
|
+
if (sourceExpression) {
|
|
99
|
+
imageName = imageNameFromSource(sourceExpression, environment);
|
|
99
100
|
if (imageName != null) {
|
|
100
|
-
const path =
|
|
101
|
+
const path = environment.imageNames?.get(imageName); // a baked import (vs. a bare {uri} name the app supplies)
|
|
101
102
|
if (path) {
|
|
102
|
-
|
|
103
|
+
output.images.set(imageName, path);
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
else {
|
|
106
107
|
// Fall back to a dynamic runtime image name when the source cannot be folded.
|
|
107
108
|
// Emits it as a runtime string. The engine resolves it against the image registry by name each frame,
|
|
108
|
-
// so the candidate assets must be baked. They can't be enumerated, so bake them ALL (
|
|
109
|
+
// so the candidate assets must be baked. They can't be enumerated, so bake them ALL (output.bakeAllImages).
|
|
109
110
|
// Only triggered when a dynamic source is actually REACHED.
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
113
|
-
const
|
|
111
|
+
output.bakeAllImages = true;
|
|
112
|
+
const nameExpression = lowerExpr(sourceExpression, environment);
|
|
113
|
+
if (nameExpression.type.kind !== 'string') {
|
|
114
|
+
const error = aotError('AOT: an <Image source> must resolve to an asset NAME (a string)', "use an imported image (`import logo from './logo.png'` → source={logo}), " +
|
|
114
115
|
"a string asset name, source={{ uri: 'name' }}, or a string-valued " +
|
|
115
116
|
'state / list-item field for a dynamic source.');
|
|
116
|
-
if (
|
|
117
|
-
|
|
117
|
+
if (sourceExpression.loc) {
|
|
118
|
+
error.aotLoc = sourceExpression.loc.start;
|
|
118
119
|
}
|
|
119
120
|
{
|
|
120
|
-
throw
|
|
121
|
+
throw error;
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
|
-
|
|
124
|
+
imageNameDynamic = nameExpression;
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
// Resolve the optional resize mode and validate it against the supported engine modes.
|
|
127
128
|
let resizeMode = null;
|
|
128
|
-
const
|
|
129
|
-
if (
|
|
130
|
-
const
|
|
131
|
-
resizeMode = RESIZE_MODES[
|
|
129
|
+
const resizeModeAttribute = find('resizeMode');
|
|
130
|
+
if (resizeModeAttribute) {
|
|
131
|
+
const resizeModeValue = evalStaticOr(attrExpr(resizeModeAttribute), environment, null);
|
|
132
|
+
resizeMode = RESIZE_MODES[resizeModeValue];
|
|
132
133
|
if (!resizeMode) {
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
135
|
-
|
|
134
|
+
const error = aotError(`AOT: unsupported <Image resizeMode> "${resizeModeValue}"`, `resizeMode must be one of: ${Object.keys(RESIZE_MODES).join(' / ')}.`);
|
|
135
|
+
if (resizeModeAttribute.loc) {
|
|
136
|
+
error.aotLoc = resizeModeAttribute.loc.start;
|
|
136
137
|
}
|
|
137
|
-
throw
|
|
138
|
+
throw error;
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
// Resolve the optional tint color into the ARGB literal expected by the engine.
|
|
141
142
|
let tintColor = null;
|
|
142
|
-
const
|
|
143
|
-
if (
|
|
144
|
-
const
|
|
145
|
-
if (typeof
|
|
146
|
-
throw at(aotError('AOT: <Image tintColor> must be a constant color', 'the tint is baked into the node when it is built; a state-driven one is not lowered yet.'),
|
|
143
|
+
const tintColorAttribute = find('tintColor');
|
|
144
|
+
if (tintColorAttribute) {
|
|
145
|
+
const tintValue = evalStaticOr(attrExpr(tintColorAttribute), environment, null);
|
|
146
|
+
if (typeof tintValue !== 'string' && typeof tintValue !== 'number') {
|
|
147
|
+
throw at(aotError('AOT: <Image tintColor> must be a constant color', 'the tint is baked into the node when it is built; a state-driven one is not lowered yet.'), tintColorAttribute);
|
|
147
148
|
}
|
|
148
|
-
tintColor =
|
|
149
|
+
tintColor = argbValue(tintValue);
|
|
149
150
|
}
|
|
150
|
-
return { imageName,
|
|
151
|
+
return { imageName, imageNameDynamic, resizeMode, tintColor };
|
|
151
152
|
}
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
-
import {
|
|
20
|
-
import { aotError } from '../diagnostics.mjs';
|
|
19
|
+
import { parseColorValue } from '../../style-map.mjs';
|
|
20
|
+
import { aotError, currentLoc } from '../diagnostics.mjs';
|
|
21
21
|
import { evalStatic } from '../static-eval.mjs';
|
|
22
22
|
import { lowerExpr } from '../expressions.mjs';
|
|
23
23
|
import { attrExpr, styleWrites, collectStyleAssigns } from '../style-text.mjs';
|
|
@@ -30,13 +30,13 @@ import { at, elementSpec } from './props.mjs';
|
|
|
30
30
|
// Overlay defaults: absolute, fill the parent via four 0 insets (the robust "stretch" for an absolute
|
|
31
31
|
// node), center the content. The user's style overrides any of these.
|
|
32
32
|
const DEFAULTS = [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
{ field: 'position', value: 'ER_POSITION_ABSOLUTE' },
|
|
34
|
+
{ field: 'left', value: 0 },
|
|
35
|
+
{ field: 'top', value: 0 },
|
|
36
|
+
{ field: 'right', value: 0 },
|
|
37
|
+
{ field: 'bottom', value: 0 },
|
|
38
|
+
{ field: 'align_items', value: 'ER_ALIGN_CENTER' },
|
|
39
|
+
{ field: 'justify_content', value: 'ER_JUSTIFY_CENTER' },
|
|
40
40
|
];
|
|
41
41
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
42
42
|
- Implementation
|
|
@@ -50,45 +50,45 @@ const DEFAULTS = [
|
|
|
50
50
|
*
|
|
51
51
|
* @param element The <Modal>.
|
|
52
52
|
* @param scope Compile-time constants in reach.
|
|
53
|
-
* @param
|
|
54
|
-
* @param
|
|
53
|
+
* @param output Everything emitted so far.
|
|
54
|
+
* @param environment The expression environment.
|
|
55
55
|
* @param state The component's state table.
|
|
56
56
|
*
|
|
57
57
|
* @returns The node's variable.
|
|
58
58
|
*/
|
|
59
|
-
export function emitModal(element, scope,
|
|
59
|
+
export function emitModal(element, scope, output, environment, state) {
|
|
60
60
|
// get node id
|
|
61
|
-
const nodeId = `n${
|
|
61
|
+
const nodeId = `n${output.allocateNodeId()}`;
|
|
62
62
|
// collect style assignments
|
|
63
|
-
const { staticAssigns,
|
|
64
|
-
const hasField = (
|
|
63
|
+
const { staticAssigns, dynamicAssigns, binds } = collectStyleAssigns(element.openingElement, scope, environment, elementSpec('Modal'));
|
|
64
|
+
const hasField = (field) => styleWrites(staticAssigns, dynamicAssigns, field);
|
|
65
65
|
// Apply modal overlay defaults only for fields the user's style has not already set.
|
|
66
|
-
for (const
|
|
67
|
-
if (!hasField(field)) {
|
|
68
|
-
staticAssigns.push({
|
|
66
|
+
for (const assign of DEFAULTS) {
|
|
67
|
+
if (!hasField(assign.field)) {
|
|
68
|
+
staticAssigns.push({ ...assign });
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
// process element attributes
|
|
72
72
|
let visibleNode = null;
|
|
73
|
-
for (const
|
|
73
|
+
for (const attribute of element.openingElement.attributes) {
|
|
74
74
|
// Ensure all props are explicit named attributes.
|
|
75
75
|
// Spread props cannot be analyzed statically
|
|
76
|
-
if (
|
|
76
|
+
if (attribute.type !== 'JSXAttribute') {
|
|
77
77
|
throw aotError('AOT: spread props on <Modal> are not supported');
|
|
78
78
|
}
|
|
79
79
|
// skip non-props
|
|
80
|
-
const name =
|
|
80
|
+
const name = attribute.name.name;
|
|
81
81
|
if (name === 'style' || name === 'ref' || name === 'key')
|
|
82
82
|
continue;
|
|
83
83
|
// process props
|
|
84
|
-
const node = attrExpr(
|
|
84
|
+
const node = attrExpr(attribute);
|
|
85
85
|
if (name === 'visible') {
|
|
86
86
|
visibleNode = node;
|
|
87
87
|
}
|
|
88
88
|
else if (name === 'backdropColor') {
|
|
89
89
|
staticAssigns.push({
|
|
90
90
|
field: 'backdrop_color',
|
|
91
|
-
|
|
91
|
+
value: parseColorValue(String(evalStatic(node, scope))),
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
else if (name === 'animationType') {
|
|
@@ -101,7 +101,7 @@ export function emitModal(element, scope, out, env, state) {
|
|
|
101
101
|
/* state-driven: refused below */
|
|
102
102
|
}
|
|
103
103
|
if (animationType !== 'none') {
|
|
104
|
-
throw at(aotError(`AOT: <Modal animationType> ${typeof animationType === 'string' ? `"${animationType}"` : 'from state'} is not supported`, 'the engine shows and hides a Modal at once; use animationType="none", or drop the prop.'),
|
|
104
|
+
throw at(aotError(`AOT: <Modal animationType> ${typeof animationType === 'string' ? `"${animationType}"` : 'from state'} is not supported`, 'the engine shows and hides a Modal at once; use animationType="none", or drop the prop.'), attribute);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
else if (name === 'onRequestClose' || name === 'statusBarTranslucent') {
|
|
@@ -118,15 +118,15 @@ export function emitModal(element, scope, out, env, state) {
|
|
|
118
118
|
try {
|
|
119
119
|
staticAssigns.push({
|
|
120
120
|
field: 'modal_visible',
|
|
121
|
-
|
|
121
|
+
value: evalStatic(visibleNode, scope) ? 1 : 0,
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
catch {
|
|
125
|
-
|
|
125
|
+
dynamicAssigns.push({
|
|
126
126
|
field: 'modal_visible',
|
|
127
127
|
value: {
|
|
128
128
|
kind: 'flag',
|
|
129
|
-
test: lowerExpr(visibleNode,
|
|
129
|
+
test: lowerExpr(visibleNode, environment),
|
|
130
130
|
truthiness: 'value',
|
|
131
131
|
negate: false,
|
|
132
132
|
whenTrue: 1,
|
|
@@ -135,9 +135,10 @@ export function emitModal(element, scope, out, env, state) {
|
|
|
135
135
|
}
|
|
136
136
|
const node = {
|
|
137
137
|
id: nodeId,
|
|
138
|
+
location: currentLoc(),
|
|
138
139
|
type: 'ER_NODE_MODAL',
|
|
139
140
|
constantProps: staticAssigns,
|
|
140
|
-
stateProps:
|
|
141
|
+
stateProps: dynamicAssigns,
|
|
141
142
|
placeholder: null,
|
|
142
143
|
text: null,
|
|
143
144
|
image: null,
|
|
@@ -145,7 +146,7 @@ export function emitModal(element, scope, out, env, state) {
|
|
|
145
146
|
children: [],
|
|
146
147
|
wiring: [
|
|
147
148
|
...binds.map((bind, index) => ({ kind: 'bind', bind, index })),
|
|
148
|
-
...lowerRefBinds(element.openingElement,
|
|
149
|
+
...lowerRefBinds(element.openingElement, environment).map(slot => ({
|
|
149
150
|
kind: 'ref',
|
|
150
151
|
slot,
|
|
151
152
|
})),
|
|
@@ -153,6 +154,6 @@ export function emitModal(element, scope, out, env, state) {
|
|
|
153
154
|
};
|
|
154
155
|
checkInterpolations(node);
|
|
155
156
|
// The modal's content, shown and hidden with the modal.
|
|
156
|
-
node.children = emitChildren(element.children, scope,
|
|
157
|
+
node.children = emitChildren(element.children, scope, output, environment, state);
|
|
157
158
|
return node;
|
|
158
159
|
}
|
|
@@ -132,8 +132,8 @@ const SVG_PAINT = [
|
|
|
132
132
|
'strokeLinejoin',
|
|
133
133
|
'strokeMiterlimit',
|
|
134
134
|
'fillRule',
|
|
135
|
-
'
|
|
136
|
-
'
|
|
135
|
+
'fillGradient',
|
|
136
|
+
'strokeGradient',
|
|
137
137
|
];
|
|
138
138
|
/** The attributes every host node lowers: style, visibility, a node ref, and its events. */
|
|
139
139
|
const HOST_PROPS = [
|
|
@@ -237,7 +237,7 @@ const ELEMENTS = {
|
|
|
237
237
|
ref: 'Flow A cannot pass a ref through <FlatList> either; use <ScrollView ref={…}> with .map.',
|
|
238
238
|
}),
|
|
239
239
|
// The Flow A wrapper warns about these too, so a list that runs in the simulator also compiles.
|
|
240
|
-
|
|
240
|
+
takesPlatformProps: false,
|
|
241
241
|
},
|
|
242
242
|
Svg: element('Svg', ['style', 'ref', 'width', 'height', 'viewBox', 'source', ...SVG_PAINT], LAYOUT_STYLE, 'shapes', {
|
|
243
243
|
visible: 'wrap it: <View visible={…}><Svg …/></View> — the View carries the hide and the whole subtree goes with it.',
|
|
@@ -279,7 +279,7 @@ function element(tag, props, styleKeys, children, refused = {}, animatedStyleKey
|
|
|
279
279
|
tag,
|
|
280
280
|
props: new Set(props),
|
|
281
281
|
refused,
|
|
282
|
-
|
|
282
|
+
takesPlatformProps: true,
|
|
283
283
|
styleKeys: new Set(styleKeys),
|
|
284
284
|
animatedStyleKeys: new Set(animatedStyleKeys),
|
|
285
285
|
children,
|
|
@@ -298,7 +298,7 @@ function shape(tag, geometry) {
|
|
|
298
298
|
tag,
|
|
299
299
|
props: new Set([...geometry, ...SVG_PAINT]),
|
|
300
300
|
refused: {},
|
|
301
|
-
|
|
301
|
+
takesPlatformProps: false,
|
|
302
302
|
styleKeys: null,
|
|
303
303
|
animatedStyleKeys: new Set(),
|
|
304
304
|
children: 'none',
|
|
@@ -327,13 +327,13 @@ export const svgShapeSpec = (tag) => Object.hasOwn(SVG_SHAPES, tag) ? SVG_SHAPES
|
|
|
327
327
|
/**
|
|
328
328
|
* An attribute's name as written, a namespaced one (`xlink:href`) included.
|
|
329
329
|
*
|
|
330
|
-
* @param
|
|
330
|
+
* @param attribute The attribute.
|
|
331
331
|
*
|
|
332
332
|
* @returns Its name.
|
|
333
333
|
*/
|
|
334
|
-
export const attrName = (
|
|
335
|
-
? `${
|
|
336
|
-
:
|
|
334
|
+
export const attrName = (attribute) => attribute.name.type === 'JSXNamespacedName'
|
|
335
|
+
? `${attribute.name.namespace.name}:${attribute.name.name.name}`
|
|
336
|
+
: attribute.name.name;
|
|
337
337
|
/**
|
|
338
338
|
* Pins an error to a construct's location.
|
|
339
339
|
*
|
|
@@ -358,17 +358,17 @@ export function at(error, node) {
|
|
|
358
358
|
*/
|
|
359
359
|
const declares = (spec, name) => name === 'key' ||
|
|
360
360
|
spec.props.has(name) ||
|
|
361
|
-
(spec.
|
|
361
|
+
(spec.takesPlatformProps && RN_PLATFORM_NO_OPS.includes(name));
|
|
362
362
|
/**
|
|
363
|
-
* Whether `
|
|
363
|
+
* Whether `attribute` sits on a built-in element or shape that does not declare it. A component's props are its own,
|
|
364
364
|
* so an attribute on one is never undeclared.
|
|
365
365
|
*
|
|
366
366
|
* @param openingElement The element's opening tag.
|
|
367
|
-
* @param
|
|
367
|
+
* @param attribute One of its attributes.
|
|
368
368
|
*
|
|
369
369
|
* @returns Whether the element would refuse it.
|
|
370
370
|
*/
|
|
371
|
-
export function isUndeclaredAttribute(openingElement,
|
|
371
|
+
export function isUndeclaredAttribute(openingElement, attribute) {
|
|
372
372
|
const nameNode = openingElement.name;
|
|
373
373
|
const tag = nameNode.type === 'JSXIdentifier'
|
|
374
374
|
? nameNode.name
|
|
@@ -378,7 +378,7 @@ export function isUndeclaredAttribute(openingElement, attr) {
|
|
|
378
378
|
? nameNode.property.name
|
|
379
379
|
: null;
|
|
380
380
|
const spec = tag == null ? undefined : (elementSpec(tag) ?? svgShapeSpec(tag));
|
|
381
|
-
return spec != null && !declares(spec, attrName(
|
|
381
|
+
return spec != null && !declares(spec, attrName(attribute));
|
|
382
382
|
}
|
|
383
383
|
/**
|
|
384
384
|
* Refuses every attribute `spec` does not declare, at the attribute. Spreads are left to the element's
|
|
@@ -388,16 +388,16 @@ export function isUndeclaredAttribute(openingElement, attr) {
|
|
|
388
388
|
* @param openingElement Its opening tag.
|
|
389
389
|
*/
|
|
390
390
|
export function checkAttributes(spec, openingElement) {
|
|
391
|
-
for (const
|
|
392
|
-
if (
|
|
391
|
+
for (const attribute of openingElement.attributes) {
|
|
392
|
+
if (attribute.type !== 'JSXAttribute')
|
|
393
393
|
continue;
|
|
394
|
-
const name = attrName(
|
|
394
|
+
const name = attrName(attribute);
|
|
395
395
|
if (declares(spec, name))
|
|
396
396
|
continue;
|
|
397
397
|
const refusal = Object.hasOwn(spec.refused, name)
|
|
398
398
|
? spec.refused[name]
|
|
399
399
|
: undefined;
|
|
400
|
-
throw at(aotError(`AOT: <${spec.tag}> prop "${name}" is not supported`, refusal ?? `supported props: ${[...spec.props].join(', ')}.`),
|
|
400
|
+
throw at(aotError(`AOT: <${spec.tag}> prop "${name}" is not supported`, refusal ?? `supported props: ${[...spec.props].join(', ')}.`), attribute);
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
403
|
/**
|
|
@@ -410,12 +410,12 @@ export function checkAttributes(spec, openingElement) {
|
|
|
410
410
|
* @returns The element, or a copy of it without those attributes.
|
|
411
411
|
*/
|
|
412
412
|
export function withoutPlatformNoOps(spec, element) {
|
|
413
|
-
if (!spec.
|
|
413
|
+
if (!spec.takesPlatformProps)
|
|
414
414
|
return element;
|
|
415
|
-
const
|
|
416
|
-
const kept =
|
|
417
|
-
!RN_PLATFORM_NO_OPS.includes(attrName(
|
|
418
|
-
return kept.length ===
|
|
415
|
+
const attributes = element.openingElement.attributes;
|
|
416
|
+
const kept = attributes.filter(attribute => attribute.type !== 'JSXAttribute' ||
|
|
417
|
+
!RN_PLATFORM_NO_OPS.includes(attrName(attribute)));
|
|
418
|
+
return kept.length === attributes.length
|
|
419
419
|
? element
|
|
420
420
|
: {
|
|
421
421
|
...element,
|