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.
- package/NOTICE +5 -0
- package/README.md +1 -0
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +16 -46
- package/aot/compiler/animations.mjs +299 -57
- package/aot/compiler/boot.mjs +27 -2
- package/aot/compiler/check.mjs +61 -9
- package/aot/compiler/collect.mjs +516 -136
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +276 -117
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +2 -1
- package/aot/compiler/elements/props.mjs +38 -3
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/expressions.mjs +1351 -97
- package/aot/compiler/handlers.mjs +1761 -365
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/nodes.mjs +40 -1
- package/aot/compiler/ir/reads.mjs +206 -5
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +12 -0
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/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 +191 -53
- package/aot/compiler/native-files.mjs +439 -0
- package/aot/compiler/native-header.mjs +335 -0
- package/aot/compiler/native-modules.mjs +1173 -0
- package/aot/compiler/nodes.mjs +28 -22
- package/aot/compiler/options.mjs +3 -2
- package/aot/compiler/out.mjs +14 -1
- package/aot/compiler/package/animations.mjs +133 -23
- package/aot/compiler/package/assemble.mjs +2 -4
- package/aot/compiler/package/bytecode.mjs +37 -8
- package/aot/compiler/package/checks.mjs +4 -0
- package/aot/compiler/package/codegen.mjs +870 -31
- package/aot/compiler/package/enums.mjs +10 -0
- package/aot/compiler/package/format.mjs +12 -1
- package/aot/compiler/package/lower.mjs +658 -161
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +24 -0
- package/aot/compiler/package/writer.mjs +22 -0
- package/aot/compiler/parse.mjs +3 -1
- package/aot/compiler/record-shapes.mjs +246 -0
- package/aot/compiler/records.mjs +654 -0
- package/aot/compiler/reducers.mjs +272 -0
- package/aot/compiler/static-eval.mjs +315 -7
- package/aot/compiler/style-text.mjs +18 -3
- package/aot/compiler/svg.mjs +7 -4
- 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/style-map.mjs +50 -2
- package/build.mjs +9 -1
- package/cli.mjs +44 -1
- package/hotreload/pack-split.mjs +29 -40
- package/pack-container.mjs +9 -1
- package/package.json +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/sim-server.mjs +22 -22
- package/src/embedded-react/Dimensions.js +37 -0
- package/src/embedded-react/SectionList.js +1 -3
- package/src/embedded-react/index.d.ts +83 -3
- package/src/embedded-react/index.js +2 -0
- package/src/embedded-react/nativeModule.js +462 -0
|
@@ -0,0 +1,391 @@
|
|
|
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
|
+
* Contexts, worked out at compile time: `const Theme = createContext(…)`, `<Theme.Provider value={…}>` and
|
|
18
|
+
* `useContext(Theme)`. Each component instance is inlined where it is rendered, so the nearest provider above it is
|
|
19
|
+
* known, and a value read from the context binds as a prop given that provider's value would. With no provider above,
|
|
20
|
+
* it reads the context's default.
|
|
21
|
+
*/
|
|
22
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
23
|
+
- Imports
|
|
24
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
25
|
+
import { traverse } from '@babel/core';
|
|
26
|
+
import { aotError } from './diagnostics.mjs';
|
|
27
|
+
import { evalStatic } from './static-eval.mjs';
|
|
28
|
+
import { attrExpr } from './style-text.mjs';
|
|
29
|
+
import { bindProp, propDescriptorOf } from './control-flow.mjs';
|
|
30
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
31
|
+
- Implementation
|
|
32
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
33
|
+
/**
|
|
34
|
+
* An error located at a node.
|
|
35
|
+
*
|
|
36
|
+
* @param message The message.
|
|
37
|
+
* @param hint How to fix it.
|
|
38
|
+
* @param node Where it is.
|
|
39
|
+
*
|
|
40
|
+
* @returns The error.
|
|
41
|
+
*/
|
|
42
|
+
function refusal(message, hint, node) {
|
|
43
|
+
const error = aotError(message, hint);
|
|
44
|
+
if (node?.loc) {
|
|
45
|
+
error.aotLoc = node.loc.start;
|
|
46
|
+
}
|
|
47
|
+
return error;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The name a call is made to, `React.` stripped: `useContext(…)` and `React.useContext(…)` are both `useContext`.
|
|
51
|
+
*
|
|
52
|
+
* @param node Any node.
|
|
53
|
+
*
|
|
54
|
+
* @returns The name, or null when it isn't a call to a name.
|
|
55
|
+
*/
|
|
56
|
+
function calleeName(node) {
|
|
57
|
+
if (node?.type !== 'CallExpression')
|
|
58
|
+
return null;
|
|
59
|
+
const callee = node.callee;
|
|
60
|
+
if (callee.type === 'Identifier')
|
|
61
|
+
return callee.name;
|
|
62
|
+
if (callee.type === 'MemberExpression' &&
|
|
63
|
+
!callee.computed &&
|
|
64
|
+
callee.object.type === 'Identifier' &&
|
|
65
|
+
callee.object.name === 'React' &&
|
|
66
|
+
callee.property.type === 'Identifier') {
|
|
67
|
+
return callee.property.name;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Whether a node is a `useContext(…)` call, whose value bindContextUses binds.
|
|
73
|
+
*
|
|
74
|
+
* @param node Any node.
|
|
75
|
+
*
|
|
76
|
+
* @returns Whether it is.
|
|
77
|
+
*/
|
|
78
|
+
export const isContextRead = (node) => calleeName(node) === 'useContext';
|
|
79
|
+
/**
|
|
80
|
+
* The module's contexts: each module-level `const C = createContext(default)`.
|
|
81
|
+
*
|
|
82
|
+
* @param program The module.
|
|
83
|
+
*
|
|
84
|
+
* @returns The contexts, by name.
|
|
85
|
+
*/
|
|
86
|
+
export function contextsOf(program) {
|
|
87
|
+
const contexts = new Map();
|
|
88
|
+
for (const statement of program.body) {
|
|
89
|
+
const declaration = statement.type === 'ExportNamedDeclaration'
|
|
90
|
+
? statement.declaration
|
|
91
|
+
: statement;
|
|
92
|
+
if (declaration?.type !== 'VariableDeclaration')
|
|
93
|
+
continue;
|
|
94
|
+
for (const declarator of declaration.declarations) {
|
|
95
|
+
if (calleeName(declarator.init) !== 'createContext')
|
|
96
|
+
continue;
|
|
97
|
+
if (declarator.id.type !== 'Identifier') {
|
|
98
|
+
throw refusal('AOT: a context must be bound to a name', 'const Theme = createContext(…);', declarator);
|
|
99
|
+
}
|
|
100
|
+
const argument = declarator.init.arguments[0];
|
|
101
|
+
contexts.set(declarator.id.name, {
|
|
102
|
+
name: declarator.id.name,
|
|
103
|
+
value: argument ?? null,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return contexts;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Refuses a context's name where a binding of that name hides it, in `useContext(C)` or `<C.Provider>`, since contexts
|
|
111
|
+
* are found by name.
|
|
112
|
+
*
|
|
113
|
+
* @param ast The parsed module.
|
|
114
|
+
*/
|
|
115
|
+
export function refuseHiddenContexts(ast) {
|
|
116
|
+
const names = new Set(contextsOf(ast.program).keys());
|
|
117
|
+
if (!names.size)
|
|
118
|
+
return;
|
|
119
|
+
const check = (name, scope, node) => {
|
|
120
|
+
if (!names.has(name))
|
|
121
|
+
return;
|
|
122
|
+
if (scope.getBinding(name)?.scope.block.type === 'Program')
|
|
123
|
+
return;
|
|
124
|
+
throw refusal(`AOT: "${name}" here is not the context: a binding of that name hides it`, `rename the binding, so ${name} names the context made with createContext.`, node);
|
|
125
|
+
};
|
|
126
|
+
traverse.cache.clear();
|
|
127
|
+
traverse(ast, {
|
|
128
|
+
JSXOpeningElement(path) {
|
|
129
|
+
const name = path.node.name;
|
|
130
|
+
if (name.type === 'JSXMemberExpression' &&
|
|
131
|
+
name.object.type === 'JSXIdentifier') {
|
|
132
|
+
check(name.object.name, path.scope, path.node);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
CallExpression(path) {
|
|
136
|
+
const argument = path.node.arguments[0];
|
|
137
|
+
if (isContextRead(path.node) && argument?.type === 'Identifier') {
|
|
138
|
+
check(argument.name, path.scope, argument);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
traverse.cache.clear();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The context a `<C.Provider>` provides. `<C.Consumer>` is refused.
|
|
146
|
+
*
|
|
147
|
+
* @param element Any element.
|
|
148
|
+
* @param environment The expression environment.
|
|
149
|
+
*
|
|
150
|
+
* @returns The context's name, or null when the element isn't a provider.
|
|
151
|
+
*/
|
|
152
|
+
export function providedContextOf(element, environment) {
|
|
153
|
+
const name = element.openingElement.name;
|
|
154
|
+
if (name.type !== 'JSXMemberExpression' ||
|
|
155
|
+
name.object.type !== 'JSXIdentifier' ||
|
|
156
|
+
!environment.contexts?.records.has(name.object.name)) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
if (name.property.name === 'Provider')
|
|
160
|
+
return name.object.name;
|
|
161
|
+
throw refusal(`AOT: <${name.object.name}.${name.property.name}> is not supported`, `read the context with useContext(${name.object.name}) at the top of the component instead.`, element);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The environment inside a `<C.Provider value={…}>`: what is lowered there reads C from it.
|
|
165
|
+
*
|
|
166
|
+
* @param element The provider.
|
|
167
|
+
* @param context The context it provides.
|
|
168
|
+
* @param scope Compile-time constants in reach.
|
|
169
|
+
* @param environment The expression environment around it.
|
|
170
|
+
* @param state The component's state table.
|
|
171
|
+
*
|
|
172
|
+
* @returns The environment.
|
|
173
|
+
*/
|
|
174
|
+
export function providedEnvironment(element, context, scope, environment, state) {
|
|
175
|
+
let value = null;
|
|
176
|
+
for (const attribute of element.openingElement.attributes) {
|
|
177
|
+
if (attribute.type === 'JSXAttribute' &&
|
|
178
|
+
attribute.name.type === 'JSXIdentifier' &&
|
|
179
|
+
attribute.name.name === 'key') {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (attribute.type !== 'JSXAttribute' ||
|
|
183
|
+
attribute.name.type !== 'JSXIdentifier' ||
|
|
184
|
+
attribute.name.name !== 'value') {
|
|
185
|
+
throw refusal(`AOT: <${context}.Provider> takes only a value`, `<${context}.Provider value={…}>.`, attribute);
|
|
186
|
+
}
|
|
187
|
+
value = attrExpr(attribute);
|
|
188
|
+
}
|
|
189
|
+
const providers = new Map(environment.providers);
|
|
190
|
+
providers.set(context, { value, scope, environment, state });
|
|
191
|
+
return { ...environment, providers };
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The provider of a context in reach, or the context's default when there is none.
|
|
195
|
+
*
|
|
196
|
+
* @param context The context.
|
|
197
|
+
* @param environment The expression environment.
|
|
198
|
+
*
|
|
199
|
+
* @returns The provider.
|
|
200
|
+
*/
|
|
201
|
+
function providerOf(context, environment) {
|
|
202
|
+
const provider = environment.providers?.get(context.name);
|
|
203
|
+
if (provider)
|
|
204
|
+
return provider;
|
|
205
|
+
const defaults = environment.contexts.defaults;
|
|
206
|
+
return {
|
|
207
|
+
value: context.value,
|
|
208
|
+
scope: defaults.constants,
|
|
209
|
+
environment: defaults,
|
|
210
|
+
state: { byName: new Map(), bySetter: new Map() },
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The descriptor of a value a provider gives, worked out where the provider is written.
|
|
215
|
+
*
|
|
216
|
+
* @param name The name it is bound to.
|
|
217
|
+
* @param node The value, or null for none.
|
|
218
|
+
* @param provider The provider.
|
|
219
|
+
*
|
|
220
|
+
* @returns The descriptor.
|
|
221
|
+
*/
|
|
222
|
+
function describe(name, node, provider) {
|
|
223
|
+
if (!node)
|
|
224
|
+
return { static: true, value: undefined };
|
|
225
|
+
if (node.type === 'Identifier' && provider.state.bySetter.has(node.name)) {
|
|
226
|
+
throw refusal(`AOT: a context's value can't hold the setter "${node.name}"`, `give it a function that calls the setter instead: {toggle: () => ${node.name}(…)}.`, node);
|
|
227
|
+
}
|
|
228
|
+
return propDescriptorOf(name, node, provider.scope, provider.environment);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* The value an object a provider gives has under a key.
|
|
232
|
+
*
|
|
233
|
+
* @param object The object.
|
|
234
|
+
* @param key The key.
|
|
235
|
+
* @param context The context's name, for the error.
|
|
236
|
+
*
|
|
237
|
+
* @returns The value, or null when it has none.
|
|
238
|
+
*/
|
|
239
|
+
function valueOfKey(object, key, context) {
|
|
240
|
+
for (const property of object.properties) {
|
|
241
|
+
if (property.type === 'SpreadElement') {
|
|
242
|
+
throw refusal(`AOT: the value of context "${context}" is an object with a spread`, 'list each value: value={{theme, toggle}}.', property);
|
|
243
|
+
}
|
|
244
|
+
const name = property.computed
|
|
245
|
+
? property.key.type === 'StringLiteral'
|
|
246
|
+
? property.key.value
|
|
247
|
+
: null
|
|
248
|
+
: property.key.type === 'Identifier'
|
|
249
|
+
? property.key.name
|
|
250
|
+
: property.key.type === 'StringLiteral'
|
|
251
|
+
? property.key.value
|
|
252
|
+
: null;
|
|
253
|
+
if (name !== key)
|
|
254
|
+
continue;
|
|
255
|
+
if (property.type === 'ObjectMethod') {
|
|
256
|
+
return {
|
|
257
|
+
type: 'FunctionExpression',
|
|
258
|
+
params: property.params,
|
|
259
|
+
body: property.body,
|
|
260
|
+
generator: property.generator,
|
|
261
|
+
async: property.async,
|
|
262
|
+
loc: property.loc,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
return property.value;
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Binds the values a component body reads with `const x = useContext(C)` or `const {a, b} = useContext(C)`, each as
|
|
271
|
+
* a prop of that value from the nearest provider would be. A `useContext` call anywhere else is refused.
|
|
272
|
+
*
|
|
273
|
+
* @param body The component's body.
|
|
274
|
+
* @param environment The expression environment the component is rendered in, whose providers are in reach.
|
|
275
|
+
* @param tables The component's tables, which the values are bound into.
|
|
276
|
+
*
|
|
277
|
+
* @returns The names bound.
|
|
278
|
+
*/
|
|
279
|
+
export function bindContextUses(body, environment, tables) {
|
|
280
|
+
const names = new Set();
|
|
281
|
+
const allowed = new WeakSet();
|
|
282
|
+
for (const statement of body.body) {
|
|
283
|
+
if (statement.type !== 'VariableDeclaration')
|
|
284
|
+
continue;
|
|
285
|
+
for (const declarator of statement.declarations) {
|
|
286
|
+
if (calleeName(declarator.init) !== 'useContext')
|
|
287
|
+
continue;
|
|
288
|
+
const call = declarator.init;
|
|
289
|
+
allowed.add(call);
|
|
290
|
+
// The argument is a context the module makes.
|
|
291
|
+
const argument = call.arguments[0];
|
|
292
|
+
const context = argument?.type === 'Identifier'
|
|
293
|
+
? environment.contexts?.records.get(argument.name)
|
|
294
|
+
: undefined;
|
|
295
|
+
if (!context || call.arguments.length !== 1) {
|
|
296
|
+
throw refusal('AOT: useContext takes a context made in this file', 'make it at module level and pass it: const Theme = createContext(…); … useContext(Theme).', call);
|
|
297
|
+
}
|
|
298
|
+
const provider = providerOf(context, environment);
|
|
299
|
+
const bind = (name, descriptor) => {
|
|
300
|
+
bindProp(name, descriptor, tables, provider.environment, provider.state);
|
|
301
|
+
names.add(name);
|
|
302
|
+
};
|
|
303
|
+
// `const value = useContext(C)`: the whole value.
|
|
304
|
+
const pattern = declarator.id;
|
|
305
|
+
if (pattern.type === 'Identifier') {
|
|
306
|
+
bind(pattern.name, describe(pattern.name, provider.value, provider));
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (pattern.type !== 'ObjectPattern') {
|
|
310
|
+
throw refusal(`AOT: the value of context "${context.name}" can only be destructured as an object`, `const {a, b} = useContext(${context.name}), or const value = useContext(${context.name}).`, pattern);
|
|
311
|
+
}
|
|
312
|
+
// `const {a, b: c = 1} = useContext(C)`: each key, from an object written out in the provider, or from a
|
|
313
|
+
// constant one.
|
|
314
|
+
const value = provider.value;
|
|
315
|
+
const whole = value && value.type !== 'ObjectExpression'
|
|
316
|
+
? describe('value', value, provider)
|
|
317
|
+
: null;
|
|
318
|
+
for (const property of pattern.properties) {
|
|
319
|
+
if (property.type === 'RestElement' ||
|
|
320
|
+
(property.computed && property.key.type !== 'StringLiteral')) {
|
|
321
|
+
throw refusal(`AOT: the value of context "${context.name}" can only be destructured by key`, `name each key: const {a, b} = useContext(${context.name}).`, property);
|
|
322
|
+
}
|
|
323
|
+
const key = property.key.type === 'Identifier'
|
|
324
|
+
? property.key.name
|
|
325
|
+
: property.key.value;
|
|
326
|
+
const target = property.value;
|
|
327
|
+
const name = target.type === 'Identifier'
|
|
328
|
+
? target.name
|
|
329
|
+
: target.type === 'AssignmentPattern' &&
|
|
330
|
+
target.left.type === 'Identifier'
|
|
331
|
+
? target.left.name
|
|
332
|
+
: null;
|
|
333
|
+
if (!name) {
|
|
334
|
+
throw refusal(`AOT: the value of context "${context.name}" can only be destructured one level deep`, 'bind each key to a name, then destructure that name on its own.', target);
|
|
335
|
+
}
|
|
336
|
+
let descriptor;
|
|
337
|
+
if (whole) {
|
|
338
|
+
if (whole.static !== true ||
|
|
339
|
+
whole.value === null ||
|
|
340
|
+
typeof whole.value !== 'object') {
|
|
341
|
+
throw refusal(`AOT: the value of context "${context.name}" must be an object to destructure`, 'give the provider an object written out in place: value={{theme, toggle}}.', value);
|
|
342
|
+
}
|
|
343
|
+
descriptor = {
|
|
344
|
+
static: true,
|
|
345
|
+
value: whole.value[key],
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
descriptor = describe(name, value
|
|
350
|
+
? valueOfKey(value, key, context.name)
|
|
351
|
+
: null, provider);
|
|
352
|
+
}
|
|
353
|
+
// A default stands in for a key the value has no value for.
|
|
354
|
+
if (descriptor.static === true &&
|
|
355
|
+
descriptor.value === undefined &&
|
|
356
|
+
target.type === 'AssignmentPattern') {
|
|
357
|
+
descriptor = {
|
|
358
|
+
static: true,
|
|
359
|
+
value: evalStatic(target.right, tables.scope, 'boot'),
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
bind(name, descriptor);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
// Anywhere else, useContext would read a provider this pass doesn't know.
|
|
367
|
+
const walk = (node) => {
|
|
368
|
+
if (!node || typeof node !== 'object')
|
|
369
|
+
return;
|
|
370
|
+
if (Array.isArray(node)) {
|
|
371
|
+
node.forEach(walk);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const astNode = node;
|
|
375
|
+
if (typeof astNode.type !== 'string')
|
|
376
|
+
return;
|
|
377
|
+
if (calleeName(astNode) === 'useContext' && !allowed.has(astNode)) {
|
|
378
|
+
throw refusal('AOT: useContext must be called at the top of a component', 'bind its value on a line of its own at the top of the component: const theme = useContext(Theme).', astNode);
|
|
379
|
+
}
|
|
380
|
+
for (const key of Object.keys(astNode)) {
|
|
381
|
+
if (key === 'loc' ||
|
|
382
|
+
key === 'leadingComments' ||
|
|
383
|
+
key === 'trailingComments') {
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
walk(astNode[key]);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
walk(body);
|
|
390
|
+
return names;
|
|
391
|
+
}
|