@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.
Files changed (63) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +37 -0
  3. package/dist/analyze.d.ts +4 -0
  4. package/dist/analyze.js +195 -0
  5. package/dist/cpp-canvas-colors.d.ts +4 -0
  6. package/dist/cpp-canvas-colors.js +226 -0
  7. package/dist/cpp-field-access.d.ts +49 -0
  8. package/dist/cpp-field-access.js +144 -0
  9. package/dist/cpp-ir-dom-style.d.ts +1 -0
  10. package/dist/cpp-ir-dom-style.js +49 -0
  11. package/dist/cpp-ir.d.ts +30 -0
  12. package/dist/cpp-ir.js +2426 -0
  13. package/dist/cpp-keyed-component-diagnostics.d.ts +8 -0
  14. package/dist/cpp-keyed-component-diagnostics.js +74 -0
  15. package/dist/cpp-keyed-list-diagnostics.d.ts +17 -0
  16. package/dist/cpp-keyed-list-diagnostics.js +84 -0
  17. package/dist/cpp-mounted-lowering.d.ts +81 -0
  18. package/dist/cpp-mounted-lowering.js +2235 -0
  19. package/dist/cpp-mounted.d.ts +25 -0
  20. package/dist/cpp-mounted.js +1376 -0
  21. package/dist/cpp-reactive-component-diagnostics.d.ts +2 -0
  22. package/dist/cpp-reactive-component-diagnostics.js +76 -0
  23. package/dist/cpp-reactive-component.d.ts +14 -0
  24. package/dist/cpp-reactive-component.js +349 -0
  25. package/dist/cpp-replacements.d.ts +14 -0
  26. package/dist/cpp-replacements.js +787 -0
  27. package/dist/cpp-source-replacements.d.ts +11 -0
  28. package/dist/cpp-source-replacements.js +257 -0
  29. package/dist/cpp-store-hub.d.ts +7 -0
  30. package/dist/cpp-store-hub.js +160 -0
  31. package/dist/cpp-store-method-body-parser.d.ts +2 -0
  32. package/dist/cpp-store-method-body-parser.js +392 -0
  33. package/dist/cpp-store-method-context.d.ts +48 -0
  34. package/dist/cpp-store-method-context.js +114 -0
  35. package/dist/cpp-store-method-expressions.d.ts +12 -0
  36. package/dist/cpp-store-method-expressions.js +1263 -0
  37. package/dist/cpp-store-method-replacements.d.ts +5 -0
  38. package/dist/cpp-store-method-replacements.js +1521 -0
  39. package/dist/cpp-store-method-targets.d.ts +19 -0
  40. package/dist/cpp-store-method-targets.js +296 -0
  41. package/dist/cpp-store-typed-arrays.d.ts +2 -0
  42. package/dist/cpp-store-typed-arrays.js +655 -0
  43. package/dist/cpp-stores.d.ts +73 -0
  44. package/dist/cpp-stores.js +1739 -0
  45. package/dist/cpp-template-renderer.d.ts +23 -0
  46. package/dist/cpp-template-renderer.js +3530 -0
  47. package/dist/css-style-declaration-shims.d.ts +3 -0
  48. package/dist/css-style-declaration-shims.js +47 -0
  49. package/dist/host-declarations.d.ts +11 -0
  50. package/dist/host-declarations.js +320 -0
  51. package/dist/host-shims.d.ts +3 -0
  52. package/dist/host-shims.js +3217 -0
  53. package/dist/index.d.ts +3 -0
  54. package/dist/index.js +1239 -0
  55. package/dist/load-ir.d.ts +7 -0
  56. package/dist/load-ir.js +40 -0
  57. package/dist/types.d.ts +604 -0
  58. package/dist/types.js +1 -0
  59. package/dist/utils.d.ts +26 -0
  60. package/dist/utils.js +723 -0
  61. package/dist/validate.d.ts +3 -0
  62. package/dist/validate.js +226 -0
  63. package/package.json +57 -0
