embedded-react 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +1 -0
  3. package/aot/app-file-loader.mjs +116 -0
  4. package/aot/compile.mjs +16 -46
  5. package/aot/compiler/animations.mjs +299 -57
  6. package/aot/compiler/boot.mjs +27 -2
  7. package/aot/compiler/check.mjs +61 -9
  8. package/aot/compiler/collect.mjs +516 -136
  9. package/aot/compiler/contexts.mjs +391 -0
  10. package/aot/compiler/control-flow.mjs +276 -117
  11. package/aot/compiler/custom-hooks.mjs +686 -0
  12. package/aot/compiler/elements/button.mjs +182 -0
  13. package/aot/compiler/elements/image-background.mjs +76 -0
  14. package/aot/compiler/elements/image.mjs +2 -1
  15. package/aot/compiler/elements/props.mjs +38 -3
  16. package/aot/compiler/elements/rewrite.mjs +118 -0
  17. package/aot/compiler/elements/section-list.mjs +370 -0
  18. package/aot/compiler/expressions.mjs +1351 -97
  19. package/aot/compiler/handlers.mjs +1761 -365
  20. package/aot/compiler/helper-values.mjs +312 -0
  21. package/aot/compiler/ir/nodes.mjs +40 -1
  22. package/aot/compiler/ir/reads.mjs +206 -5
  23. package/aot/compiler/ir/text.mjs +5 -1
  24. package/aot/compiler/ir/types.mjs +12 -0
  25. package/aot/compiler/kept-states.mjs +177 -0
  26. package/aot/compiler/list-items.mjs +226 -0
  27. package/aot/compiler/list-order.mjs +586 -0
  28. package/aot/compiler/list-split.mjs +259 -0
  29. package/aot/compiler/loops.mjs +582 -0
  30. package/aot/compiler/lower.mjs +191 -53
  31. package/aot/compiler/native-files.mjs +439 -0
  32. package/aot/compiler/native-header.mjs +335 -0
  33. package/aot/compiler/native-modules.mjs +1173 -0
  34. package/aot/compiler/nodes.mjs +28 -22
  35. package/aot/compiler/options.mjs +3 -2
  36. package/aot/compiler/out.mjs +14 -1
  37. package/aot/compiler/package/animations.mjs +133 -23
  38. package/aot/compiler/package/assemble.mjs +2 -4
  39. package/aot/compiler/package/bytecode.mjs +37 -8
  40. package/aot/compiler/package/checks.mjs +4 -0
  41. package/aot/compiler/package/codegen.mjs +870 -31
  42. package/aot/compiler/package/enums.mjs +10 -0
  43. package/aot/compiler/package/format.mjs +12 -1
  44. package/aot/compiler/package/lower.mjs +658 -161
  45. package/aot/compiler/package/string-caps.mjs +515 -0
  46. package/aot/compiler/package/tables.mjs +24 -0
  47. package/aot/compiler/package/writer.mjs +22 -0
  48. package/aot/compiler/parse.mjs +3 -1
  49. package/aot/compiler/record-shapes.mjs +246 -0
  50. package/aot/compiler/records.mjs +654 -0
  51. package/aot/compiler/reducers.mjs +272 -0
  52. package/aot/compiler/static-eval.mjs +315 -7
  53. package/aot/compiler/style-text.mjs +18 -3
  54. package/aot/compiler/svg.mjs +7 -4
  55. package/aot/compiler/switch-cases.mjs +198 -0
  56. package/aot/compiler/tagged-records.mjs +450 -0
  57. package/aot/compiler/typing.mjs +307 -0
  58. package/aot/compiler/updaters.mjs +320 -0
  59. package/aot/compiler/window-dimensions.mjs +94 -0
  60. package/aot/compiler/worked-values.mjs +319 -0
  61. package/aot/demo-file.mjs +30 -0
  62. package/aot/style-map.mjs +50 -2
  63. package/build.mjs +9 -1
  64. package/cli.mjs +44 -1
  65. package/hotreload/pack-split.mjs +29 -40
  66. package/pack-container.mjs +9 -1
  67. package/package.json +1 -1
  68. package/sim/embedded-react.wasm +0 -0
  69. package/sim-server.mjs +22 -22
  70. package/src/embedded-react/Dimensions.js +37 -0
  71. package/src/embedded-react/SectionList.js +1 -3
  72. package/src/embedded-react/index.d.ts +83 -3
  73. package/src/embedded-react/index.js +2 -0
  74. package/src/embedded-react/nativeModule.js +462 -0
