@komaci/esm-generator 244.1.8 → 244.2.0
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__/compositionAstGeneration.spec.js +43 -261
- package/build/__tests__/functionAstGeneration.spec.js +0 -11
- package/build/__tests__/genericAstGeneration.spec.js +0 -44
- package/build/__tests__/komaci-bundle-module.fixtures.spec.js +1 -1
- package/build/compositionAstGeneration.d.ts +2 -3
- package/build/compositionAstGeneration.js +39 -47
- package/build/functionAstGeneration.d.ts +0 -7
- package/build/functionAstGeneration.js +11 -27
- package/build/genericAstGeneration.d.ts +0 -16
- package/build/genericAstGeneration.js +4 -53
- package/build/types.js +0 -1
- package/package.json +4 -4
|
@@ -35,7 +35,6 @@ const common_shared_1 = require("@komaci/common-shared");
|
|
|
35
35
|
const generator_1 = __importDefault(require("@babel/generator"));
|
|
36
36
|
const complexDoc = JSON.parse(fs.readFileSync((0, path_1.join)(__dirname, './general-komaci-docs/complexTemplateDoc/template.json'), 'utf-8'));
|
|
37
37
|
describe('imageToExpression', () => {
|
|
38
|
-
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
39
38
|
it('should return an expression for a KomaciDocument Image node', () => {
|
|
40
39
|
const komaciDocImagePrimitive = {
|
|
41
40
|
type: 'Image',
|
|
@@ -44,13 +43,13 @@ describe('imageToExpression', () => {
|
|
|
44
43
|
value: 'testPrimitive.jpg', // this is string literal of a relative URL
|
|
45
44
|
},
|
|
46
45
|
};
|
|
47
|
-
let expression = (0, compositionAstGeneration_1.imageToExpression)(
|
|
46
|
+
let expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImagePrimitive);
|
|
48
47
|
expect(expression.type).toBe('CallExpression');
|
|
49
48
|
let callExpression = expression;
|
|
50
49
|
expect(callExpression).not.toBeUndefined();
|
|
51
50
|
expect(callExpression.callee).toBe(types_2.ID.IMG_FUNC);
|
|
52
51
|
expect(callExpression.arguments).not.toBeUndefined();
|
|
53
|
-
expect(callExpression.arguments).toHaveLength(
|
|
52
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
54
53
|
expect(callExpression.arguments[0]).not.toBeUndefined();
|
|
55
54
|
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
56
55
|
let objExpression = callExpression
|
|
@@ -60,8 +59,7 @@ describe('imageToExpression', () => {
|
|
|
60
59
|
expect(objExpression.properties[0].type).toBe('ObjectProperty');
|
|
61
60
|
let objProperty = objExpression.properties[0];
|
|
62
61
|
expect(objProperty.key).toBe(types_2.ID.IMG_SRC);
|
|
63
|
-
expect(objProperty.value.
|
|
64
|
-
.value).toEqual((0, types_1.stringLiteral)('testPrimitive.jpg')); // img({src: "testPrimitive.jpg"})
|
|
62
|
+
expect(objProperty.value).toEqual((0, types_1.stringLiteral)('testPrimitive.jpg')); // img({src: "testPrimitive.jpg"})
|
|
65
63
|
const komaciDocImageBinding = {
|
|
66
64
|
type: 'Image',
|
|
67
65
|
src: {
|
|
@@ -69,13 +67,13 @@ describe('imageToExpression', () => {
|
|
|
69
67
|
value: 'testBinding', // this is a string literal, but represents a variable name
|
|
70
68
|
},
|
|
71
69
|
};
|
|
72
|
-
expression = (0, compositionAstGeneration_1.imageToExpression)(
|
|
70
|
+
expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImageBinding);
|
|
73
71
|
expect(expression.type).toBe('CallExpression');
|
|
74
72
|
callExpression = expression;
|
|
75
73
|
expect(callExpression).not.toBeUndefined();
|
|
76
74
|
expect(callExpression.callee).toBe(types_2.ID.IMG_FUNC);
|
|
77
75
|
expect(callExpression.arguments).not.toBeUndefined();
|
|
78
|
-
expect(callExpression.arguments).toHaveLength(
|
|
76
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
79
77
|
expect(callExpression.arguments[0]).not.toBeUndefined();
|
|
80
78
|
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
81
79
|
objExpression = callExpression.arguments[0];
|
|
@@ -85,13 +83,12 @@ describe('imageToExpression', () => {
|
|
|
85
83
|
expect(objExpression.properties[0].type).toBe('ObjectProperty');
|
|
86
84
|
objProperty = objExpression.properties[0];
|
|
87
85
|
expect(objProperty.key).toBe(types_2.ID.IMG_SRC);
|
|
88
|
-
|
|
86
|
+
let segments = ['ctx', 'props', 'testBinding'];
|
|
89
87
|
let expr = (0, types_1.identifier)(segments[0]);
|
|
90
88
|
for (let i = 1; i < segments.length; i++) {
|
|
91
89
|
expr = (0, types_1.optionalMemberExpression)(expr, (0, types_1.identifier)(segments[i]), false, false);
|
|
92
90
|
}
|
|
93
|
-
expect(objProperty.value.
|
|
94
|
-
.value).toEqual((0, types_1.stringLiteral)('testBinding')); // img({src: ctx.props.testBinding})
|
|
91
|
+
expect(objProperty.value).toEqual(expr); // img({src: ctx.props.testBinding})
|
|
95
92
|
const komaciDocImageNestedBinding = {
|
|
96
93
|
type: 'Image',
|
|
97
94
|
src: {
|
|
@@ -99,13 +96,13 @@ describe('imageToExpression', () => {
|
|
|
99
96
|
value: 'imageObject/nested/imageName', // this is a string literal, represents nested-scoped variable names
|
|
100
97
|
},
|
|
101
98
|
};
|
|
102
|
-
expression = (0, compositionAstGeneration_1.imageToExpression)(
|
|
99
|
+
expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImageNestedBinding);
|
|
103
100
|
expect(expression.type).toBe('CallExpression');
|
|
104
101
|
callExpression = expression;
|
|
105
102
|
expect(callExpression).not.toBeUndefined();
|
|
106
103
|
expect(callExpression.callee).toBe(types_2.ID.IMG_FUNC);
|
|
107
104
|
expect(callExpression.arguments).not.toBeUndefined();
|
|
108
|
-
expect(callExpression.arguments).toHaveLength(
|
|
105
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
109
106
|
expect(callExpression.arguments[0]).not.toBeUndefined();
|
|
110
107
|
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
111
108
|
objExpression = callExpression.arguments[0];
|
|
@@ -115,8 +112,13 @@ describe('imageToExpression', () => {
|
|
|
115
112
|
expect(objExpression.properties[0].type).toBe('ObjectProperty');
|
|
116
113
|
objProperty = objExpression.properties[0];
|
|
117
114
|
expect(objProperty.key).toBe(types_2.ID.IMG_SRC);
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
segments = ['ctx', 'props', 'imageObject', 'nested', 'imageName'];
|
|
116
|
+
expr = (0, types_1.identifier)(segments[0]);
|
|
117
|
+
const chainingStartIdx = 2;
|
|
118
|
+
for (let i = 1; i < segments.length; i++) {
|
|
119
|
+
expr = (0, types_1.optionalMemberExpression)(expr, (0, types_1.identifier)(segments[i]), false, i > chainingStartIdx);
|
|
120
|
+
}
|
|
121
|
+
expect(objProperty.value).toEqual(expr); // img({src: ctx.props.imageObject?.nested?.imageName})
|
|
120
122
|
});
|
|
121
123
|
it('should not return an expression for invalid KomaciDocument Image nodes due to invalid src.value type (boolean)', () => {
|
|
122
124
|
const komaciDocImagePrimitive = {
|
|
@@ -126,14 +128,14 @@ describe('imageToExpression', () => {
|
|
|
126
128
|
value: false, // not a supported type (boolean)
|
|
127
129
|
},
|
|
128
130
|
};
|
|
129
|
-
const expression = (0, compositionAstGeneration_1.imageToExpression)(
|
|
131
|
+
const expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImagePrimitive);
|
|
130
132
|
expect(expression.type).toBe('CallExpression');
|
|
131
133
|
const callExpression = expression;
|
|
132
134
|
expect(callExpression).not.toBeUndefined();
|
|
133
135
|
expect(callExpression.callee).not.toBeUndefined();
|
|
134
136
|
expect(callExpression.callee).toBe(types_2.ID.IMG_FUNC);
|
|
135
137
|
expect(callExpression.arguments).not.toBeUndefined();
|
|
136
|
-
expect(callExpression.arguments).toHaveLength(
|
|
138
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
137
139
|
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
138
140
|
const objExpression = callExpression
|
|
139
141
|
.arguments[0];
|
|
@@ -148,15 +150,15 @@ describe('imageToExpression', () => {
|
|
|
148
150
|
value: '', // blanks not supported
|
|
149
151
|
},
|
|
150
152
|
};
|
|
151
|
-
let expression = (0, compositionAstGeneration_1.imageToExpression)(
|
|
152
|
-
expression = (0, compositionAstGeneration_1.imageToExpression)(
|
|
153
|
+
let expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImagePrimitiveBlank);
|
|
154
|
+
expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImagePrimitiveBlank);
|
|
153
155
|
expect(expression.type).toBe('CallExpression');
|
|
154
156
|
const callExpression = expression;
|
|
155
157
|
expect(callExpression).not.toBeUndefined();
|
|
156
158
|
expect(callExpression.callee).not.toBeUndefined();
|
|
157
159
|
expect(callExpression.callee).toBe(types_2.ID.IMG_FUNC);
|
|
158
160
|
expect(callExpression.arguments).not.toBeUndefined();
|
|
159
|
-
expect(callExpression.arguments).toHaveLength(
|
|
161
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
160
162
|
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
161
163
|
const objExpression = callExpression
|
|
162
164
|
.arguments[0];
|
|
@@ -173,15 +175,15 @@ describe('imageToExpression', () => {
|
|
|
173
175
|
};
|
|
174
176
|
// change the src.value type to something invalid, a number
|
|
175
177
|
komaciDocImageInvalidSrcValType.src.value = 12345;
|
|
176
|
-
let expression = (0, compositionAstGeneration_1.imageToExpression)(
|
|
177
|
-
expression = (0, compositionAstGeneration_1.imageToExpression)(
|
|
178
|
+
let expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImageInvalidSrcValType);
|
|
179
|
+
expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImageInvalidSrcValType);
|
|
178
180
|
expect(expression.type).toBe('CallExpression');
|
|
179
181
|
const callExpression = expression;
|
|
180
182
|
expect(callExpression).not.toBeUndefined();
|
|
181
183
|
expect(callExpression.callee).not.toBeUndefined();
|
|
182
184
|
expect(callExpression.callee).toBe(types_2.ID.IMG_FUNC);
|
|
183
185
|
expect(callExpression.arguments).not.toBeUndefined();
|
|
184
|
-
expect(callExpression.arguments).toHaveLength(
|
|
186
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
185
187
|
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
186
188
|
const objExpression = callExpression
|
|
187
189
|
.arguments[0];
|
|
@@ -216,66 +218,23 @@ describe('compositionToExpression', () => {
|
|
|
216
218
|
(0, common_shared_1.initializeImportMetdataFromKomaciDocument)(complexDoc, moduleMetadata, 0);
|
|
217
219
|
moduleMetadata.adgs.set(0, (0, common_shared_1.initAdgMetadataObject)('adg0'));
|
|
218
220
|
(0, common_shared_1.addTemplateUsageForAdg)(complexDoc, 0, moduleMetadata);
|
|
219
|
-
it('
|
|
221
|
+
it('effectiely builds a conditional expression for a component with isActive', () => {
|
|
220
222
|
const res = (0, compositionAstGeneration_1.compositionToExpression)(moduleMetadata, complexDoc.compositions[0].compositions[2].compositions[1]);
|
|
221
|
-
expect(res.type).toBe('
|
|
222
|
-
expect(res.callee).toBe(types_2.ID.CONDITION_FUNC);
|
|
223
|
+
expect(res.type).toBe('ConditionalExpression');
|
|
223
224
|
const code = (0, generator_1.default)(res).code;
|
|
224
|
-
expect(code).toBe(
|
|
225
|
-
c: {
|
|
226
|
-
t: "b",
|
|
227
|
-
v: "apexResult"
|
|
228
|
-
},
|
|
229
|
-
slot: ""
|
|
230
|
-
}, ctx => [i({
|
|
231
|
-
c: {
|
|
232
|
-
t: "b",
|
|
233
|
-
v: "apexResult.data.names"
|
|
234
|
-
}
|
|
235
|
-
}, ctx, user_var_test => {
|
|
236
|
-
return [e({}, ctx, []), cg(i4, {
|
|
237
|
-
componentId: "c-name-detail",
|
|
238
|
-
props: ctx => ({
|
|
239
|
-
name: user_var_test.value?.name
|
|
240
|
-
})
|
|
241
|
-
}, ctx, [], [])];
|
|
242
|
-
}), c(ctx, {
|
|
243
|
-
c: {
|
|
244
|
-
t: "b",
|
|
245
|
-
v: "apexResult.data"
|
|
246
|
-
}
|
|
247
|
-
}, ctx => i({
|
|
248
|
-
c: {
|
|
249
|
-
t: "b",
|
|
250
|
-
v: "apexResult.data"
|
|
251
|
-
}
|
|
252
|
-
}, ctx, user_var_contactName => {
|
|
253
|
-
return [e({}, ctx, [])];
|
|
254
|
-
}), false), c(ctx, {
|
|
255
|
-
c: {
|
|
256
|
-
t: "b",
|
|
257
|
-
v: "apexResult.error"
|
|
258
|
-
}
|
|
259
|
-
}, ctx => [], false)], false)`);
|
|
225
|
+
expect(code).toBe('u(ctx.props.apexResult) || ctx.props.apexResult ? [i(ctx.props.apexResult?.data?.names, ctx, user_var_test => {\n return [e({}, ctx, []), cg(i4, {\n componentId: "c-name-detail",\n props: {\n name: user_var_test.value?.name\n }\n }, ctx)];\n}), u(ctx.props.apexResult) || ctx.props.apexResult?.data ? i(ctx.props.apexResult?.data, ctx, user_var_contactName => {\n return [e({}, ctx, [])];\n}) : undefined, u(ctx.props.apexResult) || ctx.props.apexResult?.error ? [] : undefined] : undefined');
|
|
260
226
|
});
|
|
261
227
|
it('effectiely builds a conditional expression for a component with negated isActive', () => {
|
|
262
228
|
const res = (0, compositionAstGeneration_1.compositionToExpression)(moduleMetadata, complexDoc.compositions[0].compositions[2].compositions[2]);
|
|
263
|
-
expect(res.type).toBe('
|
|
264
|
-
expect(res.callee).toBe(types_2.ID.CONDITION_FUNC);
|
|
229
|
+
expect(res.type).toBe('ConditionalExpression');
|
|
265
230
|
const code = (0, generator_1.default)(res).code;
|
|
266
|
-
expect(code).toBe(
|
|
267
|
-
c: {
|
|
268
|
-
t: "b",
|
|
269
|
-
v: "apexResult"
|
|
270
|
-
},
|
|
271
|
-
slot: ""
|
|
272
|
-
}, ctx => [], true)`);
|
|
231
|
+
expect(code).toBe('u(ctx.props.apexResult) || !ctx.props.apexResult ? [] : undefined');
|
|
273
232
|
});
|
|
274
233
|
it('returns a basic reference when isActive is not set', () => {
|
|
275
234
|
const res = (0, compositionAstGeneration_1.compositionToExpression)(moduleMetadata, complexDoc.compositions[0].compositions[2].compositions[0]);
|
|
276
235
|
expect(res.type).toBe('CallExpression');
|
|
277
236
|
const code = (0, generator_1.default)(res).code;
|
|
278
|
-
expect(code).toBe('cg(i1, {\n slot: "title",\n componentId: "c-title",\n props:
|
|
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)');
|
|
279
238
|
});
|
|
280
239
|
});
|
|
281
240
|
describe('containerToExpression', () => {
|
|
@@ -314,109 +273,14 @@ describe('composedAdgToExpression', () => {
|
|
|
314
273
|
expect(res.type).toBe('CallExpression');
|
|
315
274
|
expect(res.callee.name).toBe('cg');
|
|
316
275
|
const code = (0, generator_1.default)(res).code;
|
|
317
|
-
expect(code).toBe('cg(i3, {\n componentId: "c-lookup-field-row",\n props:
|
|
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)');
|
|
318
277
|
});
|
|
319
278
|
it('properly composed composedAdg with children', () => {
|
|
320
279
|
const res = (0, compositionAstGeneration_1.composedAdgToExpression)(moduleMetadata, complexDoc.compositions[0].compositions[0]);
|
|
321
280
|
expect(res.type).toBe('CallExpression');
|
|
322
281
|
expect(res.callee.name).toBe('cg');
|
|
323
282
|
const code = (0, generator_1.default)(res).code;
|
|
324
|
-
expect(code).toBe(
|
|
325
|
-
componentId: "lightning-card",
|
|
326
|
-
props: ctx => ({})
|
|
327
|
-
}, ctx, [cg(i1, {
|
|
328
|
-
slot: "title",
|
|
329
|
-
componentId: "c-title",
|
|
330
|
-
props: ctx => ({
|
|
331
|
-
icon: "standard:account",
|
|
332
|
-
size: "large"
|
|
333
|
-
})
|
|
334
|
-
}, ctx, [], []), c(ctx, {
|
|
335
|
-
c: {
|
|
336
|
-
t: "b",
|
|
337
|
-
v: "record.data"
|
|
338
|
-
},
|
|
339
|
-
slot: ""
|
|
340
|
-
}, ctx => [cg(i2, {
|
|
341
|
-
componentId: "c-fieldrow",
|
|
342
|
-
props: ctx => ({
|
|
343
|
-
label: "Object Type",
|
|
344
|
-
value: ctx.props.objectApiName
|
|
345
|
-
})
|
|
346
|
-
}, ctx, [], ["objectApiName"]), cg(i2, {
|
|
347
|
-
componentId: "c-fieldrow",
|
|
348
|
-
props: ctx => ({
|
|
349
|
-
label: "Account Id",
|
|
350
|
-
value: ctx.props.record?.data?.fields?.Id?.value
|
|
351
|
-
})
|
|
352
|
-
}, ctx, [], ["record"]), cg(i2, {
|
|
353
|
-
componentId: "c-fieldrow",
|
|
354
|
-
props: ctx => ({
|
|
355
|
-
label: "Account Name",
|
|
356
|
-
value: ctx.props.record?.data?.fields?.Name?.value
|
|
357
|
-
})
|
|
358
|
-
}, ctx, [], ["record"]), c(ctx, {
|
|
359
|
-
c: {
|
|
360
|
-
t: "b",
|
|
361
|
-
v: "ownerRecord.data"
|
|
362
|
-
}
|
|
363
|
-
}, ctx => cg(i2, {
|
|
364
|
-
componentId: "c-fieldrow",
|
|
365
|
-
props: ctx => ({
|
|
366
|
-
label: "Account Owner",
|
|
367
|
-
value: ctx.props.ownerRecord?.data?.fields?.Name?.value
|
|
368
|
-
})
|
|
369
|
-
}, ctx, [], ["ownerRecord"]), false), c(ctx, {
|
|
370
|
-
c: {
|
|
371
|
-
t: "b",
|
|
372
|
-
v: "createdByRecord.data"
|
|
373
|
-
}
|
|
374
|
-
}, ctx => cg(i2, {
|
|
375
|
-
componentId: "c-fieldrow",
|
|
376
|
-
props: ctx => ({
|
|
377
|
-
label: "Created By",
|
|
378
|
-
value: ctx.props.createdByRecord?.data?.fields?.Name?.value
|
|
379
|
-
})
|
|
380
|
-
}, ctx, [], ["createdByRecord"]), false)], false)], [])`);
|
|
381
|
-
});
|
|
382
|
-
it('properly generated dependentProps', () => {
|
|
383
|
-
const res = (0, compositionAstGeneration_1.composedAdgToExpression)(moduleMetadata, {
|
|
384
|
-
type: 'ComposedAdg',
|
|
385
|
-
input: {
|
|
386
|
-
type: 'ImportReference',
|
|
387
|
-
value: 't0-0/names/0',
|
|
388
|
-
},
|
|
389
|
-
properties: {
|
|
390
|
-
attr1: {
|
|
391
|
-
type: 'Binding',
|
|
392
|
-
value: 'recordId',
|
|
393
|
-
},
|
|
394
|
-
attr2: {
|
|
395
|
-
type: 'Binding',
|
|
396
|
-
value: 'recordId',
|
|
397
|
-
},
|
|
398
|
-
attr3: {
|
|
399
|
-
type: 'Binding',
|
|
400
|
-
value: 'record',
|
|
401
|
-
},
|
|
402
|
-
attr4: {
|
|
403
|
-
type: 'Binding',
|
|
404
|
-
value: 'record/data/Name',
|
|
405
|
-
},
|
|
406
|
-
},
|
|
407
|
-
});
|
|
408
|
-
expect(res.type).toBe('CallExpression');
|
|
409
|
-
expect(res.callee.name).toBe('cg');
|
|
410
|
-
const code = (0, generator_1.default)(res).code;
|
|
411
|
-
expect(code).toBe(`cg(i0, {
|
|
412
|
-
componentId: "lightning-card",
|
|
413
|
-
props: ctx => ({
|
|
414
|
-
attr1: ctx.props.recordId,
|
|
415
|
-
attr2: ctx.props.recordId,
|
|
416
|
-
attr3: ctx.props.record,
|
|
417
|
-
attr4: ctx.props.record?.data?.Name
|
|
418
|
-
})
|
|
419
|
-
}, ctx, [], ["recordId", "record"])`);
|
|
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])');
|
|
420
284
|
});
|
|
421
285
|
});
|
|
422
286
|
describe('iterationToExpression', () => {
|
|
@@ -457,92 +321,7 @@ describe('iterationToExpression', () => {
|
|
|
457
321
|
expect(res.type).toBe('CallExpression');
|
|
458
322
|
expect(res.callee.name).toBe('i');
|
|
459
323
|
const code = (0, generator_1.default)(res).code;
|
|
460
|
-
expect(code).toBe(
|
|
461
|
-
c: {
|
|
462
|
-
t: "b",
|
|
463
|
-
v: "contacts"
|
|
464
|
-
}
|
|
465
|
-
}, ctx, user_var_contact => {
|
|
466
|
-
return [cg(i0, {
|
|
467
|
-
componentId: "lightning-card",
|
|
468
|
-
props: ctx => ({
|
|
469
|
-
label: user_var_contact.value?.Name,
|
|
470
|
-
myIndex: user_var_contact.index
|
|
471
|
-
})
|
|
472
|
-
}, ctx, [], [])];
|
|
473
|
-
})`);
|
|
474
|
-
});
|
|
475
|
-
it('can compose an iteration factory call from a two nested iterator composition', () => {
|
|
476
|
-
const res = (0, compositionAstGeneration_1.iterationToExpression)(moduleMetadata, {
|
|
477
|
-
type: 'Iteration',
|
|
478
|
-
input: {
|
|
479
|
-
type: 'Binding',
|
|
480
|
-
value: 'contacts',
|
|
481
|
-
},
|
|
482
|
-
iterator: 'contact',
|
|
483
|
-
compositions: [
|
|
484
|
-
{
|
|
485
|
-
type: 'Iteration',
|
|
486
|
-
input: {
|
|
487
|
-
type: 'Binding',
|
|
488
|
-
value: 'actions',
|
|
489
|
-
},
|
|
490
|
-
iterator: 'action',
|
|
491
|
-
compositions: [
|
|
492
|
-
{
|
|
493
|
-
type: 'ComposedAdg',
|
|
494
|
-
input: {
|
|
495
|
-
type: 'ImportReference',
|
|
496
|
-
value: 't0-0/names/0',
|
|
497
|
-
},
|
|
498
|
-
properties: {
|
|
499
|
-
label: {
|
|
500
|
-
type: 'Binding',
|
|
501
|
-
value: 'contact/value/Name',
|
|
502
|
-
},
|
|
503
|
-
myIndex: {
|
|
504
|
-
type: 'Binding',
|
|
505
|
-
value: 'contact/index',
|
|
506
|
-
},
|
|
507
|
-
actionName: {
|
|
508
|
-
type: 'Binding',
|
|
509
|
-
value: 'action/name',
|
|
510
|
-
},
|
|
511
|
-
},
|
|
512
|
-
key: {
|
|
513
|
-
type: 'Binding',
|
|
514
|
-
value: 'contact/value/Id',
|
|
515
|
-
},
|
|
516
|
-
},
|
|
517
|
-
],
|
|
518
|
-
},
|
|
519
|
-
],
|
|
520
|
-
});
|
|
521
|
-
expect(res.type).toBe('CallExpression');
|
|
522
|
-
expect(res.callee.name).toBe('i');
|
|
523
|
-
const code = (0, generator_1.default)(res).code;
|
|
524
|
-
expect(code).toBe(`i({
|
|
525
|
-
c: {
|
|
526
|
-
t: "b",
|
|
527
|
-
v: "contacts"
|
|
528
|
-
}
|
|
529
|
-
}, ctx, user_var_contact => {
|
|
530
|
-
return [i({
|
|
531
|
-
c: {
|
|
532
|
-
t: "b",
|
|
533
|
-
v: "actions"
|
|
534
|
-
}
|
|
535
|
-
}, ctx, user_var_action => {
|
|
536
|
-
return [cg(i0, {
|
|
537
|
-
componentId: "lightning-card",
|
|
538
|
-
props: ctx => ({
|
|
539
|
-
actionName: user_var_action.name,
|
|
540
|
-
label: user_var_contact.value?.Name,
|
|
541
|
-
myIndex: user_var_contact.index
|
|
542
|
-
})
|
|
543
|
-
}, ctx, [], [])];
|
|
544
|
-
})];
|
|
545
|
-
})`);
|
|
324
|
+
expect(code).toBe('i(ctx.props.contacts, ctx, user_var_contact => {\n return [cg(i0, {\n componentId: "lightning-card",\n props: {\n label: user_var_contact.value?.Name,\n myIndex: user_var_contact.index\n }\n }, ctx)];\n})');
|
|
546
325
|
});
|
|
547
326
|
});
|
|
548
327
|
describe('slotToExpression', () => {
|
|
@@ -593,7 +372,7 @@ describe('getCompositionConfig', () => {
|
|
|
593
372
|
it('collects composition config for a composedAdg', () => {
|
|
594
373
|
const res = (0, compositionAstGeneration_1.getCompositionConfig)(complexDoc.compositions[0].compositions[2].compositions[0]);
|
|
595
374
|
const code = (0, generator_1.default)(res).code;
|
|
596
|
-
expect(code).toBe('{\n slot: "title",\n props:
|
|
375
|
+
expect(code).toBe('{\n slot: "title",\n props: {\n icon: "standard:apex",\n size: "medium"\n }\n}');
|
|
597
376
|
});
|
|
598
377
|
it('generates duplicate composition configs for similar composedAdgs', () => {
|
|
599
378
|
const res = (0, compositionAstGeneration_1.getCompositionConfig)(complexDoc.compositions[0].compositions[2].compositions[0]);
|
|
@@ -618,7 +397,7 @@ describe('getCompositionConfig', () => {
|
|
|
618
397
|
});
|
|
619
398
|
const swappedCode = (0, generator_1.default)(swapRes).code;
|
|
620
399
|
const code = (0, generator_1.default)(res).code;
|
|
621
|
-
const expected = '{\n slot: "title",\n props:
|
|
400
|
+
const expected = '{\n slot: "title",\n props: {\n icon: "standard:apex",\n size: "medium"\n }\n}';
|
|
622
401
|
expect(code).toBe(expected);
|
|
623
402
|
expect(swappedCode).toBe(expected);
|
|
624
403
|
});
|
|
@@ -666,11 +445,14 @@ describe('getCompositionConfig', () => {
|
|
|
666
445
|
},
|
|
667
446
|
},
|
|
668
447
|
});
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
expect(
|
|
672
|
-
|
|
673
|
-
expect(
|
|
448
|
+
expect(res.properties[0].value
|
|
449
|
+
.properties[0].key.type).toBe('Identifier');
|
|
450
|
+
expect(res.properties[0].value
|
|
451
|
+
.properties[1].key.type).toBe('StringLiteral');
|
|
452
|
+
expect(res.properties[0].value
|
|
453
|
+
.properties[2].key.type).toBe('Identifier');
|
|
454
|
+
expect(res.properties[0].value
|
|
455
|
+
.properties[3].key.type).toBe('StringLiteral');
|
|
674
456
|
});
|
|
675
457
|
});
|
|
676
458
|
//# sourceMappingURL=compositionAstGeneration.spec.js.map
|
|
@@ -571,15 +571,4 @@ describe('composeStaticMetadataAssignmentExpression', () => {
|
|
|
571
571
|
expect(right.name).toBe('Adg0Meta');
|
|
572
572
|
});
|
|
573
573
|
});
|
|
574
|
-
describe('composeSelfServiceAssignmentExpression', () => {
|
|
575
|
-
it('returns proper expression statement', () => {
|
|
576
|
-
const expr = (0, functionAstGeneration_1.composeSelfServiceAssignmentExpression)('adg0')
|
|
577
|
-
.expression;
|
|
578
|
-
const left = expr.left;
|
|
579
|
-
expect(left.object.name).toBe('adg0');
|
|
580
|
-
expect(left.property.name).toBe('self');
|
|
581
|
-
const right = expr.right;
|
|
582
|
-
expect(right.value).toBeTruthy();
|
|
583
|
-
});
|
|
584
|
-
});
|
|
585
574
|
//# sourceMappingURL=functionAstGeneration.spec.js.map
|
|
@@ -922,48 +922,4 @@ describe('collectMetadataForImportedTemplates', () => {
|
|
|
922
922
|
expect(moduleMetadata.adgs.get(1)?.properties.size).toBe(2);
|
|
923
923
|
});
|
|
924
924
|
});
|
|
925
|
-
describe('valueReferenceToExpression', () => {
|
|
926
|
-
it('properly references the property that we want to refernce as a string', () => {
|
|
927
|
-
const obj = (0, genericAstGeneration_1.valueReferenceToExpression)((0, common_shared_1.initModuleMetadataObject)(), {
|
|
928
|
-
type: 'Binding',
|
|
929
|
-
value: 'record/sub/path',
|
|
930
|
-
});
|
|
931
|
-
expect(obj.properties[0].key.name).toBe('t');
|
|
932
|
-
expect(obj.properties[0].value.value).toBe('b');
|
|
933
|
-
expect(obj.properties[1].key.name).toBe('v');
|
|
934
|
-
expect(obj.properties[1].value.value).toBe('record.sub.path');
|
|
935
|
-
});
|
|
936
|
-
it('properly references a binding in an iteration context by value', () => {
|
|
937
|
-
const obj = (0, genericAstGeneration_1.valueReferenceToExpression)((0, common_shared_1.initModuleMetadataObject)(), {
|
|
938
|
-
type: 'Binding',
|
|
939
|
-
value: 'item/val',
|
|
940
|
-
}, ['item']);
|
|
941
|
-
expect(obj.properties[0].key.name).toBe('t');
|
|
942
|
-
expect(obj.properties[0].value.value).toBe('s');
|
|
943
|
-
expect(obj.properties[1].key.name).toBe('v');
|
|
944
|
-
expect(obj.properties[1]
|
|
945
|
-
.value.object.name).toBe('user_var_item');
|
|
946
|
-
expect(obj.properties[1]
|
|
947
|
-
.value.property.name).toBe('val');
|
|
948
|
-
});
|
|
949
|
-
it('handles whatever this weird typing edge case is where value is undefined', () => {
|
|
950
|
-
const obj = (0, genericAstGeneration_1.valueReferenceToExpression)((0, common_shared_1.initModuleMetadataObject)(), {
|
|
951
|
-
type: 'PrimitiveValue',
|
|
952
|
-
});
|
|
953
|
-
expect(obj.properties[0].key.name).toBe('t');
|
|
954
|
-
expect(obj.properties[0].value.value).toBe('s');
|
|
955
|
-
expect(obj.properties[1].key.name).toBe('v');
|
|
956
|
-
expect(obj.properties[1].value.name).toBe('undefined');
|
|
957
|
-
});
|
|
958
|
-
it('properly references a static value', () => {
|
|
959
|
-
const obj = (0, genericAstGeneration_1.valueReferenceToExpression)((0, common_shared_1.initModuleMetadataObject)(), {
|
|
960
|
-
type: 'PrimitiveValue',
|
|
961
|
-
value: 'reference',
|
|
962
|
-
});
|
|
963
|
-
expect(obj.properties[0].key.name).toBe('t');
|
|
964
|
-
expect(obj.properties[0].value.value).toBe('s');
|
|
965
|
-
expect(obj.properties[1].key.name).toBe('v');
|
|
966
|
-
expect(obj.properties[1].value.value).toBe('reference');
|
|
967
|
-
});
|
|
968
|
-
});
|
|
969
925
|
//# sourceMappingURL=genericAstGeneration.spec.js.map
|
|
@@ -38,7 +38,7 @@ function generateModuleSource(komaciHTMLDoc, komaciJSDoc, srcFileMap) {
|
|
|
38
38
|
// eslint-disable-next-line jest/no-disabled-tests
|
|
39
39
|
describe('fixtures', () => {
|
|
40
40
|
// find all folder paths containing a file whose name ends in ".src"
|
|
41
|
-
const fixtures = glob_1.default.sync(path_1.default.resolve(FIXTURES_DIR, '**/*.
|
|
41
|
+
const fixtures = glob_1.default.sync(path_1.default.resolve(FIXTURES_DIR, '**/*.src'));
|
|
42
42
|
for (const caseEntry of fixtures) {
|
|
43
43
|
const caseFolder = path_1.default.dirname(caseEntry);
|
|
44
44
|
const caseName = path_1.default.relative(FIXTURES_DIR, caseFolder);
|
|
@@ -63,15 +63,14 @@ export declare function slotToExpression(moduleMetadata: ModuleMetadata, slot: S
|
|
|
63
63
|
* @param {string[]} iterationContext if this is being called from inside an iteration we need that prepend context for bindingToExpression
|
|
64
64
|
* @returns {Expression} the babel Expression representing the Image prompt into the Resolver API
|
|
65
65
|
*/
|
|
66
|
-
export declare function imageToExpression(
|
|
66
|
+
export declare function imageToExpression(image: Image, iterationContext?: string[]): t.Expression;
|
|
67
67
|
/**
|
|
68
68
|
* Creates a babel configuration ObjectExpression for provided composition. This is the `CompositionConfig`
|
|
69
69
|
* from Resolver API in its babel ObjectExpression form.
|
|
70
70
|
* @param {ComposedAdg | Container | Slot} composition the Composition from which to create a configuration (as a ComposedAdg, Container, or Slot)
|
|
71
71
|
* @param {string} componentId the component indentifier, as a string
|
|
72
72
|
* @param {string[]} iterationContext if this is being called from inside an iteration we need that prepend context for bindingToExpression
|
|
73
|
-
* @param {t.Expression[]} dependentProps list of properties which are dependencies of this composition
|
|
74
73
|
* @returns {ObjectExpression} the babel ObjectExpression representing the Resolver API CompositionConfig
|
|
75
74
|
*/
|
|
76
|
-
export declare function getCompositionConfig(composition: ComposedAdg | Container | Slot
|
|
75
|
+
export declare function getCompositionConfig(composition: ComposedAdg | Container | Slot, componentId?: string, iterationContext?: string[]): t.ObjectExpression;
|
|
77
76
|
//# sourceMappingURL=compositionAstGeneration.d.ts.map
|
|
@@ -91,26 +91,20 @@ function compositionToExpression(moduleMetadata, composition, iterationContext)
|
|
|
91
91
|
expression = slotToExpression(moduleMetadata, composition, iterationContext);
|
|
92
92
|
break;
|
|
93
93
|
case 'Image':
|
|
94
|
-
expression = imageToExpression(
|
|
94
|
+
expression = imageToExpression(composition, iterationContext);
|
|
95
95
|
break;
|
|
96
96
|
}
|
|
97
97
|
// If the composition has an isActive condition, then
|
|
98
98
|
// expression needs to be proceded by a conditional check.
|
|
99
99
|
if (composition.isActive) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const container = composition;
|
|
104
|
-
if (container.slot !== undefined) {
|
|
105
|
-
props.push(t.objectProperty(t.identifier('slot'), t.stringLiteral(container.slot)));
|
|
100
|
+
let conditionalTest = (0, genericAstGeneration_1.bindingToExpression)(composition.isActive.input, iterationContext);
|
|
101
|
+
if (composition.isActive.negate) {
|
|
102
|
+
conditionalTest = t.unaryExpression('!', conditionalTest);
|
|
106
103
|
}
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
compositionFunc,
|
|
112
|
-
t.booleanLiteral(composition.isActive.negate || false),
|
|
113
|
-
]);
|
|
104
|
+
const prop = (0, genericAstGeneration_1.bindingToExpression)(composition.isActive.input, iterationContext, true);
|
|
105
|
+
const unresolvedTest = t.callExpression(types_1.ID.UNRESOLVED_FUNC, [prop]);
|
|
106
|
+
const test = t.logicalExpression('||', unresolvedTest, conditionalTest);
|
|
107
|
+
expression = t.conditionalExpression(test, expression, types_1.ID.UNDEFINED);
|
|
114
108
|
}
|
|
115
109
|
return expression;
|
|
116
110
|
}
|
|
@@ -127,7 +121,7 @@ function containerToExpression(moduleMetadata, container, iterationContext) {
|
|
|
127
121
|
const children = compositionsToArrayExpression(moduleMetadata, container.compositions, iterationContext) || t.arrayExpression([]);
|
|
128
122
|
// If key or slot is specified, then the container will need to be
|
|
129
123
|
// accounted for in the module via the element function.
|
|
130
|
-
if (container.key ||
|
|
124
|
+
if (container.key || container.slot) {
|
|
131
125
|
const params = [];
|
|
132
126
|
// arg1: Composition configuration.
|
|
133
127
|
params.push(getCompositionConfig(container, undefined, iterationContext));
|
|
@@ -173,9 +167,7 @@ function composedAdgToExpression(moduleMetadata, composedAdg, iterationContext)
|
|
|
173
167
|
throw new Error(common_shared_1.ERROR_PREFIX + 'binding not yet supported for ComposedAdg input');
|
|
174
168
|
}
|
|
175
169
|
// arg2: Composition configuration.
|
|
176
|
-
|
|
177
|
-
const config = getCompositionConfig(composedAdg, componentId, iterationContext, dependentProps);
|
|
178
|
-
params.push(config);
|
|
170
|
+
params.push(getCompositionConfig(composedAdg, componentId, iterationContext));
|
|
179
171
|
// arg3: Context.
|
|
180
172
|
params.push(types_1.ID.CONTEXT);
|
|
181
173
|
// arg4: Array of expressions for each child.
|
|
@@ -183,12 +175,6 @@ function composedAdgToExpression(moduleMetadata, composedAdg, iterationContext)
|
|
|
183
175
|
if (children && children.elements.length) {
|
|
184
176
|
params.push(children);
|
|
185
177
|
}
|
|
186
|
-
else {
|
|
187
|
-
params.push(t.arrayExpression());
|
|
188
|
-
}
|
|
189
|
-
// arg5: Array of dependent properties
|
|
190
|
-
const expArray = [...dependentProps].map((ele) => t.stringLiteral(ele));
|
|
191
|
-
params.push(t.arrayExpression(expArray));
|
|
192
178
|
return t.callExpression(types_1.ID.COMPOSED_GRAPH_FUNC, params);
|
|
193
179
|
}
|
|
194
180
|
exports.composedAdgToExpression = composedAdgToExpression;
|
|
@@ -202,13 +188,7 @@ exports.composedAdgToExpression = composedAdgToExpression;
|
|
|
202
188
|
function iterationToExpression(moduleMetadata, iteration, iterationContext = []) {
|
|
203
189
|
const params = [];
|
|
204
190
|
// arg1: Expression for the collection being iterated.
|
|
205
|
-
|
|
206
|
-
t.objectProperty(t.identifier('c'), (0, genericAstGeneration_1.valueReferenceToExpression)(moduleMetadata, iteration.input, iterationContext)),
|
|
207
|
-
];
|
|
208
|
-
if (iteration.slot !== undefined) {
|
|
209
|
-
props.push(t.objectProperty(t.identifier('slot'), t.stringLiteral(iteration.slot)));
|
|
210
|
-
}
|
|
211
|
-
params.push(t.objectExpression(props));
|
|
191
|
+
params.push((0, genericAstGeneration_1.bindingToExpression)(iteration.input, iterationContext));
|
|
212
192
|
// arg2: Context.
|
|
213
193
|
params.push(types_1.ID.CONTEXT);
|
|
214
194
|
// arg3: Function to return compositions inside the the iteration.
|
|
@@ -253,15 +233,33 @@ exports.slotToExpression = slotToExpression;
|
|
|
253
233
|
* @param {string[]} iterationContext if this is being called from inside an iteration we need that prepend context for bindingToExpression
|
|
254
234
|
* @returns {Expression} the babel Expression representing the Image prompt into the Resolver API
|
|
255
235
|
*/
|
|
256
|
-
function imageToExpression(
|
|
236
|
+
function imageToExpression(image, iterationContext) {
|
|
257
237
|
const params = [];
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
238
|
+
const funcObjProps = [];
|
|
239
|
+
if ((0, common_shared_1.isCompositionAnImage)(image)) {
|
|
240
|
+
if ((0, common_shared_1.isSrcPrimitiveValue)(image.src)) {
|
|
241
|
+
// type guard ensures `image.src` is a PrimitiveValue
|
|
242
|
+
// lwc-platform will NOT produce an Image KomaciNode with a blank or missing src attribute.
|
|
243
|
+
// However, just in case we do encounter this, we handle it here by simply NOT producing the
|
|
244
|
+
// function ObjectProperty for such a node.
|
|
245
|
+
if (image.src.value &&
|
|
246
|
+
typeof image.src.value === 'string' &&
|
|
247
|
+
image.src.value !== '') {
|
|
248
|
+
funcObjProps.push(t.objectProperty(types_1.ID.IMG_SRC, t.stringLiteral(image.src.value)));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
else if ((0, common_shared_1.isSrcABinding)(image.src)) {
|
|
252
|
+
// type guard ensures `image.src` is a Binding
|
|
253
|
+
// lwc-platform will NOT produce an Image KomaciNode with a blank or missing src attribute.
|
|
254
|
+
// However, just in case we do encounter this, we handle it here by simply NOT producing the
|
|
255
|
+
// function ObjectProperty for such a node.
|
|
256
|
+
if (image.src.value !== '') {
|
|
257
|
+
funcObjProps.push(t.objectProperty(types_1.ID.IMG_SRC, (0, genericAstGeneration_1.bindingToExpression)(image.src, iterationContext)));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
263
260
|
}
|
|
264
|
-
|
|
261
|
+
params.push(t.objectExpression(funcObjProps));
|
|
262
|
+
return t.callExpression(types_1.ID.IMG_FUNC, params);
|
|
265
263
|
}
|
|
266
264
|
exports.imageToExpression = imageToExpression;
|
|
267
265
|
/**
|
|
@@ -270,12 +268,11 @@ exports.imageToExpression = imageToExpression;
|
|
|
270
268
|
* @param {ComposedAdg | Container | Slot} composition the Composition from which to create a configuration (as a ComposedAdg, Container, or Slot)
|
|
271
269
|
* @param {string} componentId the component indentifier, as a string
|
|
272
270
|
* @param {string[]} iterationContext if this is being called from inside an iteration we need that prepend context for bindingToExpression
|
|
273
|
-
* @param {t.Expression[]} dependentProps list of properties which are dependencies of this composition
|
|
274
271
|
* @returns {ObjectExpression} the babel ObjectExpression representing the Resolver API CompositionConfig
|
|
275
272
|
*/
|
|
276
|
-
function getCompositionConfig(composition, componentId, iterationContext
|
|
273
|
+
function getCompositionConfig(composition, componentId, iterationContext) {
|
|
277
274
|
const config = [];
|
|
278
|
-
if (composition.slot
|
|
275
|
+
if (composition.slot) {
|
|
279
276
|
config.push(t.objectProperty(types_1.ID.SLOT, t.stringLiteral(composition.slot)));
|
|
280
277
|
}
|
|
281
278
|
// ComposedAdg config contains additional information.
|
|
@@ -292,11 +289,6 @@ function getCompositionConfig(composition, componentId, iterationContext, depend
|
|
|
292
289
|
props.push(t.objectProperty(hasSpecialCharacters.test(propName)
|
|
293
290
|
? t.stringLiteral(propName)
|
|
294
291
|
: t.identifier(propName), (0, genericAstGeneration_1.bindingToExpression)(prop, iterationContext)));
|
|
295
|
-
const propValue = prop.value.split('/')[0];
|
|
296
|
-
// exclude iteration bindings from dependent prop list
|
|
297
|
-
if (!iterationContext?.includes(propValue)) {
|
|
298
|
-
dependentProps?.add(propValue);
|
|
299
|
-
}
|
|
300
292
|
}
|
|
301
293
|
else if (prop.type === 'PrimitiveValue') {
|
|
302
294
|
props.push(t.objectProperty(hasSpecialCharacters.test(propName)
|
|
@@ -304,7 +296,7 @@ function getCompositionConfig(composition, componentId, iterationContext, depend
|
|
|
304
296
|
: t.identifier(propName), (0, genericAstGeneration_1.primitiveToExpression)(prop)));
|
|
305
297
|
}
|
|
306
298
|
}
|
|
307
|
-
config.push(t.objectProperty(types_1.ID.PROPS, t.
|
|
299
|
+
config.push(t.objectProperty(types_1.ID.PROPS, t.objectExpression(props)));
|
|
308
300
|
}
|
|
309
301
|
}
|
|
310
302
|
return t.objectExpression(config);
|
|
@@ -92,11 +92,4 @@ export declare function produceErrorAdgFunction(moduleMetadata: ModuleMetadata,
|
|
|
92
92
|
* @returns an expression statement, eg: adg0.meta = adg0meta
|
|
93
93
|
*/
|
|
94
94
|
export declare function composeStaticMetadataAssignmentExpression(adgName: string, staticMetadataObject: t.VariableDeclaration): t.ExpressionStatement;
|
|
95
|
-
/**
|
|
96
|
-
* Helper function to set self service as true. This way we can indicate at the resolver level what resolution
|
|
97
|
-
* flow to use
|
|
98
|
-
* @param adgName the name of the adg function to associate the adgMeta object with.
|
|
99
|
-
* @returns an expression statement, eg: adg0.self = true
|
|
100
|
-
*/
|
|
101
|
-
export declare function composeSelfServiceAssignmentExpression(adgName: string): t.ExpressionStatement;
|
|
102
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.
|
|
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");
|
|
@@ -307,17 +307,15 @@ function collectChildrenStaticMetadata(rootComposition, moduleMetadata) {
|
|
|
307
307
|
const childrenArray = [];
|
|
308
308
|
let imgFound = false;
|
|
309
309
|
if (rootComposition) {
|
|
310
|
-
(0, common_shared_1.traverseComposition)(rootComposition, {
|
|
311
|
-
|
|
312
|
-
if (comp.type == '
|
|
313
|
-
|
|
314
|
-
imgFound = true;
|
|
315
|
-
}
|
|
316
|
-
const childProp = generateComposisitonMetadata(comp, moduleMetadata);
|
|
317
|
-
childrenArray.push(childProp);
|
|
310
|
+
(0, common_shared_1.traverseComposition)(rootComposition, (comp) => {
|
|
311
|
+
if (comp.type == 'ComposedAdg' || comp.type == 'Image') {
|
|
312
|
+
if (comp.type == 'Image') {
|
|
313
|
+
imgFound = true;
|
|
318
314
|
}
|
|
319
|
-
|
|
320
|
-
|
|
315
|
+
const childProp = generateComposisitonMetadata(comp, moduleMetadata);
|
|
316
|
+
childrenArray.push(childProp);
|
|
317
|
+
}
|
|
318
|
+
return false;
|
|
321
319
|
});
|
|
322
320
|
}
|
|
323
321
|
return { childrenArray, imgFound };
|
|
@@ -436,17 +434,13 @@ function getInlineFunctionFromTemplateCompositions(moduleMetadata, requiredFacto
|
|
|
436
434
|
const statements = [];
|
|
437
435
|
const body = t.blockStatement(statements);
|
|
438
436
|
const emptyCompositionsArray = compositions.length < 1;
|
|
439
|
-
if (moduleMetadata.
|
|
437
|
+
if (moduleMetadata.hasRenderFunction && adgMetadata.exportName == 'default') {
|
|
440
438
|
// function body destructured factory object. e.g. `const { cg } = fct;`
|
|
441
439
|
const fctFuncs = getFactoryFuncDeclaration(requiredFactoryFunctions); // passing in false because we are not processing the script file in this method
|
|
442
440
|
if (fctFuncs) {
|
|
443
441
|
statements.push(fctFuncs);
|
|
444
442
|
}
|
|
445
|
-
const rtFuncParams = [
|
|
446
|
-
types_1.ID.HOISTED_RENDER_FUNC_ID,
|
|
447
|
-
types_1.ID.CONTEXT,
|
|
448
|
-
t.arrayExpression(moduleMetadata.renderFunction.requiredProperties.map((prop) => t.stringLiteral(prop))),
|
|
449
|
-
];
|
|
443
|
+
const rtFuncParams = [types_1.ID.HOISTED_RENDER_FUNC_ID, types_1.ID.CONTEXT];
|
|
450
444
|
// rf(hoistedRenderFunction, CTX)
|
|
451
445
|
const rtFunc = t.callExpression(types_1.ID.RENDER_FUNC, rtFuncParams);
|
|
452
446
|
//creating the return statement
|
|
@@ -533,14 +527,4 @@ function composeStaticMetadataAssignmentExpression(adgName, staticMetadataObject
|
|
|
533
527
|
.id.name)));
|
|
534
528
|
}
|
|
535
529
|
exports.composeStaticMetadataAssignmentExpression = composeStaticMetadataAssignmentExpression;
|
|
536
|
-
/**
|
|
537
|
-
* Helper function to set self service as true. This way we can indicate at the resolver level what resolution
|
|
538
|
-
* flow to use
|
|
539
|
-
* @param adgName the name of the adg function to associate the adgMeta object with.
|
|
540
|
-
* @returns an expression statement, eg: adg0.self = true
|
|
541
|
-
*/
|
|
542
|
-
function composeSelfServiceAssignmentExpression(adgName) {
|
|
543
|
-
return t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier(adgName), t.identifier('self')), t.booleanLiteral(true)));
|
|
544
|
-
}
|
|
545
|
-
exports.composeSelfServiceAssignmentExpression = composeSelfServiceAssignmentExpression;
|
|
546
530
|
//# sourceMappingURL=functionAstGeneration.js.map
|
|
@@ -72,22 +72,6 @@ export declare function primitiveToExpression(primitive: PrimitiveValue): t.Expr
|
|
|
72
72
|
* @returns A composed member expression
|
|
73
73
|
*/
|
|
74
74
|
export declare function bindingToExpression(binding: Binding | PropertyReference, iterationContext?: string[], parseRootOnly?: boolean): t.Identifier | t.OptionalMemberExpression;
|
|
75
|
-
/**
|
|
76
|
-
* compose a object that references a value for use in iteration and conditional factory functions.
|
|
77
|
-
* for times when we are operating inside of an iteration context, we want to leverage bindings so we can
|
|
78
|
-
* straight up hoist the iteration value. in every other use case we will be either a property reference or static value
|
|
79
|
-
*
|
|
80
|
-
* - t represent "type"
|
|
81
|
-
* - t could be either `b` (binding) or `s` (static value)
|
|
82
|
-
* - v represents "value"
|
|
83
|
-
* - maps to the value whatever that may be.
|
|
84
|
-
*
|
|
85
|
-
* @param moduleMetadata metadata about the module we are composing
|
|
86
|
-
* @param ref the value that needs to be referenced by this prop
|
|
87
|
-
* @param iterationContext if this value is based on some iteration
|
|
88
|
-
* @returns an object of the form { t: 'b' | 's', v: 'some value or prop ref' }
|
|
89
|
-
*/
|
|
90
|
-
export declare function valueReferenceToExpression(moduleMetadata: ModuleMetadata, ref: Binding | Value, iterationContext?: string[]): t.ObjectExpression;
|
|
91
75
|
/**
|
|
92
76
|
* Convert a single Komaci function to an object expression in the shape of a
|
|
93
77
|
* FunctionDefinition as defined in Resolver API.
|
|
@@ -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.collectMetadataForImportedTemplates = exports.exportNamedDeclarationForDynamicImport = exports.addUndefinedDefaultExport = exports.propertyToExpression = exports.functionToExpression = exports.
|
|
26
|
+
exports.collectMetadataForImportedTemplates = exports.exportNamedDeclarationForDynamicImport = exports.addUndefinedDefaultExport = exports.propertyToExpression = exports.functionToExpression = exports.bindingToExpression = exports.primitiveToExpression = exports.valueToExpression = exports.processWireFunctionType = exports.processErrorFunction = exports.addImportStatements = exports.generateResolvableModule = void 0;
|
|
27
27
|
const common_shared_1 = require("@komaci/common-shared");
|
|
28
28
|
const static_analyzer_1 = require("@komaci/static-analyzer");
|
|
29
29
|
const t = __importStar(require("@babel/types"));
|
|
@@ -95,7 +95,7 @@ function generateResolvableModule(input, scriptKomaciDoc, templateKomaciDocMap,
|
|
|
95
95
|
if (renderFunction) {
|
|
96
96
|
renderFunctionMetadata = (0, componentAstProcessing_1.processRenderFunction)(componentDefaultAdgIndex, moduleContext, moduleMetadata, renderFunction);
|
|
97
97
|
if (renderFunctionMetadata) {
|
|
98
|
-
moduleMetadata.
|
|
98
|
+
moduleMetadata.hasRenderFunction = true;
|
|
99
99
|
moduleMetadata.adgs
|
|
100
100
|
.get(componentDefaultAdgIndex)
|
|
101
101
|
?.requiredCompositionFactoryFunctions.add(common_shared_1.IdKeys.RENDER_FUNC);
|
|
@@ -104,7 +104,7 @@ function generateResolvableModule(input, scriptKomaciDoc, templateKomaciDocMap,
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
//has a default html file but no render funciton ***
|
|
107
|
-
if (hasTemplateKomaciDoc && !moduleMetadata.
|
|
107
|
+
if (hasTemplateKomaciDoc && !moduleMetadata.hasRenderFunction) {
|
|
108
108
|
componentDefaultAdgIndex = (0, common_shared_1.reconcileDefaultAdg)(componentDefaultAdgIndex, moduleMetadata);
|
|
109
109
|
if (componentDefaultAdgIndex !== undefined) {
|
|
110
110
|
(0, common_shared_1.initializeImportMetdataFromKomaciDocument)(defaultTemplateKomaciDoc, moduleMetadata, componentDefaultAdgIndex);
|
|
@@ -125,7 +125,7 @@ function generateResolvableModule(input, scriptKomaciDoc, templateKomaciDocMap,
|
|
|
125
125
|
}
|
|
126
126
|
//as long as we have at least one template and theres a valid render function, check to see if its imported. In the case the default html doc is imported, the assocated adg refernce will be set.
|
|
127
127
|
if (Object.keys(moduleMetadata.templateKomaciDocMap).length > 0 &&
|
|
128
|
-
moduleMetadata.
|
|
128
|
+
moduleMetadata.hasRenderFunction) {
|
|
129
129
|
collectMetadataForImportedTemplates(moduleMetadata);
|
|
130
130
|
}
|
|
131
131
|
// all metadata collected at this point, time to start building ast
|
|
@@ -192,9 +192,6 @@ function generateResolvableModule(input, scriptKomaciDoc, templateKomaciDocMap,
|
|
|
192
192
|
statements.push(staticMetadataObject);
|
|
193
193
|
statements.push(adgFunctionDefinition);
|
|
194
194
|
statements.push(staticMetadataAssignmentExpression);
|
|
195
|
-
// the default export is the only adg that we care to hook the self service thing to since default adgs are always what is passed to the resolver
|
|
196
|
-
const selfServiceAssignmentExpression = (0, functionAstGeneration_1.composeSelfServiceAssignmentExpression)(adg.defaultGeneratedName);
|
|
197
|
-
statements.push(selfServiceAssignmentExpression);
|
|
198
195
|
}
|
|
199
196
|
for (const [exportName, adg] of Object.entries(moduleMetadata.exports)) {
|
|
200
197
|
statements.push((0, functionAstGeneration_1.addExportStatement)(adg.defaultGeneratedName, exportName));
|
|
@@ -546,52 +543,6 @@ function bindingToExpression(binding, iterationContext, parseRootOnly = false) {
|
|
|
546
543
|
return expr;
|
|
547
544
|
}
|
|
548
545
|
exports.bindingToExpression = bindingToExpression;
|
|
549
|
-
/**
|
|
550
|
-
* compose a object that references a value for use in iteration and conditional factory functions.
|
|
551
|
-
* for times when we are operating inside of an iteration context, we want to leverage bindings so we can
|
|
552
|
-
* straight up hoist the iteration value. in every other use case we will be either a property reference or static value
|
|
553
|
-
*
|
|
554
|
-
* - t represent "type"
|
|
555
|
-
* - t could be either `b` (binding) or `s` (static value)
|
|
556
|
-
* - v represents "value"
|
|
557
|
-
* - maps to the value whatever that may be.
|
|
558
|
-
*
|
|
559
|
-
* @param moduleMetadata metadata about the module we are composing
|
|
560
|
-
* @param ref the value that needs to be referenced by this prop
|
|
561
|
-
* @param iterationContext if this value is based on some iteration
|
|
562
|
-
* @returns an object of the form { t: 'b' | 's', v: 'some value or prop ref' }
|
|
563
|
-
*/
|
|
564
|
-
function valueReferenceToExpression(moduleMetadata, ref, iterationContext) {
|
|
565
|
-
let objectRef;
|
|
566
|
-
if (ref.type !== 'Binding' ||
|
|
567
|
-
(ref.type === 'Binding' &&
|
|
568
|
-
iterationContext &&
|
|
569
|
-
iterationContext.length !== 0 &&
|
|
570
|
-
iterationContext.includes(ref.value.split('/')[0]))) {
|
|
571
|
-
let objectValue;
|
|
572
|
-
if (ref.type === 'Binding') {
|
|
573
|
-
objectValue = bindingToExpression(ref, iterationContext);
|
|
574
|
-
}
|
|
575
|
-
else if (ref.value) {
|
|
576
|
-
objectValue = valueToExpression(ref, moduleMetadata);
|
|
577
|
-
}
|
|
578
|
-
else {
|
|
579
|
-
objectValue = t.identifier('undefined');
|
|
580
|
-
}
|
|
581
|
-
objectRef = t.objectExpression([
|
|
582
|
-
t.objectProperty(t.identifier('t'), t.stringLiteral('s')),
|
|
583
|
-
t.objectProperty(t.identifier('v'), objectValue),
|
|
584
|
-
]);
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
objectRef = t.objectExpression([
|
|
588
|
-
t.objectProperty(t.identifier('t'), t.stringLiteral('b')),
|
|
589
|
-
t.objectProperty(t.identifier('v'), t.stringLiteral(ref.value.replace(/\//g, '.'))),
|
|
590
|
-
]);
|
|
591
|
-
}
|
|
592
|
-
return objectRef;
|
|
593
|
-
}
|
|
594
|
-
exports.valueReferenceToExpression = valueReferenceToExpression;
|
|
595
546
|
/**
|
|
596
547
|
* Convert a single Komaci function to an object expression in the shape of a
|
|
597
548
|
* FunctionDefinition as defined in Resolver API.
|
package/build/types.js
CHANGED
|
@@ -70,7 +70,6 @@ exports.ID = {
|
|
|
70
70
|
IMG_SRC: t.identifier('src'),
|
|
71
71
|
IMG_FUNC: t.identifier('img'),
|
|
72
72
|
HOISTED_RENDER_FUNC_ID: t.identifier('hoistedRender'),
|
|
73
|
-
CONDITION_FUNC: t.identifier('c'),
|
|
74
73
|
};
|
|
75
74
|
// enum representing the different states of the way an Import is used
|
|
76
75
|
var ImportUsageState;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@komaci/esm-generator",
|
|
3
|
-
"version": "244.
|
|
3
|
+
"version": "244.2.0",
|
|
4
4
|
"description": "Komaci generator for ADG ES modules",
|
|
5
5
|
"homepage": "https://komaci.dev/",
|
|
6
6
|
"repository": {
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"@babel/core": "^7.9.0",
|
|
30
30
|
"@babel/generator": "^7.9.0",
|
|
31
31
|
"@babel/types": "^7.9.0",
|
|
32
|
-
"@komaci/common-shared": "244.
|
|
33
|
-
"@komaci/static-analyzer": "244.
|
|
32
|
+
"@komaci/common-shared": "244.2.0",
|
|
33
|
+
"@komaci/static-analyzer": "244.2.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@komaci/types": "244.
|
|
36
|
+
"@komaci/types": "244.2.0",
|
|
37
37
|
"@lwc-platform/sfdc-lwc-compiler": "242.15.1-2.28.0",
|
|
38
38
|
"@lwc/metadata": "^2.28.0-0"
|
|
39
39
|
}
|