@geastack/geatsc-plugin-gea 0.1.6
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/LICENSE +202 -0
- package/README.md +37 -0
- package/dist/analyze.d.ts +4 -0
- package/dist/analyze.js +195 -0
- package/dist/cpp-canvas-colors.d.ts +4 -0
- package/dist/cpp-canvas-colors.js +226 -0
- package/dist/cpp-field-access.d.ts +49 -0
- package/dist/cpp-field-access.js +144 -0
- package/dist/cpp-ir-dom-style.d.ts +1 -0
- package/dist/cpp-ir-dom-style.js +49 -0
- package/dist/cpp-ir.d.ts +30 -0
- package/dist/cpp-ir.js +2426 -0
- package/dist/cpp-keyed-component-diagnostics.d.ts +8 -0
- package/dist/cpp-keyed-component-diagnostics.js +74 -0
- package/dist/cpp-keyed-list-diagnostics.d.ts +17 -0
- package/dist/cpp-keyed-list-diagnostics.js +84 -0
- package/dist/cpp-mounted-lowering.d.ts +81 -0
- package/dist/cpp-mounted-lowering.js +2235 -0
- package/dist/cpp-mounted.d.ts +25 -0
- package/dist/cpp-mounted.js +1376 -0
- package/dist/cpp-reactive-component-diagnostics.d.ts +2 -0
- package/dist/cpp-reactive-component-diagnostics.js +76 -0
- package/dist/cpp-reactive-component.d.ts +14 -0
- package/dist/cpp-reactive-component.js +349 -0
- package/dist/cpp-replacements.d.ts +14 -0
- package/dist/cpp-replacements.js +787 -0
- package/dist/cpp-source-replacements.d.ts +11 -0
- package/dist/cpp-source-replacements.js +257 -0
- package/dist/cpp-store-hub.d.ts +7 -0
- package/dist/cpp-store-hub.js +160 -0
- package/dist/cpp-store-method-body-parser.d.ts +2 -0
- package/dist/cpp-store-method-body-parser.js +392 -0
- package/dist/cpp-store-method-context.d.ts +48 -0
- package/dist/cpp-store-method-context.js +114 -0
- package/dist/cpp-store-method-expressions.d.ts +12 -0
- package/dist/cpp-store-method-expressions.js +1263 -0
- package/dist/cpp-store-method-replacements.d.ts +5 -0
- package/dist/cpp-store-method-replacements.js +1521 -0
- package/dist/cpp-store-method-targets.d.ts +19 -0
- package/dist/cpp-store-method-targets.js +296 -0
- package/dist/cpp-store-typed-arrays.d.ts +2 -0
- package/dist/cpp-store-typed-arrays.js +655 -0
- package/dist/cpp-stores.d.ts +73 -0
- package/dist/cpp-stores.js +1739 -0
- package/dist/cpp-template-renderer.d.ts +23 -0
- package/dist/cpp-template-renderer.js +3530 -0
- package/dist/css-style-declaration-shims.d.ts +3 -0
- package/dist/css-style-declaration-shims.js +47 -0
- package/dist/host-declarations.d.ts +11 -0
- package/dist/host-declarations.js +320 -0
- package/dist/host-shims.d.ts +3 -0
- package/dist/host-shims.js +3217 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1239 -0
- package/dist/load-ir.d.ts +7 -0
- package/dist/load-ir.js +40 -0
- package/dist/types.d.ts +604 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +26 -0
- package/dist/utils.js +723 -0
- package/dist/validate.d.ts +3 -0
- package/dist/validate.js +226 -0
- package/package.json +57 -0
|
@@ -0,0 +1,787 @@
|
|
|
1
|
+
import { collectSingletonMethodsFromSourceFiles, collectStoreArraySources, collectStoreFields, collectStoreMethods, enrichConstantInitializerShapes } from './cpp-stores.js';
|
|
2
|
+
import { isRootSetupSlot, objectArrayConstant, rootSetupLines } from './cpp-mounted-lowering.js';
|
|
3
|
+
import { canMountComponent, mountedRendererForComponent, mountedRendererName, selfStoreMountedRenderer } from './cpp-mounted.js';
|
|
4
|
+
import { collectIrConstants } from './cpp-ir.js';
|
|
5
|
+
import { parseTemplateRoot } from './cpp-template-renderer.js';
|
|
6
|
+
import { isRuntimeNumericConstantIdentifier, sanitizeCppIdentifier } from './utils.js';
|
|
7
|
+
export { replaceGeneratedRenderers } from './cpp-source-replacements.js';
|
|
8
|
+
export function rendererReplacementsForIr(ir) {
|
|
9
|
+
const constants = collectIrConstants(ir);
|
|
10
|
+
enrichConstantInitializerShapes(ir.stores, constants, ir.modules.map((module) => module.file));
|
|
11
|
+
const storeArrayFields = collectStoreArraySources(ir.stores);
|
|
12
|
+
const storeFields = collectStoreFields(ir.stores);
|
|
13
|
+
const storeMethods = collectStoreMethods(ir.stores).concat(collectSingletonMethodsFromSourceFiles(ir.modules.map((module) => module.file), ir.stores));
|
|
14
|
+
const replacements = [];
|
|
15
|
+
for (const component of ir.components) {
|
|
16
|
+
const rendererIsGenerated = () => mountedRendererForComponent(component, ir.components, storeFields, storeArrayFields, constants, storeMethods) !== null;
|
|
17
|
+
// EXPERIMENTAL (ReactiveComponent): a self-store component's store is
|
|
18
|
+
// unambiguously itself, so we don't run the slot-by-slot store inference
|
|
19
|
+
// (which requires every slot to reduce to a single `store.field`). The gate
|
|
20
|
+
// is exactly "the unified typed renderer can be generated" — the SAME call
|
|
21
|
+
// generateCppIrMountedSource makes, so replacement and renderer stay in
|
|
22
|
+
// lockstep; the direct-mount planner mounts via `make_shared<Class>()`.
|
|
23
|
+
const reactiveSelfStore = withRootRefs(component, reactiveSelfStoreReplacement(component, ir.components, storeFields, storeArrayFields, constants, storeMethods));
|
|
24
|
+
if (reactiveSelfStore) {
|
|
25
|
+
replacements.push(reactiveSelfStore);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const staticRenderer = withRootRefs(component, staticComponentReplacement(component, storeFields));
|
|
29
|
+
if (staticRenderer && rendererIsGenerated()) {
|
|
30
|
+
replacements.push(staticRenderer);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const keyed = withRootRefs(component, keyedListReplacement(component, storeArrayFields, storeFields));
|
|
34
|
+
if (keyed && rendererIsGenerated()) {
|
|
35
|
+
replacements.push(keyed);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const style = withRootRefs(component, styleComponentReplacement(component, ir.components, storeFields, storeArrayFields, constants, storeMethods));
|
|
39
|
+
if (style && rendererIsGenerated()) {
|
|
40
|
+
replacements.push(style);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const text = withRootRefs(component, textComponentReplacement(component, ir.components, storeFields, storeArrayFields, constants, storeMethods));
|
|
44
|
+
if (text && rendererIsGenerated()) {
|
|
45
|
+
replacements.push(text);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const mount = withRootRefs(component, mountComponentReplacement(component, ir.components, storeFields, storeArrayFields, constants, storeMethods));
|
|
49
|
+
if (mount && rendererIsGenerated()) {
|
|
50
|
+
replacements.push(mount);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const template = withRootRefs(component, templateComponentReplacement(component, ir.components, storeFields, storeArrayFields, constants, storeMethods));
|
|
54
|
+
if (template && rendererIsGenerated())
|
|
55
|
+
replacements.push(template);
|
|
56
|
+
}
|
|
57
|
+
return replacements;
|
|
58
|
+
}
|
|
59
|
+
export function inlineOnlyComponentClassesForIr(ir) {
|
|
60
|
+
const replacements = rendererReplacementsForIr(ir);
|
|
61
|
+
const replaceableClasses = new Set(replacements.map((replacement) => replacement.className));
|
|
62
|
+
const componentsByName = new Map(ir.components.map((component) => [component.exportName, component]));
|
|
63
|
+
const inlineOnly = new Set();
|
|
64
|
+
const maybeAddInlineOnlyMount = (slot) => {
|
|
65
|
+
if (slot.kind !== 'mount' || mountSlotAttrs(slot).length === 0)
|
|
66
|
+
return;
|
|
67
|
+
const tag = mountSlotTag(slot);
|
|
68
|
+
const child = tag ? componentsByName.get(tag) : null;
|
|
69
|
+
if (!child)
|
|
70
|
+
return;
|
|
71
|
+
const childClass = sanitizeCppIdentifier(child.exportName);
|
|
72
|
+
if (!replaceableClasses.has(childClass))
|
|
73
|
+
inlineOnly.add(childClass);
|
|
74
|
+
};
|
|
75
|
+
for (const component of ir.components) {
|
|
76
|
+
if (!replaceableClasses.has(sanitizeCppIdentifier(component.exportName)))
|
|
77
|
+
continue;
|
|
78
|
+
for (const slot of component.template.slots) {
|
|
79
|
+
maybeAddInlineOnlyMount(slot);
|
|
80
|
+
if (slot.kind === 'keyed-list') {
|
|
81
|
+
for (const rowSlot of keyedListRowTemplateSlots(slot))
|
|
82
|
+
maybeAddInlineOnlyMount(rowSlot);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return inlineOnly;
|
|
87
|
+
}
|
|
88
|
+
function keyedListRowTemplateSlots(slot) {
|
|
89
|
+
const payload = slot.payload;
|
|
90
|
+
if (!payload || typeof payload !== 'object')
|
|
91
|
+
return [];
|
|
92
|
+
const rowTemplate = payload.rowTemplate;
|
|
93
|
+
if (!rowTemplate || typeof rowTemplate !== 'object')
|
|
94
|
+
return [];
|
|
95
|
+
const slots = rowTemplate.slots;
|
|
96
|
+
return Array.isArray(slots) ? slots : [];
|
|
97
|
+
}
|
|
98
|
+
function withRootRefs(component, replacement) {
|
|
99
|
+
if (!replacement)
|
|
100
|
+
return null;
|
|
101
|
+
const refFields = component.template.slots
|
|
102
|
+
.filter((slot) => slot.kind === 'ref' && slot.walk.length === 0 && slot.exprPath?.length === 2 && slot.exprPath[0] === 'this')
|
|
103
|
+
.map((slot) => sanitizeCppIdentifier(slot.exprPath[1]));
|
|
104
|
+
if (refFields.length > 0)
|
|
105
|
+
replacement.refFields = [...new Set(refFields)];
|
|
106
|
+
return replacement;
|
|
107
|
+
}
|
|
108
|
+
function reactiveSelfStoreReplacement(component, components, storeFields, storeArrayFields, constants, storeMethods) {
|
|
109
|
+
if (!component.reactiveState)
|
|
110
|
+
return null;
|
|
111
|
+
// Mountable iff the unified typed renderer generates for this template.
|
|
112
|
+
if (!selfStoreMountedRenderer(component, components, storeFields, storeArrayFields, new Map(constants), storeMethods))
|
|
113
|
+
return null;
|
|
114
|
+
return {
|
|
115
|
+
className: sanitizeCppIdentifier(component.exportName),
|
|
116
|
+
rendererName: `render_${sanitizeCppIdentifier(component.exportName)}`,
|
|
117
|
+
mountedRendererName: mountedRendererName(component),
|
|
118
|
+
// Placeholder: the direct-mount planner sees `reactiveState` and mounts the
|
|
119
|
+
// live `make_shared<Class>()` instance, so this value is never read.
|
|
120
|
+
storeExpression: 'this',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function staticComponentReplacement(component, storeFields) {
|
|
124
|
+
if (component.template.slots.length !== 0) {
|
|
125
|
+
if (!component.template.slots.every((slot) => isRootSetupSlot(slot)))
|
|
126
|
+
return null;
|
|
127
|
+
if (!rootSetupLines('root', component.template.slots, storeFields))
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
const eventStoreExpression = eventStoreExpressionForComponent(component);
|
|
131
|
+
if (eventStoreExpression === undefined)
|
|
132
|
+
return null;
|
|
133
|
+
return {
|
|
134
|
+
className: sanitizeCppIdentifier(component.exportName),
|
|
135
|
+
rendererName: `render_${sanitizeCppIdentifier(component.exportName)}`,
|
|
136
|
+
mountedRendererName: mountedRendererName(component),
|
|
137
|
+
storeExpression: eventStoreExpression ?? 'gea_cpp_value::missing()',
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function keyedListReplacement(component, storeArrayFields, storeFields) {
|
|
141
|
+
const slots = component.template.slots.filter((slot) => slot.kind === 'keyed-list');
|
|
142
|
+
if (slots.length !== 1)
|
|
143
|
+
return null;
|
|
144
|
+
if (!component.template.slots.every((slot) => slot === slots[0] || isRootSetupSlot(slot)))
|
|
145
|
+
return null;
|
|
146
|
+
if (!rootSetupLines('root', component.template.slots, storeFields))
|
|
147
|
+
return null;
|
|
148
|
+
const slot = slots[0];
|
|
149
|
+
const storeExpression = storeExpressionForSlot(slot);
|
|
150
|
+
const fieldName = slotFieldName(slot);
|
|
151
|
+
if (!storeExpression || !fieldName)
|
|
152
|
+
return null;
|
|
153
|
+
const matches = storeArrayFields.filter((field) => field.fieldName === fieldName);
|
|
154
|
+
if (matches.length !== 1)
|
|
155
|
+
return null;
|
|
156
|
+
return {
|
|
157
|
+
className: sanitizeCppIdentifier(component.exportName),
|
|
158
|
+
rendererName: `render_${sanitizeCppIdentifier(component.exportName)}_${matches[0].fieldName}`,
|
|
159
|
+
mountedRendererName: mountedRendererName(component),
|
|
160
|
+
stateReaderName: `read_${matches[0].stateType}`,
|
|
161
|
+
storeExpression: sanitizeCppIdentifier(storeExpression),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function styleComponentReplacement(component, components, storeFields, storeArrayFields, constants, storeMethods) {
|
|
165
|
+
// The shell this replacement produces calls `gea_ir::mount_<Name>` — it must
|
|
166
|
+
// only exist when the mounted renderer will actually be generated, or the
|
|
167
|
+
// reference dangles at link time. `canMountComponent` is the same gate the
|
|
168
|
+
// renderer generator applies (a reactive self-store component reaching this
|
|
169
|
+
// point has already failed its typed renderer, so it never gets a mount).
|
|
170
|
+
if (component.reactiveState)
|
|
171
|
+
return null;
|
|
172
|
+
if (!canMountComponent(component, components, storeFields, storeArrayFields, constants, storeMethods))
|
|
173
|
+
return null;
|
|
174
|
+
if (component.template.slots.some((slot) => slot.kind === 'keyed-list'))
|
|
175
|
+
return null;
|
|
176
|
+
if (!component.template.slots.every((slot) => slot.kind === 'style' || isRootSetupSlot(slot)))
|
|
177
|
+
return null;
|
|
178
|
+
if (!rootSetupLines('root', component.template.slots, storeFields))
|
|
179
|
+
return null;
|
|
180
|
+
const fields = component.template.slots.flatMap((slot) => (slot.kind === 'style' ? (slot.exprObjectFields ?? []) : []));
|
|
181
|
+
if (fields.length === 0)
|
|
182
|
+
return null;
|
|
183
|
+
const refs = [];
|
|
184
|
+
for (const field of fields) {
|
|
185
|
+
const fieldRefs = expressionReferences(field.expr, new Map(), constants);
|
|
186
|
+
if (!fieldRefs)
|
|
187
|
+
return null;
|
|
188
|
+
refs.push(...fieldRefs);
|
|
189
|
+
}
|
|
190
|
+
const replacement = replacementFromReferences(component, refs, storeFields);
|
|
191
|
+
return replacementMatchesEventStore(component, replacement);
|
|
192
|
+
}
|
|
193
|
+
function textComponentReplacement(component, components, storeFields, storeArrayFields, constants, storeMethods) {
|
|
194
|
+
// Same lockstep rule as styleComponentReplacement: no shell without a
|
|
195
|
+
// generated `mount_<Name>` renderer behind it.
|
|
196
|
+
if (component.reactiveState)
|
|
197
|
+
return null;
|
|
198
|
+
if (!canMountComponent(component, components, storeFields, storeArrayFields, constants, storeMethods))
|
|
199
|
+
return null;
|
|
200
|
+
if (component.template.slots.some((slot) => slot.kind === 'keyed-list'))
|
|
201
|
+
return null;
|
|
202
|
+
if (!component.template.slots.every((slot) => slot.kind === 'text' || slot.kind === 'style' || isRootSetupSlot(slot)))
|
|
203
|
+
return null;
|
|
204
|
+
if (!rootSetupLines('root', component.template.slots, storeFields))
|
|
205
|
+
return null;
|
|
206
|
+
const slots = component.template.slots.filter((slot) => slot.kind === 'text');
|
|
207
|
+
if (slots.length === 0 || slots.some((slot) => !slot.directText))
|
|
208
|
+
return null;
|
|
209
|
+
const refs = [];
|
|
210
|
+
for (const slot of slots) {
|
|
211
|
+
const slotRefs = textSlotReferences(slot, constants);
|
|
212
|
+
if (!slotRefs)
|
|
213
|
+
return null;
|
|
214
|
+
refs.push(...slotRefs);
|
|
215
|
+
}
|
|
216
|
+
if (refs.length === 0)
|
|
217
|
+
return null;
|
|
218
|
+
const replacement = replacementFromReferences(component, refs, storeFields);
|
|
219
|
+
return replacementMatchesEventStore(component, replacement);
|
|
220
|
+
}
|
|
221
|
+
function mountComponentReplacement(component, components, storeFields, storeArrayFields, constants, storeMethods) {
|
|
222
|
+
const slots = component.template.slots.filter((slot) => slot.kind === 'mount');
|
|
223
|
+
if (slots.length === 0)
|
|
224
|
+
return null;
|
|
225
|
+
if (!component.template.slots.every((slot) => slot.kind === 'mount' || isRootSetupSlot(slot)))
|
|
226
|
+
return null;
|
|
227
|
+
if (!rootSetupLines('root', component.template.slots, storeFields))
|
|
228
|
+
return null;
|
|
229
|
+
if (!canMountComponent(component, components, storeFields, storeArrayFields, constants, storeMethods))
|
|
230
|
+
return null;
|
|
231
|
+
const refs = [];
|
|
232
|
+
for (const slot of slots) {
|
|
233
|
+
const tag = mountSlotTag(slot);
|
|
234
|
+
const child = tag ? components.find((candidate) => candidate.exportName === tag) : null;
|
|
235
|
+
if (!child)
|
|
236
|
+
return null;
|
|
237
|
+
const childRefs = componentStoreReferences(child, components, storeFields, storeArrayFields, constants, storeMethods);
|
|
238
|
+
if (!childRefs)
|
|
239
|
+
return null;
|
|
240
|
+
refs.push(...childRefs);
|
|
241
|
+
}
|
|
242
|
+
if (refs.length === 0)
|
|
243
|
+
return null;
|
|
244
|
+
// Single-store case: every child slot references the same store. Thread it
|
|
245
|
+
// through as the parent's `storeExpression` so `mount_<child>(store, …)`
|
|
246
|
+
// bindings (`bindReactiveApply(store, …)`, `read_<Store>_field_X(store)`)
|
|
247
|
+
// see the actual store, not `missing()`. This is the path analog-clock and
|
|
248
|
+
// every other single-store composition takes — passing `missing()` here
|
|
249
|
+
// makes every reactive field read return 0 and freezes the UI.
|
|
250
|
+
const singleStoreReplacement = replacementFromReferences(component, refs, storeFields);
|
|
251
|
+
if (singleStoreReplacement)
|
|
252
|
+
return replacementMatchesEventStore(component, singleStoreReplacement);
|
|
253
|
+
// Multi-store composition (e.g. launcher's <App> whose children touch both
|
|
254
|
+
// `launcher` and `Settings`). No single store fits the parent, but every
|
|
255
|
+
// child's own `mount_<child>` renderer fetches its store via
|
|
256
|
+
// `__gea_global_*()`, so passing `missing()` here is harmless — the param
|
|
257
|
+
// store is never read inside any analyzable single-store child renderer.
|
|
258
|
+
// (`replacementFromReferences` returned null only when the ref set spans
|
|
259
|
+
// multiple distinct store expressions; that's the case the comment about
|
|
260
|
+
// "children may collectively use any number of stores" covers, and the only
|
|
261
|
+
// case where this fallback is reached.)
|
|
262
|
+
return replacementMatchesEventStore(component, {
|
|
263
|
+
className: sanitizeCppIdentifier(component.exportName),
|
|
264
|
+
rendererName: `render_${sanitizeCppIdentifier(component.exportName)}`,
|
|
265
|
+
mountedRendererName: mountedRendererName(component),
|
|
266
|
+
storeExpression: 'gea_cpp_value::missing()',
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
function templateComponentReplacement(component, components, storeFields, storeArrayFields, constants, storeMethods) {
|
|
270
|
+
const refs = componentStoreReferences(component, components, storeFields, storeArrayFields, constants, storeMethods);
|
|
271
|
+
if (!refs)
|
|
272
|
+
return null;
|
|
273
|
+
if (refs.length === 0) {
|
|
274
|
+
const eventStoreExpression = eventStoreExpressionForComponent(component);
|
|
275
|
+
if (eventStoreExpression === undefined)
|
|
276
|
+
return null;
|
|
277
|
+
return {
|
|
278
|
+
className: sanitizeCppIdentifier(component.exportName),
|
|
279
|
+
rendererName: `render_${sanitizeCppIdentifier(component.exportName)}`,
|
|
280
|
+
mountedRendererName: mountedRendererName(component),
|
|
281
|
+
storeExpression: eventStoreExpression ?? 'gea_cpp_value::missing()',
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
const replacement = replacementFromReferences(component, refs, storeFields);
|
|
285
|
+
if (replacement)
|
|
286
|
+
return replacementMatchesEventStore(component, replacement);
|
|
287
|
+
// Multi-store templates (for example an app shell with status, routed
|
|
288
|
+
// screens, and an action bar) still have a single native `mount_<Name>`
|
|
289
|
+
// renderer. That renderer reads each referenced global directly, so the
|
|
290
|
+
// generated class shell does not need a single threaded store parameter.
|
|
291
|
+
return replacementMatchesEventStore(component, {
|
|
292
|
+
className: sanitizeCppIdentifier(component.exportName),
|
|
293
|
+
rendererName: `render_${sanitizeCppIdentifier(component.exportName)}`,
|
|
294
|
+
mountedRendererName: mountedRendererName(component),
|
|
295
|
+
storeExpression: 'gea_cpp_value::missing()',
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
// Exported for cpp-mounted's typed child store-arg resolution (the typed
|
|
299
|
+
// parent threads the same single global store the boxed entry would).
|
|
300
|
+
export function componentStoreReferences(component, components, storeFields, storeArrayFields, constants, storeMethods = [], propBindings = new Map(), seenComponents = new Set()) {
|
|
301
|
+
if (seenComponents.has(component.id))
|
|
302
|
+
return [];
|
|
303
|
+
const nextSeen = new Set(seenComponents);
|
|
304
|
+
nextSeen.add(component.id);
|
|
305
|
+
const refs = [];
|
|
306
|
+
const eventStoreExpression = eventStoreExpressionForComponent(component);
|
|
307
|
+
if (eventStoreExpression === undefined)
|
|
308
|
+
return null;
|
|
309
|
+
if (eventStoreExpression)
|
|
310
|
+
refs.push({ storeExpression: eventStoreExpression });
|
|
311
|
+
for (const slot of component.template.slots) {
|
|
312
|
+
if (slot.kind === 'keyed-list') {
|
|
313
|
+
if (isStaticKeyedListSlot(slot))
|
|
314
|
+
continue;
|
|
315
|
+
if (objectArrayConstant(slot.expr, constants))
|
|
316
|
+
continue;
|
|
317
|
+
const storeExpression = storeExpressionForSlot(slot);
|
|
318
|
+
const fieldName = slotFieldName(slot);
|
|
319
|
+
if (!storeExpression || !fieldName)
|
|
320
|
+
return null;
|
|
321
|
+
refs.push({ storeExpression, fieldName });
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (slot.kind === 'style') {
|
|
325
|
+
for (const field of slot.exprObjectFields ?? []) {
|
|
326
|
+
const fieldRefs = expressionReferences(field.expr, propBindings, constants);
|
|
327
|
+
if (!fieldRefs)
|
|
328
|
+
return null;
|
|
329
|
+
refs.push(...fieldRefs);
|
|
330
|
+
}
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (slot.kind === 'class') {
|
|
334
|
+
const classRefs = expressionReferences(slot.expr, propBindings, constants);
|
|
335
|
+
if (!classRefs)
|
|
336
|
+
return null;
|
|
337
|
+
refs.push(...classRefs);
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
if (slot.kind === 'text') {
|
|
341
|
+
const textRefs = expressionReferences(slot.expr, propBindings, constants);
|
|
342
|
+
if (!textRefs)
|
|
343
|
+
return null;
|
|
344
|
+
refs.push(...textRefs);
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (slot.kind === 'mount') {
|
|
348
|
+
const tag = mountSlotTag(slot);
|
|
349
|
+
if (tag === 'Image') {
|
|
350
|
+
const imageRefs = imageMountReferences(slot, propBindings, constants);
|
|
351
|
+
if (!imageRefs)
|
|
352
|
+
return null;
|
|
353
|
+
refs.push(...imageRefs);
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const child = childForMountName(tag, components);
|
|
357
|
+
if (!child)
|
|
358
|
+
return null;
|
|
359
|
+
const childProps = mountPropBindings(slot, propBindings);
|
|
360
|
+
// A ReactiveComponent child consumes none of the threaded store — it
|
|
361
|
+
// mounts a fresh typed instance of its own class. It contributes no
|
|
362
|
+
// references; an unmountable one (or one with props, which the renderer
|
|
363
|
+
// can't inline) makes the whole template unanalyzable, matching the
|
|
364
|
+
// emission gates.
|
|
365
|
+
if (child.reactiveState) {
|
|
366
|
+
if (childProps.size > 0 || !canMountComponent(child, components, storeFields, storeArrayFields, constants, storeMethods))
|
|
367
|
+
return null;
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
for (const expr of childProps.values()) {
|
|
371
|
+
const propRefs = expressionReferences(expr, propBindings, constants);
|
|
372
|
+
if (!propRefs)
|
|
373
|
+
return null;
|
|
374
|
+
refs.push(...propRefs);
|
|
375
|
+
}
|
|
376
|
+
if (!canMountComponent(child, components, storeFields, storeArrayFields, constants, storeMethods) &&
|
|
377
|
+
canMountGenericZeroPropChild(child, childProps)) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
const childRefs = componentStoreReferences(child, components, storeFields, storeArrayFields, constants, storeMethods, childProps, nextSeen);
|
|
381
|
+
if (!childRefs)
|
|
382
|
+
return null;
|
|
383
|
+
refs.push(...childRefs);
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
if (slot.kind === 'event') {
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (slot.kind === 'attr') {
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return refs;
|
|
394
|
+
}
|
|
395
|
+
function canMountGenericZeroPropChild(component, propBindings) {
|
|
396
|
+
return propBindings.size === 0 && parseTemplateRoot(component.template.html) !== null;
|
|
397
|
+
}
|
|
398
|
+
function imageMountReferences(slot, propBindings, constants) {
|
|
399
|
+
const refs = [];
|
|
400
|
+
for (const attr of mountSlotAttrs(slot)) {
|
|
401
|
+
const parsed = parseMountAttr(attr);
|
|
402
|
+
if (!parsed)
|
|
403
|
+
continue;
|
|
404
|
+
if (parsed.name === 'src' && isBareIdentifier(parsed.expr))
|
|
405
|
+
continue;
|
|
406
|
+
const attrRefs = expressionReferences(parsed.expr, propBindings, constants);
|
|
407
|
+
if (!attrRefs)
|
|
408
|
+
return null;
|
|
409
|
+
refs.push(...attrRefs);
|
|
410
|
+
}
|
|
411
|
+
return refs;
|
|
412
|
+
}
|
|
413
|
+
export function isStaticKeyedListSlot(slot) {
|
|
414
|
+
const values = staticStringArrayValues(slot.expr);
|
|
415
|
+
if (!values)
|
|
416
|
+
return false;
|
|
417
|
+
const payload = slot.payload;
|
|
418
|
+
if (!payload || typeof payload !== 'object')
|
|
419
|
+
return false;
|
|
420
|
+
const record = payload;
|
|
421
|
+
const itemParam = typeof record.itemParam === 'string' ? record.itemParam : null;
|
|
422
|
+
const rowTemplate = record.rowTemplate && typeof record.rowTemplate === 'object'
|
|
423
|
+
? record.rowTemplate
|
|
424
|
+
: null;
|
|
425
|
+
if (!itemParam || !rowTemplate || !Array.isArray(rowTemplate.slots))
|
|
426
|
+
return false;
|
|
427
|
+
return rowTemplate.slots.every((rowSlot) => isStaticKeyedListRowSlot(rowSlot, itemParam));
|
|
428
|
+
}
|
|
429
|
+
function isStaticKeyedListRowSlot(slot, itemParam) {
|
|
430
|
+
if (slot.walk.length !== 0)
|
|
431
|
+
return false;
|
|
432
|
+
if (slot.kind !== 'class' && slot.kind !== 'text')
|
|
433
|
+
return false;
|
|
434
|
+
if (slot.exprPath && slot.exprPath.length === 1 && slot.exprPath[0] === itemParam)
|
|
435
|
+
return true;
|
|
436
|
+
return slot.expr?.trim() === itemParam;
|
|
437
|
+
}
|
|
438
|
+
function staticStringArrayValues(expr) {
|
|
439
|
+
if (!expr)
|
|
440
|
+
return null;
|
|
441
|
+
const text = expr.trim();
|
|
442
|
+
if (!text.startsWith('[') || !text.endsWith(']'))
|
|
443
|
+
return null;
|
|
444
|
+
const inner = text.slice(1, -1).trim();
|
|
445
|
+
if (!inner)
|
|
446
|
+
return [];
|
|
447
|
+
const values = [];
|
|
448
|
+
for (const part of splitTopLevelComma(inner)) {
|
|
449
|
+
if (!isStringLiteral(part))
|
|
450
|
+
return null;
|
|
451
|
+
values.push(part);
|
|
452
|
+
}
|
|
453
|
+
return values;
|
|
454
|
+
}
|
|
455
|
+
function replacementMatchesEventStore(component, replacement) {
|
|
456
|
+
if (!replacement)
|
|
457
|
+
return null;
|
|
458
|
+
const eventStoreExpression = eventStoreExpressionForComponent(component);
|
|
459
|
+
// `undefined` means the receiver couldn't be parsed (anonymous handler,
|
|
460
|
+
// unsupported shape) — we still bail in that case because the event
|
|
461
|
+
// lowering has nothing to bind to.
|
|
462
|
+
if (eventStoreExpression === undefined)
|
|
463
|
+
return null;
|
|
464
|
+
return replacement;
|
|
465
|
+
}
|
|
466
|
+
function replacementFromReferences(component, refs, storeFields) {
|
|
467
|
+
const storeExpressions = new Set(refs.map((ref) => sanitizeCppIdentifier(ref.storeExpression)));
|
|
468
|
+
if (storeExpressions.size !== 1)
|
|
469
|
+
return null;
|
|
470
|
+
const storeExpression = [...storeExpressions][0];
|
|
471
|
+
const fieldRefs = refs.filter((ref) => !!ref.fieldName);
|
|
472
|
+
if (fieldRefs.length === 0) {
|
|
473
|
+
return {
|
|
474
|
+
className: sanitizeCppIdentifier(component.exportName),
|
|
475
|
+
rendererName: `render_${sanitizeCppIdentifier(component.exportName)}`,
|
|
476
|
+
mountedRendererName: mountedRendererName(component),
|
|
477
|
+
storeExpression,
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
const stores = fieldRefs.map((ref) => storeFieldByName(ref.fieldName, storeFields, ref.storeExpression));
|
|
481
|
+
if (stores.some((store) => store === null))
|
|
482
|
+
return null;
|
|
483
|
+
const storeClasses = new Set(stores.map((store) => store.storeClass));
|
|
484
|
+
if (storeClasses.size !== 1)
|
|
485
|
+
return null;
|
|
486
|
+
const store = stores[0];
|
|
487
|
+
return {
|
|
488
|
+
className: sanitizeCppIdentifier(component.exportName),
|
|
489
|
+
rendererName: `render_${sanitizeCppIdentifier(component.exportName)}`,
|
|
490
|
+
mountedRendererName: mountedRendererName(component),
|
|
491
|
+
stateReaderName: `read_${store.stateType}`,
|
|
492
|
+
storeExpression,
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
function storeFieldByName(fieldName, storeFields, receiver) {
|
|
496
|
+
const matches = storeFields.filter((candidate) => candidate.fieldName === sanitizeCppIdentifier(fieldName));
|
|
497
|
+
if (matches.length === 1)
|
|
498
|
+
return matches[0];
|
|
499
|
+
// Disambiguate colliding field names across bundled stores by the receiver
|
|
500
|
+
// (e.g. `store.status` vs the SettingsStore's `status`). See the matching
|
|
501
|
+
// logic in cpp-template-renderer.ts's storeFieldByName.
|
|
502
|
+
if (matches.length > 1 && receiver) {
|
|
503
|
+
const recv = sanitizeCppIdentifier(receiver);
|
|
504
|
+
const byReceiver = matches.filter((candidate) => candidate.storeGlobalName === recv);
|
|
505
|
+
if (byReceiver.length === 1)
|
|
506
|
+
return byReceiver[0];
|
|
507
|
+
}
|
|
508
|
+
return null;
|
|
509
|
+
}
|
|
510
|
+
function textSlotReferences(slot, constants) {
|
|
511
|
+
if (slot.exprPath && slot.exprPath.length === 2)
|
|
512
|
+
return [{ storeExpression: slot.exprPath[0], fieldName: slot.exprPath[1] }];
|
|
513
|
+
const refs = [];
|
|
514
|
+
for (const part of splitTopLevelPlus(slot.expr ?? '')) {
|
|
515
|
+
if (isStringLiteral(part))
|
|
516
|
+
continue;
|
|
517
|
+
if (isKnownConstantExpression(part, constants))
|
|
518
|
+
continue;
|
|
519
|
+
const match = part.match(/^([A-Za-z_$][A-Za-z0-9_$]*)\.([A-Za-z_$][A-Za-z0-9_$]*)$/);
|
|
520
|
+
if (!match)
|
|
521
|
+
return null;
|
|
522
|
+
refs.push({ storeExpression: match[1], fieldName: match[2] });
|
|
523
|
+
}
|
|
524
|
+
return refs;
|
|
525
|
+
}
|
|
526
|
+
function mountSlotTag(slot) {
|
|
527
|
+
const payload = slot.payload;
|
|
528
|
+
if (!payload || typeof payload !== 'object' || !('tag' in payload))
|
|
529
|
+
return null;
|
|
530
|
+
const tag = payload.tag;
|
|
531
|
+
return typeof tag === 'string' ? tag : null;
|
|
532
|
+
}
|
|
533
|
+
function childForMountName(tag, components) {
|
|
534
|
+
return tag ? (components.find((component) => component.exportName === tag) ?? null) : null;
|
|
535
|
+
}
|
|
536
|
+
function mountSlotAttrs(slot) {
|
|
537
|
+
const payload = slot.payload;
|
|
538
|
+
if (!payload || typeof payload !== 'object' || !('attrs' in payload))
|
|
539
|
+
return [];
|
|
540
|
+
const attrs = payload.attrs;
|
|
541
|
+
if (!Array.isArray(attrs))
|
|
542
|
+
return [];
|
|
543
|
+
return attrs
|
|
544
|
+
.map((attr) => {
|
|
545
|
+
if (!attr || typeof attr !== 'object' || !('code' in attr))
|
|
546
|
+
return null;
|
|
547
|
+
const code = attr.code;
|
|
548
|
+
return typeof code === 'string' ? code : null;
|
|
549
|
+
})
|
|
550
|
+
.filter((code) => !!code);
|
|
551
|
+
}
|
|
552
|
+
function mountPropBindings(slot, parentProps) {
|
|
553
|
+
const out = new Map();
|
|
554
|
+
for (const attr of mountSlotAttrs(slot)) {
|
|
555
|
+
const parsed = parseMountAttr(attr);
|
|
556
|
+
if (!parsed)
|
|
557
|
+
continue;
|
|
558
|
+
out.set(parsed.name, resolvePropExpression(parsed.expr, parentProps) ?? parsed.expr);
|
|
559
|
+
}
|
|
560
|
+
return out;
|
|
561
|
+
}
|
|
562
|
+
function parseMountAttr(code) {
|
|
563
|
+
const trimmed = code.trim();
|
|
564
|
+
const stringAttr = trimmed.match(/^([A-Za-z_$][A-Za-z0-9_$]*)=(["'])(.*)\2$/s);
|
|
565
|
+
if (stringAttr)
|
|
566
|
+
return { name: stringAttr[1], expr: `${stringAttr[2]}${stringAttr[3]}${stringAttr[2]}` };
|
|
567
|
+
const expressionAttr = trimmed.match(/^([A-Za-z_$][A-Za-z0-9_$]*)=\{([\s\S]*)\}$/);
|
|
568
|
+
if (expressionAttr)
|
|
569
|
+
return { name: expressionAttr[1], expr: expressionAttr[2].trim() };
|
|
570
|
+
const bareAttr = trimmed.match(/^([A-Za-z_$][A-Za-z0-9_$]*)$/);
|
|
571
|
+
return bareAttr ? { name: bareAttr[1], expr: 'true' } : null;
|
|
572
|
+
}
|
|
573
|
+
function expressionReferences(expr, propBindings, constants) {
|
|
574
|
+
if (!expr)
|
|
575
|
+
return [];
|
|
576
|
+
const resolved = resolvePropExpression(expr, propBindings) ?? expr;
|
|
577
|
+
if (/\bthis\.props\./.test(resolved))
|
|
578
|
+
return null;
|
|
579
|
+
const refs = [];
|
|
580
|
+
const dependencySource = resolved.replace(/\b([A-Za-z_$][A-Za-z0-9_$]*\.[A-Za-z_$][A-Za-z0-9_$]*)\.length\b/g, '$1');
|
|
581
|
+
const pattern = /\b([A-Za-z_$][A-Za-z0-9_$]*)\.([A-Za-z_$][A-Za-z0-9_$]*)\b/g;
|
|
582
|
+
let match;
|
|
583
|
+
while ((match = pattern.exec(dependencySource)) !== null) {
|
|
584
|
+
if (match[1] === 'this')
|
|
585
|
+
return null;
|
|
586
|
+
// `props.X` references contribute no store dependency at top-level
|
|
587
|
+
// analysis. Wrapper components like `<View>` reference `props.class`,
|
|
588
|
+
// `props.style`, etc. — when nothing is bound (top-level mount), those
|
|
589
|
+
// slots are no-ops (see `slotReferencesUnboundProp` in the renderer).
|
|
590
|
+
// When the wrapper is inlined, the parent passes literal/store refs and
|
|
591
|
+
// those flow through the slot's own analysis path.
|
|
592
|
+
if (match[1] === 'props')
|
|
593
|
+
continue;
|
|
594
|
+
if (match[1] === 'Math')
|
|
595
|
+
continue;
|
|
596
|
+
refs.push({ storeExpression: match[1], fieldName: match[2] });
|
|
597
|
+
}
|
|
598
|
+
if (refs.length === 0 && /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(resolved.trim()) && !isKnownConstantExpression(resolved, constants)) {
|
|
599
|
+
// A bare identifier that isn't a known compile-time constant is normally a
|
|
600
|
+
// bail signal (could be an unresolvable local). But SCREAMING_SNAKE_CASE
|
|
601
|
+
// module constants computed at runtime (e.g. `ITEM_HEIGHT = 126 * CSS_PX`)
|
|
602
|
+
// never make it into the IR constant map, yet they carry no store
|
|
603
|
+
// dependency. Treat them as zero-reference so the component still qualifies
|
|
604
|
+
// for the optimized template mount path.
|
|
605
|
+
if (isRuntimeNumericConstantIdentifier(resolved.trim()))
|
|
606
|
+
return refs;
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
return refs;
|
|
610
|
+
}
|
|
611
|
+
function isKnownConstantExpression(expr, constants) {
|
|
612
|
+
return constants.has(expr.trim());
|
|
613
|
+
}
|
|
614
|
+
function isBareIdentifier(expr) {
|
|
615
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(expr.trim());
|
|
616
|
+
}
|
|
617
|
+
function resolvePropExpression(expr, propBindings) {
|
|
618
|
+
if (propBindings.size === 0)
|
|
619
|
+
return null;
|
|
620
|
+
let out = expr;
|
|
621
|
+
let changed = false;
|
|
622
|
+
for (const [name, value] of propBindings) {
|
|
623
|
+
const escaped = escapeRegExp(name);
|
|
624
|
+
const pattern = new RegExp(`\\bthis\\.props\\.${escaped}\\b|\\bprops\\.${escaped}\\b|(?<!\\.)\\b${escaped}\\b`, 'g');
|
|
625
|
+
out = out.replace(pattern, () => {
|
|
626
|
+
changed = true;
|
|
627
|
+
return `(${value})`;
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
return changed ? out : null;
|
|
631
|
+
}
|
|
632
|
+
function storeExpressionForSlot(slot) {
|
|
633
|
+
if (slot.exprPath && slot.exprPath.length > 1)
|
|
634
|
+
return slot.exprPath[0];
|
|
635
|
+
return firstObjectIdentifier(slot.expr);
|
|
636
|
+
}
|
|
637
|
+
export function slotFieldName(slot) {
|
|
638
|
+
if (slot.exprPath && slot.exprPath.length > 1)
|
|
639
|
+
return sanitizeCppIdentifier(slot.exprPath[slot.exprPath.length - 1]);
|
|
640
|
+
const match = slot.expr?.match(/\.([A-Za-z_$][A-Za-z0-9_$]*)$/);
|
|
641
|
+
return match ? sanitizeCppIdentifier(match[1]) : null;
|
|
642
|
+
}
|
|
643
|
+
function firstObjectIdentifier(expr) {
|
|
644
|
+
const match = expr?.match(/^([A-Za-z_$][A-Za-z0-9_$]*)\./);
|
|
645
|
+
return match ? match[1] : null;
|
|
646
|
+
}
|
|
647
|
+
function eventStoreExpressionForComponent(component) {
|
|
648
|
+
const receivers = component.template.slots
|
|
649
|
+
.filter((slot) => slot.kind === 'event')
|
|
650
|
+
.map((slot) => eventReceiver(slot.expr));
|
|
651
|
+
if (receivers.some((receiver) => receiver === undefined))
|
|
652
|
+
return undefined;
|
|
653
|
+
const uniqueReceivers = [...new Set(receivers.filter((receiver) => typeof receiver === 'string'))];
|
|
654
|
+
if (uniqueReceivers.length === 0)
|
|
655
|
+
return null;
|
|
656
|
+
return uniqueReceivers.length === 1 ? sanitizeCppIdentifier(uniqueReceivers[0]) : undefined;
|
|
657
|
+
}
|
|
658
|
+
function eventReceiver(expr) {
|
|
659
|
+
if (!expr)
|
|
660
|
+
return undefined;
|
|
661
|
+
// Prop-forwarding events (`onClick={props.onClick}`) — common in the
|
|
662
|
+
// gea-embedded wrappers — don't constrain the event store. The parent
|
|
663
|
+
// decides what handler runs; we return null (no contribution) instead of
|
|
664
|
+
// undefined (failure) so `componentStoreReferences` doesn't bail when
|
|
665
|
+
// analyzing a wrapper component that's only meant to be inlined.
|
|
666
|
+
const trimmed = expr.trim();
|
|
667
|
+
if (/^props\.[A-Za-z_$][A-Za-z0-9_$]*$/.test(trimmed))
|
|
668
|
+
return null;
|
|
669
|
+
const arrow = expr.indexOf('=>');
|
|
670
|
+
if (arrow < 0)
|
|
671
|
+
return undefined;
|
|
672
|
+
const rawParams = expr.slice(0, arrow).trim();
|
|
673
|
+
const params = rawParams.startsWith('(')
|
|
674
|
+
? rawParams.slice(1, -1).split(',').map((part) => part.trim()).filter(Boolean)
|
|
675
|
+
: rawParams.length === 0
|
|
676
|
+
? []
|
|
677
|
+
: [rawParams];
|
|
678
|
+
let body = expr.slice(arrow + 2).trim();
|
|
679
|
+
let statements;
|
|
680
|
+
if (body.startsWith('{') && body.endsWith('}')) {
|
|
681
|
+
const inner = body.slice(1, -1).trim();
|
|
682
|
+
const returnMatch = inner.match(/^return\s+(.+?);?$/s);
|
|
683
|
+
statements = returnMatch
|
|
684
|
+
? [returnMatch[1].trim()]
|
|
685
|
+
: splitTopLevelSemicolon(inner).map((statement) => statement.trim()).filter(Boolean);
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
statements = [body.replace(/;$/, '').trim()].filter(Boolean);
|
|
689
|
+
}
|
|
690
|
+
const receivers = [];
|
|
691
|
+
for (const statement of statements) {
|
|
692
|
+
const guarded = statement.match(/^if\s*\(([\s\S]+?)\)\s*([\s\S]+)$/);
|
|
693
|
+
const eventStatement = guarded ? guarded[2].trim().replace(/;$/, '') : statement;
|
|
694
|
+
if (/^[A-Za-z_$][A-Za-z0-9_$]*\(/.test(eventStatement))
|
|
695
|
+
continue;
|
|
696
|
+
const call = eventStatement.match(/^([A-Za-z_$][A-Za-z0-9_$]*)\.([A-Za-z_$][A-Za-z0-9_$]*)\((.*)\)$/s);
|
|
697
|
+
if (!call)
|
|
698
|
+
return undefined;
|
|
699
|
+
const [, receiver, method, rawArgs] = call;
|
|
700
|
+
if (params.includes(receiver) && (method === 'preventDefault' || method === 'stopPropagation')) {
|
|
701
|
+
if (splitTopLevelComma(rawArgs).filter((arg) => arg !== '').length > 0)
|
|
702
|
+
return undefined;
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
if (params.includes(receiver))
|
|
706
|
+
return undefined;
|
|
707
|
+
receivers.push(receiver);
|
|
708
|
+
}
|
|
709
|
+
const uniqueReceivers = [...new Set(receivers)];
|
|
710
|
+
if (uniqueReceivers.length === 0)
|
|
711
|
+
return null;
|
|
712
|
+
return uniqueReceivers.length === 1 ? uniqueReceivers[0] : undefined;
|
|
713
|
+
}
|
|
714
|
+
function splitTopLevelComma(expr) {
|
|
715
|
+
return splitTopLevelDelimiter(expr, ',');
|
|
716
|
+
}
|
|
717
|
+
function splitTopLevelSemicolon(expr) {
|
|
718
|
+
return splitTopLevelDelimiter(expr, ';');
|
|
719
|
+
}
|
|
720
|
+
function splitTopLevelDelimiter(expr, delimiter) {
|
|
721
|
+
const parts = [];
|
|
722
|
+
let start = 0;
|
|
723
|
+
let quote = null;
|
|
724
|
+
let escaped = false;
|
|
725
|
+
let depth = 0;
|
|
726
|
+
for (let index = 0; index < expr.length; index += 1) {
|
|
727
|
+
const char = expr[index];
|
|
728
|
+
if (quote) {
|
|
729
|
+
if (escaped)
|
|
730
|
+
escaped = false;
|
|
731
|
+
else if (char === '\\')
|
|
732
|
+
escaped = true;
|
|
733
|
+
else if (char === quote)
|
|
734
|
+
quote = null;
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
if (char === '"' || char === "'") {
|
|
738
|
+
quote = char;
|
|
739
|
+
continue;
|
|
740
|
+
}
|
|
741
|
+
if (char === '(' || char === '[' || char === '{')
|
|
742
|
+
depth += 1;
|
|
743
|
+
else if (char === ')' || char === ']' || char === '}')
|
|
744
|
+
depth -= 1;
|
|
745
|
+
else if (char === delimiter && depth === 0) {
|
|
746
|
+
parts.push(expr.slice(start, index).trim());
|
|
747
|
+
start = index + 1;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
parts.push(expr.slice(start).trim());
|
|
751
|
+
return parts;
|
|
752
|
+
}
|
|
753
|
+
function splitTopLevelPlus(expr) {
|
|
754
|
+
const parts = [];
|
|
755
|
+
let start = 0;
|
|
756
|
+
let quote = null;
|
|
757
|
+
let escaped = false;
|
|
758
|
+
for (let index = 0; index < expr.length; index += 1) {
|
|
759
|
+
const char = expr[index];
|
|
760
|
+
if (quote) {
|
|
761
|
+
if (escaped)
|
|
762
|
+
escaped = false;
|
|
763
|
+
else if (char === '\\')
|
|
764
|
+
escaped = true;
|
|
765
|
+
else if (char === quote)
|
|
766
|
+
quote = null;
|
|
767
|
+
continue;
|
|
768
|
+
}
|
|
769
|
+
if (char === '"' || char === "'") {
|
|
770
|
+
quote = char;
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
if (char !== '+')
|
|
774
|
+
continue;
|
|
775
|
+
parts.push(expr.slice(start, index).trim());
|
|
776
|
+
start = index + 1;
|
|
777
|
+
}
|
|
778
|
+
parts.push(expr.slice(start).trim());
|
|
779
|
+
return parts.filter(Boolean);
|
|
780
|
+
}
|
|
781
|
+
function isStringLiteral(expr) {
|
|
782
|
+
const quote = expr[0];
|
|
783
|
+
return (quote === '"' || quote === "'") && expr[expr.length - 1] === quote;
|
|
784
|
+
}
|
|
785
|
+
function escapeRegExp(value) {
|
|
786
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
787
|
+
}
|