@@ -0,0 +1,182 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /*----------------------------------------------------------------------------------------------------------------------
17
+ - Imports
18
+ ---------------------------------------------------------------------------------------------------------------------*/
19
+ import { evalStatic, evalStaticOrThrow, withUndefined } from '../static-eval.mjs';
20
+ import { attrExpr } from '../style-text.mjs';
21
+ import { emitNode } from '../nodes.mjs';
22
+ import { attributeOf, elementOf, expressionChild, literalObject, refuseSpreads, } from './rewrite.mjs';
23
+ import { at } from './props.mjs';
24
+ /*----------------------------------------------------------------------------------------------------------------------
25
+ - Constants
26
+ ---------------------------------------------------------------------------------------------------------------------*/
27
+ // Button.js's styles. Flow B has no textAlign, so the Pressable centres the label instead.
28
+ const BUTTON_STYLE = {
29
+ backgroundColor: '#2196F3',
30
+ borderRadius: 2,
31
+ alignItems: 'center',
32
+ };
33
+ const BUTTON_DISABLED_STYLE = { backgroundColor: '#dfdfdf' };
34
+ const TEXT_STYLE = { color: '#ffffff', padding: 8, fontWeight: '500' };
35
+ const TEXT_DISABLED_STYLE = { color: '#a1a1a1' };
36
+ /*----------------------------------------------------------------------------------------------------------------------
37
+ - Implementation
38
+ ---------------------------------------------------------------------------------------------------------------------*/
39
+ /**
40
+ * <Button title onPress color disabled /> → the tree Button.js renders: a styled <Pressable> around one <Text>.
41
+ *
42
+ * @param element The <Button>, its props already checked.
43
+ * @param scope Compile-time constants in reach.
44
+ * @param output Everything emitted so far.
45
+ * @param environment The expression environment.
46
+ * @param state The component's state table.
47
+ * @param options How the element is placed.
48
+ *
49
+ * @returns What the <Pressable> lowers to.
50
+ */
51
+ export function emitButton(element, scope, output, environment, state, options) {
52
+ refuseSpreads(element, 'Button');
53
+ const attributes = new Map();
54
+ for (const attribute of element.openingElement.attributes) {
55
+ attributes.set(attribute.name.name, attribute);
56
+ }
57
+ // `disabled` picks the styles and drops the press handler, so it must fold.
58
+ const disabledAttribute = attributes.get('disabled');
59
+ let disabled = false;
60
+ if (disabledAttribute) {
61
+ try {
62
+ disabled = !!evalStaticOrThrow(attrExpr(disabledAttribute), scope, 'AOT: <Button disabled> must be a compile-time constant', 'it picks the grey styles and drops onPress at build time. To gate on state, leave it ' +
63
+ 'enabled and return early in the handler, or build the <Pressable> + <Text> yourself.');
64
+ }
65
+ catch (error) {
66
+ throw at(error, disabledAttribute);
67
+ }
68
+ }
69
+ // A color that folds to nothing keeps the default blue, as `if (color)` does in Flow A.
70
+ const buttonStyles = [literalObject(BUTTON_STYLE)];
71
+ const textStyles = [literalObject(TEXT_STYLE)];
72
+ const colorAttribute = attributes.get('color');
73
+ if (colorAttribute && !disabled && !foldsFalsy(colorAttribute, scope)) {
74
+ buttonStyles.push({
75
+ type: 'ObjectExpression',
76
+ properties: [
77
+ {
78
+ type: 'ObjectProperty',
79
+ key: { type: 'Identifier', name: 'backgroundColor' },
80
+ value: attrExpr(colorAttribute),
81
+ computed: false,
82
+ shorthand: false,
83
+ },
84
+ ],
85
+ });
86
+ }
87
+ if (disabled) {
88
+ buttonStyles.push(literalObject(BUTTON_DISABLED_STYLE));
89
+ textStyles.push(literalObject(TEXT_DISABLED_STYLE));
90
+ }
91
+ // The label, coerced as Flow A coerces it: a missing title draws nothing.
92
+ const titleAttribute = attributes.get('title');
93
+ const label = titleAttribute
94
+ ? [
95
+ expressionChild(titleText(attrExpr(titleAttribute), scope)),
96
+ ]
97
+ : [];
98
+ const text = elementOf('Text', [attributeOf('style', { type: 'ArrayExpression', elements: textStyles })], label, element);
99
+ const pressableAttributes = [
100
+ attributeOf('style', { type: 'ArrayExpression', elements: buttonStyles }),
101
+ ];
102
+ const onPress = attributes.get('onPress');
103
+ if (onPress && !disabled) {
104
+ pressableAttributes.push(onPress);
105
+ }
106
+ return emitNode(elementOf('Pressable', pressableAttributes, [text], element), scope, output, environment, state, options);
107
+ }
108
+ /**
109
+ * A title as Button.js draws it, `title == null ? '' : String(title)`: worked out now when it folds, else
110
+ * `String(title)`, so a boolean draws as "true" or "false" rather than nothing. No value worked out at run time
111
+ * is null, so only a ternary's branches can be, and each is worked out on its own.
112
+ *
113
+ * @param title The title.
114
+ * @param scope Compile-time constants in reach.
115
+ *
116
+ * @returns The label's text.
117
+ */
118
+ function titleText(title, scope) {
119
+ const folded = foldedTitle(title, scope);
120
+ if (folded)
121
+ return folded;
122
+ if (title.type === 'ConditionalExpression')
123
+ return titleBranches(title, scope);
124
+ return {
125
+ type: 'CallExpression',
126
+ callee: { type: 'Identifier', name: 'String' },
127
+ arguments: [title],
128
+ };
129
+ }
130
+ /**
131
+ * A ternary title with each branch that folds as its text, `null` and `undefined` as nothing. A branch worked
132
+ * out at run time stays as written, since text lowers no call inside a ternary.
133
+ *
134
+ * @param title The ternary.
135
+ * @param scope Compile-time constants in reach.
136
+ *
137
+ * @returns The ternary of texts.
138
+ */
139
+ function titleBranches(title, scope) {
140
+ const branch = (expression) => foldedTitle(expression, scope) ??
141
+ (expression.type === 'ConditionalExpression'
142
+ ? titleBranches(expression, scope)
143
+ : expression);
144
+ return {
145
+ ...title,
146
+ consequent: branch(title.consequent),
147
+ alternate: branch(title.alternate),
148
+ };
149
+ }
150
+ /**
151
+ * A title that folds, as its text.
152
+ *
153
+ * @param title The title.
154
+ * @param scope Compile-time constants in reach.
155
+ *
156
+ * @returns The text, or null when it is worked out at run time.
157
+ */
158
+ function foldedTitle(title, scope) {
159
+ try {
160
+ const value = evalStatic(title, withUndefined(scope));
161
+ return { type: 'StringLiteral', value: value == null ? '' : String(value) };
162
+ }
163
+ catch {
164
+ return null;
165
+ }
166
+ }
167
+ /**
168
+ * Whether an attribute folds to a falsy value. One that does not fold is a value worked out at run time.
169
+ *
170
+ * @param attribute The attribute.
171
+ * @param scope Compile-time constants in reach.
172
+ *
173
+ * @returns Whether it folds falsy.
174
+ */
175
+ function foldsFalsy(attribute, scope) {
176
+ try {
177
+ return !evalStatic(attrExpr(attribute), scope);
178
+ }
179
+ catch {
180
+ return false;
181
+ }
182
+ }
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /*----------------------------------------------------------------------------------------------------------------------
17
+ - Imports
18
+ ---------------------------------------------------------------------------------------------------------------------*/
19
+ import { attrExpr } from '../style-text.mjs';
20
+ import { emitNode } from '../nodes.mjs';
21
+ import { attributeOf, elementOf, literalObject, refuseSpreads, renamed, } from './rewrite.mjs';
22
+ /*----------------------------------------------------------------------------------------------------------------------
23
+ - Constants
24
+ ---------------------------------------------------------------------------------------------------------------------*/
25
+ /** StyleSheet.absoluteFill: the image fills the container's padding box. */
26
+ const ABSOLUTE_FILL = {
27
+ position: 'absolute',
28
+ left: 0,
29
+ right: 0,
30
+ top: 0,
31
+ bottom: 0,
32
+ };
33
+ /*----------------------------------------------------------------------------------------------------------------------
34
+ - Implementation
35
+ ---------------------------------------------------------------------------------------------------------------------*/
36
+ /**
37
+ * <ImageBackground style imageStyle imageRef …imageProps>children</ImageBackground> → the tree
38
+ * ImageBackground.js renders: a <View> holding an <Image> that fills it, then the children. `style` and `ref`
39
+ * go to the View, every other prop to the Image.
40
+ *
41
+ * @param element The <ImageBackground>, its props already checked.
42
+ * @param scope Compile-time constants in reach.
43
+ * @param output Everything emitted so far.
44
+ * @param environment The expression environment.
45
+ * @param state The component's state table.
46
+ * @param options How the element is placed.
47
+ *
48
+ * @returns What the <View> lowers to.
49
+ */
50
+ export function emitImageBackground(element, scope, output, environment, state, options) {
51
+ refuseSpreads(element, 'ImageBackground');
52
+ const viewAttributes = [];
53
+ const imageAttributes = [];
54
+ const imageStyles = [literalObject(ABSOLUTE_FILL)];
55
+ for (const attribute of element.openingElement
56
+ .attributes) {
57
+ const name = attribute.name.name;
58
+ if (name === 'key')
59
+ continue;
60
+ if (name === 'style' || name === 'ref') {
61
+ viewAttributes.push(attribute);
62
+ }
63
+ else if (name === 'imageStyle') {
64
+ imageStyles.push(attrExpr(attribute));
65
+ }
66
+ else if (name === 'imageRef') {
67
+ imageAttributes.push(renamed(attribute, 'ref'));
68
+ }
69
+ else {
70
+ imageAttributes.push(attribute);
71
+ }
72
+ }
73
+ imageAttributes.push(attributeOf('style', { type: 'ArrayExpression', elements: imageStyles }));
74
+ const image = elementOf('Image', imageAttributes, [], element);
75
+ return emitNode(elementOf('View', viewAttributes, [image, ...element.children], element), scope, output, environment, state, options);
76
+ }
@@ -16,6 +16,7 @@
16
16
  /*----------------------------------------------------------------------------------------------------------------------
17
17
  - Imports
18
18
  ---------------------------------------------------------------------------------------------------------------------*/
