@komaci/esm-generator 240.1.3 → 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__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.js +5 -1
- package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.js +5 -1
- package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.js +5 -1
- package/build/__tests__/fixtures-script-files/imports/actual.js +5 -1
- package/build/__tests__/fixtures-script-files/imports-namespaced/actual.js +5 -1
- package/build/__tests__/fixtures-script-files/wire-imports/actual.js +5 -1
- package/build/__tests__/functionAstGeneration.spec.d.ts +2 -0
- package/build/__tests__/functionAstGeneration.spec.js +412 -0
- package/build/__tests__/general-komaci-docs/import-types/source.js +5 -1
- 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 +13 -9
- 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 +6 -0
- package/build/index.js +85 -88
- 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 -62
- 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 -1027
- package/build/modGenTemplate.d.ts +0 -37
- package/build/modGenTemplate.js +0 -402
- package/build/shared.d.ts +0 -170
- package/build/shared.js +0 -588
|
@@ -0,0 +1,586 @@
|
|
|
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 generator_1 = __importDefault(require("@babel/generator"));
|
|
30
|
+
const common_shared_1 = require("@komaci/common-shared");
|
|
31
|
+
const genericAstGeneration_1 = require("../genericAstGeneration");
|
|
32
|
+
const t = __importStar(require("@babel/types"));
|
|
33
|
+
describe('valueToExpression', () => {
|
|
34
|
+
it('composes proper statement for complex object. Includes ObjectValue, ArrayValue, PropertyReference, and Primitive Value', () => {
|
|
35
|
+
const wireFunctionObject = {
|
|
36
|
+
type: 'ObjectValue',
|
|
37
|
+
value: {
|
|
38
|
+
fields: {
|
|
39
|
+
type: 'ArrayValue',
|
|
40
|
+
value: [
|
|
41
|
+
{ type: 'PrimitiveValue', value: 'Account.Id' },
|
|
42
|
+
{ type: 'PrimitiveValue', value: 'Account.Name' },
|
|
43
|
+
{ type: 'PrimitiveValue', value: 'Account.CreatedById' },
|
|
44
|
+
{ type: 'PrimitiveValue', value: 'Account.CreatedDate' },
|
|
45
|
+
{ type: 'PrimitiveValue', value: 'Account.OwnerId' },
|
|
46
|
+
{ type: 'PrimitiveValue', value: 'Account.ParentId' },
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
recordId: { type: 'PropertyReference', value: 'recordId' },
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
53
|
+
const result = (0, genericAstGeneration_1.valueToExpression)(wireFunctionObject, moduleMetadata);
|
|
54
|
+
expect(result).not.toBeUndefined();
|
|
55
|
+
expect(result.properties).toHaveLength(2);
|
|
56
|
+
const objExprProperties = result.properties;
|
|
57
|
+
expect(objExprProperties[0].key.value).toEqual('fields');
|
|
58
|
+
expect(objExprProperties[0].value.elements).toHaveLength(6);
|
|
59
|
+
expect(objExprProperties[0].value
|
|
60
|
+
.elements[0].value).toEqual('Account.Id');
|
|
61
|
+
expect(objExprProperties[0].value
|
|
62
|
+
.elements[1].value).toEqual('Account.Name');
|
|
63
|
+
expect(objExprProperties[0].value
|
|
64
|
+
.elements[2].value).toEqual('Account.CreatedById');
|
|
65
|
+
expect(objExprProperties[0].value
|
|
66
|
+
.elements[3].value).toEqual('Account.CreatedDate');
|
|
67
|
+
expect(objExprProperties[0].value
|
|
68
|
+
.elements[4].value).toEqual('Account.OwnerId');
|
|
69
|
+
expect(objExprProperties[0].value
|
|
70
|
+
.elements[5].value).toEqual('Account.ParentId');
|
|
71
|
+
expect(objExprProperties[1].key.value).toEqual('recordId');
|
|
72
|
+
expect(objExprProperties[1].value
|
|
73
|
+
.property.name).toEqual('recordId');
|
|
74
|
+
});
|
|
75
|
+
it('composes proper statement when komaci value is an importReference', () => {
|
|
76
|
+
const komaciValue = {
|
|
77
|
+
type: 'ImportReference',
|
|
78
|
+
value: '0/names/0',
|
|
79
|
+
namespacedMember: 'p1',
|
|
80
|
+
};
|
|
81
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
82
|
+
const komaciDoc = {
|
|
83
|
+
imports: [
|
|
84
|
+
{ resourceName: 'force/shared', names: ['*'] },
|
|
85
|
+
{ resourceName: 'laf/transformWire', names: ['*'] },
|
|
86
|
+
{ resourceName: 'lightning/uiRecordApi', names: ['getRecord'] },
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
(0, common_shared_1.initializeImportMetdataFromKomaciDocument)(komaciDoc, moduleMetadata);
|
|
90
|
+
const result = (0, genericAstGeneration_1.valueToExpression)(komaciValue, moduleMetadata);
|
|
91
|
+
expect(result).not.toBeUndefined();
|
|
92
|
+
expect(result.object.name).toEqual('i0');
|
|
93
|
+
expect(result.property.name).toEqual('p1');
|
|
94
|
+
});
|
|
95
|
+
it('composes proper statement when komaci value is an unsupported importReference', () => {
|
|
96
|
+
const komaciValue = {
|
|
97
|
+
type: 'ImportReference',
|
|
98
|
+
value: '0/names/0',
|
|
99
|
+
namespacedMember: 'p1',
|
|
100
|
+
};
|
|
101
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
102
|
+
const komaciDoc = {
|
|
103
|
+
imports: [
|
|
104
|
+
{ resourceName: 'unsuported/shared', names: ['*'] },
|
|
105
|
+
{ resourceName: 'laf/transformWire', names: ['*'] },
|
|
106
|
+
{ resourceName: 'lightning/uiRecordApi', names: ['getRecord'] },
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
(0, common_shared_1.initializeImportMetdataFromKomaciDocument)(komaciDoc, moduleMetadata);
|
|
110
|
+
const result = (0, genericAstGeneration_1.valueToExpression)(komaciValue, moduleMetadata);
|
|
111
|
+
expect(result).not.toBeUndefined();
|
|
112
|
+
expect(result.type).toBe('Identifier');
|
|
113
|
+
expect(result.name).toBe('unresolved');
|
|
114
|
+
});
|
|
115
|
+
it('marks invalid import reference as unresolved', () => {
|
|
116
|
+
const komaciValue = {
|
|
117
|
+
type: 'ImportReference',
|
|
118
|
+
value: '7/names/0',
|
|
119
|
+
namespacedMember: 'p1',
|
|
120
|
+
};
|
|
121
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
122
|
+
const komaciDoc = {
|
|
123
|
+
imports: [
|
|
124
|
+
{ resourceName: 'unsuported/shared', names: ['*'] },
|
|
125
|
+
{ resourceName: 'laf/transformWire', names: ['*'] },
|
|
126
|
+
{ resourceName: 'lightning/uiRecordApi', names: ['getRecord'] },
|
|
127
|
+
],
|
|
128
|
+
};
|
|
129
|
+
(0, common_shared_1.initializeImportMetdataFromKomaciDocument)(komaciDoc, moduleMetadata);
|
|
130
|
+
const result = (0, genericAstGeneration_1.valueToExpression)(komaciValue, moduleMetadata);
|
|
131
|
+
expect(result).not.toBeUndefined();
|
|
132
|
+
expect(result.type).toBe('Identifier');
|
|
133
|
+
expect(result.name).toBe('unresolved');
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
describe('functionToExpression', () => {
|
|
137
|
+
it('composes proper object expression for a valid getter function', () => {
|
|
138
|
+
//need to make a hoistedGetterFunction object
|
|
139
|
+
// module metadata based on komaci document.
|
|
140
|
+
const functionMeta = {
|
|
141
|
+
type: common_shared_1.FunctionTypes.GETTER_FUNCTION,
|
|
142
|
+
componentAstNode: undefined,
|
|
143
|
+
requiredProperties: ['tempProp'],
|
|
144
|
+
generatedName: `g${0}`,
|
|
145
|
+
};
|
|
146
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
147
|
+
const result = (0, genericAstGeneration_1.functionToExpression)(moduleMetadata, functionMeta);
|
|
148
|
+
expect(result).not.toBeUndefined();
|
|
149
|
+
expect(result?.type).toEqual('ObjectExpression');
|
|
150
|
+
expect(result?.properties).toHaveLength(3);
|
|
151
|
+
const properties = result?.properties;
|
|
152
|
+
expect(properties[0].key.name).toEqual('f');
|
|
153
|
+
expect(properties[0].value.name).toEqual('g0');
|
|
154
|
+
expect(properties[1].key.name).toEqual('t');
|
|
155
|
+
expect(properties[1].value.value).toEqual('GetterFunction');
|
|
156
|
+
expect(properties[2].key.name).toEqual('in');
|
|
157
|
+
expect(properties[2].value.elements).toHaveLength(1);
|
|
158
|
+
});
|
|
159
|
+
it('composes proper object expression for a valid template string', () => {
|
|
160
|
+
//need to make a hoistedGetterFunction object
|
|
161
|
+
// module metadata based on komaci document.
|
|
162
|
+
const functionMeta = {
|
|
163
|
+
type: common_shared_1.FunctionTypes.TEMPLATE_STRING,
|
|
164
|
+
componentAstNode: undefined,
|
|
165
|
+
requiredProperties: ['tempProp'],
|
|
166
|
+
generatedName: `t${0}`,
|
|
167
|
+
};
|
|
168
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
169
|
+
const result = (0, genericAstGeneration_1.functionToExpression)(moduleMetadata, functionMeta);
|
|
170
|
+
expect(result).not.toBeUndefined();
|
|
171
|
+
expect(result?.type).toEqual('ObjectExpression');
|
|
172
|
+
expect(result?.properties).toHaveLength(3);
|
|
173
|
+
const properties = result?.properties;
|
|
174
|
+
expect(properties[0].key.name).toEqual('f');
|
|
175
|
+
expect(properties[0].value.name).toEqual('t0');
|
|
176
|
+
expect(properties[1].key.name).toEqual('t');
|
|
177
|
+
expect(properties[1].value.value).toEqual('TemplatedStringFunction');
|
|
178
|
+
expect(properties[2].key.name).toEqual('in');
|
|
179
|
+
expect(properties[2].value.elements).toHaveLength(1);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
describe('propertyToExpression', () => {
|
|
183
|
+
it('composes proper object expression when input is property with inital value', () => {
|
|
184
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
185
|
+
const propertyConext = {
|
|
186
|
+
type: common_shared_1.PropertyTypes.BASE,
|
|
187
|
+
inital: { type: 'PrimitiveValue', value: 5 },
|
|
188
|
+
usedInPriming: false,
|
|
189
|
+
isPublic: true,
|
|
190
|
+
};
|
|
191
|
+
const result = (0, genericAstGeneration_1.propertyToExpression)(moduleMetadata, propertyConext);
|
|
192
|
+
expect(result).not.toBeUndefined();
|
|
193
|
+
expect(result?.type).toEqual('ObjectExpression');
|
|
194
|
+
expect(result?.properties).toHaveLength(2);
|
|
195
|
+
const properties = result?.properties;
|
|
196
|
+
expect(properties).toHaveLength(2);
|
|
197
|
+
expect(properties[0].key.name).toEqual('a');
|
|
198
|
+
expect(properties[0].value.value).toBeTruthy();
|
|
199
|
+
expect(properties[1].key.name).toEqual('i');
|
|
200
|
+
expect(properties[1].value.value).toEqual(5);
|
|
201
|
+
});
|
|
202
|
+
it('composes proper object expression when property is a getter', () => {
|
|
203
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
204
|
+
const propertyConext = {
|
|
205
|
+
type: common_shared_1.PropertyTypes.GETTER,
|
|
206
|
+
usedInPriming: false,
|
|
207
|
+
functionIndex: 0,
|
|
208
|
+
isPublic: false,
|
|
209
|
+
};
|
|
210
|
+
const result = (0, genericAstGeneration_1.propertyToExpression)(moduleMetadata, propertyConext);
|
|
211
|
+
expect(result).not.toBeUndefined();
|
|
212
|
+
expect(result?.type).toEqual('ObjectExpression');
|
|
213
|
+
expect(result?.properties).toHaveLength(2);
|
|
214
|
+
const properties = result?.properties;
|
|
215
|
+
expect(properties).toHaveLength(2);
|
|
216
|
+
expect(properties[0].key.name).toEqual('a');
|
|
217
|
+
expect(properties[0].value.value).toBeFalsy();
|
|
218
|
+
expect(properties[1].key.name).toEqual('f');
|
|
219
|
+
expect(properties[1].value.value).toEqual(0);
|
|
220
|
+
});
|
|
221
|
+
it('composes proper object expression when property is a Template string', () => {
|
|
222
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
223
|
+
const propertyConext = {
|
|
224
|
+
type: common_shared_1.PropertyTypes.TEMPLATE_STRING,
|
|
225
|
+
usedInPriming: false,
|
|
226
|
+
functionIndex: 0,
|
|
227
|
+
isPublic: false,
|
|
228
|
+
};
|
|
229
|
+
const result = (0, genericAstGeneration_1.propertyToExpression)(moduleMetadata, propertyConext);
|
|
230
|
+
expect(result).not.toBeUndefined();
|
|
231
|
+
expect(result?.type).toEqual('ObjectExpression');
|
|
232
|
+
expect(result?.properties).toHaveLength(2);
|
|
233
|
+
const properties = result?.properties;
|
|
234
|
+
expect(properties).toHaveLength(2);
|
|
235
|
+
expect(properties[0].key.name).toEqual('a');
|
|
236
|
+
expect(properties[0].value.value).toBeFalsy();
|
|
237
|
+
expect(properties[1].key.name).toEqual('f');
|
|
238
|
+
expect(properties[1].value.value).toEqual(0);
|
|
239
|
+
});
|
|
240
|
+
it('composes proper object expression when property is a wire', () => {
|
|
241
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
242
|
+
const propertyConext = {
|
|
243
|
+
type: common_shared_1.PropertyTypes.WIRE,
|
|
244
|
+
usedInPriming: false,
|
|
245
|
+
functionIndex: 1,
|
|
246
|
+
isPublic: false,
|
|
247
|
+
};
|
|
248
|
+
const result = (0, genericAstGeneration_1.propertyToExpression)(moduleMetadata, propertyConext);
|
|
249
|
+
expect(result).not.toBeUndefined();
|
|
250
|
+
expect(result?.type).toEqual('ObjectExpression');
|
|
251
|
+
expect(result?.properties).toHaveLength(2);
|
|
252
|
+
const properties = result?.properties;
|
|
253
|
+
expect(properties).toHaveLength(2);
|
|
254
|
+
expect(properties[0].key.name).toEqual('a');
|
|
255
|
+
expect(properties[0].value.value).toBeFalsy();
|
|
256
|
+
expect(properties[1].key.name).toEqual('f');
|
|
257
|
+
expect(properties[1].value.value).toEqual(1);
|
|
258
|
+
});
|
|
259
|
+
it('composes proper object expression when property is a wire that is unresolvabe', () => {
|
|
260
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
261
|
+
const propertyConext = {
|
|
262
|
+
type: common_shared_1.PropertyTypes.WIRE,
|
|
263
|
+
usedInPriming: false,
|
|
264
|
+
functionIndex: common_shared_1.UNSUPPORTED_FUNCTION,
|
|
265
|
+
isPublic: false,
|
|
266
|
+
};
|
|
267
|
+
const result = (0, genericAstGeneration_1.propertyToExpression)(moduleMetadata, propertyConext);
|
|
268
|
+
expect(result).not.toBeUndefined();
|
|
269
|
+
expect(result?.type).toEqual('ObjectExpression');
|
|
270
|
+
expect(result?.properties).toHaveLength(2);
|
|
271
|
+
const properties = result?.properties;
|
|
272
|
+
expect(properties).toHaveLength(2);
|
|
273
|
+
expect(properties[0].key.name).toEqual('a');
|
|
274
|
+
expect(properties[0].value.value).toBeFalsy();
|
|
275
|
+
expect(properties[1].key.name).toEqual('g');
|
|
276
|
+
expect(properties[1].value.value).toEqual(undefined);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
describe('processWireFunctionType', () => {
|
|
280
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
281
|
+
(0, common_shared_1.composeImportMetadata)('randomWire', 'laf/transformWire', true, '0/names/0', moduleMetadata);
|
|
282
|
+
(0, common_shared_1.composeImportMetadata)('apexWire', '@salesforce/apex/recordApi', true, '1/names/0', moduleMetadata);
|
|
283
|
+
(0, common_shared_1.composeImportMetadata)('getRecord', 'lightning/uiRecordApi', true, '2/names/0', moduleMetadata);
|
|
284
|
+
(0, common_shared_1.composeImportMetadata)('bacth_getRecord', 'lightning/uiRecordApi', true, '2/names/1', moduleMetadata);
|
|
285
|
+
(0, common_shared_1.composeImportMetadata)('reducer', 'lightning/uiRecordApi', true, '2/names/2', moduleMetadata);
|
|
286
|
+
(0, common_shared_1.composeImportMetadata)('CurrentPageReference', 'laf/transformWire', true, '3/names/0', moduleMetadata);
|
|
287
|
+
it('throws an error when a function that isnt a wire is passed in', () => {
|
|
288
|
+
const throwingFunc = () => (0, genericAstGeneration_1.processWireFunctionType)({
|
|
289
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
290
|
+
type: common_shared_1.FunctionTypes.GETTER_FUNCTION,
|
|
291
|
+
requiredProperties: [],
|
|
292
|
+
importReference: { functionName: '' },
|
|
293
|
+
}, moduleMetadata);
|
|
294
|
+
expect(throwingFunc).toThrow();
|
|
295
|
+
});
|
|
296
|
+
it('does nothing when function refers to a non existent import', () => {
|
|
297
|
+
const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
|
|
298
|
+
type: common_shared_1.FunctionTypes.WIRE_FUNCTION,
|
|
299
|
+
requiredProperties: [],
|
|
300
|
+
importReference: { functionName: 'test' },
|
|
301
|
+
}, moduleMetadata);
|
|
302
|
+
expect(astStatements).toBeUndefined();
|
|
303
|
+
});
|
|
304
|
+
it('effectively builds metadata for a non priming adapter wire', () => {
|
|
305
|
+
const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
|
|
306
|
+
type: common_shared_1.FunctionTypes.WIRE_FUNCTION,
|
|
307
|
+
requiredProperties: [],
|
|
308
|
+
input: [
|
|
309
|
+
{
|
|
310
|
+
type: 'ObjectValue',
|
|
311
|
+
value: {
|
|
312
|
+
fields: {
|
|
313
|
+
type: 'ArrayValue',
|
|
314
|
+
value: [
|
|
315
|
+
{
|
|
316
|
+
type: 'PrimitiveValue',
|
|
317
|
+
value: 'Account.Name',
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
},
|
|
321
|
+
resourceId: {
|
|
322
|
+
type: 'PropertyReference',
|
|
323
|
+
value: 'recordId',
|
|
324
|
+
},
|
|
325
|
+
recordType: {
|
|
326
|
+
type: 'PropertyReference',
|
|
327
|
+
value: 'recordType',
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
],
|
|
332
|
+
importReference: { functionName: 'randomWire' },
|
|
333
|
+
}, moduleMetadata);
|
|
334
|
+
expect(astStatements).not.toBeUndefined();
|
|
335
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
336
|
+
const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
|
|
337
|
+
expect(code).toBe(`{
|
|
338
|
+
f: i0,
|
|
339
|
+
fN: "randomWire",
|
|
340
|
+
t: "WireFunction",
|
|
341
|
+
c: ctx => ({
|
|
342
|
+
"fields": ["Account.Name"],
|
|
343
|
+
"resourceId": ctx.props.recordId,
|
|
344
|
+
"recordType": ctx.props.recordType
|
|
345
|
+
}),
|
|
346
|
+
in: ["recordId", "recordType"]
|
|
347
|
+
}`);
|
|
348
|
+
});
|
|
349
|
+
it('effectively builds metadata for an apex wire', () => {
|
|
350
|
+
const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
|
|
351
|
+
type: common_shared_1.FunctionTypes.WIRE_FUNCTION,
|
|
352
|
+
requiredProperties: [],
|
|
353
|
+
importReference: { functionName: 'apexWire' },
|
|
354
|
+
}, moduleMetadata);
|
|
355
|
+
expect(astStatements).not.toBeUndefined();
|
|
356
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
357
|
+
const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
|
|
358
|
+
expect(code).toBe(`{
|
|
359
|
+
f: i1,
|
|
360
|
+
fN: "recordApi",
|
|
361
|
+
t: "WireFunction",
|
|
362
|
+
wt: "apex",
|
|
363
|
+
c: ctx => ({})
|
|
364
|
+
}`);
|
|
365
|
+
});
|
|
366
|
+
it('effectively builds metadata for a context wire', () => {
|
|
367
|
+
const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
|
|
368
|
+
type: common_shared_1.FunctionTypes.WIRE_FUNCTION,
|
|
369
|
+
requiredProperties: [],
|
|
370
|
+
importReference: { functionName: 'CurrentPageReference' },
|
|
371
|
+
}, moduleMetadata);
|
|
372
|
+
expect(astStatements).not.toBeUndefined();
|
|
373
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
374
|
+
const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
|
|
375
|
+
expect(code).toBe(`{
|
|
376
|
+
f: i5,
|
|
377
|
+
fN: "CurrentPageReference",
|
|
378
|
+
t: "WireFunction",
|
|
379
|
+
wt: "cpr",
|
|
380
|
+
c: ctx => ({})
|
|
381
|
+
}`);
|
|
382
|
+
});
|
|
383
|
+
it('effectively builds metadata for a priming adapter wire with neither a batcher or reducer', () => {
|
|
384
|
+
const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
|
|
385
|
+
type: common_shared_1.FunctionTypes.PRIMING_FUNCTION,
|
|
386
|
+
requiredProperties: [],
|
|
387
|
+
importReference: { functionName: 'getRecord' },
|
|
388
|
+
}, moduleMetadata);
|
|
389
|
+
expect(astStatements).not.toBeUndefined();
|
|
390
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
391
|
+
const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
|
|
392
|
+
expect(code).toBe(`{
|
|
393
|
+
f: i2,
|
|
394
|
+
fN: "getRecord",
|
|
395
|
+
t: "PrimingFunction",
|
|
396
|
+
c: ctx => ({})
|
|
397
|
+
}`);
|
|
398
|
+
});
|
|
399
|
+
it('effectively builds metadata for a priming adapter wire without a reducer', () => {
|
|
400
|
+
const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
|
|
401
|
+
type: common_shared_1.FunctionTypes.PRIMING_FUNCTION,
|
|
402
|
+
requiredProperties: [],
|
|
403
|
+
importReference: {
|
|
404
|
+
functionName: 'getRecord',
|
|
405
|
+
batchingName: 'bacth_getRecord',
|
|
406
|
+
},
|
|
407
|
+
}, moduleMetadata);
|
|
408
|
+
expect(astStatements).not.toBeUndefined();
|
|
409
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
410
|
+
const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
|
|
411
|
+
expect(code).toBe(`{
|
|
412
|
+
f: i2,
|
|
413
|
+
fN: "getRecord",
|
|
414
|
+
b: i3,
|
|
415
|
+
bN: "bacth_getRecord",
|
|
416
|
+
t: "PrimingFunction",
|
|
417
|
+
c: ctx => ({})
|
|
418
|
+
}`);
|
|
419
|
+
});
|
|
420
|
+
it('effectively builds metadata for a priming adapter wire', () => {
|
|
421
|
+
const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
|
|
422
|
+
type: common_shared_1.FunctionTypes.PRIMING_FUNCTION,
|
|
423
|
+
requiredProperties: [],
|
|
424
|
+
importReference: {
|
|
425
|
+
functionName: 'getRecord',
|
|
426
|
+
batchingName: 'bacth_getRecord',
|
|
427
|
+
reducer: 'reducer',
|
|
428
|
+
},
|
|
429
|
+
}, moduleMetadata);
|
|
430
|
+
expect(astStatements).not.toBeUndefined();
|
|
431
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
432
|
+
const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
|
|
433
|
+
expect(code).toBe(`{
|
|
434
|
+
f: i2,
|
|
435
|
+
fN: "getRecord",
|
|
436
|
+
b: i3,
|
|
437
|
+
bN: "bacth_getRecord",
|
|
438
|
+
r: i4,
|
|
439
|
+
t: "PrimingFunction",
|
|
440
|
+
c: ctx => ({})
|
|
441
|
+
}`);
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
describe('processErrorFunction', () => {
|
|
445
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
446
|
+
it('should compose ast nodes properly for error function', () => {
|
|
447
|
+
const res = (0, genericAstGeneration_1.processErrorFunction)({
|
|
448
|
+
type: common_shared_1.FunctionTypes.ERROR,
|
|
449
|
+
input: [
|
|
450
|
+
{
|
|
451
|
+
type: 'ObjectValue',
|
|
452
|
+
value: {
|
|
453
|
+
error: {
|
|
454
|
+
type: 'PrimitiveValue',
|
|
455
|
+
value: common_shared_1.ERROR_PREFIX +
|
|
456
|
+
'Something that is not an error was thrown',
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
],
|
|
461
|
+
}, moduleMetadata);
|
|
462
|
+
expect(res).not.toBeUndefined();
|
|
463
|
+
const { code } = (0, generator_1.default)(t.objectExpression(res));
|
|
464
|
+
expect(code).toBe(`{
|
|
465
|
+
t: "ErrorFunction",
|
|
466
|
+
c: {
|
|
467
|
+
"error": "[komaci] Something that is not an error was thrown"
|
|
468
|
+
}
|
|
469
|
+
}`);
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
describe('addImportStatements', () => {
|
|
473
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
474
|
+
(0, common_shared_1.composeImportMetadata)('default', 'lightning/uiTestingApi', true, '0/names/0', moduleMetadata, 'test');
|
|
475
|
+
(0, common_shared_1.composeImportMetadata)('regularImport', 'lightning/uiTestingApi', true, '0/names/1', moduleMetadata);
|
|
476
|
+
(0, common_shared_1.composeImportMetadata)('tes1', 'badImport', false, '1/names/0', moduleMetadata);
|
|
477
|
+
(0, common_shared_1.composeImportMetadata)('tes2', 'badImport', false, '1/names/1', moduleMetadata);
|
|
478
|
+
(0, common_shared_1.composeImportMetadata)('*', '@salesforce/labels', true, '2/names/0', moduleMetadata, 'labels');
|
|
479
|
+
(0, common_shared_1.composeImportMetadata)('tes3', 'lightning/uiRecordApi', true, '3/names/0', moduleMetadata);
|
|
480
|
+
(0, common_shared_1.composeImportMetadata)('tes4', 'lightning/uiRecordApi', true, '3/names/1', moduleMetadata, 'changed');
|
|
481
|
+
(0, common_shared_1.composeImportMetadata)('tes5', 'lightning/uiRecordApi', true, '3/names/2', moduleMetadata);
|
|
482
|
+
(0, common_shared_1.composeImportMetadata)('adg', '@salesforce/komaci/c__foo__foo.js', true, '4/names/0', moduleMetadata);
|
|
483
|
+
moduleMetadata.importsByNamespace.set('lightning/uiTestingApi', {
|
|
484
|
+
names: new Set(['default', 'regularImport']),
|
|
485
|
+
isDefaultSpecifier: true,
|
|
486
|
+
isSupported: true,
|
|
487
|
+
isNamespaceSpecifier: false,
|
|
488
|
+
resourceName: 'lightning/uiTestingApi',
|
|
489
|
+
});
|
|
490
|
+
moduleMetadata.importsByNamespace.set('badImport', {
|
|
491
|
+
names: new Set(['tes1', 'tes2']),
|
|
492
|
+
isDefaultSpecifier: false,
|
|
493
|
+
isSupported: false,
|
|
494
|
+
isNamespaceSpecifier: false,
|
|
495
|
+
resourceName: 'badImport',
|
|
496
|
+
});
|
|
497
|
+
moduleMetadata.importsByNamespace.set('@salesforce/labels', {
|
|
498
|
+
names: new Set(['*']),
|
|
499
|
+
isDefaultSpecifier: false,
|
|
500
|
+
isSupported: true,
|
|
501
|
+
isNamespaceSpecifier: true,
|
|
502
|
+
resourceName: '@salesforce/labels',
|
|
503
|
+
});
|
|
504
|
+
moduleMetadata.importsByNamespace.set('lightning/uiRecordApi', {
|
|
505
|
+
names: new Set(['tes3', 'tes4', 'tes5']),
|
|
506
|
+
isDefaultSpecifier: false,
|
|
507
|
+
isSupported: true,
|
|
508
|
+
isNamespaceSpecifier: false,
|
|
509
|
+
resourceName: 'lightning/uiRecordApi',
|
|
510
|
+
});
|
|
511
|
+
moduleMetadata.importsByNamespace.set('@salesforce/komaci/c__foo__foo.js', {
|
|
512
|
+
names: new Set(['adg']),
|
|
513
|
+
isDefaultSpecifier: false,
|
|
514
|
+
isSupported: true,
|
|
515
|
+
isNamespaceSpecifier: false,
|
|
516
|
+
resourceName: '@salesforce/komaci/c__foo__foo.js',
|
|
517
|
+
});
|
|
518
|
+
// lazy way to say almost all are used in priming
|
|
519
|
+
for (const importMetadata of moduleMetadata.importsByName.values()) {
|
|
520
|
+
importMetadata.usedInPriming =
|
|
521
|
+
importMetadata.name !== 'tes5' && importMetadata.name !== 'tes2';
|
|
522
|
+
}
|
|
523
|
+
const findImportDeclaration = (statements, resourceName) => statements.find((statement) => statement.source.value === resourceName);
|
|
524
|
+
const validateForEachList = (statements, cb) => statements.forEach(cb);
|
|
525
|
+
const scriptModuleOnlyStatements = [];
|
|
526
|
+
const combinedModuleStatements = [];
|
|
527
|
+
(0, genericAstGeneration_1.addImportStatements)(moduleMetadata, scriptModuleOnlyStatements, {
|
|
528
|
+
calledFromGenerateCombinedModule: false,
|
|
529
|
+
});
|
|
530
|
+
(0, genericAstGeneration_1.addImportStatements)(moduleMetadata, combinedModuleStatements, {
|
|
531
|
+
calledFromGenerateCombinedModule: true,
|
|
532
|
+
});
|
|
533
|
+
it('can compose an import with a default and a normal import together', () => {
|
|
534
|
+
validateForEachList([scriptModuleOnlyStatements, combinedModuleStatements], (statements) => {
|
|
535
|
+
const importStatement = findImportDeclaration(statements, 'lightning/uiTestingApi');
|
|
536
|
+
expect(importStatement).not.toBeUndefined();
|
|
537
|
+
expect(importStatement.specifiers).toHaveLength(2);
|
|
538
|
+
expect(importStatement.specifiers[0].type).toBe('ImportDefaultSpecifier');
|
|
539
|
+
expect(importStatement
|
|
540
|
+
.specifiers[0].local.name).toBe(moduleMetadata.importsByName.get('test')?.generatorAlias);
|
|
541
|
+
expect(importStatement.specifiers[1].type).toBe('ImportSpecifier');
|
|
542
|
+
expect(importStatement
|
|
543
|
+
.specifiers[1].local.name).toBe(moduleMetadata.importsByName.get('regularImport')?.generatorAlias);
|
|
544
|
+
expect(importStatement
|
|
545
|
+
.specifiers[1].imported.name).toBe('regularImport');
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
it('will not compose a bad import', () => {
|
|
549
|
+
validateForEachList([scriptModuleOnlyStatements, combinedModuleStatements], (statements) => {
|
|
550
|
+
const importStatement = findImportDeclaration(statements, 'badImport');
|
|
551
|
+
expect(importStatement).toBeUndefined();
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
it('can compose an import with a namespace import', () => {
|
|
555
|
+
validateForEachList([scriptModuleOnlyStatements, combinedModuleStatements], (statements) => {
|
|
556
|
+
const importStatement = findImportDeclaration(statements, '@salesforce/labels');
|
|
557
|
+
expect(importStatement).not.toBeUndefined();
|
|
558
|
+
expect(importStatement.specifiers).toHaveLength(1);
|
|
559
|
+
expect(importStatement.specifiers[0].type).toBe('ImportNamespaceSpecifier');
|
|
560
|
+
expect(importStatement
|
|
561
|
+
.specifiers[0].local.name).toBe(moduleMetadata.importsByName.get('labels')?.generatorAlias);
|
|
562
|
+
});
|
|
563
|
+
});
|
|
564
|
+
it('will leave out an import not used in priming from the composed specifiers', () => {
|
|
565
|
+
validateForEachList([scriptModuleOnlyStatements, combinedModuleStatements], (statements) => {
|
|
566
|
+
const importStatement = findImportDeclaration(statements, 'lightning/uiRecordApi');
|
|
567
|
+
expect(importStatement).not.toBeUndefined();
|
|
568
|
+
expect(importStatement.specifiers).toHaveLength(2);
|
|
569
|
+
expect(importStatement.specifiers[0].type).toBe('ImportSpecifier');
|
|
570
|
+
expect(importStatement
|
|
571
|
+
.specifiers[0].imported.name).toBe('tes3');
|
|
572
|
+
expect(importStatement.specifiers[1].type).toBe('ImportSpecifier');
|
|
573
|
+
expect(importStatement
|
|
574
|
+
.specifiers[1].local.name).toBe(moduleMetadata.importsByName.get('changed')?.generatorAlias);
|
|
575
|
+
expect(importStatement
|
|
576
|
+
.specifiers[1].imported.name).toBe('tes4');
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
it('will lop the last portion of a @salesforce/komaci import off if its a combined module only', () => {
|
|
580
|
+
const scriptImport = findImportDeclaration(scriptModuleOnlyStatements, '@salesforce/komaci/c__foo__foo.js');
|
|
581
|
+
expect(scriptImport).not.toBeUndefined();
|
|
582
|
+
const combinedImport = findImportDeclaration(combinedModuleStatements, '@salesforce/komaci/c__foo');
|
|
583
|
+
expect(combinedImport).not.toBeUndefined();
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
//# sourceMappingURL=genericAstGeneration.spec.js.map
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -20,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
20
24
|
};
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
26
|
const __1 = require("..");
|
|
23
|
-
const modgen = __importStar(require("../
|
|
27
|
+
const modgen = __importStar(require("../genericAstGeneration"));
|
|
24
28
|
describe('Handling errors that throw inside a call to generateKomaciModule', () => {
|
|
25
29
|
it('should return error adg when an error is produced', () => {
|
|
26
30
|
const input = {
|
|
@@ -45,7 +49,7 @@ describe('Handling errors that throw inside a call to generateKomaciModule', ()
|
|
|
45
49
|
' t: "ErrorFunction",\n' +
|
|
46
50
|
' c: {\n' +
|
|
47
51
|
' "error": "[komaci esm-generator] unrecognized input type",\n';
|
|
48
|
-
const expectedModuleSecondHalf = '
|
|
52
|
+
const expectedModuleSecondHalf = ' return [];\n' + ' }, []);\n' + '}';
|
|
49
53
|
const lines = res.split('\n');
|
|
50
54
|
const skipStack = lines.slice(0, 8).join('\n') + '\n';
|
|
51
55
|
const skipStackEnd = lines.slice(lines.length - 3).join('\n');
|
|
@@ -66,7 +70,7 @@ describe('Handling errors that throw inside a call to generateKomaciModule', ()
|
|
|
66
70
|
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
67
71
|
},
|
|
68
72
|
};
|
|
69
|
-
const mock = jest.spyOn(modgen, '
|
|
73
|
+
const mock = jest.spyOn(modgen, 'generateResolvableModule');
|
|
70
74
|
mock.mockImplementationOnce(() => {
|
|
71
75
|
throw 'not an error';
|
|
72
76
|
});
|
|
@@ -78,8 +82,8 @@ describe('Handling errors that throw inside a call to generateKomaciModule', ()
|
|
|
78
82
|
' return adg(undefined, {}, [{\n' +
|
|
79
83
|
' t: "ErrorFunction",\n' +
|
|
80
84
|
' c: {\n' +
|
|
81
|
-
' "error": "[komaci
|
|
82
|
-
const expectedModuleSecondHalf = '
|
|
85
|
+
' "error": "[komaci] Something that is not an error was thrown"\n';
|
|
86
|
+
const expectedModuleSecondHalf = ' return [];\n' + ' }, []);\n' + '}';
|
|
83
87
|
const lines = res.split('\n');
|
|
84
88
|
const skipStack = lines.slice(0, 8).join('\n') + '\n';
|
|
85
89
|
const skipStackEnd = lines.slice(lines.length - 3).join('\n');
|
|
@@ -100,7 +104,7 @@ describe('Handling errors that throw inside a call to generateKomaciModule', ()
|
|
|
100
104
|
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
101
105
|
},
|
|
102
106
|
};
|
|
103
|
-
const mock = jest.spyOn(modgen, '
|
|
107
|
+
const mock = jest.spyOn(modgen, 'generateResolvableModule');
|
|
104
108
|
mock.mockImplementationOnce(() => {
|
|
105
109
|
throw undefined;
|
|
106
110
|
});
|
|
@@ -112,8 +116,8 @@ describe('Handling errors that throw inside a call to generateKomaciModule', ()
|
|
|
112
116
|
' return adg(undefined, {}, [{\n' +
|
|
113
117
|
' t: "ErrorFunction",\n' +
|
|
114
118
|
' c: {\n' +
|
|
115
|
-
' "error": "[komaci
|
|
116
|
-
const expectedModuleSecondHalf = '
|
|
119
|
+
' "error": "[komaci] Something that is not an error was thrown"\n';
|
|
120
|
+
const expectedModuleSecondHalf = ' return [];\n' + ' }, []);\n' + '}';
|
|
117
121
|
const lines = res.split('\n');
|
|
118
122
|
const skipStack = lines.slice(0, 8).join('\n') + '\n';
|
|
119
123
|
const skipStackEnd = lines.slice(lines.length - 3).join('\n');
|