@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,8 @@
|
|
|
1
|
+
import type { GeaIrBundleV1, PluginDiagnostic } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* A typed keyed-list item must never cross a child-component boundary through
|
|
4
|
+
* `gea_cpp_value`. If the native renderer cannot inline/lower the row, stop the
|
|
5
|
+
* embedded build here instead of letting geatsc's generic component lifecycle
|
|
6
|
+
* instantiate the child, box its props, and emit invalid render/dispose calls.
|
|
7
|
+
*/
|
|
8
|
+
export declare function diagnoseBoxedKeyedComponentProps(ir: GeaIrBundleV1): PluginDiagnostic[];
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { collectSingletonMethodsFromSourceFiles, collectStoreArraySources, collectStoreFields, collectStoreMethods, } from './cpp-stores.js';
|
|
2
|
+
import { collectIrConstants } from './cpp-ir.js';
|
|
3
|
+
import { mountedRendererForComponent } from './cpp-mounted.js';
|
|
4
|
+
import { fieldNameForSlot, keyedListPayload, mountSlotAttrs, mountSlotTag, parseMountAttr } from './cpp-mounted-lowering.js';
|
|
5
|
+
import { sanitizeCppIdentifier } from './utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* A typed keyed-list item must never cross a child-component boundary through
|
|
8
|
+
* `gea_cpp_value`. If the native renderer cannot inline/lower the row, stop the
|
|
9
|
+
* embedded build here instead of letting geatsc's generic component lifecycle
|
|
10
|
+
* instantiate the child, box its props, and emit invalid render/dispose calls.
|
|
11
|
+
*/
|
|
12
|
+
export function diagnoseBoxedKeyedComponentProps(ir) {
|
|
13
|
+
const storeFields = collectStoreFields(ir.stores);
|
|
14
|
+
const storeArrayFields = collectStoreArraySources(ir.stores);
|
|
15
|
+
const storeMethods = collectStoreMethods(ir.stores).concat(collectSingletonMethodsFromSourceFiles(ir.modules.map((module) => module.file), ir.stores));
|
|
16
|
+
const constants = collectIrConstants(ir);
|
|
17
|
+
const diagnostics = [];
|
|
18
|
+
for (const component of ir.components) {
|
|
19
|
+
const typedRows = component.template.slots.flatMap((slot) => typedComponentRows(slot, storeArrayFields));
|
|
20
|
+
if (typedRows.length === 0)
|
|
21
|
+
continue;
|
|
22
|
+
if (mountedRendererForComponent(component, ir.components, storeFields, storeArrayFields, constants, storeMethods))
|
|
23
|
+
continue;
|
|
24
|
+
for (const row of typedRows) {
|
|
25
|
+
diagnostics.push({
|
|
26
|
+
kind: 'unsupported',
|
|
27
|
+
code: 'gea-boxed-keyed-component-props',
|
|
28
|
+
file: component.module,
|
|
29
|
+
severity: 'error',
|
|
30
|
+
message: `<${component.exportName}> maps the typed list \`${row.fieldName}\` into <${row.childTag} ${row.propName}={${row.itemName}} />, ` +
|
|
31
|
+
`but the parent template has no complete native renderer. The embedded compiler refuses to box the typed ` +
|
|
32
|
+
`\`${row.itemType}\` item into \`gea_cpp_value\` or enter the generic component render/dispose lifecycle. ` +
|
|
33
|
+
`Lower the unsupported parent slot or extend the native template renderer for that expression.`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return diagnostics;
|
|
38
|
+
}
|
|
39
|
+
function typedComponentRows(slot, fields) {
|
|
40
|
+
if (slot.kind !== 'keyed-list')
|
|
41
|
+
return [];
|
|
42
|
+
const payload = keyedListPayload(slot);
|
|
43
|
+
if (!payload?.rowTemplate || !payload.itemParam)
|
|
44
|
+
return [];
|
|
45
|
+
const fieldName = fieldNameForSlot(slot);
|
|
46
|
+
if (!fieldName)
|
|
47
|
+
return [];
|
|
48
|
+
const receiver = slot.exprPath && slot.exprPath.length > 1 ? sanitizeCppIdentifier(slot.exprPath[0]) : null;
|
|
49
|
+
const candidates = fields.filter((field) => field.fieldName === fieldName && (!receiver || !field.storeGlobalName || field.storeGlobalName === receiver));
|
|
50
|
+
if (candidates.length !== 1)
|
|
51
|
+
return [];
|
|
52
|
+
const itemName = sanitizeCppIdentifier(payload.itemParam);
|
|
53
|
+
const rows = [];
|
|
54
|
+
for (const rowSlot of payload.rowTemplate.slots) {
|
|
55
|
+
if (rowSlot.kind !== 'mount')
|
|
56
|
+
continue;
|
|
57
|
+
const childTag = mountSlotTag(rowSlot);
|
|
58
|
+
if (!childTag || childTag === 'Image')
|
|
59
|
+
continue;
|
|
60
|
+
for (const attr of mountSlotAttrs(rowSlot)) {
|
|
61
|
+
const parsed = parseMountAttr(attr);
|
|
62
|
+
if (!parsed || sanitizeCppIdentifier(parsed.expr) !== itemName)
|
|
63
|
+
continue;
|
|
64
|
+
rows.push({
|
|
65
|
+
fieldName,
|
|
66
|
+
itemName,
|
|
67
|
+
itemType: candidates[0].itemTypeRef,
|
|
68
|
+
childTag,
|
|
69
|
+
propName: parsed.name,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return rows;
|
|
74
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { GeaIrBundleV1, PluginDiagnostic } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Detect `{x.map(...)}` lists whose source is not a reactive array-of-objects
|
|
4
|
+
* store field. On the embedded target such a list silently renders nothing (the
|
|
5
|
+
* keyed-list mount bails to a placeholder anchor — see `keyedListMountedRenderer`
|
|
6
|
+
* in cpp-mounted.ts), which is a hard-to-diagnose trap. We surface it as a
|
|
7
|
+
* warning so the build tells the author exactly why the list is empty.
|
|
8
|
+
*
|
|
9
|
+
* The predicate mirrors the emitter exactly: a keyed-list renders reactively
|
|
10
|
+
* only when it is a compile-time static string-literal list
|
|
11
|
+
* (`isStaticKeyedListSlot`) or its name resolves to an array source collected by
|
|
12
|
+
* `collectStoreArraySources` — an array-of-objects field OR an array-returning
|
|
13
|
+
* getter. Anything else — a local/derived array, a primitive array, a getter
|
|
14
|
+
* whose element type can't be resolved, or a typo'd field — produces no row
|
|
15
|
+
* renderer and is flagged.
|
|
16
|
+
*/
|
|
17
|
+
export declare function diagnoseNonReactiveLists(ir: GeaIrBundleV1): PluginDiagnostic[];
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { collectStoreArraySources } from './cpp-stores.js';
|
|
2
|
+
import { collectIrConstants } from './cpp-ir.js';
|
|
3
|
+
import { objectArrayConstant } from './cpp-mounted-lowering.js';
|
|
4
|
+
import { isStaticKeyedListSlot, slotFieldName } from './cpp-replacements.js';
|
|
5
|
+
/**
|
|
6
|
+
* Detect `{x.map(...)}` lists whose source is not a reactive array-of-objects
|
|
7
|
+
* store field. On the embedded target such a list silently renders nothing (the
|
|
8
|
+
* keyed-list mount bails to a placeholder anchor — see `keyedListMountedRenderer`
|
|
9
|
+
* in cpp-mounted.ts), which is a hard-to-diagnose trap. We surface it as a
|
|
10
|
+
* warning so the build tells the author exactly why the list is empty.
|
|
11
|
+
*
|
|
12
|
+
* The predicate mirrors the emitter exactly: a keyed-list renders reactively
|
|
13
|
+
* only when it is a compile-time static string-literal list
|
|
14
|
+
* (`isStaticKeyedListSlot`) or its name resolves to an array source collected by
|
|
15
|
+
* `collectStoreArraySources` — an array-of-objects field OR an array-returning
|
|
16
|
+
* getter. Anything else — a local/derived array, a primitive array, a getter
|
|
17
|
+
* whose element type can't be resolved, or a typo'd field — produces no row
|
|
18
|
+
* renderer and is flagged.
|
|
19
|
+
*/
|
|
20
|
+
export function diagnoseNonReactiveLists(ir) {
|
|
21
|
+
const diagnostics = [];
|
|
22
|
+
// Sources include array-of-objects fields AND array-returning getters, so a
|
|
23
|
+
// getter-backed list does not get flagged as non-reactive.
|
|
24
|
+
const reactiveFieldNames = new Set(collectStoreArraySources(ir.stores).map((field) => field.fieldName));
|
|
25
|
+
const constants = collectIrConstants(ir);
|
|
26
|
+
for (const component of ir.components) {
|
|
27
|
+
for (const slot of component.template.slots) {
|
|
28
|
+
if (slot.kind !== 'keyed-list')
|
|
29
|
+
continue;
|
|
30
|
+
if (isStaticKeyedListSlot(slot))
|
|
31
|
+
continue;
|
|
32
|
+
if (objectArrayConstant(slot.expr, constants))
|
|
33
|
+
continue;
|
|
34
|
+
const fieldName = slotFieldName(slot);
|
|
35
|
+
if (fieldName && reactiveFieldNames.has(fieldName))
|
|
36
|
+
continue;
|
|
37
|
+
if (fieldName && isNamedTypedArrayField(fieldName, ir.stores))
|
|
38
|
+
continue;
|
|
39
|
+
diagnostics.push(buildDiagnostic(component, slot, fieldName, ir.stores));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return diagnostics;
|
|
43
|
+
}
|
|
44
|
+
function buildDiagnostic(component, slot, fieldName, stores) {
|
|
45
|
+
const source = slot.expr ?? fieldName ?? '<list>';
|
|
46
|
+
const reason = describeReason(fieldName, stores);
|
|
47
|
+
const message = `<${component.exportName}> renders the list \`{${source}.map(...)}\`, but ${reason}. ` +
|
|
48
|
+
`On the embedded target a list only renders when its source is a typed array-of-objects ` +
|
|
49
|
+
`field on a Store (e.g. \`${fieldName ?? 'items'}: Tile[]\` where \`Tile\` is an object), mutated/reassigned ` +
|
|
50
|
+
`through the store. Getters, local/derived arrays, and primitive arrays are not reactive ` +
|
|
51
|
+
`lists, so this list renders nothing.`;
|
|
52
|
+
return {
|
|
53
|
+
kind: 'unsupported',
|
|
54
|
+
code: 'gea-nonreactive-list',
|
|
55
|
+
message,
|
|
56
|
+
file: component.module,
|
|
57
|
+
severity: 'warning',
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function describeReason(fieldName, stores) {
|
|
61
|
+
if (!fieldName)
|
|
62
|
+
return 'its source is not a reactive store field';
|
|
63
|
+
for (const store of stores) {
|
|
64
|
+
const field = store.fields.find((candidate) => candidate.name === fieldName);
|
|
65
|
+
if (field) {
|
|
66
|
+
const shape = field.shape;
|
|
67
|
+
if (shape?.kind === 'array')
|
|
68
|
+
return `\`${fieldName}\` is an array of primitives, not of objects`;
|
|
69
|
+
return `\`${fieldName}\` is not an array field`;
|
|
70
|
+
}
|
|
71
|
+
if (store.methods?.some((method) => method.name === fieldName)) {
|
|
72
|
+
return `\`${fieldName}\` is a method (getters/methods never reach the embedded IR)`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return `\`${fieldName}\` is not a reactive store field (it looks like a getter or local array)`;
|
|
76
|
+
}
|
|
77
|
+
function isNamedTypedArrayField(fieldName, stores) {
|
|
78
|
+
for (const store of stores) {
|
|
79
|
+
const field = store.fields.find((candidate) => candidate.name === fieldName);
|
|
80
|
+
if (field?.shape?.kind === 'array' && !!field.shape.elementTypeName)
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { StoreArrayFieldPlan, StoreFieldPlan, StoreMethodPlan } from './cpp-stores.js';
|
|
2
|
+
import type { FieldAccess } from './cpp-field-access.js';
|
|
3
|
+
import type { GeaIrComponent, GeaIrConstant, GeaIrConstantObjectArrayItem, GeaIrExpressionObjectField, GeaIrKeyedListPayload, GeaIrSlot, GeaIrStoreValueShape } from './types.js';
|
|
4
|
+
export interface HtmlRoot {
|
|
5
|
+
tag: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
attrs?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export interface LoweredSlots {
|
|
10
|
+
stateType: string;
|
|
11
|
+
deps: string[];
|
|
12
|
+
fields: StoreFieldPlan[];
|
|
13
|
+
fieldReadPlan: LoweredFieldReadPlan;
|
|
14
|
+
staticLines: string[];
|
|
15
|
+
lines: string[];
|
|
16
|
+
}
|
|
17
|
+
export interface LoweredFieldReadPlan {
|
|
18
|
+
stateType: string;
|
|
19
|
+
fields: LoweredFieldRead[];
|
|
20
|
+
}
|
|
21
|
+
export interface LoweredFieldRead {
|
|
22
|
+
fieldName: string;
|
|
23
|
+
fieldType: string;
|
|
24
|
+
localName: string;
|
|
25
|
+
readerName: string;
|
|
26
|
+
}
|
|
27
|
+
export interface LoweredRowSlots {
|
|
28
|
+
lines: string[];
|
|
29
|
+
patches: LoweredRowPatch[];
|
|
30
|
+
unconditionalPatches: string[];
|
|
31
|
+
itemFieldNames: string[];
|
|
32
|
+
storeFields: StoreFieldPlan[];
|
|
33
|
+
treeLines: string[];
|
|
34
|
+
eventLines: string[];
|
|
35
|
+
}
|
|
36
|
+
export interface LoweredRowPatch {
|
|
37
|
+
itemFieldName: string;
|
|
38
|
+
lines: string[];
|
|
39
|
+
}
|
|
40
|
+
export type ConstantMap = ReadonlyMap<string, GeaIrConstant>;
|
|
41
|
+
export declare function storeGlobalIsTyped(globalName: string, storeFields: StoreFieldPlan[]): boolean;
|
|
42
|
+
export declare function attributeLines(varName: string, root: HtmlRoot, slots?: GeaIrSlot[]): string[];
|
|
43
|
+
export declare function rootSetupLines(varName: string, slots: GeaIrSlot[], storeFields?: StoreFieldPlan[], storeMethods?: StoreMethodPlan[], fieldAccess?: FieldAccess, rootTag?: string, constants?: ConstantMap, disposerVar?: string): string[] | null;
|
|
44
|
+
export declare function eventSetupLines(varName: string, slot: GeaIrSlot, storeFields?: StoreFieldPlan[], storeMethods?: StoreMethodPlan[], fieldAccess?: FieldAccess, rootTag?: string, constants?: ConstantMap, disposerVar?: string): string[] | null;
|
|
45
|
+
export declare function rootSetupSlotsSupported(slots: GeaIrSlot[], storeFields?: StoreFieldPlan[], storeMethods?: StoreMethodPlan[], constants?: ConstantMap): boolean;
|
|
46
|
+
export declare function isRootSetupSlot(slot: GeaIrSlot, constants?: ConstantMap): boolean;
|
|
47
|
+
export declare function childForMount(slot: GeaIrSlot, components: GeaIrComponent[]): GeaIrComponent | null;
|
|
48
|
+
export declare function mountSlotTag(slot: GeaIrSlot): string | null;
|
|
49
|
+
export declare function mountSlotAttrs(slot: GeaIrSlot): string[];
|
|
50
|
+
export declare function parseMountAttr(code: string): {
|
|
51
|
+
name: string;
|
|
52
|
+
expr: string;
|
|
53
|
+
} | null;
|
|
54
|
+
export declare function mountSlotStyleSlot(slot: GeaIrSlot): GeaIrSlot | null;
|
|
55
|
+
export declare function mountSlotImageSourceLines(varName: string, slot: GeaIrSlot): string[] | null;
|
|
56
|
+
export declare function fieldNameForSlot(slot: GeaIrSlot): string | null;
|
|
57
|
+
export declare function keyedListPayload(slot: GeaIrSlot): GeaIrKeyedListPayload | null;
|
|
58
|
+
export declare function keyedListKeyExpression(payload: GeaIrKeyedListPayload, itemName: string, field: StoreArrayFieldPlan): string;
|
|
59
|
+
export declare function lowerSlots(slots: GeaIrSlot[], storeFields: StoreFieldPlan[], constants?: ConstantMap): LoweredSlots | null;
|
|
60
|
+
export declare function parseHtmlRoot(html: string): HtmlRoot | null;
|
|
61
|
+
export declare function lowerRowSlots(slots: GeaIrSlot[], itemName: string, field: StoreArrayFieldPlan, constants?: ConstantMap, pathVars?: Map<string, string>, storeFields?: StoreFieldPlan[], storeMethods?: StoreMethodPlan[]): LoweredRowSlots;
|
|
62
|
+
export declare function parseExpressionObjectFields(expr: string): GeaIrExpressionObjectField[] | null;
|
|
63
|
+
export declare function constantExpression(name: string, constants: ConstantMap): {
|
|
64
|
+
expr: string;
|
|
65
|
+
shape: GeaIrStoreValueShape;
|
|
66
|
+
} | null;
|
|
67
|
+
export declare function objectArrayConstant(name: string | undefined, constants: ConstantMap): GeaIrConstantObjectArrayItem[] | null;
|
|
68
|
+
export declare function imageSrcAssetIdExpression(relPath: string): string;
|
|
69
|
+
export declare function unique<T>(values: T[]): T | null;
|
|
70
|
+
export declare function fieldReadPlanForLoweredSlots(stateType: string, fields: StoreFieldPlan[]): LoweredFieldReadPlan | null;
|
|
71
|
+
export declare function fieldReadLines(plan: LoweredFieldReadPlan, storeExpression?: string): string[];
|
|
72
|
+
export declare function attributeSlotLines(varName: string, slot: GeaIrSlot, constants?: ConstantMap): string[] | null;
|
|
73
|
+
export declare function slotAttrName(slot: GeaIrSlot): string | null;
|
|
74
|
+
export declare function lowerTextSlot(slot: GeaIrSlot, storeFields: StoreFieldPlan[]): {
|
|
75
|
+
stateType: string;
|
|
76
|
+
deps: string[];
|
|
77
|
+
fields: StoreFieldPlan[];
|
|
78
|
+
expr: string;
|
|
79
|
+
} | null;
|
|
80
|
+
export declare function storeFieldLocalName(fieldName: string): string;
|
|
81
|
+
export declare function stringLiteralValue(expr: string): string | null;
|