@komaci/esm-generator 244.0.0 → 244.1.2
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/build/__tests__/adgAstGeneration.spec.js +172 -0
- package/build/__tests__/compositionAstGeneration.spec.js +31 -4
- package/build/__tests__/functionAstGeneration.spec.js +36 -0
- package/build/compositionAstGeneration.js +2 -1
- package/build/functionAstGeneration.d.ts +14 -0
- package/build/functionAstGeneration.js +143 -1
- package/build/genericAstGeneration.js +17 -1
- package/build/types.d.ts +2 -0
- package/package.json +5 -5
|
@@ -29,4 +29,176 @@ describe('composeAdgFunction', () => {
|
|
|
29
29
|
expect(res.id.name).toBe('adg0');
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
|
+
describe('composeAdgStaticMetadata', () => {
|
|
33
|
+
it('creates a static metadata object', () => {
|
|
34
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
35
|
+
const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
|
|
36
|
+
adg.exportName = 'default';
|
|
37
|
+
moduleMetadata.staticMetadataId = 'c-test-comp';
|
|
38
|
+
const res = (0, functionAstGeneration_1.composeAdgStaticMetadata)(adg, moduleMetadata);
|
|
39
|
+
expect(res.type).toBe('VariableDeclaration');
|
|
40
|
+
const varDeclarator = res.declarations[0];
|
|
41
|
+
expect(varDeclarator.id.name).toBe('adg0Meta');
|
|
42
|
+
const properties = varDeclarator.init.properties;
|
|
43
|
+
expect(properties).toHaveLength(4);
|
|
44
|
+
expect(properties[0].value.value).toBe('c-test-comp');
|
|
45
|
+
});
|
|
46
|
+
it('creates a static metadata object for non default export', () => {
|
|
47
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
48
|
+
const adg = (0, common_shared_1.initAdgMetadataObject)('adg1');
|
|
49
|
+
adg.exportName = 'base';
|
|
50
|
+
moduleMetadata.staticMetadataId = 'c-test-comp';
|
|
51
|
+
const res = (0, functionAstGeneration_1.composeAdgStaticMetadata)(adg, moduleMetadata);
|
|
52
|
+
expect(res.type).toBe('VariableDeclaration');
|
|
53
|
+
const varDeclarator = res.declarations[0];
|
|
54
|
+
expect(varDeclarator.id.name).toBe('adg1Meta');
|
|
55
|
+
const properties = varDeclarator.init.properties;
|
|
56
|
+
expect(properties).toHaveLength(4);
|
|
57
|
+
expect(properties[0].value.value).toBe('c-test-comp__base');
|
|
58
|
+
});
|
|
59
|
+
it('creates a static metadata object with child metadata and true for img', () => {
|
|
60
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
61
|
+
const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
|
|
62
|
+
adg.exportName = 'default';
|
|
63
|
+
moduleMetadata.staticMetadataId = 'c-test-comp';
|
|
64
|
+
adg.compositionRootIndex = 0;
|
|
65
|
+
adg.compositions = [
|
|
66
|
+
{
|
|
67
|
+
type: 'Container',
|
|
68
|
+
compositions: [
|
|
69
|
+
{
|
|
70
|
+
type: 'ComposedAdg',
|
|
71
|
+
input: { type: 'ImportReference', value: 'test' },
|
|
72
|
+
properties: {
|
|
73
|
+
attr1: { type: 'Binding', value: 'input1' },
|
|
74
|
+
attr2: { type: 'Binding', value: 'input2' },
|
|
75
|
+
attr3: { type: 'PrimitiveValue', value: 'Literal!' },
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: 'Image',
|
|
80
|
+
src: { type: 'Binding', value: 'input1' },
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
moduleMetadata.importIndexReference.set('test', 'import1');
|
|
86
|
+
moduleMetadata.importsByName.set('import1', {
|
|
87
|
+
generatorAlias: 'i0',
|
|
88
|
+
name: '',
|
|
89
|
+
resourceName: '',
|
|
90
|
+
komaciDocImportRef: '',
|
|
91
|
+
isFromInternalNamespace: false,
|
|
92
|
+
isFromSupportedLibrary: false,
|
|
93
|
+
usedInPriming: false,
|
|
94
|
+
staticallyAnalyzable: false,
|
|
95
|
+
});
|
|
96
|
+
const res = (0, functionAstGeneration_1.composeAdgStaticMetadata)(adg, moduleMetadata);
|
|
97
|
+
expect(res.type).toBe('VariableDeclaration');
|
|
98
|
+
const varDeclarator = res.declarations[0];
|
|
99
|
+
expect(varDeclarator.id.name).toBe('adg0Meta');
|
|
100
|
+
const properties = varDeclarator.init.properties;
|
|
101
|
+
expect(properties).toHaveLength(4);
|
|
102
|
+
expect(properties[0].value.value).toBe('c-test-comp');
|
|
103
|
+
expect(properties[1].value
|
|
104
|
+
.properties[0].value.type).toBe('ArrayExpression');
|
|
105
|
+
const childMetaArr = properties[1].value
|
|
106
|
+
.properties[0].value;
|
|
107
|
+
expect(childMetaArr.elements).toHaveLength(2);
|
|
108
|
+
expect(childMetaArr.elements[0].properties).toHaveLength(2);
|
|
109
|
+
expect(childMetaArr.elements[1].properties).toHaveLength(1);
|
|
110
|
+
expect(childMetaArr.elements[0].properties).toHaveLength(2);
|
|
111
|
+
const prop1 = childMetaArr.elements[0]
|
|
112
|
+
.properties[0];
|
|
113
|
+
expect(prop1.value.name).toEqual('i0');
|
|
114
|
+
const prop2 = childMetaArr.elements[0]
|
|
115
|
+
.properties[1];
|
|
116
|
+
expect(prop2.value.properties).toHaveLength(3);
|
|
117
|
+
const propObj = prop2.value.properties[0].value;
|
|
118
|
+
expect(propObj.properties[1].value.value).toEqual('input1');
|
|
119
|
+
expect(childMetaArr.elements[1].properties).toHaveLength(1);
|
|
120
|
+
expect(properties[3].value.value).toBeTruthy();
|
|
121
|
+
});
|
|
122
|
+
it('static meta data object has true for PF', () => {
|
|
123
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
124
|
+
const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
|
|
125
|
+
adg.exportName = 'default';
|
|
126
|
+
moduleMetadata.staticMetadataId = 'c-test-comp';
|
|
127
|
+
adg.compositionRootIndex = 0;
|
|
128
|
+
const primingFunction = {
|
|
129
|
+
requiredProperties: [],
|
|
130
|
+
importReference: { functionName: 'test' },
|
|
131
|
+
type: common_shared_1.FunctionTypes.PRIMING_FUNCTION,
|
|
132
|
+
};
|
|
133
|
+
adg.functions.push(primingFunction);
|
|
134
|
+
const res = (0, functionAstGeneration_1.composeAdgStaticMetadata)(adg, moduleMetadata);
|
|
135
|
+
expect(res.type).toBe('VariableDeclaration');
|
|
136
|
+
const varDeclarator = res.declarations[0];
|
|
137
|
+
expect(varDeclarator.id.name).toBe('adg0Meta');
|
|
138
|
+
const properties = varDeclarator.init.properties;
|
|
139
|
+
expect(properties).toHaveLength(4);
|
|
140
|
+
expect(properties[0].value.value).toBe('c-test-comp');
|
|
141
|
+
expect(properties[2].value.value).toBeTruthy();
|
|
142
|
+
});
|
|
143
|
+
it('static meta data object has true for PF for wire function', () => {
|
|
144
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
145
|
+
const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
|
|
146
|
+
adg.exportName = 'default';
|
|
147
|
+
moduleMetadata.staticMetadataId = 'c-test-comp';
|
|
148
|
+
adg.compositionRootIndex = 0;
|
|
149
|
+
const primingFunction = {
|
|
150
|
+
requiredProperties: [],
|
|
151
|
+
importReference: { functionName: 'test' },
|
|
152
|
+
type: common_shared_1.FunctionTypes.WIRE_FUNCTION,
|
|
153
|
+
};
|
|
154
|
+
adg.functions.push(primingFunction);
|
|
155
|
+
const res = (0, functionAstGeneration_1.composeAdgStaticMetadata)(adg, moduleMetadata);
|
|
156
|
+
expect(res.type).toBe('VariableDeclaration');
|
|
157
|
+
const varDeclarator = res.declarations[0];
|
|
158
|
+
expect(varDeclarator.id.name).toBe('adg0Meta');
|
|
159
|
+
const properties = varDeclarator.init.properties;
|
|
160
|
+
expect(properties).toHaveLength(4);
|
|
161
|
+
expect(properties[0].value.value).toBe('c-test-comp');
|
|
162
|
+
expect(properties[2].value.value).toBeTruthy();
|
|
163
|
+
});
|
|
164
|
+
it('static meta data object has false for PF for getter', () => {
|
|
165
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
166
|
+
const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
|
|
167
|
+
adg.exportName = 'default';
|
|
168
|
+
moduleMetadata.staticMetadataId = 'c-test-comp';
|
|
169
|
+
adg.compositionRootIndex = 0;
|
|
170
|
+
const primingFunction = {
|
|
171
|
+
requiredProperties: [],
|
|
172
|
+
type: common_shared_1.FunctionTypes.GETTER_FUNCTION,
|
|
173
|
+
};
|
|
174
|
+
adg.functions.push(primingFunction);
|
|
175
|
+
const res = (0, functionAstGeneration_1.composeAdgStaticMetadata)(adg, moduleMetadata);
|
|
176
|
+
expect(res.type).toBe('VariableDeclaration');
|
|
177
|
+
const varDeclarator = res.declarations[0];
|
|
178
|
+
expect(varDeclarator.id.name).toBe('adg0Meta');
|
|
179
|
+
const properties = varDeclarator.init.properties;
|
|
180
|
+
expect(properties).toHaveLength(4);
|
|
181
|
+
expect(properties[0].value.value).toBe('c-test-comp');
|
|
182
|
+
expect(properties[2].value.value).toBeFalsy();
|
|
183
|
+
});
|
|
184
|
+
it('Correct id for non exported class', () => {
|
|
185
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
186
|
+
const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
|
|
187
|
+
moduleMetadata.staticMetadataId = 'c-test-comp';
|
|
188
|
+
adg.compositionRootIndex = 0;
|
|
189
|
+
const primingFunction = {
|
|
190
|
+
requiredProperties: [],
|
|
191
|
+
type: common_shared_1.FunctionTypes.GETTER_FUNCTION,
|
|
192
|
+
};
|
|
193
|
+
adg.functions.push(primingFunction);
|
|
194
|
+
const res = (0, functionAstGeneration_1.composeAdgStaticMetadata)(adg, moduleMetadata);
|
|
195
|
+
expect(res.type).toBe('VariableDeclaration');
|
|
196
|
+
const varDeclarator = res.declarations[0];
|
|
197
|
+
expect(varDeclarator.id.name).toBe('adg0Meta');
|
|
198
|
+
const properties = varDeclarator.init.properties;
|
|
199
|
+
expect(properties).toHaveLength(4);
|
|
200
|
+
expect(properties[0].value.value).toBe('c-test-comp__$nonExportedClass$');
|
|
201
|
+
expect(properties[2].value.value).toBeFalsy();
|
|
202
|
+
});
|
|
203
|
+
});
|
|
32
204
|
//# sourceMappingURL=adgAstGeneration.spec.js.map
|
|
@@ -234,7 +234,7 @@ describe('compositionToExpression', () => {
|
|
|
234
234
|
const res = (0, compositionAstGeneration_1.compositionToExpression)(moduleMetadata, complexDoc.compositions[0].compositions[2].compositions[0]);
|
|
235
235
|
expect(res.type).toBe('CallExpression');
|
|
236
236
|
const code = (0, generator_1.default)(res).code;
|
|
237
|
-
expect(code).toBe('cg(i1, {\n slot: "title",\n componentId: "c-title",\n props: {\n
|
|
237
|
+
expect(code).toBe('cg(i1, {\n slot: "title",\n componentId: "c-title",\n props: {\n icon: "standard:apex",\n size: "medium"\n }\n}, ctx)');
|
|
238
238
|
});
|
|
239
239
|
});
|
|
240
240
|
describe('containerToExpression', () => {
|
|
@@ -273,14 +273,14 @@ describe('composedAdgToExpression', () => {
|
|
|
273
273
|
expect(res.type).toBe('CallExpression');
|
|
274
274
|
expect(res.callee.name).toBe('cg');
|
|
275
275
|
const code = (0, generator_1.default)(res).code;
|
|
276
|
-
expect(code).toBe('cg(i3, {\n componentId: "c-lookup-field-row",\n props: {\n
|
|
276
|
+
expect(code).toBe('cg(i3, {\n componentId: "c-lookup-field-row",\n props: {\n label: "CreatedBy User Info",\n objectApiName: "User",\n recordId: ctx.props.record?.data?.fields?.CreatedById?.value\n }\n}, ctx)');
|
|
277
277
|
});
|
|
278
278
|
it('properly composed composedAdg with children', () => {
|
|
279
279
|
const res = (0, compositionAstGeneration_1.composedAdgToExpression)(moduleMetadata, complexDoc.compositions[0].compositions[0]);
|
|
280
280
|
expect(res.type).toBe('CallExpression');
|
|
281
281
|
expect(res.callee.name).toBe('cg');
|
|
282
282
|
const code = (0, generator_1.default)(res).code;
|
|
283
|
-
expect(code).toBe('cg(i0, {\n componentId: "lightning-card",\n props: {}\n}, ctx, [cg(i1, {\n slot: "title",\n componentId: "c-title",\n props: {\n
|
|
283
|
+
expect(code).toBe('cg(i0, {\n componentId: "lightning-card",\n props: {}\n}, ctx, [cg(i1, {\n slot: "title",\n componentId: "c-title",\n props: {\n icon: "standard:account",\n size: "large"\n }\n}, ctx), u(ctx.props.record) || ctx.props.record?.data ? [cg(i2, {\n componentId: "c-fieldrow",\n props: {\n label: "Object Type",\n value: ctx.props.objectApiName\n }\n}, ctx), cg(i2, {\n componentId: "c-fieldrow",\n props: {\n label: "Account Id",\n value: ctx.props.record?.data?.fields?.Id?.value\n }\n}, ctx), cg(i2, {\n componentId: "c-fieldrow",\n props: {\n label: "Account Name",\n value: ctx.props.record?.data?.fields?.Name?.value\n }\n}, ctx), u(ctx.props.ownerRecord) || ctx.props.ownerRecord?.data ? cg(i2, {\n componentId: "c-fieldrow",\n props: {\n label: "Account Owner",\n value: ctx.props.ownerRecord?.data?.fields?.Name?.value\n }\n}, ctx) : undefined, u(ctx.props.createdByRecord) || ctx.props.createdByRecord?.data ? cg(i2, {\n componentId: "c-fieldrow",\n props: {\n label: "Created By",\n value: ctx.props.createdByRecord?.data?.fields?.Name?.value\n }\n}, ctx) : undefined] : undefined])');
|
|
284
284
|
});
|
|
285
285
|
});
|
|
286
286
|
describe('iterationToExpression', () => {
|
|
@@ -372,7 +372,34 @@ describe('getCompositionConfig', () => {
|
|
|
372
372
|
it('collects composition config for a composedAdg', () => {
|
|
373
373
|
const res = (0, compositionAstGeneration_1.getCompositionConfig)(complexDoc.compositions[0].compositions[2].compositions[0]);
|
|
374
374
|
const code = (0, generator_1.default)(res).code;
|
|
375
|
-
expect(code).toBe('{\n slot: "title",\n props: {\n
|
|
375
|
+
expect(code).toBe('{\n slot: "title",\n props: {\n icon: "standard:apex",\n size: "medium"\n }\n}');
|
|
376
|
+
});
|
|
377
|
+
it('generates duplicate composition configs for similar composedAdgs', () => {
|
|
378
|
+
const res = (0, compositionAstGeneration_1.getCompositionConfig)(complexDoc.compositions[0].compositions[2].compositions[0]);
|
|
379
|
+
// generate config for composedAdg that is identical apart from ordering of props
|
|
380
|
+
const swapRes = (0, compositionAstGeneration_1.getCompositionConfig)({
|
|
381
|
+
type: 'ComposedAdg',
|
|
382
|
+
input: {
|
|
383
|
+
type: 'ImportReference',
|
|
384
|
+
value: '1names/0',
|
|
385
|
+
},
|
|
386
|
+
properties: {
|
|
387
|
+
icon: {
|
|
388
|
+
type: 'PrimitiveValue',
|
|
389
|
+
value: 'standard:apex',
|
|
390
|
+
},
|
|
391
|
+
size: {
|
|
392
|
+
type: 'PrimitiveValue',
|
|
393
|
+
value: 'medium',
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
slot: 'title',
|
|
397
|
+
});
|
|
398
|
+
const swappedCode = (0, generator_1.default)(swapRes).code;
|
|
399
|
+
const code = (0, generator_1.default)(res).code;
|
|
400
|
+
const expected = '{\n slot: "title",\n props: {\n icon: "standard:apex",\n size: "medium"\n }\n}';
|
|
401
|
+
expect(code).toBe(expected);
|
|
402
|
+
expect(swappedCode).toBe(expected);
|
|
376
403
|
});
|
|
377
404
|
it('collects composition config for a slot', () => {
|
|
378
405
|
const res = (0, compositionAstGeneration_1.getCompositionConfig)({
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -11,6 +34,7 @@ const types_1 = require("@babel/types");
|
|
|
11
34
|
const functionAstGeneration_1 = require("../functionAstGeneration");
|
|
12
35
|
const generator_1 = __importDefault(require("@babel/generator"));
|
|
13
36
|
const badImportRef_1 = require("./fixtures-source-code/badImportRef");
|
|
37
|
+
const t = __importStar(require("@babel/types"));
|
|
14
38
|
const generalMockSourceCode_1 = require("./fixtures-source-code/generalMockSourceCode");
|
|
15
39
|
describe('hoistLocalFunction', () => {
|
|
16
40
|
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/assorted-template-strings');
|
|
@@ -535,4 +559,16 @@ export default registerAdgFunction(adg0);`;
|
|
|
535
559
|
expect((0, generator_1.default)((0, types_1.file)(res)).code).toBe(expected);
|
|
536
560
|
});
|
|
537
561
|
});
|
|
562
|
+
describe('composeStaticMetadataAssignmentExpression', () => {
|
|
563
|
+
it('returns proper expression statement', () => {
|
|
564
|
+
const metaVarDeclarator = t.variableDeclarator(t.identifier(`Adg0Meta`), t.objectExpression([]));
|
|
565
|
+
const staticMetadataObject = t.variableDeclaration('const', [metaVarDeclarator]);
|
|
566
|
+
const expr = (0, functionAstGeneration_1.composeStaticMetadataAssignmentExpression)('adg0', staticMetadataObject).expression;
|
|
567
|
+
const left = expr.left;
|
|
568
|
+
expect(left.object.name).toBe('adg0');
|
|
569
|
+
expect(left.property.name).toBe('meta');
|
|
570
|
+
const right = expr.right;
|
|
571
|
+
expect(right.name).toBe('Adg0Meta');
|
|
572
|
+
});
|
|
573
|
+
});
|
|
538
574
|
//# sourceMappingURL=functionAstGeneration.spec.js.map
|
|
@@ -281,7 +281,8 @@ function getCompositionConfig(composition, componentId, iterationContext) {
|
|
|
281
281
|
}
|
|
282
282
|
if (composition.properties) {
|
|
283
283
|
const props = [];
|
|
284
|
-
|
|
284
|
+
const sortedCompositions = Object.keys(composition.properties).sort();
|
|
285
|
+
for (const propName of sortedCompositions) {
|
|
285
286
|
const prop = composition.properties[propName];
|
|
286
287
|
if (prop.type === 'Binding') {
|
|
287
288
|
props.push(t.objectProperty(t.identifier(propName), (0, genericAstGeneration_1.bindingToExpression)(prop, iterationContext)));
|
|
@@ -48,6 +48,13 @@ export declare function getFactoryFuncDeclaration(factoryFuncs: Set<IdKeys>): t.
|
|
|
48
48
|
* @returns the declaration for a given adg
|
|
49
49
|
*/
|
|
50
50
|
export declare function composeAdgFunction(adg: AdgMetadata, moduleMetadata: ModuleMetadata): t.ExportNamedDeclaration | t.ExportDefaultDeclaration | t.FunctionDeclaration;
|
|
51
|
+
/**
|
|
52
|
+
* Helper function to compose the static metadata object for a specific adg.
|
|
53
|
+
* @param adg the adg object we are building a metadata object for
|
|
54
|
+
* @param moduleMetadata the module metadata object.
|
|
55
|
+
* @returns a babel representation of a static metadata object.
|
|
56
|
+
*/
|
|
57
|
+
export declare function composeAdgStaticMetadata(adg: AdgMetadata, moduleMetadata: ModuleMetadata): t.VariableDeclaration;
|
|
51
58
|
/**
|
|
52
59
|
* associate composed adgs with their exported names
|
|
53
60
|
* @param adgName the name of the adg
|
|
@@ -78,4 +85,11 @@ export declare function getInlineFunctionFromTemplateCompositions(moduleMetadata
|
|
|
78
85
|
* @returns A default export representing the error state for this resolvable module
|
|
79
86
|
*/
|
|
80
87
|
export declare function produceErrorAdgFunction(moduleMetadata: ModuleMetadata, error: Error): t.Program;
|
|
88
|
+
/**
|
|
89
|
+
* Helper function to return the static metadata assignemnt expression statement.
|
|
90
|
+
* @param adgName the name of the adg function to associate the adgMeta object with.
|
|
91
|
+
* @param staticMetadataObject the staticMetadatObject to get the assicated adgMeta object name.
|
|
92
|
+
* @returns an expression statement, eg: adg0.meta = adg0meta
|
|
93
|
+
*/
|
|
94
|
+
export declare function composeStaticMetadataAssignmentExpression(adgName: string, staticMetadataObject: t.VariableDeclaration): t.ExpressionStatement;
|
|
81
95
|
//# sourceMappingURL=functionAstGeneration.d.ts.map
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.produceErrorAdgFunction = exports.getInlineFunctionFromTemplateCompositions = exports.getAdgFunctionBody = exports.addExportStatement = exports.composeAdgFunction = exports.getFactoryFuncDeclaration = exports.adgToExpression = exports.sanitizeFunction = exports.hoistLocalFunction = void 0;
|
|
26
|
+
exports.composeStaticMetadataAssignmentExpression = exports.produceErrorAdgFunction = exports.getInlineFunctionFromTemplateCompositions = exports.getAdgFunctionBody = exports.addExportStatement = exports.composeAdgStaticMetadata = exports.composeAdgFunction = exports.getFactoryFuncDeclaration = exports.adgToExpression = exports.sanitizeFunction = exports.hoistLocalFunction = void 0;
|
|
27
27
|
const t = __importStar(require("@babel/types"));
|
|
28
28
|
const common_shared_1 = require("@komaci/common-shared");
|
|
29
29
|
const compositionAstGeneration_1 = require("./compositionAstGeneration");
|
|
@@ -235,6 +235,137 @@ function composeAdgFunction(adg, moduleMetadata) {
|
|
|
235
235
|
return t.functionDeclaration(t.identifier(adg.defaultGeneratedName), [types_1.ID.FACTORY, types_1.ID.CONTEXT], body);
|
|
236
236
|
}
|
|
237
237
|
exports.composeAdgFunction = composeAdgFunction;
|
|
238
|
+
/**
|
|
239
|
+
* Helper function to compose the static metadata object for a specific adg.
|
|
240
|
+
* @param adg the adg object we are building a metadata object for
|
|
241
|
+
* @param moduleMetadata the module metadata object.
|
|
242
|
+
* @returns a babel representation of a static metadata object.
|
|
243
|
+
*/
|
|
244
|
+
function composeAdgStaticMetadata(adg, moduleMetadata) {
|
|
245
|
+
const Id = adg.exportName == 'default' ||
|
|
246
|
+
moduleMetadata.moduleType == common_shared_1.ModuleTypes.TEMPLATE_ONLY
|
|
247
|
+
? moduleMetadata.staticMetadataId
|
|
248
|
+
: adg.exportName
|
|
249
|
+
? `${moduleMetadata.staticMetadataId}__${adg.exportName}`
|
|
250
|
+
: `${moduleMetadata.staticMetadataId}__$nonExportedClass$`;
|
|
251
|
+
const metaDataProps = [];
|
|
252
|
+
//creating id: "comp-id";
|
|
253
|
+
const idProp = t.objectProperty(t.identifier('id'), t.stringLiteral(Id));
|
|
254
|
+
metaDataProps.push(idProp);
|
|
255
|
+
if (adg.parentReference != undefined) {
|
|
256
|
+
if (adg.parentReference.type == 'ImportReference') {
|
|
257
|
+
const importName = moduleMetadata.importIndexReference.get(adg.parentReference.value);
|
|
258
|
+
if (importName) {
|
|
259
|
+
const importId = moduleMetadata.importsByName.get(importName)?.generatorAlias;
|
|
260
|
+
if (importId) {
|
|
261
|
+
const parentProp = t.objectProperty(t.identifier('p'), t.identifier(importId));
|
|
262
|
+
metaDataProps.push(parentProp);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
else if (adg.parentReference.type == 'AdgReference') {
|
|
267
|
+
const parentAdgName = moduleMetadata.adgs.get(adg.parentReference.value)?.defaultGeneratedName;
|
|
268
|
+
if (parentAdgName) {
|
|
269
|
+
const parentProp = t.objectProperty(t.identifier('p'), t.identifier(parentAdgName));
|
|
270
|
+
metaDataProps.push(parentProp);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const tPropBody = [];
|
|
275
|
+
let hasImg = false;
|
|
276
|
+
if (adg.compositions && adg.compositionRootIndex != undefined) {
|
|
277
|
+
// creating an array of child metadata objects from composition.
|
|
278
|
+
const childMetadataObjects = collectChildrenStaticMetadata(adg.compositions[adg.compositionRootIndex], moduleMetadata);
|
|
279
|
+
//eg creating -> t0: [] with the array of child metadata objects.
|
|
280
|
+
const tmplEntry = t.objectProperty(t.identifier('t0'), t.arrayExpression(childMetadataObjects.childrenArray));
|
|
281
|
+
tPropBody.push(tmplEntry);
|
|
282
|
+
hasImg = childMetadataObjects.imgFound;
|
|
283
|
+
}
|
|
284
|
+
//creating t: {...tPropBody}
|
|
285
|
+
const tProp = t.objectProperty(t.identifier('t'), t.objectExpression(tPropBody));
|
|
286
|
+
metaDataProps.push(tProp);
|
|
287
|
+
const hasPrimableFunction = adg.functions.filter((f) => f.type == common_shared_1.FunctionTypes.PRIMING_FUNCTION ||
|
|
288
|
+
f.type == common_shared_1.FunctionTypes.WIRE_FUNCTION).length > 0;
|
|
289
|
+
//creating pf: false as the default.
|
|
290
|
+
const pfProp = t.objectProperty(t.identifier('pf'), t.booleanLiteral(hasPrimableFunction));
|
|
291
|
+
//creating img: prop based on if we found an img in the children traversal
|
|
292
|
+
const imgProp = t.objectProperty(t.identifier('img'), t.booleanLiteral(hasImg));
|
|
293
|
+
metaDataProps.push(pfProp);
|
|
294
|
+
metaDataProps.push(imgProp);
|
|
295
|
+
//eg: adg0Meta: {...metadataProps}
|
|
296
|
+
const metaVarDeclarator = t.variableDeclarator(t.identifier(`${adg.defaultGeneratedName}Meta`), t.objectExpression(metaDataProps));
|
|
297
|
+
return t.variableDeclaration('const', [metaVarDeclarator]);
|
|
298
|
+
}
|
|
299
|
+
exports.composeAdgStaticMetadata = composeAdgStaticMetadata;
|
|
300
|
+
/**
|
|
301
|
+
* Function to traverse a composition and collect static metada about children in the composition.
|
|
302
|
+
* @param compositions the compisition array.
|
|
303
|
+
* @param moduleMetadata the module metadata object.
|
|
304
|
+
* @returns a collection of children static metadata objects.
|
|
305
|
+
*/
|
|
306
|
+
function collectChildrenStaticMetadata(rootComposition, moduleMetadata) {
|
|
307
|
+
const childrenArray = [];
|
|
308
|
+
let imgFound = false;
|
|
309
|
+
if (rootComposition) {
|
|
310
|
+
(0, common_shared_1.traverseComposition)(rootComposition, (comp) => {
|
|
311
|
+
if (comp.type == 'ComposedAdg' || comp.type == 'Image') {
|
|
312
|
+
if (comp.type == 'Image') {
|
|
313
|
+
imgFound = true;
|
|
314
|
+
}
|
|
315
|
+
const childProp = generateComposisitonMetadata(comp, moduleMetadata);
|
|
316
|
+
childrenArray.push(childProp);
|
|
317
|
+
}
|
|
318
|
+
return false;
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
return { childrenArray, imgFound };
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Function to generate a babel object expression based on the compisition type.
|
|
325
|
+
* @param comp the compisition
|
|
326
|
+
* @param moduleMetadata the module metadata object.
|
|
327
|
+
* @returns a babel object expression.
|
|
328
|
+
*/
|
|
329
|
+
function generateComposisitonMetadata(comp, moduleMetadata) {
|
|
330
|
+
const propsArray = [];
|
|
331
|
+
if ((0, common_shared_1.isCompositionAComposedAdg)(comp)) {
|
|
332
|
+
//create child metadata object.
|
|
333
|
+
if (comp.input.type == 'ImportReference') {
|
|
334
|
+
const importName = moduleMetadata.importIndexReference.get(comp.input.value);
|
|
335
|
+
if (importName) {
|
|
336
|
+
const importMetadata = moduleMetadata.importsByName.get(importName);
|
|
337
|
+
if (importMetadata) {
|
|
338
|
+
propsArray.push(t.objectProperty(t.identifier('a'), t.identifier(importMetadata.generatorAlias)));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (comp.properties) {
|
|
343
|
+
const props = [];
|
|
344
|
+
for (const [key, value] of Object.entries(comp.properties)) {
|
|
345
|
+
//eg. creating -> type: "Binding"
|
|
346
|
+
const typeProp = t.objectProperty(t.identifier('type'), t.stringLiteral(value.type));
|
|
347
|
+
const stringValue = value.value != undefined ? value.value.toString() : 'undefined';
|
|
348
|
+
//eg. creating -> value: "input1"
|
|
349
|
+
const valueProp = t.objectProperty(t.identifier('value'), t.stringLiteral(stringValue));
|
|
350
|
+
const propObject = t.objectExpression([typeProp, valueProp]);
|
|
351
|
+
//eg creating -> prop1: {type: "", value: ""};
|
|
352
|
+
props.push(t.objectProperty(t.identifier(key), propObject));
|
|
353
|
+
}
|
|
354
|
+
propsArray.push(t.objectProperty(t.identifier('p'), t.objectExpression(props)));
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
else if ((0, common_shared_1.isCompositionAnImage)(comp)) {
|
|
358
|
+
//eg. creating -> type: "Binding"
|
|
359
|
+
const typeProp = t.objectProperty(t.identifier('type'), t.stringLiteral(comp.src.type));
|
|
360
|
+
const stringValue = comp.src.value != undefined ? comp.src.value.toString() : 'undefined';
|
|
361
|
+
//eg. creating -> value: "input1"
|
|
362
|
+
const valueProp = t.objectProperty(t.identifier('value'), t.stringLiteral(stringValue));
|
|
363
|
+
const propObject = t.objectExpression([typeProp, valueProp]);
|
|
364
|
+
//eg creating -> prop1: {type: "", value: ""};
|
|
365
|
+
propsArray.push(t.objectProperty(t.identifier('p'), propObject));
|
|
366
|
+
}
|
|
367
|
+
return t.objectExpression(propsArray);
|
|
368
|
+
}
|
|
238
369
|
/**
|
|
239
370
|
* associate composed adgs with their exported names
|
|
240
371
|
* @param adgName the name of the adg
|
|
@@ -371,4 +502,15 @@ function produceErrorAdgFunction(moduleMetadata, error) {
|
|
|
371
502
|
]);
|
|
372
503
|
}
|
|
373
504
|
exports.produceErrorAdgFunction = produceErrorAdgFunction;
|
|
505
|
+
/**
|
|
506
|
+
* Helper function to return the static metadata assignemnt expression statement.
|
|
507
|
+
* @param adgName the name of the adg function to associate the adgMeta object with.
|
|
508
|
+
* @param staticMetadataObject the staticMetadatObject to get the assicated adgMeta object name.
|
|
509
|
+
* @returns an expression statement, eg: adg0.meta = adg0meta
|
|
510
|
+
*/
|
|
511
|
+
function composeStaticMetadataAssignmentExpression(adgName, staticMetadataObject) {
|
|
512
|
+
return t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(adgName), t.identifier('meta')), t.identifier(staticMetadataObject.declarations[0]
|
|
513
|
+
.id.name)));
|
|
514
|
+
}
|
|
515
|
+
exports.composeStaticMetadataAssignmentExpression = composeStaticMetadataAssignmentExpression;
|
|
374
516
|
//# sourceMappingURL=functionAstGeneration.js.map
|
|
@@ -61,8 +61,16 @@ function generateResolvableModule(input, scriptKomaciDoc, templateKomaciDocMap,
|
|
|
61
61
|
: undefined;
|
|
62
62
|
const hasScriptKomaciDoc = scriptKomaciDoc && Object.keys(scriptKomaciDoc).length !== 0;
|
|
63
63
|
const hasTemplateKomaciDoc = defaultTemplateKomaciDoc && Object.keys(defaultTemplateKomaciDoc).length !== 0;
|
|
64
|
+
//generates the component name eg. komaciAction.js/html -> c-komaci-action
|
|
65
|
+
moduleMetadata.staticMetadataId = (0, common_shared_1.getComponentId)(input.moduleInfo.namespace, input.moduleInfo.name);
|
|
64
66
|
const combinedModule = scriptKomaciDoc !== undefined && defaultTemplateKomaciDoc !== undefined;
|
|
65
67
|
const isBundle = input.moduleInfo.type === 'bundle';
|
|
68
|
+
moduleMetadata.moduleType =
|
|
69
|
+
hasTemplateKomaciDoc && hasScriptKomaciDoc
|
|
70
|
+
? common_shared_1.ModuleTypes.BUNDLE_MODULE
|
|
71
|
+
: hasScriptKomaciDoc
|
|
72
|
+
? common_shared_1.ModuleTypes.SCRIPT_ONLY
|
|
73
|
+
: common_shared_1.ModuleTypes.TEMPLATE_ONLY;
|
|
66
74
|
let renderFunctionMetadata = undefined;
|
|
67
75
|
// start of metadata collection
|
|
68
76
|
if (scriptKomaciDoc) {
|
|
@@ -175,7 +183,15 @@ function generateResolvableModule(input, scriptKomaciDoc, templateKomaciDocMap,
|
|
|
175
183
|
statements.push(addUndefinedDefaultExport());
|
|
176
184
|
}
|
|
177
185
|
for (const adg of moduleMetadata.adgs.values()) {
|
|
178
|
-
|
|
186
|
+
//eg: const adgoMeta = {...}
|
|
187
|
+
const staticMetadataObject = (0, functionAstGeneration_1.composeAdgStaticMetadata)(adg, moduleMetadata);
|
|
188
|
+
//eg: function adg0(fct, ctx) {...}
|
|
189
|
+
const adgFunctionDefinition = (0, functionAstGeneration_1.composeAdgFunction)(adg, moduleMetadata);
|
|
190
|
+
//eg: adg0.meta = adg0Meta;
|
|
191
|
+
const staticMetadataAssignmentExpression = (0, functionAstGeneration_1.composeStaticMetadataAssignmentExpression)(adg.defaultGeneratedName, staticMetadataObject);
|
|
192
|
+
statements.push(staticMetadataObject);
|
|
193
|
+
statements.push(adgFunctionDefinition);
|
|
194
|
+
statements.push(staticMetadataAssignmentExpression);
|
|
179
195
|
}
|
|
180
196
|
for (const [exportName, adg] of Object.entries(moduleMetadata.exports)) {
|
|
181
197
|
statements.push((0, functionAstGeneration_1.addExportStatement)(adg.defaultGeneratedName, exportName));
|
package/build/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
2
|
import { KomaciDocument } from '@komaci/types';
|
|
3
3
|
import { IdKeys } from '@komaci/common-shared';
|
|
4
|
+
import { LuvioMetadata } from '@lwc/metadata/dist/schema/typescript-types/luvio-metadata-types';
|
|
4
5
|
export declare const ERROR_PREFIX = "[komaci esm-generator] ";
|
|
5
6
|
export declare const CONTEXT = "ctx";
|
|
6
7
|
export declare const PROPS = "props";
|
|
@@ -18,6 +19,7 @@ export declare type GeneratorInput = {
|
|
|
18
19
|
srcFileMap?: {
|
|
19
20
|
[filename: string]: string;
|
|
20
21
|
};
|
|
22
|
+
luvioMetadata?: Map<string, LuvioMetadata | undefined>;
|
|
21
23
|
};
|
|
22
24
|
declare type ModuleInfo = {
|
|
23
25
|
type: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@komaci/esm-generator",
|
|
3
|
-
"version": "244.
|
|
3
|
+
"version": "244.1.2",
|
|
4
4
|
"description": "Komaci generator for ADG ES modules",
|
|
5
5
|
"homepage": "https://komaci.dev/",
|
|
6
6
|
"repository": {
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/core": "^7.9.0",
|
|
30
30
|
"@babel/generator": "^7.9.0",
|
|
31
|
-
"@
|
|
32
|
-
"@komaci/
|
|
31
|
+
"@babel/types": "^7.9.0",
|
|
32
|
+
"@komaci/common-shared": "244.1.2",
|
|
33
|
+
"@komaci/static-analyzer": "244.1.2"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@komaci/types": "244.0.0",
|
|
36
|
+
"@komaci/types": "244.1.2",
|
|
37
37
|
"@lwc-platform/sfdc-lwc-compiler": "242.15.1-2.28.0",
|
|
38
38
|
"@lwc/metadata": "^2.28.0-0"
|
|
39
39
|
}
|