@komaci/esm-generator 242.0.0 → 242.1.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__/adgAstGeneration.spec.d.ts +2 -0
- package/build/__tests__/adgAstGeneration.spec.js +31 -0
- package/build/__tests__/compositionAstGeneration.spec.d.ts +2 -0
- package/build/__tests__/compositionAstGeneration.spec.js +394 -0
- package/build/__tests__/functionAstGeneration.spec.d.ts +2 -0
- package/build/__tests__/functionAstGeneration.spec.js +412 -0
- package/build/__tests__/general-komaci-docs/template-component/source.js +3 -3
- package/build/__tests__/genericAstGeneration.spec.d.ts +2 -0
- package/build/__tests__/genericAstGeneration.spec.js +586 -0
- package/build/__tests__/index.spec.js +8 -8
- package/build/__tests__/komaci-ast-unit.spec.js +240 -448
- package/build/__tests__/komaci-bundle-module.fixtures.spec.js +1 -0
- package/build/__tests__/komaci-script-module.fixtures.spec.js +5 -1
- package/build/__tests__/komaci-template-module.fixtures.spec.js +2 -1
- package/build/componentAstProcessing.d.ts +34 -0
- package/build/componentAstProcessing.js +105 -0
- package/build/compositionAstGeneration.d.ts +76 -0
- package/build/compositionAstGeneration.js +299 -0
- package/build/functionAstGeneration.d.ts +81 -0
- package/build/functionAstGeneration.js +337 -0
- package/build/genericAstGeneration.d.ts +107 -0
- package/build/genericAstGeneration.js +600 -0
- package/build/index.d.ts +2 -3
- package/build/index.js +19 -36
- package/build/types.d.ts +13 -2
- package/build/types.js +69 -1
- package/package.json +4 -4
- package/build/__tests__/modGenScript.spec.d.ts +0 -2
- package/build/__tests__/modGenScript.spec.js +0 -110
- package/build/__tests__/modGenTemplate.spec.d.ts +0 -2
- package/build/__tests__/modGenTemplate.spec.js +0 -196
- package/build/__tests__/shared.spec.d.ts +0 -2
- package/build/__tests__/shared.spec.js +0 -66
- package/build/__tests__/templateStrings.spec.d.ts +0 -2
- package/build/__tests__/templateStrings.spec.js +0 -130
- package/build/modGenScript.d.ts +0 -38
- package/build/modGenScript.js +0 -1031
- package/build/modGenTemplate.d.ts +0 -37
- package/build/modGenTemplate.js +0 -406
- package/build/shared.d.ts +0 -149
- package/build/shared.js +0 -480
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_shared_1 = require("@komaci/common-shared");
|
|
4
|
+
const functionAstGeneration_1 = require("../functionAstGeneration");
|
|
5
|
+
describe('getAdgFunctionBody', () => {
|
|
6
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
7
|
+
it('includes a statement for factory functions if needed', () => {
|
|
8
|
+
const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
|
|
9
|
+
adg.requiredAdgFactoryFunctions.add(common_shared_1.IdKeys.ADG_FUNC);
|
|
10
|
+
const res = (0, functionAstGeneration_1.getAdgFunctionBody)(adg, moduleMetadata);
|
|
11
|
+
expect(res.body).toHaveLength(2);
|
|
12
|
+
expect(res.body[0].type).toBe('VariableDeclaration');
|
|
13
|
+
expect(res.body[1].type).toBe('ReturnStatement');
|
|
14
|
+
});
|
|
15
|
+
it('only contains a return statement if no factory functions are needed', () => {
|
|
16
|
+
const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
|
|
17
|
+
const res = (0, functionAstGeneration_1.getAdgFunctionBody)(adg, moduleMetadata);
|
|
18
|
+
expect(res.body).toHaveLength(1);
|
|
19
|
+
expect(res.body[0].type).toBe('ReturnStatement');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe('composeAdgFunction', () => {
|
|
23
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
24
|
+
it('can return a function declaration for a non exported function', () => {
|
|
25
|
+
const adg = (0, common_shared_1.initAdgMetadataObject)('adg0');
|
|
26
|
+
const res = (0, functionAstGeneration_1.composeAdgFunction)(adg, moduleMetadata);
|
|
27
|
+
expect(res.type).toBe('FunctionDeclaration');
|
|
28
|
+
expect(res.id.name).toBe('adg0');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=adgAstGeneration.spec.js.map
|
|
@@ -0,0 +1,394 @@
|
|
|
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
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const compositionAstGeneration_1 = require("../compositionAstGeneration");
|
|
30
|
+
const types_1 = require("@babel/types");
|
|
31
|
+
const types_2 = require("../types");
|
|
32
|
+
const fs = __importStar(require("fs"));
|
|
33
|
+
const path_1 = require("path");
|
|
34
|
+
const common_shared_1 = require("@komaci/common-shared");
|
|
35
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
36
|
+
const complexDoc = JSON.parse(fs.readFileSync((0, path_1.join)(__dirname, './general-komaci-docs/complexTemplateDoc/template.json'), 'utf-8'));
|
|
37
|
+
describe('imageToExpression', () => {
|
|
38
|
+
it('should return an expression for a KomaciDocument Image node', () => {
|
|
39
|
+
const komaciDocImagePrimitive = {
|
|
40
|
+
type: 'Image',
|
|
41
|
+
src: {
|
|
42
|
+
type: 'PrimitiveValue',
|
|
43
|
+
value: 'testPrimitive.jpg', // this is string literal of a relative URL
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
let expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImagePrimitive);
|
|
47
|
+
expect(expression.type).toBe('CallExpression');
|
|
48
|
+
let callExpression = expression;
|
|
49
|
+
expect(callExpression).not.toBeUndefined();
|
|
50
|
+
expect(callExpression.callee).toBe(types_2.ID.IMG_FUNC);
|
|
51
|
+
expect(callExpression.arguments).not.toBeUndefined();
|
|
52
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
53
|
+
expect(callExpression.arguments[0]).not.toBeUndefined();
|
|
54
|
+
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
55
|
+
let objExpression = callExpression
|
|
56
|
+
.arguments[0];
|
|
57
|
+
expect(objExpression.properties).not.toBeUndefined();
|
|
58
|
+
expect(objExpression.properties).toHaveLength(1);
|
|
59
|
+
expect(objExpression.properties[0].type).toBe('ObjectProperty');
|
|
60
|
+
let objProperty = objExpression.properties[0];
|
|
61
|
+
expect(objProperty.key).toBe(types_2.ID.IMG_SRC);
|
|
62
|
+
expect(objProperty.value).toEqual((0, types_1.stringLiteral)('testPrimitive.jpg')); // img({src: "testPrimitive.jpg"})
|
|
63
|
+
const komaciDocImageBinding = {
|
|
64
|
+
type: 'Image',
|
|
65
|
+
src: {
|
|
66
|
+
type: 'Binding',
|
|
67
|
+
value: 'testBinding', // this is a string literal, but represents a variable name
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImageBinding);
|
|
71
|
+
expect(expression.type).toBe('CallExpression');
|
|
72
|
+
callExpression = expression;
|
|
73
|
+
expect(callExpression).not.toBeUndefined();
|
|
74
|
+
expect(callExpression.callee).toBe(types_2.ID.IMG_FUNC);
|
|
75
|
+
expect(callExpression.arguments).not.toBeUndefined();
|
|
76
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
77
|
+
expect(callExpression.arguments[0]).not.toBeUndefined();
|
|
78
|
+
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
79
|
+
objExpression = callExpression.arguments[0];
|
|
80
|
+
expect(objExpression).not.toBeUndefined();
|
|
81
|
+
expect(objExpression.properties).not.toBeUndefined();
|
|
82
|
+
expect(objExpression.properties).toHaveLength(1);
|
|
83
|
+
expect(objExpression.properties[0].type).toBe('ObjectProperty');
|
|
84
|
+
objProperty = objExpression.properties[0];
|
|
85
|
+
expect(objProperty.key).toBe(types_2.ID.IMG_SRC);
|
|
86
|
+
let segments = ['ctx', 'props', 'testBinding'];
|
|
87
|
+
let expr = (0, types_1.identifier)(segments[0]);
|
|
88
|
+
for (let i = 1; i < segments.length; i++) {
|
|
89
|
+
expr = (0, types_1.optionalMemberExpression)(expr, (0, types_1.identifier)(segments[i]), false, false);
|
|
90
|
+
}
|
|
91
|
+
expect(objProperty.value).toEqual(expr); // img({src: ctx.props.testBinding})
|
|
92
|
+
const komaciDocImageNestedBinding = {
|
|
93
|
+
type: 'Image',
|
|
94
|
+
src: {
|
|
95
|
+
type: 'Binding',
|
|
96
|
+
value: 'imageObject/nested/imageName', // this is a string literal, represents nested-scoped variable names
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImageNestedBinding);
|
|
100
|
+
expect(expression.type).toBe('CallExpression');
|
|
101
|
+
callExpression = expression;
|
|
102
|
+
expect(callExpression).not.toBeUndefined();
|
|
103
|
+
expect(callExpression.callee).toBe(types_2.ID.IMG_FUNC);
|
|
104
|
+
expect(callExpression.arguments).not.toBeUndefined();
|
|
105
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
106
|
+
expect(callExpression.arguments[0]).not.toBeUndefined();
|
|
107
|
+
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
108
|
+
objExpression = callExpression.arguments[0];
|
|
109
|
+
expect(objExpression).not.toBeUndefined();
|
|
110
|
+
expect(objExpression.properties).not.toBeUndefined();
|
|
111
|
+
expect(objExpression.properties).toHaveLength(1);
|
|
112
|
+
expect(objExpression.properties[0].type).toBe('ObjectProperty');
|
|
113
|
+
objProperty = objExpression.properties[0];
|
|
114
|
+
expect(objProperty.key).toBe(types_2.ID.IMG_SRC);
|
|
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})
|
|
122
|
+
});
|
|
123
|
+
it('should not return an expression for invalid KomaciDocument Image nodes due to invalid src.value type (boolean)', () => {
|
|
124
|
+
const komaciDocImagePrimitive = {
|
|
125
|
+
type: 'Image',
|
|
126
|
+
src: {
|
|
127
|
+
type: 'PrimitiveValue',
|
|
128
|
+
value: false, // not a supported type (boolean)
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
const expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImagePrimitive);
|
|
132
|
+
expect(expression.type).toBe('CallExpression');
|
|
133
|
+
const callExpression = expression;
|
|
134
|
+
expect(callExpression).not.toBeUndefined();
|
|
135
|
+
expect(callExpression.callee).not.toBeUndefined();
|
|
136
|
+
expect(callExpression.callee).toBe(types_2.ID.IMG_FUNC);
|
|
137
|
+
expect(callExpression.arguments).not.toBeUndefined();
|
|
138
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
139
|
+
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
140
|
+
const objExpression = callExpression
|
|
141
|
+
.arguments[0];
|
|
142
|
+
expect(objExpression.properties).not.toBeUndefined();
|
|
143
|
+
expect(objExpression.properties).toHaveLength(0); // no img() populated with a valid src attribute
|
|
144
|
+
});
|
|
145
|
+
it('should not return an expression for invalid KomaciDocument Image nodes due to blank src.value', () => {
|
|
146
|
+
const komaciDocImagePrimitiveBlank = {
|
|
147
|
+
type: 'Image',
|
|
148
|
+
src: {
|
|
149
|
+
type: 'PrimitiveValue',
|
|
150
|
+
value: '', // blanks not supported
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
let expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImagePrimitiveBlank);
|
|
154
|
+
expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImagePrimitiveBlank);
|
|
155
|
+
expect(expression.type).toBe('CallExpression');
|
|
156
|
+
const callExpression = expression;
|
|
157
|
+
expect(callExpression).not.toBeUndefined();
|
|
158
|
+
expect(callExpression.callee).not.toBeUndefined();
|
|
159
|
+
expect(callExpression.callee).toBe(types_2.ID.IMG_FUNC);
|
|
160
|
+
expect(callExpression.arguments).not.toBeUndefined();
|
|
161
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
162
|
+
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
163
|
+
const objExpression = callExpression
|
|
164
|
+
.arguments[0];
|
|
165
|
+
expect(objExpression.properties).not.toBeUndefined();
|
|
166
|
+
expect(objExpression.properties).toHaveLength(0); // no img() populated with a valid src attribute
|
|
167
|
+
});
|
|
168
|
+
it('should not return an expression for invalid KomaciDocument Image nodes with src.type that is neither Binding nor PrimitiveType', () => {
|
|
169
|
+
const komaciDocImageInvalidSrcValType = {
|
|
170
|
+
type: 'Image',
|
|
171
|
+
src: {
|
|
172
|
+
type: 'PrimitiveValue',
|
|
173
|
+
value: 'some random string',
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
// change the src.value type to something invalid, a number
|
|
177
|
+
komaciDocImageInvalidSrcValType.src.value = 12345;
|
|
178
|
+
let expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImageInvalidSrcValType);
|
|
179
|
+
expression = (0, compositionAstGeneration_1.imageToExpression)(komaciDocImageInvalidSrcValType);
|
|
180
|
+
expect(expression.type).toBe('CallExpression');
|
|
181
|
+
const callExpression = expression;
|
|
182
|
+
expect(callExpression).not.toBeUndefined();
|
|
183
|
+
expect(callExpression.callee).not.toBeUndefined();
|
|
184
|
+
expect(callExpression.callee).toBe(types_2.ID.IMG_FUNC);
|
|
185
|
+
expect(callExpression.arguments).not.toBeUndefined();
|
|
186
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
187
|
+
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
188
|
+
const objExpression = callExpression
|
|
189
|
+
.arguments[0];
|
|
190
|
+
expect(objExpression.properties).not.toBeUndefined();
|
|
191
|
+
expect(objExpression.properties).toHaveLength(0);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
describe('compositionToArrayExpression', () => {
|
|
195
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
196
|
+
(0, common_shared_1.initializeImportMetdataFromKomaciDocument)(complexDoc, moduleMetadata, true);
|
|
197
|
+
it('could handle a single composition', () => {
|
|
198
|
+
const res = (0, compositionAstGeneration_1.compositionsToArrayExpression)(moduleMetadata, [
|
|
199
|
+
complexDoc.compositions[0].compositions[2].compositions[0],
|
|
200
|
+
]);
|
|
201
|
+
expect(res?.elements).toHaveLength(1);
|
|
202
|
+
});
|
|
203
|
+
it('can handle multiple compositions being passed in', () => {
|
|
204
|
+
const res = (0, compositionAstGeneration_1.compositionsToArrayExpression)(moduleMetadata, complexDoc.compositions[0].compositions);
|
|
205
|
+
expect(res?.elements).toHaveLength(3);
|
|
206
|
+
});
|
|
207
|
+
it('returns an empty array when given an empty array element of compositions', () => {
|
|
208
|
+
const res = (0, compositionAstGeneration_1.compositionsToArrayExpression)(moduleMetadata, []);
|
|
209
|
+
expect(res?.elements).toHaveLength(0);
|
|
210
|
+
});
|
|
211
|
+
it('returns undefined if we are given no compositions', () => {
|
|
212
|
+
const res = (0, compositionAstGeneration_1.compositionsToArrayExpression)(moduleMetadata, undefined);
|
|
213
|
+
expect(res).toBeUndefined();
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
describe('compositionToExpression', () => {
|
|
217
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
218
|
+
(0, common_shared_1.initializeImportMetdataFromKomaciDocument)(complexDoc, moduleMetadata, true);
|
|
219
|
+
it('effectiely builds a conditional expression for a component with isActive', () => {
|
|
220
|
+
const res = (0, compositionAstGeneration_1.compositionToExpression)(moduleMetadata, complexDoc.compositions[0].compositions[2].compositions[1]);
|
|
221
|
+
expect(res.type).toBe('ConditionalExpression');
|
|
222
|
+
const code = (0, generator_1.default)(res).code;
|
|
223
|
+
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');
|
|
224
|
+
});
|
|
225
|
+
it('effectiely builds a conditional expression for a component with negated isActive', () => {
|
|
226
|
+
const res = (0, compositionAstGeneration_1.compositionToExpression)(moduleMetadata, complexDoc.compositions[0].compositions[2].compositions[2]);
|
|
227
|
+
expect(res.type).toBe('ConditionalExpression');
|
|
228
|
+
const code = (0, generator_1.default)(res).code;
|
|
229
|
+
expect(code).toBe('u(ctx.props.apexResult) || !ctx.props.apexResult ? [] : undefined');
|
|
230
|
+
});
|
|
231
|
+
it('returns a basic reference when isActive is not set', () => {
|
|
232
|
+
const res = (0, compositionAstGeneration_1.compositionToExpression)(moduleMetadata, complexDoc.compositions[0].compositions[2].compositions[0]);
|
|
233
|
+
expect(res.type).toBe('CallExpression');
|
|
234
|
+
const code = (0, generator_1.default)(res).code;
|
|
235
|
+
expect(code).toBe('cg(i1, {\n slot: "title",\n componentId: "c-title",\n props: {\n size: "medium",\n icon: "standard:apex"\n }\n}, ctx)');
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
describe('containerToExpression', () => {
|
|
239
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
240
|
+
(0, common_shared_1.initializeImportMetdataFromKomaciDocument)(complexDoc, moduleMetadata, true);
|
|
241
|
+
it('uses the element function when container has a key', () => {
|
|
242
|
+
const container = Object.assign({}, complexDoc.compositions[0].compositions[2].compositions[0]);
|
|
243
|
+
container.key = { type: 'Binding', value: 'test' };
|
|
244
|
+
const res = (0, compositionAstGeneration_1.containerToExpression)(moduleMetadata, container);
|
|
245
|
+
expect(res.type).toBe('CallExpression');
|
|
246
|
+
expect(res.callee.name).toBe('e');
|
|
247
|
+
});
|
|
248
|
+
it('uses the element function when container has a slot ref', () => {
|
|
249
|
+
const container = Object.assign({}, complexDoc.compositions[0].compositions[2].compositions[0]);
|
|
250
|
+
container.slot = 'test';
|
|
251
|
+
const res = (0, compositionAstGeneration_1.containerToExpression)(moduleMetadata, container);
|
|
252
|
+
expect(res.type).toBe('CallExpression');
|
|
253
|
+
expect(res.callee.name).toBe('e');
|
|
254
|
+
});
|
|
255
|
+
it('returns first element when theres one child', () => {
|
|
256
|
+
const res = (0, compositionAstGeneration_1.containerToExpression)(moduleMetadata, complexDoc.compositions[0].compositions[1].compositions[1]);
|
|
257
|
+
expect(res.type).toBe('CallExpression');
|
|
258
|
+
expect(res.callee.name).not.toBe('e');
|
|
259
|
+
});
|
|
260
|
+
it('returns an array element when there are multiple children', () => {
|
|
261
|
+
const res = (0, compositionAstGeneration_1.containerToExpression)(moduleMetadata, complexDoc.compositions[0].compositions[2].compositions[1]);
|
|
262
|
+
expect(res.type).toBe('ArrayExpression');
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
describe('composedAdgToExpression', () => {
|
|
266
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
267
|
+
(0, common_shared_1.initializeImportMetdataFromKomaciDocument)(complexDoc, moduleMetadata, true);
|
|
268
|
+
it('properly composed composedAdg with no children', () => {
|
|
269
|
+
const res = (0, compositionAstGeneration_1.composedAdgToExpression)(moduleMetadata, complexDoc.compositions[0].compositions[1].compositions[1]
|
|
270
|
+
.compositions[0]);
|
|
271
|
+
expect(res.type).toBe('CallExpression');
|
|
272
|
+
expect(res.callee.name).toBe('cg');
|
|
273
|
+
const code = (0, generator_1.default)(res).code;
|
|
274
|
+
expect(code).toBe('cg(i3, {\n componentId: "c-lookup-field-row",\n props: {\n recordId: ctx.props.record?.data?.fields?.CreatedById?.value,\n label: "CreatedBy User Info",\n objectApiName: "User"\n }\n}, ctx)');
|
|
275
|
+
});
|
|
276
|
+
it('properly composed composedAdg with children', () => {
|
|
277
|
+
const res = (0, compositionAstGeneration_1.composedAdgToExpression)(moduleMetadata, complexDoc.compositions[0].compositions[0]);
|
|
278
|
+
expect(res.type).toBe('CallExpression');
|
|
279
|
+
expect(res.callee.name).toBe('cg');
|
|
280
|
+
const code = (0, generator_1.default)(res).code;
|
|
281
|
+
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 size: "large",\n icon: "standard:account"\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])');
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
describe('iterationToExpression', () => {
|
|
285
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
286
|
+
(0, common_shared_1.initializeImportMetdataFromKomaciDocument)(complexDoc, moduleMetadata, true);
|
|
287
|
+
it('can compose an iteration factory call from a iterator composition', () => {
|
|
288
|
+
const res = (0, compositionAstGeneration_1.iterationToExpression)(moduleMetadata, {
|
|
289
|
+
type: 'Iteration',
|
|
290
|
+
input: {
|
|
291
|
+
type: 'Binding',
|
|
292
|
+
value: 'contacts',
|
|
293
|
+
},
|
|
294
|
+
iterator: 'contact',
|
|
295
|
+
compositions: [
|
|
296
|
+
{
|
|
297
|
+
type: 'ComposedAdg',
|
|
298
|
+
input: {
|
|
299
|
+
type: 'ImportReference',
|
|
300
|
+
value: '0/names/0',
|
|
301
|
+
},
|
|
302
|
+
properties: {
|
|
303
|
+
label: {
|
|
304
|
+
type: 'Binding',
|
|
305
|
+
value: 'contact/value/Name',
|
|
306
|
+
},
|
|
307
|
+
myIndex: {
|
|
308
|
+
type: 'Binding',
|
|
309
|
+
value: 'contact/index',
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
key: {
|
|
313
|
+
type: 'Binding',
|
|
314
|
+
value: 'contact/value/Id',
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
});
|
|
319
|
+
expect(res.type).toBe('CallExpression');
|
|
320
|
+
expect(res.callee.name).toBe('i');
|
|
321
|
+
const code = (0, generator_1.default)(res).code;
|
|
322
|
+
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})');
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
describe('slotToExpression', () => {
|
|
326
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
327
|
+
(0, common_shared_1.initializeImportMetdataFromKomaciDocument)(complexDoc, moduleMetadata);
|
|
328
|
+
it('can compose a slot factory call from a iterator composition', () => {
|
|
329
|
+
const res = (0, compositionAstGeneration_1.slotToExpression)(moduleMetadata, {
|
|
330
|
+
type: 'Slot',
|
|
331
|
+
name: 'full-name',
|
|
332
|
+
compositions: [
|
|
333
|
+
{
|
|
334
|
+
type: 'Slot',
|
|
335
|
+
name: 'first-name',
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
type: 'Slot',
|
|
339
|
+
name: 'last-name',
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
});
|
|
343
|
+
expect(res.type).toBe('CallExpression');
|
|
344
|
+
expect(res.callee.name).toBe('s');
|
|
345
|
+
const code = (0, generator_1.default)(res).code;
|
|
346
|
+
expect(code).toBe('s("full-name", {}, ctx, [s("first-name", {}, ctx), s("last-name", {}, ctx)])');
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
describe('getCompositionConfig', () => {
|
|
350
|
+
it('collects composition config for a container', () => {
|
|
351
|
+
const res = (0, compositionAstGeneration_1.getCompositionConfig)({
|
|
352
|
+
type: 'Container',
|
|
353
|
+
isActive: {
|
|
354
|
+
input: {
|
|
355
|
+
type: 'Binding',
|
|
356
|
+
value: 'fukuoka',
|
|
357
|
+
},
|
|
358
|
+
negate: false,
|
|
359
|
+
},
|
|
360
|
+
compositions: [
|
|
361
|
+
{
|
|
362
|
+
type: 'Slot',
|
|
363
|
+
name: '',
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
});
|
|
367
|
+
const code = (0, generator_1.default)(res).code;
|
|
368
|
+
expect(code).toBe('{}');
|
|
369
|
+
});
|
|
370
|
+
it('collects composition config for a composedAdg', () => {
|
|
371
|
+
const res = (0, compositionAstGeneration_1.getCompositionConfig)(complexDoc.compositions[0].compositions[2].compositions[0]);
|
|
372
|
+
const code = (0, generator_1.default)(res).code;
|
|
373
|
+
expect(code).toBe('{\n slot: "title",\n props: {\n size: "medium",\n icon: "standard:apex"\n }\n}');
|
|
374
|
+
});
|
|
375
|
+
it('collects composition config for a slot', () => {
|
|
376
|
+
const res = (0, compositionAstGeneration_1.getCompositionConfig)({
|
|
377
|
+
type: 'Slot',
|
|
378
|
+
name: 'full-name',
|
|
379
|
+
compositions: [
|
|
380
|
+
{
|
|
381
|
+
type: 'Slot',
|
|
382
|
+
name: 'first-name',
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
type: 'Slot',
|
|
386
|
+
name: 'last-name',
|
|
387
|
+
},
|
|
388
|
+
],
|
|
389
|
+
});
|
|
390
|
+
const code = (0, generator_1.default)(res).code;
|
|
391
|
+
expect(code).toBe('{}');
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
//# sourceMappingURL=compositionAstGeneration.spec.js.map
|