@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,76 @@
|
|
|
1
|
+
// A ReactiveComponent whose template falls off the typed fast path has NO
|
|
2
|
+
// renderer at all: the direct-mount planner finds no replacement, the boxed
|
|
3
|
+
// fallback mounts a class whose `__gea_to_value()` is neutralized (so its
|
|
4
|
+
// `render` lookup misses), and the app draws NOTHING — the frame loop runs at
|
|
5
|
+
// full rate over a black screen with zero log output. That silent-empty mode
|
|
6
|
+
// cost a real on-device debugging cycle; fail the build loudly instead.
|
|
7
|
+
import { collectStoreArraySources, collectStoreFields, collectStoreMethods } from './cpp-stores.js';
|
|
8
|
+
import { collectIrConstants } from './cpp-ir.js';
|
|
9
|
+
import { childSubtreeGlobalStoreName, mountedRendererForComponent, rendererReadsStoreParam, selfStoreMountedRenderer, } from './cpp-mounted.js';
|
|
10
|
+
import { childForMount, mountSlotAttrs, mountSlotTag } from './cpp-mounted-lowering.js';
|
|
11
|
+
export function diagnoseUnmountableReactiveComponents(ir) {
|
|
12
|
+
const reactive = ir.components.filter((component) => component.reactiveState);
|
|
13
|
+
if (reactive.length === 0)
|
|
14
|
+
return [];
|
|
15
|
+
const storeFields = collectStoreFields(ir.stores);
|
|
16
|
+
const storeArrayFields = collectStoreArraySources(ir.stores);
|
|
17
|
+
const storeMethods = collectStoreMethods(ir.stores);
|
|
18
|
+
const constants = new Map(collectIrConstants(ir));
|
|
19
|
+
const diagnostics = [];
|
|
20
|
+
for (const component of reactive) {
|
|
21
|
+
if (selfStoreMountedRenderer(component, ir.components, storeFields, storeArrayFields, constants, storeMethods))
|
|
22
|
+
continue;
|
|
23
|
+
const blockers = mountBlockers(component, ir.components, storeFields, storeArrayFields, constants, storeMethods);
|
|
24
|
+
const detail = blockers.length > 0
|
|
25
|
+
? blockers.join('; ')
|
|
26
|
+
: 'the template uses a construct the typed renderer does not support yet (e.g. reactive array/record fields in slots, or conditionals over self fields)';
|
|
27
|
+
diagnostics.push({
|
|
28
|
+
kind: 'unsupported',
|
|
29
|
+
code: 'gea-unmountable-reactive-component',
|
|
30
|
+
message: `ReactiveComponent <${component.exportName}> has no typed mounted renderer: ${detail}. ` +
|
|
31
|
+
`Without a renderer the component renders NOTHING at runtime (black screen, no diagnostics) — ` +
|
|
32
|
+
`inline the blocking child markup or drop back to \`Component\` until the construct is supported.`,
|
|
33
|
+
file: component.module,
|
|
34
|
+
severity: 'error',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return diagnostics;
|
|
38
|
+
}
|
|
39
|
+
// Best-effort explanation of WHY the typed renderer bailed: re-run the child
|
|
40
|
+
// gate from selfStoreMountedRenderer per mount slot and name each blocker.
|
|
41
|
+
// Other bail causes (unsupported slot kinds, unresolved readers) fall through
|
|
42
|
+
// to the generic message above.
|
|
43
|
+
function mountBlockers(component, components, storeFields, storeArrayFields, constants, storeMethods) {
|
|
44
|
+
const blockers = [];
|
|
45
|
+
for (const slot of component.template.slots) {
|
|
46
|
+
if (slot.kind !== 'mount')
|
|
47
|
+
continue;
|
|
48
|
+
const tag = mountSlotTag(slot);
|
|
49
|
+
if (tag === 'Image')
|
|
50
|
+
continue;
|
|
51
|
+
const child = childForMount(slot, components);
|
|
52
|
+
if (!child) {
|
|
53
|
+
blockers.push(`child <${tag ?? '?'} /> is not in the compiled IR (its module may have been tree-shaken)`);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (child.reactiveState) {
|
|
57
|
+
if (mountSlotAttrs(slot).length > 0) {
|
|
58
|
+
blockers.push(`child <${tag} /> is a ReactiveComponent mounted with props — props mean inlining, which a reactive child can't do (lift the props into its own state or a shared store)`);
|
|
59
|
+
}
|
|
60
|
+
else if (!selfStoreMountedRenderer(child, components, storeFields, storeArrayFields, constants, storeMethods)) {
|
|
61
|
+
blockers.push(`child <${tag} /> is a ReactiveComponent whose own template has no typed renderer (see its own diagnostic; a reactive mount cycle also lands here)`);
|
|
62
|
+
}
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const renderer = mountedRendererForComponent(child, components, storeFields, storeArrayFields, constants, storeMethods);
|
|
66
|
+
if (!renderer) {
|
|
67
|
+
blockers.push(`child <${tag} /> has no compilable mounted renderer`);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (rendererReadsStoreParam(renderer) &&
|
|
71
|
+
!childSubtreeGlobalStoreName(child, components, storeFields, storeArrayFields, constants)) {
|
|
72
|
+
blockers.push(`child <${tag} />'s renderer reads its boxed store parameter, and its template doesn't resolve to exactly one bundled global store (subtrees spanning multiple stores or reading an outer \`this\` can't be threaded from a typed parent)`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return blockers;
|
|
76
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GeaIrComponent } from './types.js';
|
|
2
|
+
export declare function isReactiveComponentIr(component: GeaIrComponent): boolean;
|
|
3
|
+
export interface ReactiveArrayFieldInfo {
|
|
4
|
+
name: string;
|
|
5
|
+
elementCppType: string;
|
|
6
|
+
elementValueType: 'string' | 'number' | 'boolean';
|
|
7
|
+
}
|
|
8
|
+
export declare function reactiveArrayFieldInfo(component: GeaIrComponent): ReactiveArrayFieldInfo[];
|
|
9
|
+
export declare function arrayRevFieldName(fieldName: string): string;
|
|
10
|
+
export declare function inlineReactiveComponentGetters(component: GeaIrComponent): GeaIrComponent;
|
|
11
|
+
export declare function rewriteReactiveComponentFields(source: string, components: GeaIrComponent[]): string;
|
|
12
|
+
export declare function insertReactiveSignalSupport(source: string, components: GeaIrComponent[]): string;
|
|
13
|
+
export declare function insertReactiveRendererForwardDeclarations(source: string, components: GeaIrComponent[]): string;
|
|
14
|
+
export declare function neutralizeReactiveComponentToValue(source: string, components: GeaIrComponent[]): string;
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
// EXPERIMENTAL (component-as-store): class-level source transforms for the
|
|
2
|
+
// LEAN, FULLY-TYPED ReactiveComponent path.
|
|
3
|
+
//
|
|
4
|
+
// A `class App extends ReactiveComponent` compiles (via the vite-plugin) to a
|
|
5
|
+
// base-less, typed C++ class: `mutable double count{}`, `void bump()`,
|
|
6
|
+
// `std::string label()`. RENDERING goes through the ONE shared mounted renderer
|
|
7
|
+
// (cpp-template-renderer) with `TypedSelfFieldAccess` — see cpp-mounted.ts
|
|
8
|
+
// `selfStoreMountedRenderer`. This module only contains the class/source surgery
|
|
9
|
+
// that makes the typed class reactive:
|
|
10
|
+
// 1. `rewriteReactiveComponentFields` — each primitive reactive field becomes a
|
|
11
|
+
// typed `gea::embedded::ui::Signal<T>` (assignment notifies subscribers).
|
|
12
|
+
// 2. `inlineReactiveComponentGetters` — substitutes simple single-return getter
|
|
13
|
+
// reads in template slots (`{this.label}` → `{'n=' + this.count}`) so they
|
|
14
|
+
// lower through the ordinary store-field path and re-render on the fields
|
|
15
|
+
// the getter actually reads.
|
|
16
|
+
// 3. `neutralizeReactiveComponentToValue` — blanks the dead auto-emitted
|
|
17
|
+
// `__gea_to_value()` so it never boxes a Signal field.
|
|
18
|
+
// 4. `insertReactiveSignalSupport` — global `gea_cpp_to_string(Signal<T>)`
|
|
19
|
+
// overload so getter bodies stringify the value, not "[object Object]".
|
|
20
|
+
// 5. `insertReactiveRendererForwardDeclarations` — declares the typed
|
|
21
|
+
// `mount_<Name>(shared_ptr<Name>&, …)` after `class <Name>;` (the mount call
|
|
22
|
+
// site precedes the renderer definition).
|
|
23
|
+
import { sanitizeCppIdentifier } from './utils.js';
|
|
24
|
+
export function isReactiveComponentIr(component) {
|
|
25
|
+
return !!component.reactiveState;
|
|
26
|
+
}
|
|
27
|
+
function cppTypeForValueType(valueType) {
|
|
28
|
+
if (valueType === 'string')
|
|
29
|
+
return { cppType: 'std::string' };
|
|
30
|
+
if (valueType === 'boolean')
|
|
31
|
+
return { cppType: 'bool' };
|
|
32
|
+
return { cppType: 'double' };
|
|
33
|
+
}
|
|
34
|
+
// Primitive reactive fields → Signal<T>. Arrays/records are left as plain typed
|
|
35
|
+
// members for now (no Signal, no typed reader) — templates reading them fall off
|
|
36
|
+
// the fast path loudly rather than emitting broken code.
|
|
37
|
+
function reactiveFieldInfo(component) {
|
|
38
|
+
const map = new Map();
|
|
39
|
+
for (const field of component.reactiveState?.fields ?? []) {
|
|
40
|
+
if (field.shape && field.shape.kind !== 'literal')
|
|
41
|
+
continue;
|
|
42
|
+
map.set(field.name, cppTypeForValueType(field.shape?.kind === 'literal' ? field.shape.valueType : undefined));
|
|
43
|
+
}
|
|
44
|
+
return map;
|
|
45
|
+
}
|
|
46
|
+
// Reactive ARRAY fields with primitive elements (`cells: string[]`). The field
|
|
47
|
+
// stays a plain `std::vector<T>` (so all geatsc-compiled method bodies — element
|
|
48
|
+
// reads, vector_set writes, the record_get_property fallback — keep compiling
|
|
49
|
+
// untouched); reactivity comes from a companion `Signal<double> <name>__rev`
|
|
50
|
+
// that mutation helpers tick and the keyed-list renderer subscribes to.
|
|
51
|
+
export function reactiveArrayFieldInfo(component) {
|
|
52
|
+
const out = [];
|
|
53
|
+
for (const field of component.reactiveState?.fields ?? []) {
|
|
54
|
+
if (field.shape?.kind !== 'array')
|
|
55
|
+
continue;
|
|
56
|
+
const element = field.shape.element;
|
|
57
|
+
if (!element || element.kind !== 'literal')
|
|
58
|
+
continue;
|
|
59
|
+
const valueType = element.valueType === 'string' || element.valueType === 'boolean' ? element.valueType : 'number';
|
|
60
|
+
out.push({
|
|
61
|
+
name: field.name,
|
|
62
|
+
elementCppType: cppTypeForValueType(valueType).cppType,
|
|
63
|
+
elementValueType: valueType,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
export function arrayRevFieldName(fieldName) {
|
|
69
|
+
return `${sanitizeCppIdentifier(fieldName)}__rev`;
|
|
70
|
+
}
|
|
71
|
+
// ── getter inlining (template-slot rewrite, applied once at IR-load) ──────────
|
|
72
|
+
// Rewrite a self-store component's template slots so each `this.<getter>`
|
|
73
|
+
// reference is replaced by the getter's return expression (over the component's
|
|
74
|
+
// own fields). The renderer's expression lowering resolves store FIELDS, not
|
|
75
|
+
// getters; inlining a simple single-return getter (`get label() { return 'n=' +
|
|
76
|
+
// this.count }`) turns `{this.label}` into `{'n=' + this.count}`, which lowers
|
|
77
|
+
// through the existing field path and re-renders on the same fields the getter
|
|
78
|
+
// reads (`count`). Getters with non-trivial bodies are left as-is — the
|
|
79
|
+
// component then falls off the fast path exactly as before. Idempotent (after
|
|
80
|
+
// the first pass no `this.<getter>` reference remains).
|
|
81
|
+
export function inlineReactiveComponentGetters(component) {
|
|
82
|
+
const getters = component.reactiveState?.getters;
|
|
83
|
+
if (!getters || getters.length === 0)
|
|
84
|
+
return component;
|
|
85
|
+
const exprByName = new Map();
|
|
86
|
+
for (const getter of getters) {
|
|
87
|
+
const expr = getterReturnExpression(getter.body);
|
|
88
|
+
if (expr !== null)
|
|
89
|
+
exprByName.set(getter.name, expr);
|
|
90
|
+
}
|
|
91
|
+
if (exprByName.size === 0)
|
|
92
|
+
return component;
|
|
93
|
+
// Expand getter-in-getter references to a fixed point (bounded; real getters
|
|
94
|
+
// never chain anywhere near this deep, and the bound stops degenerate cycles).
|
|
95
|
+
for (let pass = 0; pass < 8; pass += 1) {
|
|
96
|
+
let changed = false;
|
|
97
|
+
for (const [name, expr] of exprByName) {
|
|
98
|
+
const expanded = substituteGetterReferences(expr, exprByName, name);
|
|
99
|
+
if (expanded !== expr) {
|
|
100
|
+
exprByName.set(name, expanded);
|
|
101
|
+
changed = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (!changed)
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
let touched = false;
|
|
108
|
+
const slots = component.template.slots.map((slot) => {
|
|
109
|
+
const nextExpr = slot.expr ? substituteGetterReferences(slot.expr, exprByName) : slot.expr;
|
|
110
|
+
const nextFields = slot.exprObjectFields?.map((field) => ({
|
|
111
|
+
...field,
|
|
112
|
+
expr: substituteGetterReferences(field.expr, exprByName),
|
|
113
|
+
}));
|
|
114
|
+
const exprChanged = nextExpr !== slot.expr;
|
|
115
|
+
const fieldsChanged = !!nextFields && nextFields.some((field, index) => field.expr !== slot.exprObjectFields[index].expr);
|
|
116
|
+
if (!exprChanged && !fieldsChanged)
|
|
117
|
+
return slot;
|
|
118
|
+
touched = true;
|
|
119
|
+
const next = { ...slot };
|
|
120
|
+
if (exprChanged) {
|
|
121
|
+
next.expr = nextExpr;
|
|
122
|
+
// No longer a bare `this.<field>` path; drop the stale path so lowering
|
|
123
|
+
// uses the substituted `expr` string.
|
|
124
|
+
delete next.exprPath;
|
|
125
|
+
}
|
|
126
|
+
if (fieldsChanged)
|
|
127
|
+
next.exprObjectFields = nextFields;
|
|
128
|
+
return next;
|
|
129
|
+
});
|
|
130
|
+
if (!touched)
|
|
131
|
+
return component;
|
|
132
|
+
return { ...component, template: { ...component.template, slots } };
|
|
133
|
+
}
|
|
134
|
+
// Extract the single returned expression from a getter body (`{ return <expr> }`).
|
|
135
|
+
// Returns null for anything that isn't exactly one return of an expression.
|
|
136
|
+
function getterReturnExpression(body) {
|
|
137
|
+
if (!body)
|
|
138
|
+
return null;
|
|
139
|
+
let text = body.trim();
|
|
140
|
+
if (text.startsWith('{') && text.endsWith('}'))
|
|
141
|
+
text = text.slice(1, -1).trim();
|
|
142
|
+
const match = text.match(/^return\b([\s\S]*?);?$/);
|
|
143
|
+
if (!match)
|
|
144
|
+
return null;
|
|
145
|
+
const expr = match[1].trim();
|
|
146
|
+
if (!expr || expr.includes(';'))
|
|
147
|
+
return null;
|
|
148
|
+
return expr;
|
|
149
|
+
}
|
|
150
|
+
function substituteGetterReferences(expr, exprByName, excludeName) {
|
|
151
|
+
let out = expr;
|
|
152
|
+
for (const [name, replacement] of exprByName) {
|
|
153
|
+
if (name === excludeName)
|
|
154
|
+
continue;
|
|
155
|
+
out = out.replace(new RegExp(`\\bthis\\.${name}\\b`, 'g'), `(${replacement})`);
|
|
156
|
+
}
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
// ── source transforms applied to the generated program ─────────────────────────
|
|
160
|
+
// Rewrite each reactive field's declaration in its class body to a typed Signal.
|
|
161
|
+
// `mutable double count{};` → `mutable gea::embedded::ui::Signal<double> count{};`
|
|
162
|
+
export function rewriteReactiveComponentFields(source, components) {
|
|
163
|
+
let next = source;
|
|
164
|
+
for (const component of components) {
|
|
165
|
+
if (!component.reactiveState)
|
|
166
|
+
continue;
|
|
167
|
+
const className = sanitizeCppIdentifier(component.exportName);
|
|
168
|
+
const fields = reactiveFieldInfo(component);
|
|
169
|
+
const arrayFields = reactiveArrayFieldInfo(component);
|
|
170
|
+
next = transformClassBody(next, className, (bodyText) => {
|
|
171
|
+
let body = bodyText;
|
|
172
|
+
for (const [name, info] of fields) {
|
|
173
|
+
const ident = sanitizeCppIdentifier(name);
|
|
174
|
+
const pattern = new RegExp(`(\\bmutable\\s+)${escapeRegExp(info.cppType)}(\\s+${escapeRegExp(ident)}\\s*\\{)`, 'g');
|
|
175
|
+
body = body.replace(pattern, `$1gea::embedded::ui::Signal<${info.cppType}>$2`);
|
|
176
|
+
// geatsc's generic cast lambdas (`([](const auto &v){ if constexpr
|
|
177
|
+
// (is_same_v<decay_t, std::string>) return v; else return
|
|
178
|
+
// gea_cpp_to_string(gea_cpp_value(v)); })((*this).turn)`) dispatch on
|
|
179
|
+
// the DECLARED type — a Signal field takes the boxing branch and
|
|
180
|
+
// stringifies as "[object Undefined]". Unwrap the read so the lambda
|
|
181
|
+
// sees the plain T value.
|
|
182
|
+
body = body.replaceAll(`})((*this).${ident})`, `})((*this).${ident}.get())`);
|
|
183
|
+
}
|
|
184
|
+
for (const arrayField of arrayFields) {
|
|
185
|
+
const ident = sanitizeCppIdentifier(arrayField.name);
|
|
186
|
+
const rev = arrayRevFieldName(arrayField.name);
|
|
187
|
+
// Companion revision Signal, declared right after the vector field. The
|
|
188
|
+
// vector itself stays plain so geatsc's array codegen compiles untouched.
|
|
189
|
+
const declPattern = new RegExp(`(\\bmutable\\s+std::vector<${escapeRegExp(arrayField.elementCppType)}>\\s+${escapeRegExp(ident)}\\s*\\{\\s*\\};)`);
|
|
190
|
+
body = body.replace(declPattern, `$1\n mutable gea::embedded::ui::Signal<double> ${rev}{};`);
|
|
191
|
+
// Route element writes through the notify wrapper so the keyed-list
|
|
192
|
+
// renderer re-renders. Only vector_set for now (the only mutation geatsc
|
|
193
|
+
// emits for `arr[i] = v`); other mutators (push/splice) get wrapped when
|
|
194
|
+
// a component actually uses them.
|
|
195
|
+
body = body.replaceAll(`gea::runtime::array::vector_set((*this).${ident}, `, `gea_rc_vector_set_notify((*this).${ident}, (*this).${rev}, `);
|
|
196
|
+
}
|
|
197
|
+
return body;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return next;
|
|
201
|
+
}
|
|
202
|
+
// geatsc compiles a getter (`get label() { return 'n=' + this.count }`) to
|
|
203
|
+
// `gea_cpp_to_string((*this).count)`. With `count` rewritten to `Signal<double>`,
|
|
204
|
+
// that bare read otherwise resolves to the generic `gea_cpp_value` overload and
|
|
205
|
+
// stringifies the Signal as "[object Object]". Inject an exact-match
|
|
206
|
+
// `gea_cpp_to_string(const Signal<T>&)` (found by ordinary lookup) right before
|
|
207
|
+
// the first reactive class DEFINITION — after the runtime declares
|
|
208
|
+
// `gea_cpp_to_string`, before any reactive read uses it. (Not in signal.h: that
|
|
209
|
+
// header is included before the runtime's `gea_cpp_to_string` is declared.)
|
|
210
|
+
export function insertReactiveSignalSupport(source, components) {
|
|
211
|
+
const reactive = components.filter((component) => component.reactiveState);
|
|
212
|
+
if (reactive.length === 0)
|
|
213
|
+
return source;
|
|
214
|
+
let earliest = -1;
|
|
215
|
+
for (const component of reactive) {
|
|
216
|
+
const at = findClassDefinition(source, sanitizeCppIdentifier(component.exportName));
|
|
217
|
+
if (at >= 0 && (earliest < 0 || at < earliest))
|
|
218
|
+
earliest = at;
|
|
219
|
+
}
|
|
220
|
+
if (earliest < 0)
|
|
221
|
+
return source;
|
|
222
|
+
// Global scope (NOT inside gea::embedded::ui): an overload inside that
|
|
223
|
+
// namespace would hide the global `gea_cpp_to_string(double)` from its own
|
|
224
|
+
// body (unqualified lookup stops at the first scope that declares the name).
|
|
225
|
+
const overload = '// @geastack/geatsc-plugin-gea ReactiveComponent typed-Signal stringify support\n' +
|
|
226
|
+
'template <typename T> inline std::string gea_cpp_to_string(const gea::embedded::ui::Signal<T> &__gea_signal) { return gea_cpp_to_string(__gea_signal.get()); }\n' +
|
|
227
|
+
// Element write + revision tick for reactive array fields. Same contract as
|
|
228
|
+
// gea::runtime::array::vector_set, plus notifying the companion Signal so
|
|
229
|
+
// keyed-list subscribers re-render. (The runtime's array helpers are
|
|
230
|
+
// declared by runtime_pch.h, included at the very top of the program.)
|
|
231
|
+
'template <typename T, typename I, typename U, typename S> inline T gea_rc_vector_set_notify(std::vector<T> &__gea_vec, gea::embedded::ui::Signal<S> &__gea_rev, I __gea_index, U &&__gea_value) { T __gea_out = gea::runtime::array::vector_set(__gea_vec, __gea_index, std::forward<U>(__gea_value)); __gea_rev.notify(); return __gea_out; }\n';
|
|
232
|
+
return `${source.slice(0, earliest)}${overload}${source.slice(earliest)}`;
|
|
233
|
+
}
|
|
234
|
+
// Locate a class DEFINITION `class <Name> {` (not the `class <Name>;` forward
|
|
235
|
+
// declaration). Returns the index of the `class` keyword, or -1.
|
|
236
|
+
function findClassDefinition(source, className) {
|
|
237
|
+
const pattern = new RegExp(`\\bclass\\s+${escapeRegExp(className)}\\b`, 'g');
|
|
238
|
+
let match;
|
|
239
|
+
while ((match = pattern.exec(source)) !== null) {
|
|
240
|
+
const brace = source.indexOf('{', match.index);
|
|
241
|
+
const semicolon = source.indexOf(';', match.index);
|
|
242
|
+
if (brace >= 0 && (semicolon < 0 || brace < semicolon))
|
|
243
|
+
return match.index;
|
|
244
|
+
}
|
|
245
|
+
return -1;
|
|
246
|
+
}
|
|
247
|
+
// Inject the typed mounted-renderer forward declaration right after the class's
|
|
248
|
+
// own forward declaration (`class App;`). It names `App`, so it can't sit in the
|
|
249
|
+
// early `gea_ir` namespace block that precedes the class forward declaration; it
|
|
250
|
+
// must come after `class App;` but before `__gea_top_level` (the mount site).
|
|
251
|
+
// An unused declaration (template unmountable → no renderer emitted) is harmless.
|
|
252
|
+
export function insertReactiveRendererForwardDeclarations(source, components) {
|
|
253
|
+
let next = source;
|
|
254
|
+
for (const component of components) {
|
|
255
|
+
if (!component.reactiveState)
|
|
256
|
+
continue;
|
|
257
|
+
const className = sanitizeCppIdentifier(component.exportName);
|
|
258
|
+
const decl = `class ${className};`;
|
|
259
|
+
const at = next.indexOf(decl);
|
|
260
|
+
if (at < 0)
|
|
261
|
+
continue;
|
|
262
|
+
const insertAt = at + decl.length;
|
|
263
|
+
// Disposer type MUST match the renderer definition emitted by
|
|
264
|
+
// cpp-template-renderer.ts (`const std::shared_ptr<NativeDisposer> &`). A
|
|
265
|
+
// stale `gea_cpp_value` here declares an inline overload that's never
|
|
266
|
+
// defined, which ESP's `-Werror=undefined-inline` rejects.
|
|
267
|
+
// This forward declaration sits right after `class App;`, which is BEFORE
|
|
268
|
+
// the `namespace gea_ir { struct NativeDisposer; … }` runtime block. A
|
|
269
|
+
// `shared_ptr<NativeDisposer>` parameter only needs an incomplete type, so
|
|
270
|
+
// forward-declare `NativeDisposer` (in the same `gea_ir` namespace it is
|
|
271
|
+
// later defined in) here too — otherwise GCC rejects the use-before-decl
|
|
272
|
+
// (`'NativeDisposer' was not declared in this scope`), which then cascades
|
|
273
|
+
// into the param decaying to `const int&`. clang was lenient; GCC is not.
|
|
274
|
+
const forward = `\nnamespace gea_ir { struct NativeDisposer; gea::embedded::ui::NodeHandle mount_${className}(const std::shared_ptr<${className}> &store, const std::shared_ptr<NativeDisposer> &disposer); }`;
|
|
275
|
+
next = `${next.slice(0, insertAt)}${forward}${next.slice(insertAt)}`;
|
|
276
|
+
}
|
|
277
|
+
return next;
|
|
278
|
+
}
|
|
279
|
+
// Blank the auto-emitted `__gea_to_value()` for a reactive component so it never
|
|
280
|
+
// boxes a Signal field (it is dead — the typed mount/renderer never call it).
|
|
281
|
+
export function neutralizeReactiveComponentToValue(source, components) {
|
|
282
|
+
let next = source;
|
|
283
|
+
for (const component of components) {
|
|
284
|
+
if (!component.reactiveState)
|
|
285
|
+
continue;
|
|
286
|
+
const className = sanitizeCppIdentifier(component.exportName);
|
|
287
|
+
const head = `gea_cpp_value ${className}::__gea_to_value() const {`;
|
|
288
|
+
const start = next.indexOf(head);
|
|
289
|
+
if (start < 0)
|
|
290
|
+
continue;
|
|
291
|
+
const open = start + head.length - 1;
|
|
292
|
+
const close = matchBrace(next, open);
|
|
293
|
+
if (close < 0)
|
|
294
|
+
continue;
|
|
295
|
+
next = `${next.slice(0, open + 1)} (void)this; return gea_cpp_value::missing(); ${next.slice(close)}`;
|
|
296
|
+
}
|
|
297
|
+
return next;
|
|
298
|
+
}
|
|
299
|
+
// ── small brace utilities (self-contained) ─────────────────────────────────────
|
|
300
|
+
function escapeRegExp(text) {
|
|
301
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
302
|
+
}
|
|
303
|
+
function transformClassBody(source, className, transform) {
|
|
304
|
+
const pattern = new RegExp(`\\bclass\\s+${escapeRegExp(className)}\\b`, 'g');
|
|
305
|
+
let match;
|
|
306
|
+
while ((match = pattern.exec(source)) !== null) {
|
|
307
|
+
const brace = source.indexOf('{', match.index);
|
|
308
|
+
if (brace < 0)
|
|
309
|
+
continue;
|
|
310
|
+
const semicolon = source.indexOf(';', match.index);
|
|
311
|
+
if (semicolon >= 0 && semicolon < brace)
|
|
312
|
+
continue; // forward declaration
|
|
313
|
+
const close = matchBrace(source, brace);
|
|
314
|
+
if (close < 0)
|
|
315
|
+
continue;
|
|
316
|
+
const transformed = transform(source.slice(brace + 1, close));
|
|
317
|
+
return `${source.slice(0, brace + 1)}${transformed}${source.slice(close)}`;
|
|
318
|
+
}
|
|
319
|
+
return source;
|
|
320
|
+
}
|
|
321
|
+
function matchBrace(source, open) {
|
|
322
|
+
let depth = 0;
|
|
323
|
+
let quote = null;
|
|
324
|
+
let escaped = false;
|
|
325
|
+
for (let i = open; i < source.length; i += 1) {
|
|
326
|
+
const ch = source[i];
|
|
327
|
+
if (quote) {
|
|
328
|
+
if (escaped)
|
|
329
|
+
escaped = false;
|
|
330
|
+
else if (ch === '\\')
|
|
331
|
+
escaped = true;
|
|
332
|
+
else if (ch === quote)
|
|
333
|
+
quote = null;
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (ch === '"' || ch === "'") {
|
|
337
|
+
quote = ch;
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
if (ch === '{')
|
|
341
|
+
depth += 1;
|
|
342
|
+
else if (ch === '}') {
|
|
343
|
+
depth -= 1;
|
|
344
|
+
if (depth === 0)
|
|
345
|
+
return i;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return -1;
|
|
349
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type StoreArrayFieldPlan, type StoreFieldPlan, type StoreMethodPlan } from './cpp-stores.js';
|
|
2
|
+
import type { RendererReplacement } from './cpp-source-replacements.js';
|
|
3
|
+
import type { GeaIrBundleV1, GeaIrComponent, GeaIrConstant, GeaIrSlot } from './types.js';
|
|
4
|
+
export { replaceGeneratedRenderers } from './cpp-source-replacements.js';
|
|
5
|
+
export type { RendererReplacement } from './cpp-source-replacements.js';
|
|
6
|
+
export declare function rendererReplacementsForIr(ir: GeaIrBundleV1): RendererReplacement[];
|
|
7
|
+
export declare function inlineOnlyComponentClassesForIr(ir: GeaIrBundleV1): Set<string>;
|
|
8
|
+
export declare function componentStoreReferences(component: GeaIrComponent, components: GeaIrComponent[], storeFields: StoreFieldPlan[], storeArrayFields: StoreArrayFieldPlan[], constants: ReadonlyMap<string, GeaIrConstant>, storeMethods?: StoreMethodPlan[], propBindings?: Map<string, string>, seenComponents?: Set<string>): StoreReference[] | null;
|
|
9
|
+
export declare function isStaticKeyedListSlot(slot: GeaIrSlot): boolean;
|
|
10
|
+
interface StoreReference {
|
|
11
|
+
storeExpression: string;
|
|
12
|
+
fieldName?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function slotFieldName(slot: GeaIrSlot): string | null;
|