19
+ import { shapeOf } from '../typing.mjs';
19
20
  import { aotError } from '../diagnostics.mjs';
20
21
  import { at } from './props.mjs';
21
22
  import { evalStatic, evalStaticOr } from '../static-eval.mjs';
@@ -110,7 +111,7 @@ export function resolveImageAttrs(element, environment, output) {
110
111
  // Only triggered when a dynamic source is actually REACHED.
111
112
  output.bakeAllImages = true;
112
113
  const nameExpression = lowerExpr(sourceExpression, environment);
113
- if (nameExpression.type.kind !== 'string') {
114
+ if (shapeOf(nameExpression) !== 'string') {
114
115
  const error = aotError('AOT: an <Image source> must resolve to an asset NAME (a string)', "use an imported image (`import logo from './logo.png'` → source={logo}), " +
115
116
  "a string asset name, source={{ uri: 'name' }}, or a string-valued " +
116
117
  'state / list-item field for a dynamic source.');
@@ -75,8 +75,17 @@ const LAYOUT_STYLE = [
75
75
  'zIndex',
76
76
  'transform',
77
77
  ];
78
+ /** The shadow a View, ScrollView, Pressable or Modal casts. */
79
+ const SHADOW_STYLE = [
80
+ 'shadowColor',
81
+ 'shadowOffset',
82
+ 'shadowOpacity',
83
+ 'shadowRadius',
84
+ 'elevation',
85
+ ];
78
86
  /** What the engine draws a View, ScrollView or Pressable with. */
79
87
  const VIEW_STYLE = [
88
+ ...SHADOW_STYLE,
80
89
  'backgroundColor',
81
90
  'borderRadius',
82
91
  'borderTopLeftRadius',
@@ -105,16 +114,18 @@ const TEXT_STYLE = [
105
114
  'letterSpacing',
106
115
  'opacity',
107
116
  ];
108
- /** What the engine draws a Modal's own box with. */
109
- const MODAL_STYLE = [
117
+ /** What the engine draws a box with: a TextInput's, and a Modal's own. */
118
+ const BOX_STYLE = [
110
119
  'backgroundColor',
111
120
  'borderRadius',
112
121
  'borderWidth',
113
122
  'borderColor',
114
123
  'opacity',
115
124
  ];
125
+ /** What the engine draws a Modal's own box with. */
126
+ const MODAL_STYLE = [...BOX_STYLE, ...SHADOW_STYLE];
116
127
  /** What the engine draws a TextInput with. */
117
- const TEXT_INPUT_STYLE = [...MODAL_STYLE, 'color', 'fontSize'];
128
+ const TEXT_INPUT_STYLE = [...BOX_STYLE, 'color', 'fontSize'];
118
129
  /** The style keys the engine animates on a View, ScrollView, Pressable or Modal; `transform` animates anywhere. */
119
130
  const VIEW_ANIMATED = ['opacity', 'backgroundColor', 'transform'];
120
131
  /** The style keys the engine animates on a Text. */
@@ -239,6 +250,30 @@ const ELEMENTS = {
239
250
  // The Flow A wrapper warns about these too, so a list that runs in the simulator also compiles.
240
251
  takesPlatformProps: false,
241
252
  },
253
+ SectionList: element('SectionList', [
254
+ 'sections',
255
+ 'renderItem',
256
+ 'renderSectionHeader',
257
+ 'renderSectionFooter',
258
+ 'keyExtractor',
259
+ 'style',
260
+ ], [...LAYOUT_STYLE, ...VIEW_STYLE], 'none', {
261
+ ref: 'Flow A cannot pass a ref through <SectionList> either; use <ScrollView ref={…}> with .map.',
262
+ }),
263
+ Button: element('Button', ['title', 'onPress', 'color', 'disabled'], [], 'none', {
264
+ style: 'a Button takes no style, as in React Native. Build the same tree yourself to style it: ' +
265
+ '<Pressable style={…} onPress={…}><Text style={…}>title</Text></Pressable>.',
266
+ }),
267
+ // Its style and ref go to the View; every other prop goes to the Image, as in Flow A.
268
+ ImageBackground: element('ImageBackground', [
269
+ ...HOST_PROPS,
270
+ 'source',
271
+ 'imageName',
272
+ 'resizeMode',
273
+ 'tintColor',
274
+ 'imageStyle',
275
+ 'imageRef',
276
+ ], [...LAYOUT_STYLE, ...VIEW_STYLE], 'nodes', {}, VIEW_ANIMATED),
242
277
  Svg: element('Svg', ['style', 'ref', 'width', 'height', 'viewBox', 'source', ...SVG_PAINT], LAYOUT_STYLE, 'shapes', {
243
278
  visible: 'wrap it: <View visible={…}><Svg …/></View> — the View carries the hide and the whole subtree goes with it.',
244
279
  ...Object.fromEntries(Object.keys(EVENT_TYPES).map(name => [name, SVG_EVENT])),
@@ -0,0 +1,118 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ // Builders for the JSX the wrapper components (Button, ImageBackground, SectionList) are rewritten to.
17
+ /*----------------------------------------------------------------------------------------------------------------------
18
+ - Imports
19
+ ---------------------------------------------------------------------------------------------------------------------*/
20
+ import { aotError } from '../diagnostics.mjs';
21
+ import { at } from './props.mjs';
22
+ /*----------------------------------------------------------------------------------------------------------------------
23
+ - Implementation
24
+ ---------------------------------------------------------------------------------------------------------------------*/
25
+ /**
26
+ * Refuses a spread on a wrapper, whose props are split by name.
27
+ *
28
+ * @param element The wrapper.
29
+ * @param tag Its tag, for the error.
30
+ */
31
+ export function refuseSpreads(element, tag) {
32
+ const spread = element.openingElement.attributes.find(attribute => attribute.type === 'JSXSpreadAttribute');
33
+ if (spread) {
34
+ throw at(aotError(`AOT: a spread {...} on <${tag}> is not supported`, 'list each prop explicitly.'), spread);
35
+ }
36
+ }
37
+ /**
38
+ * A JSX element, located at the wrapper it stands for so its errors point there.
39
+ *
40
+ * @param tag The tag.
41
+ * @param attributes Its attributes.
42
+ * @param children Its children.
43
+ * @param from The wrapper.
44
+ *
45
+ * @returns The element.
46
+ */
47
+ export function elementOf(tag, attributes, children, from) {
48
+ const name = { type: 'JSXIdentifier', name: tag };
49
+ return {
50
+ type: 'JSXElement',
51
+ openingElement: {
52
+ type: 'JSXOpeningElement',
53
+ name,
54
+ attributes,
55
+ selfClosing: children.length === 0,
56
+ },
57
+ closingElement: children.length === 0 ? null : { type: 'JSXClosingElement', name },
58
+ children,
59
+ loc: from.loc,
60
+ };
61
+ }
62
+ /**
63
+ * A `name={value}` attribute.
64
+ *
65
+ * @param name The name.
66
+ * @param value The value.
67
+ *
68
+ * @returns The attribute.
69
+ */
70
+ export function attributeOf(name, value) {
71
+ return {
72
+ type: 'JSXAttribute',
73
+ name: { type: 'JSXIdentifier', name },
74
+ value: { type: 'JSXExpressionContainer', expression: value },
75
+ };
76
+ }
77
+ /**
78
+ * An attribute under another name, keeping its value and location.
79
+ *
80
+ * @param attribute The attribute.
81
+ * @param name The new name.
82
+ *
83
+ * @returns The renamed attribute.
84
+ */
85
+ export function renamed(attribute, name) {
86
+ return { ...attribute, name: { type: 'JSXIdentifier', name } };
87
+ }
88
+ /**
89
+ * A `{value}` child.
90
+ *
91
+ * @param value The expression.
92
+ *
93
+ * @returns The child.
94
+ */
95
+ export function expressionChild(value) {
96
+ return { type: 'JSXExpressionContainer', expression: value };
97
+ }
98
+ /**
99
+ * An object literal of strings and numbers.
100
+ *
101
+ * @param fields The fields.
102
+ *
103
+ * @returns The literal.
104
+ */
105
+ export function literalObject(fields) {
106
+ return {
107
+ type: 'ObjectExpression',
108
+ properties: Object.entries(fields).map(([key, value]) => ({
109
+ type: 'ObjectProperty',
110
+ key: { type: 'Identifier', name: key },
111
+ value: typeof value === 'number'
112
+ ? { type: 'NumericLiteral', value }
113
+ : { type: 'StringLiteral', value },
114
+ computed: false,
115
+ shorthand: false,
116
+ })),
117
+ };
118
+ }