@@ -0,0 +1,19 @@
1
+ import type { GeaIrStoreExpr, GeaIrStoreMethod } from './types.js';
2
+ export declare function thisFieldName(expr: GeaIrStoreExpr): string | null;
3
+ export declare function thisArrayLengthTarget(expr: GeaIrStoreExpr): string | null;
4
+ export declare function thisArrayItemFieldTarget(expr: GeaIrStoreExpr): {
5
+ arrayField: string;
6
+ index: GeaIrStoreExpr;
7
+ itemField: string;
8
+ } | null;
9
+ export declare function thisArrayPushTarget(expr: GeaIrStoreExpr): string | null;
10
+ export declare function thisArrayUnshiftTarget(expr: GeaIrStoreExpr): string | null;
11
+ export declare function thisArraySpliceTarget(expr: GeaIrStoreExpr): string | null;
12
+ export declare function thisArrayPopTarget(expr: GeaIrStoreExpr): string | null;
13
+ export declare function thisArrayShiftTarget(expr: GeaIrStoreExpr): string | null;
14
+ export declare function exprPath(expr: GeaIrStoreExpr): string | null;
15
+ export declare function methodPrefix(method: GeaIrStoreMethod): string;
16
+ export declare function replaceClassMethodBody(source: string, className: string, methodName: string, body: string[]): string;
17
+ export declare function readClassMethodBody(source: string, className: string, methodName: string): string | null;
18
+ export declare function replaceClassMethodParameters(source: string, className: string, methodName: string, typedParams: string, body: string[]): string;
19
+ export declare function replaceClassMethodDefinition(source: string, className: string, methodName: string, signature: string | null, body: string[]): string;
@@ -0,0 +1,296 @@
1
+ import { sanitizeCppIdentifier } from './utils.js';
2
+ export function thisFieldName(expr) {
3
+ return expr.kind === 'member' && expr.object.kind === 'this' ? expr.property : null;
4
+ }
5
+ export function thisArrayLengthTarget(expr) {
6
+ return expr.kind === 'member' && expr.property === 'length' ? thisFieldName(expr.object) : null;
7
+ }
8
+ export function thisArrayItemFieldTarget(expr) {
9
+ if (expr.kind !== 'member' || expr.object.kind !== 'index')
10
+ return null;
11
+ const arrayField = thisFieldName(expr.object.object);
12
+ return arrayField ? { arrayField, index: expr.object.index, itemField: expr.property } : null;
13
+ }
14
+ export function thisArrayPushTarget(expr) {
15
+ return expr.kind === 'member' && expr.property === 'push' ? thisFieldName(expr.object) : null;
16
+ }
17
+ export function thisArrayUnshiftTarget(expr) {
18
+ return expr.kind === 'member' && expr.property === 'unshift' ? thisFieldName(expr.object) : null;
19
+ }
20
+ export function thisArraySpliceTarget(expr) {
21
+ return expr.kind === 'member' && expr.property === 'splice' ? thisFieldName(expr.object) : null;
22
+ }
23
+ export function thisArrayPopTarget(expr) {
24
+ return expr.kind === 'member' && expr.property === 'pop' ? thisFieldName(expr.object) : null;
25
+ }
26
+ export function thisArrayShiftTarget(expr) {
27
+ return expr.kind === 'member' && expr.property === 'shift' ? thisFieldName(expr.object) : null;
28
+ }
29
+ export function exprPath(expr) {
30
+ if (expr.kind === 'identifier')
31
+ return expr.name;
32
+ if (expr.kind === 'member') {
33
+ const object = exprPath(expr.object);
34
+ return object ? `${object}.${expr.property}` : null;
35
+ }
36
+ return null;
37
+ }
38
+ export function methodPrefix(method) {
39
+ return sanitizeCppIdentifier(method.name);
40
+ }
41
+ export function replaceClassMethodBody(source, className, methodName, body) {
42
+ return replaceClassMethodDefinition(source, className, methodName, null, body);
43
+ }
44
+ export function readClassMethodBody(source, className, methodName) {
45
+ const region = findMethodSignatureRegion(source, className, methodName);
46
+ return region ? source.slice(region.methodOpen + 1, region.methodClose) : null;
47
+ }
48
+ // Replace a store method's PARAMETER LIST (and body) while preserving geatsc's
49
+ // original return type and `virtual`/`const` qualifiers. Used to give a typed
50
+ // store method native primitive parameters (`double timestampMs`) without
51
+ // touching its return type — geatsc already declared the correct one, and
52
+ // rewriting it risks demoting value-returning methods to `void`. Falls back to
53
+ // a body-only replacement if the original parameter list can't be located.
54
+ export function replaceClassMethodParameters(source, className, methodName, typedParams, body) {
55
+ const region = findMethodSignatureRegion(source, className, methodName);
56
+ if (!region)
57
+ return source;
58
+ const { methodStart, methodOpen, methodClose } = region;
59
+ const signatureText = source.slice(methodStart, methodOpen);
60
+ // A deferred method's declaration lives in the generated header while this
61
+ // transform is currently visiting only its out-of-line .cpp definition.
62
+ // Rewriting that definition from geatsc's abbreviated-template parameters
63
+ // to concrete primitive parameters would leave the header declaring a
64
+ // different function. Preserve the original out-of-line signature and only
65
+ // replace its body; inline definitions can safely receive typed parameters.
66
+ //
67
+ // The preserved template still needs the CONCRETE instantiation: geatsc's
68
+ // closed-world planner treats this store method as generic (the plugin
69
+ // strips its annotations pre-compile) and only plans the boxed
70
+ // gea_cpp_value runtime-bridge variant, while native call sites deduce the
71
+ // primitive types this transform just lowered the body for (e.g.
72
+ // BallStore::tick<double> from a rAF callback's double timestamp). Emit
73
+ // that explicit instantiation next to the definition so those call sites
74
+ // link.
75
+ if (signatureText.includes(`${className}::${methodName}`)) {
76
+ const replaced = `${source.slice(0, methodOpen)}${body.join('\n')}`;
77
+ const rest = source.slice(methodClose + 1);
78
+ const instantiation = outOfLineConcreteInstantiation(signatureText, methodName, typedParams);
79
+ if (instantiation && !source.includes(instantiation)) {
80
+ return `${replaced}\n${instantiation}${rest}`;
81
+ }
82
+ return `${replaced}${rest}`;
83
+ }
84
+ // The original signature is `<prefix> <methodName> ( <params> ) <suffix>`.
85
+ // Swap only the parameter list inside the first balanced `(...)` after the
86
+ // method name; keep `<prefix>` (return type + `virtual`) and `<suffix>`
87
+ // (`const`, ref-qualifiers) verbatim.
88
+ const nameIndex = signatureText.lastIndexOf(methodName);
89
+ const parenOpen = nameIndex >= 0 ? signatureText.indexOf('(', nameIndex) : -1;
90
+ if (parenOpen < 0)
91
+ return source;
92
+ const parenClose = matchParen(signatureText, parenOpen);
93
+ if (parenClose < 0)
94
+ return `${source.slice(0, methodOpen)}${body.join('\n')}${source.slice(methodClose + 1)}`;
95
+ const rebuiltSignature = `${signatureText.slice(0, parenOpen + 1)}${typedParams}${signatureText.slice(parenClose)}`;
96
+ return `${source.slice(0, methodStart)}${rebuiltSignature}${body.join('\n')}${source.slice(methodClose + 1)}`;
97
+ }
98
+ // Build `template <ret> <Class>::<method>(<concrete params>) <quals>;` for a
99
+ // preserved out-of-line abbreviated-template definition by substituting each
100
+ // parameter's `auto` with the concrete type from typedParams (positional, per
101
+ // parameter — a parameter geatsc already typed concretely is left untouched).
102
+ // Returns null when the shapes don't line up; the caller then changes nothing.
103
+ function outOfLineConcreteInstantiation(signatureText, methodName, typedParams) {
104
+ const nameIndex = signatureText.lastIndexOf(methodName);
105
+ const parenOpen = nameIndex >= 0 ? signatureText.indexOf('(', nameIndex) : -1;
106
+ if (parenOpen < 0)
107
+ return null;
108
+ const parenClose = matchParen(signatureText, parenOpen);
109
+ if (parenClose < 0)
110
+ return null;
111
+ const originalParams = splitTopLevelParams(signatureText.slice(parenOpen + 1, parenClose));
112
+ // Only abbreviated-template definitions (at least one `auto` parameter) are
113
+ // templates that can — and must — be explicitly instantiated. geatsc emits
114
+ // fully-concrete store methods (`double savedPage(std::string id)`) as plain
115
+ // non-template definitions; prefixing `template ...;` to one is an explicit
116
+ // instantiation of a non-template ("template-id does not match any template
117
+ // declaration"). No `auto` param ⇒ nothing to instantiate.
118
+ if (!originalParams.some((param) => /\bauto\b/.test(param)))
119
+ return null;
120
+ const concreteTypes = splitTopLevelParams(typedParams).map((param) => param.replace(/\s+[A-Za-z_][A-Za-z0-9_]*$/, '').trim());
121
+ if (originalParams.length !== concreteTypes.length)
122
+ return null;
123
+ const concreteParams = [];
124
+ for (let index = 0; index < originalParams.length; index += 1) {
125
+ const param = originalParams[index];
126
+ if (!/\bauto\b/.test(param)) {
127
+ concreteParams.push(param.trim());
128
+ continue;
129
+ }
130
+ if (!concreteTypes[index])
131
+ return null;
132
+ concreteParams.push(param.replace(/\bauto\b/, concreteTypes[index]).trim());
133
+ }
134
+ const signature = `${signatureText.slice(0, parenOpen + 1)}${concreteParams.join(', ')}${signatureText.slice(parenClose)}`.trim();
135
+ if (/\bauto\b/.test(signature))
136
+ return null;
137
+ return `template ${signature};`;
138
+ }
139
+ // Split a C++ parameter list on top-level commas (template arguments keep
140
+ // their commas).
141
+ function splitTopLevelParams(params) {
142
+ const trimmed = params.trim();
143
+ if (!trimmed)
144
+ return [];
145
+ const parts = [];
146
+ let depth = 0;
147
+ let start = 0;
148
+ for (let index = 0; index < trimmed.length; index += 1) {
149
+ const char = trimmed[index];
150
+ if (char === '<' || char === '(' || char === '[')
151
+ depth += 1;
152
+ else if (char === '>' || char === ')' || char === ']')
153
+ depth -= 1;
154
+ else if (char === ',' && depth === 0) {
155
+ parts.push(trimmed.slice(start, index));
156
+ start = index + 1;
157
+ }
158
+ }
159
+ parts.push(trimmed.slice(start));
160
+ return parts;
161
+ }
162
+ export function replaceClassMethodDefinition(source, className, methodName, signature, body) {
163
+ const region = findMethodSignatureRegion(source, className, methodName);
164
+ if (!region)
165
+ return source;
166
+ const { methodStart, methodOpen, methodClose } = region;
167
+ if (signature) {
168
+ return `${source.slice(0, methodStart)}${signature}\n${body.join('\n')}${source.slice(methodClose + 1)}`;
169
+ }
170
+ return `${source.slice(0, methodOpen)}${body.join('\n')}${source.slice(methodClose + 1)}`;
171
+ }
172
+ function findMethodSignatureRegion(source, className, methodName) {
173
+ const classOpen = findClassOpenBrace(source, className);
174
+ if (classOpen >= 0) {
175
+ const classClose = findMatchingBrace(source, classOpen);
176
+ if (classClose >= 0) {
177
+ const inline = findInlineMethodRegion(source, methodName, classOpen, classClose);
178
+ if (inline)
179
+ return inline;
180
+ }
181
+ }
182
+ // geatsc moves sufficiently large method bodies into the module .cpp and
183
+ // leaves only `method(...);` in the class header. Store re-lowering runs on
184
+ // every generated source, so find that out-of-line definition as well.
185
+ const outOfLinePattern = new RegExp(`(?:^|\\n)\\s*[A-Za-z_][A-Za-z0-9_:<>,*&\\s]*\\b${escapeRegExp(className)}::${escapeRegExp(methodName)}\\s*\\(`, 'g');
186
+ let match;
187
+ while ((match = outOfLinePattern.exec(source)) !== null) {
188
+ const methodStart = match.index + (match[0].startsWith('\n') ? 1 : 0);
189
+ const region = definitionRegionAt(source, methodStart, methodName, source.length);
190
+ if (region)
191
+ return region;
192
+ }
193
+ return null;
194
+ }
195
+ // Index of the `)` matching the `(` at `open` within `text` (no nesting beyond
196
+ // the parameter list's own default-value parens, which it tracks by depth).
197
+ function matchParen(text, open) {
198
+ let depth = 0;
199
+ let quote = null;
200
+ let escaped = false;
201
+ for (let index = open; index < text.length; index += 1) {
202
+ const char = text[index];
203
+ if (quote) {
204
+ if (escaped)
205
+ escaped = false;
206
+ else if (char === '\\')
207
+ escaped = true;
208
+ else if (char === quote)
209
+ quote = null;
210
+ }
211
+ else if (char === '"' || char === "'")
212
+ quote = char;
213
+ else if (char === '(')
214
+ depth += 1;
215
+ else if (char === ')' && --depth === 0)
216
+ return index;
217
+ }
218
+ return -1;
219
+ }
220
+ function findInlineMethodRegion(source, methodName, classOpen, classClose) {
221
+ const pattern = new RegExp(`\\n\\s*(?:virtual\\s+)?[A-Za-z_][A-Za-z0-9_:<>,*&\\s]*\\b${escapeRegExp(methodName)}\\s*\\(`, 'g');
222
+ pattern.lastIndex = classOpen;
223
+ let match;
224
+ while ((match = pattern.exec(source)) !== null) {
225
+ if (match.index > classClose)
226
+ break;
227
+ const methodStart = match.index + 1;
228
+ const region = definitionRegionAt(source, methodStart, methodName, classClose);
229
+ if (region)
230
+ return region;
231
+ }
232
+ return null;
233
+ }
234
+ function definitionRegionAt(source, methodStart, methodName, limit) {
235
+ const nameIndex = source.indexOf(methodName, methodStart);
236
+ if (nameIndex < 0 || nameIndex >= limit)
237
+ return null;
238
+ const parenOpen = source.indexOf('(', nameIndex + methodName.length);
239
+ if (parenOpen < 0 || parenOpen >= limit)
240
+ return null;
241
+ const parenClose = matchParen(source, parenOpen);
242
+ if (parenClose < 0 || parenClose >= limit)
243
+ return null;
244
+ // A declaration ends at `;`. Never let its search drift into the next
245
+ // member's `{` — that used to replace a following getter with the deferred
246
+ // method body.
247
+ for (let index = parenClose + 1; index < limit; index += 1) {
248
+ const char = source[index];
249
+ if (char === ';')
250
+ return null;
251
+ if (char !== '{')
252
+ continue;
253
+ const methodClose = findMatchingBrace(source, index);
254
+ if (methodClose < 0 || methodClose > limit)
255
+ return null;
256
+ return { methodStart, methodOpen: index, methodClose };
257
+ }
258
+ return null;
259
+ }
260
+ function findClassOpenBrace(source, className) {
261
+ const pattern = new RegExp(`\\bclass\\s+${escapeRegExp(className)}\\b`, 'g');
262
+ let match;
263
+ while ((match = pattern.exec(source)) !== null) {
264
+ const brace = source.indexOf('{', match.index);
265
+ const semicolon = source.indexOf(';', match.index);
266
+ if (brace >= 0 && (semicolon < 0 || brace < semicolon))
267
+ return brace;
268
+ }
269
+ return -1;
270
+ }
271
+ function findMatchingBrace(source, open) {
272
+ let depth = 0;
273
+ let quote = null;
274
+ let escaped = false;
275
+ for (let index = open; index < source.length; index += 1) {
276
+ const char = source[index];
277
+ if (quote) {
278
+ if (escaped)
279
+ escaped = false;
280
+ else if (char === '\\')
281
+ escaped = true;
282
+ else if (char === quote)
283
+ quote = null;
284
+ }
285
+ else if (char === '"' || char === "'")
286
+ quote = char;
287
+ else if (char === '{')
288
+ depth += 1;
289
+ else if (char === '}' && --depth === 0)
290
+ return index;
291
+ }
292
+ return -1;
293
+ }
294
+ function escapeRegExp(text) {
295
+ return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
296
+ }
@@ -0,0 +1,2 @@
1
+ import type { GeaIrBundleV1 } from './types.js';
2
+ export declare function applyTypedArrayStorage(source: string, ir: GeaIrBundleV1): string;