@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
|
@@ -1,42 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
3
|
+
const componentAstProcessing_1 = require("../componentAstProcessing");
|
|
7
4
|
const generalMockSourceCode_1 = require("./fixtures-source-code/generalMockSourceCode");
|
|
8
|
-
const modGenScript_1 = require("../modGenScript");
|
|
9
5
|
const fs_1 = require("fs");
|
|
10
6
|
const path_1 = require("path");
|
|
11
|
-
const core_1 = require("@babel/core");
|
|
12
|
-
const validationStuff_1 = __importDefault(require("./general-komaci-docs/import-types/validationStuff"));
|
|
13
|
-
const generator_1 = __importDefault(require("@babel/generator"));
|
|
14
7
|
const common_shared_1 = require("@komaci/common-shared");
|
|
15
|
-
const initGeneratorInput = () => {
|
|
16
|
-
const filesMap = {};
|
|
17
|
-
filesMap['test.js'] = {
|
|
18
|
-
exports: { 'test.js': { type: 'AdgReference', value: 0 } },
|
|
19
|
-
};
|
|
20
|
-
filesMap['test.html'] = {
|
|
21
|
-
exports: { 'test.html': { type: 'CompositionReference', value: 0 } },
|
|
22
|
-
};
|
|
23
|
-
filesMap['test.css'] = {
|
|
24
|
-
exports: { 'test.css': { type: 'CompositionReference', value: 0 } },
|
|
25
|
-
};
|
|
26
|
-
return {
|
|
27
|
-
moduleInfo: {
|
|
28
|
-
name: 'test',
|
|
29
|
-
namespace: 'lightning',
|
|
30
|
-
type: 'bundle',
|
|
31
|
-
files: filesMap,
|
|
32
|
-
},
|
|
33
|
-
srcFileMap: {
|
|
34
|
-
'test.js': 'console.log("hi");',
|
|
35
|
-
'test.css': 'p { text-align: center; }',
|
|
36
|
-
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
8
|
const initGeneratorState = (input) => ({
|
|
41
9
|
input,
|
|
42
10
|
adgImportSuffix: 0,
|
|
@@ -57,62 +25,6 @@ const initGeneratorState = (input) => ({
|
|
|
57
25
|
adgNameMap: {},
|
|
58
26
|
isDefaultExportFound: true,
|
|
59
27
|
});
|
|
60
|
-
const collectResolutionModuleReturn = (ast) => {
|
|
61
|
-
const program = ast.program;
|
|
62
|
-
const body = program.body;
|
|
63
|
-
const defaultExport = body.filter((dec) => dec.type === 'ExportDefaultDeclaration')[0];
|
|
64
|
-
const defExp_declaration = defaultExport.declaration;
|
|
65
|
-
return defExp_declaration.body.body.filter((stmt) => stmt.type === 'ReturnStatement')[0];
|
|
66
|
-
};
|
|
67
|
-
const collectAdgFunctionArgs = (resolvableModuleReturn) => {
|
|
68
|
-
const adgFunctionArgs = resolvableModuleReturn.argument
|
|
69
|
-
.arguments;
|
|
70
|
-
expect(adgFunctionArgs).not.toBeUndefined();
|
|
71
|
-
expect(adgFunctionArgs).toHaveLength(5);
|
|
72
|
-
return {
|
|
73
|
-
parent: adgFunctionArgs[0],
|
|
74
|
-
properties: adgFunctionArgs[1],
|
|
75
|
-
functions: adgFunctionArgs[2],
|
|
76
|
-
composition: adgFunctionArgs[3],
|
|
77
|
-
childDependencies: adgFunctionArgs[4],
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
const collectModuleLevelFunctionDeclaration = (ast) => {
|
|
81
|
-
const body = ast?.program.body;
|
|
82
|
-
expect(body).not.toBeUndefined();
|
|
83
|
-
return body?.filter((statement) => statement.type === 'FunctionDeclaration');
|
|
84
|
-
};
|
|
85
|
-
const validateFunctions = (ast, functions) => {
|
|
86
|
-
const visitors = {
|
|
87
|
-
FunctionDeclaration: (path) => {
|
|
88
|
-
if (path.node.id) {
|
|
89
|
-
const functionInfo = functions.find((f) => f.compiledName === path.node.id.name);
|
|
90
|
-
if (functionInfo) {
|
|
91
|
-
path.traverse(validateImportInflation(functionInfo.usedImports));
|
|
92
|
-
const composedFunction = (0, generator_1.default)(path.node).code;
|
|
93
|
-
expect(composedFunction).toBe(functionInfo.expectedOutput);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
(0, core_1.traverse)(ast, visitors);
|
|
99
|
-
};
|
|
100
|
-
const validateImportInflation = (invalidKeys) => ({
|
|
101
|
-
Identifier(path) {
|
|
102
|
-
if ((path.parent.type === 'MemberExpression' &&
|
|
103
|
-
path.parent.object === path.node) ||
|
|
104
|
-
(path.parent.type === 'CallExpression' && path.parent.callee == path.node) ||
|
|
105
|
-
(path.parent.type !== 'CallExpression' &&
|
|
106
|
-
path.parent.type !== 'MemberExpression')) {
|
|
107
|
-
expect(invalidKeys.includes(path.node.name)).toBeFalsy();
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
const validateImport = (ast, resourcePath, expected) => {
|
|
112
|
-
const importNode = ast.program.body.find((item) => item.type === 'ImportDeclaration' && item.source.value === resourcePath);
|
|
113
|
-
expect(importNode).not.toBeUndefined();
|
|
114
|
-
expect((0, generator_1.default)(importNode).code).toBe(expected);
|
|
115
|
-
};
|
|
116
28
|
describe('getAstFromGenStateRawSrc', () => {
|
|
117
29
|
it('should handle LWC modules with multiple file types and multiple JS files', () => {
|
|
118
30
|
const filesMap = {};
|
|
@@ -142,8 +54,7 @@ describe('getAstFromGenStateRawSrc', () => {
|
|
|
142
54
|
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
143
55
|
},
|
|
144
56
|
};
|
|
145
|
-
const
|
|
146
|
-
const srcCode = (0, shared_1.getComponentSrcJs)(generatorState);
|
|
57
|
+
const srcCode = (0, componentAstProcessing_1.getComponentSrcJs)(input);
|
|
147
58
|
expect(srcCode).not.toBeUndefined();
|
|
148
59
|
expect(srcCode).toEqual(input.srcFileMap?.['test.js']);
|
|
149
60
|
});
|
|
@@ -178,19 +89,55 @@ describe('proccessGetters', () => {
|
|
|
178
89
|
},
|
|
179
90
|
};
|
|
180
91
|
const generatorState = initGeneratorState(input);
|
|
181
|
-
const
|
|
182
|
-
|
|
92
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
93
|
+
moduleMetadata.adgs.set(0, (0, common_shared_1.initAdgMetadataObject)('adg0'));
|
|
94
|
+
moduleMetadata.importsByName.set('getRecord', {
|
|
95
|
+
generatorAlias: 'i0',
|
|
96
|
+
usedInPriming: false,
|
|
97
|
+
staticallyAnalyzable: false,
|
|
98
|
+
name: 'getRecord',
|
|
99
|
+
resourceName: 'lightning/uiRecordApi',
|
|
100
|
+
isFromInternalNamespace: true,
|
|
101
|
+
isFromSupportedLibrary: true,
|
|
102
|
+
komaciDocImportRef: '0/names/0',
|
|
103
|
+
});
|
|
104
|
+
moduleMetadata.importsByName.set('findContacts', {
|
|
105
|
+
generatorAlias: 'i1',
|
|
106
|
+
usedInPriming: false,
|
|
107
|
+
staticallyAnalyzable: false,
|
|
108
|
+
name: '*',
|
|
109
|
+
resourceName: 'lightning/uiRecordApi',
|
|
110
|
+
isFromInternalNamespace: true,
|
|
111
|
+
isFromSupportedLibrary: true,
|
|
112
|
+
komaciDocImportRef: '0/names/0',
|
|
113
|
+
importAlias: 'findContacts',
|
|
114
|
+
});
|
|
115
|
+
moduleMetadata.adgs.get(0).properties.set('recordId', {
|
|
116
|
+
type: common_shared_1.PropertyTypes.BASE,
|
|
117
|
+
isPublic: true,
|
|
118
|
+
usedInPriming: true,
|
|
119
|
+
});
|
|
120
|
+
moduleMetadata.adgs.get(0).properties.set('record', {
|
|
121
|
+
type: common_shared_1.PropertyTypes.WIRE,
|
|
122
|
+
isPublic: false,
|
|
123
|
+
usedInPriming: true,
|
|
124
|
+
});
|
|
125
|
+
moduleMetadata.adgs.get(0).properties.set('contacts', {
|
|
126
|
+
type: common_shared_1.PropertyTypes.WIRE,
|
|
127
|
+
isPublic: false,
|
|
128
|
+
usedInPriming: true,
|
|
129
|
+
});
|
|
130
|
+
moduleMetadata.adgs.get(0).properties.set('searchKey', {
|
|
183
131
|
type: common_shared_1.PropertyTypes.GETTER,
|
|
132
|
+
isPublic: false,
|
|
184
133
|
usedInPriming: true,
|
|
185
134
|
});
|
|
186
|
-
properties.set('perfectlyGood', {
|
|
135
|
+
moduleMetadata.adgs.get(0).properties.set('perfectlyGood', {
|
|
187
136
|
type: common_shared_1.PropertyTypes.GETTER,
|
|
137
|
+
isPublic: false,
|
|
188
138
|
usedInPriming: true,
|
|
189
139
|
});
|
|
190
|
-
const src = (0,
|
|
191
|
-
const moduleLevelConsumption = {
|
|
192
|
-
consumedImports: new Map(),
|
|
193
|
-
};
|
|
140
|
+
const src = (0, componentAstProcessing_1.getComponentSrcJs)(input);
|
|
194
141
|
expect(src).not.toBeUndefined();
|
|
195
142
|
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
196
143
|
generatorState.scriptGenState.ast = ast;
|
|
@@ -198,13 +145,12 @@ describe('proccessGetters', () => {
|
|
|
198
145
|
astContext: (0, common_shared_1.getAstContextObject)(ast),
|
|
199
146
|
isExternal: (0, common_shared_1.isExternalModule)(generatorState.input.moduleInfo.namespace),
|
|
200
147
|
};
|
|
201
|
-
generatorState.scriptGenState.importMetadata =
|
|
202
|
-
moduleContext.astContext.importDeclarations;
|
|
203
148
|
const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
149
|
+
(0, componentAstProcessing_1.processGetters)(0, moduleContext, moduleMetadata, getters);
|
|
150
|
+
const prop = moduleMetadata.adgs
|
|
151
|
+
.get(0)
|
|
152
|
+
.properties.get('perfectlyGood');
|
|
153
|
+
expect(prop?.functionIndex).not.toBeUndefined();
|
|
208
154
|
});
|
|
209
155
|
it('should process and return empty array for no valid getters', () => {
|
|
210
156
|
const input = {
|
|
@@ -222,15 +168,50 @@ describe('proccessGetters', () => {
|
|
|
222
168
|
},
|
|
223
169
|
};
|
|
224
170
|
const generatorState = initGeneratorState(input);
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
171
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
172
|
+
moduleMetadata.adgs.set(0, (0, common_shared_1.initAdgMetadataObject)('adg0'));
|
|
173
|
+
moduleMetadata.importsByName.set('getRecord', {
|
|
174
|
+
generatorAlias: 'i0',
|
|
175
|
+
usedInPriming: false,
|
|
176
|
+
staticallyAnalyzable: false,
|
|
177
|
+
name: 'getRecord',
|
|
178
|
+
resourceName: 'lightning/uiRecordApi',
|
|
179
|
+
isFromInternalNamespace: true,
|
|
180
|
+
isFromSupportedLibrary: true,
|
|
181
|
+
komaciDocImportRef: '0/names/0',
|
|
182
|
+
});
|
|
183
|
+
moduleMetadata.importsByName.set('findContacts', {
|
|
184
|
+
generatorAlias: 'i1',
|
|
185
|
+
usedInPriming: false,
|
|
186
|
+
staticallyAnalyzable: false,
|
|
187
|
+
name: '*',
|
|
188
|
+
resourceName: 'lightning/uiRecordApi',
|
|
189
|
+
isFromInternalNamespace: true,
|
|
190
|
+
isFromSupportedLibrary: true,
|
|
191
|
+
komaciDocImportRef: '0/names/0',
|
|
192
|
+
importAlias: 'findContacts',
|
|
193
|
+
});
|
|
194
|
+
moduleMetadata.adgs.get(0).properties.set('recordId', {
|
|
195
|
+
type: common_shared_1.PropertyTypes.BASE,
|
|
196
|
+
isPublic: true,
|
|
228
197
|
usedInPriming: true,
|
|
229
198
|
});
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
199
|
+
moduleMetadata.adgs.get(0).properties.set('record', {
|
|
200
|
+
type: common_shared_1.PropertyTypes.WIRE,
|
|
201
|
+
isPublic: false,
|
|
202
|
+
usedInPriming: true,
|
|
203
|
+
});
|
|
204
|
+
moduleMetadata.adgs.get(0).properties.set('contacts', {
|
|
205
|
+
type: common_shared_1.PropertyTypes.WIRE,
|
|
206
|
+
isPublic: false,
|
|
207
|
+
usedInPriming: true,
|
|
208
|
+
});
|
|
209
|
+
moduleMetadata.adgs.get(0).properties.set('searchKey', {
|
|
210
|
+
type: common_shared_1.PropertyTypes.BASE,
|
|
211
|
+
isPublic: false,
|
|
212
|
+
usedInPriming: false,
|
|
213
|
+
});
|
|
214
|
+
const src = (0, componentAstProcessing_1.getComponentSrcJs)(input);
|
|
234
215
|
expect(src).not.toBeUndefined();
|
|
235
216
|
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
236
217
|
generatorState.scriptGenState.ast = ast;
|
|
@@ -238,12 +219,13 @@ describe('proccessGetters', () => {
|
|
|
238
219
|
astContext: (0, common_shared_1.getAstContextObject)(ast),
|
|
239
220
|
isExternal: (0, common_shared_1.isExternalModule)(generatorState.input.moduleInfo.namespace),
|
|
240
221
|
};
|
|
241
|
-
generatorState.scriptGenState.importMetadata =
|
|
242
|
-
moduleContext.astContext.importDeclarations;
|
|
243
222
|
const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
223
|
+
(0, componentAstProcessing_1.processGetters)(0, moduleContext, moduleMetadata, getters);
|
|
224
|
+
const prop = moduleMetadata.adgs
|
|
225
|
+
.get(0)
|
|
226
|
+
.properties.get('searchKey');
|
|
227
|
+
expect(prop?.functionIndex).toBe(common_shared_1.UNSUPPORTED_FUNCTION);
|
|
228
|
+
expect(prop?.type).toBe(common_shared_1.PropertyTypes.GETTER);
|
|
247
229
|
});
|
|
248
230
|
it('should process and return only getter with just return when namespace is not lightning', () => {
|
|
249
231
|
const input = {
|
|
@@ -261,23 +243,60 @@ describe('proccessGetters', () => {
|
|
|
261
243
|
},
|
|
262
244
|
};
|
|
263
245
|
const generatorState = initGeneratorState(input);
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
246
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
247
|
+
moduleMetadata.adgs.set(0, (0, common_shared_1.initAdgMetadataObject)('adg0'));
|
|
248
|
+
moduleMetadata.importsByName.set('getRecord', {
|
|
249
|
+
generatorAlias: 'i0',
|
|
250
|
+
usedInPriming: false,
|
|
251
|
+
staticallyAnalyzable: false,
|
|
252
|
+
name: 'getRecord',
|
|
253
|
+
resourceName: 'lightning/uiRecordApi',
|
|
254
|
+
isFromInternalNamespace: true,
|
|
255
|
+
isFromSupportedLibrary: true,
|
|
256
|
+
komaciDocImportRef: '0/names/0',
|
|
257
|
+
});
|
|
258
|
+
moduleMetadata.importsByName.set('findContacts', {
|
|
259
|
+
generatorAlias: 'i1',
|
|
260
|
+
usedInPriming: false,
|
|
261
|
+
staticallyAnalyzable: false,
|
|
262
|
+
name: '*',
|
|
263
|
+
resourceName: 'lightning/uiRecordApi',
|
|
264
|
+
isFromInternalNamespace: true,
|
|
265
|
+
isFromSupportedLibrary: true,
|
|
266
|
+
komaciDocImportRef: '0/names/0',
|
|
267
|
+
importAlias: 'findContacts',
|
|
268
|
+
});
|
|
269
|
+
moduleMetadata.adgs.get(0).properties.set('recordId', {
|
|
270
|
+
type: common_shared_1.PropertyTypes.BASE,
|
|
271
|
+
isPublic: true,
|
|
267
272
|
usedInPriming: true,
|
|
268
273
|
});
|
|
269
|
-
properties.set('
|
|
270
|
-
type: common_shared_1.PropertyTypes.
|
|
274
|
+
moduleMetadata.adgs.get(0).properties.set('record', {
|
|
275
|
+
type: common_shared_1.PropertyTypes.WIRE,
|
|
276
|
+
isPublic: false,
|
|
271
277
|
usedInPriming: true,
|
|
272
278
|
});
|
|
273
|
-
properties.set('
|
|
274
|
-
type: common_shared_1.PropertyTypes.
|
|
279
|
+
moduleMetadata.adgs.get(0).properties.set('contacts', {
|
|
280
|
+
type: common_shared_1.PropertyTypes.WIRE,
|
|
281
|
+
isPublic: false,
|
|
275
282
|
usedInPriming: true,
|
|
276
283
|
});
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
284
|
+
moduleMetadata.adgs.get(0).properties.set('searchKey', {
|
|
285
|
+
type: common_shared_1.PropertyTypes.BASE,
|
|
286
|
+
isPublic: false,
|
|
287
|
+
usedInPriming: true,
|
|
288
|
+
});
|
|
289
|
+
moduleMetadata.adgs.get(0).properties.set('perfectlyGood', {
|
|
290
|
+
type: common_shared_1.PropertyTypes.BASE,
|
|
291
|
+
isPublic: false,
|
|
292
|
+
usedInPriming: true,
|
|
293
|
+
});
|
|
294
|
+
moduleMetadata.adgs.get(0).properties.set('perfectlyGood2', {
|
|
295
|
+
type: common_shared_1.PropertyTypes.BASE,
|
|
296
|
+
isPublic: false,
|
|
297
|
+
usedInPriming: true,
|
|
298
|
+
});
|
|
299
|
+
const src = (0, componentAstProcessing_1.getComponentSrcJs)(input);
|
|
281
300
|
expect(src).not.toBeUndefined();
|
|
282
301
|
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
283
302
|
generatorState.scriptGenState.ast = ast;
|
|
@@ -285,344 +304,117 @@ describe('proccessGetters', () => {
|
|
|
285
304
|
astContext: (0, common_shared_1.getAstContextObject)(ast),
|
|
286
305
|
isExternal: (0, common_shared_1.isExternalModule)(generatorState.input.moduleInfo.namespace),
|
|
287
306
|
};
|
|
288
|
-
generatorState.scriptGenState.importMetadata =
|
|
289
|
-
moduleContext.astContext.importDeclarations;
|
|
290
307
|
const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
308
|
+
(0, componentAstProcessing_1.processGetters)(0, moduleContext, moduleMetadata, getters);
|
|
309
|
+
let prop = moduleMetadata.adgs
|
|
310
|
+
.get(0)
|
|
311
|
+
.properties.get('searchKey');
|
|
312
|
+
expect(prop?.functionIndex).toBe(common_shared_1.UNSUPPORTED_FUNCTION);
|
|
313
|
+
expect(prop?.type).toBe(common_shared_1.PropertyTypes.GETTER);
|
|
314
|
+
prop = moduleMetadata.adgs
|
|
315
|
+
.get(0)
|
|
316
|
+
.properties.get('perfectlyGood');
|
|
317
|
+
expect(prop?.functionIndex).toBe(common_shared_1.UNSUPPORTED_FUNCTION);
|
|
318
|
+
expect(prop?.type).toBe(common_shared_1.PropertyTypes.GETTER);
|
|
319
|
+
prop = moduleMetadata.adgs
|
|
320
|
+
.get(0)
|
|
321
|
+
.properties.get('perfectlyGood2');
|
|
322
|
+
expect(prop?.functionIndex).not.toBeUndefined();
|
|
323
|
+
expect(prop?.type).toBe(common_shared_1.PropertyTypes.GETTER);
|
|
294
324
|
});
|
|
295
325
|
});
|
|
296
|
-
describe('
|
|
297
|
-
it('
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
// Modified the quoting so it can be introduced in code as a JavaScript object
|
|
301
|
-
input.moduleInfo.files['test.js'] = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, 'general-komaci-docs/two-good-getters/script-komaci-doc.json'), { encoding: 'utf-8' }));
|
|
302
|
-
input.srcFileMap['test.js'] = generalMockSourceCode_1.oneGoodMockWithGetterImportUse;
|
|
303
|
-
const generatorState = initGeneratorState(input);
|
|
304
|
-
// generateCombinedModule() calls transformGetters() for us
|
|
305
|
-
const combinedModuleAST = (0, modGenScript_1.generateCombinedModule)(generatorState, input.moduleInfo.files['test.js'], input.moduleInfo.files['test.html']);
|
|
306
|
-
const functionDeclArray = collectModuleLevelFunctionDeclaration(combinedModuleAST);
|
|
307
|
-
expect(functionDeclArray).toHaveLength(2);
|
|
308
|
-
// check that getter method `perfectlyGood` was hoisted to top level
|
|
309
|
-
// functions get generated names. so perfectlyGood should be g0
|
|
310
|
-
expect(functionDeclArray[0].id?.name).toEqual('g0');
|
|
311
|
-
const inputParam = functionDeclArray[0].params[0];
|
|
312
|
-
// check that the `props` parameter was added as input parameter to the newly-hoisted getter method
|
|
313
|
-
expect(inputParam.name).toEqual('props');
|
|
314
|
-
expect(functionDeclArray[0].body.body).toHaveLength(2);
|
|
315
|
-
const variableDeclaration = functionDeclArray[0].body
|
|
316
|
-
.body[0];
|
|
317
|
-
const variableDeclarator = variableDeclaration
|
|
318
|
-
.declarations[0];
|
|
319
|
-
const optionalMemberExpression1 = variableDeclarator.init;
|
|
320
|
-
const optionalMemberExpression2 = optionalMemberExpression1.object;
|
|
321
|
-
const optionalMemberExpression3 = optionalMemberExpression2.object;
|
|
322
|
-
const ctxMemberExpression = optionalMemberExpression3.object;
|
|
323
|
-
const identifier = ctxMemberExpression.object;
|
|
324
|
-
const recordProp = ctxMemberExpression.property;
|
|
325
|
-
// check that instances of `this.<var>` in the getter where changed to `props.<var>`
|
|
326
|
-
expect(identifier.name).toEqual('props');
|
|
327
|
-
expect(recordProp.name).toEqual('record');
|
|
328
|
-
// check that Import referenced in getter has been converted to local name
|
|
329
|
-
const returnStmt = functionDeclArray[0].body
|
|
330
|
-
.body[1];
|
|
331
|
-
const returnStmtArgument = returnStmt.argument;
|
|
332
|
-
expect(returnStmtArgument.name).toEqual('i1');
|
|
333
|
-
// check that getter method `perfectlyGood2` was hoisted to top level
|
|
334
|
-
// since we process names perfectlyGood2 should map to g1
|
|
335
|
-
expect(functionDeclArray[1].id?.name).toEqual('g1');
|
|
336
|
-
// check that Import referenced in getter has been converted to local name
|
|
337
|
-
const returnStmt2 = functionDeclArray[1].body
|
|
338
|
-
.body[0];
|
|
339
|
-
const returnStmtArgument2 = returnStmt2.argument;
|
|
340
|
-
expect(returnStmtArgument2.name).toEqual('i2');
|
|
341
|
-
});
|
|
342
|
-
it('should not mutate ast for empty program', () => {
|
|
343
|
-
const input = initGeneratorInput();
|
|
344
|
-
input.moduleInfo.files['test.js'] = {};
|
|
345
|
-
input.srcFileMap['test.js'] = generalMockSourceCode_1.emptyProgram;
|
|
346
|
-
const generatorState = initGeneratorState(input);
|
|
347
|
-
// generateCombinedModule() calls transformGetters() for us
|
|
348
|
-
const combinedModuleAST = (0, modGenScript_1.generateCombinedModule)(generatorState, input.moduleInfo.files['test.js'], input.moduleInfo.files['test.html']);
|
|
349
|
-
const body = combinedModuleAST?.program.body;
|
|
350
|
-
expect(body).not.toBeUndefined();
|
|
351
|
-
expect(body).toHaveLength(1);
|
|
352
|
-
expect(body[0].type).toBe('ExportNamedDeclaration');
|
|
353
|
-
});
|
|
354
|
-
it('should mutate the komaci document to include getter nodes.', () => {
|
|
355
|
-
const input = initGeneratorInput();
|
|
356
|
-
input.moduleInfo.files['test.js'] = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, 'general-komaci-docs/two-good-getters/script-komaci-doc.json'), { encoding: 'utf-8' }));
|
|
357
|
-
input.srcFileMap['test.js'] = generalMockSourceCode_1.oneGoodMockWithGetterImportUse;
|
|
358
|
-
const generatorState = initGeneratorState(input);
|
|
359
|
-
//generateCombinedModule() calls transformGetters() for us
|
|
360
|
-
(0, modGenScript_1.generateCombinedModule)(generatorState, input.moduleInfo.files['test.js'], input.moduleInfo.files['test.html']);
|
|
361
|
-
const mutatedKomaciDoc = input.moduleInfo.files['test.js'];
|
|
362
|
-
expect(mutatedKomaciDoc.adgs).not.toBeUndefined();
|
|
363
|
-
expect(mutatedKomaciDoc.adgs?.[0].properties).not.toBeUndefined();
|
|
364
|
-
expect(Object.keys(mutatedKomaciDoc.adgs?.[0].properties)).toHaveLength(6);
|
|
365
|
-
expect(mutatedKomaciDoc.adgs?.[0].properties?.perfectlyGood.input?.type).toEqual('FunctionReference');
|
|
366
|
-
expect(mutatedKomaciDoc.adgs?.[0].properties?.perfectlyGood.input?.value).toEqual(2);
|
|
367
|
-
expect(mutatedKomaciDoc.adgs?.[0].properties?.perfectlyGood2.input?.type).toEqual('FunctionReference');
|
|
368
|
-
expect(mutatedKomaciDoc.adgs?.[0].properties?.perfectlyGood2.input?.value).toEqual(3);
|
|
369
|
-
expect(mutatedKomaciDoc.adgs?.[0].functions).not.toBeUndefined();
|
|
370
|
-
expect(mutatedKomaciDoc.adgs?.[0].functions).toHaveLength(4);
|
|
371
|
-
expect(mutatedKomaciDoc.adgs?.[0].functions?.[2].type).toEqual('GetterFunction');
|
|
372
|
-
expect(mutatedKomaciDoc.adgs?.[0].functions?.[2].reference.type).toEqual('InternalReference');
|
|
373
|
-
expect(mutatedKomaciDoc.adgs?.[0].functions?.[2].reference.value).toEqual('g0');
|
|
374
|
-
const inputArr = mutatedKomaciDoc.adgs?.[0].functions?.[2]
|
|
375
|
-
.input?.[0];
|
|
376
|
-
expect(inputArr.value[0].value).toEqual('record');
|
|
377
|
-
expect(mutatedKomaciDoc.adgs?.[0].functions?.[3].type).toEqual('GetterFunction');
|
|
378
|
-
expect(mutatedKomaciDoc.adgs?.[0].functions?.[3].reference.type).toEqual('InternalReference');
|
|
379
|
-
expect(mutatedKomaciDoc.adgs?.[0].functions?.[3].reference.value).toEqual('g1');
|
|
380
|
-
});
|
|
381
|
-
it('should build komaci module with getter nodes', () => {
|
|
382
|
-
const input = initGeneratorInput();
|
|
383
|
-
input.moduleInfo.files['test.js'] = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, 'general-komaci-docs/two-good-getters/script-komaci-doc.json'), { encoding: 'utf-8' }));
|
|
384
|
-
input.srcFileMap['test.js'] = generalMockSourceCode_1.oneGoodMockWithGetterImportUse;
|
|
385
|
-
const generatorState = initGeneratorState(input);
|
|
386
|
-
//generateCombinedModule() calls transformGetters() for us
|
|
387
|
-
const combinedModuleAST = (0, modGenScript_1.generateCombinedModule)(generatorState, input.moduleInfo.files['test.js'], input.moduleInfo.files['test.html']);
|
|
388
|
-
const resolvableModuleReturn = collectResolutionModuleReturn(combinedModuleAST);
|
|
389
|
-
const adgArgs = collectAdgFunctionArgs(resolvableModuleReturn);
|
|
390
|
-
const functionArgs = adgArgs.functions.elements;
|
|
391
|
-
expect(functionArgs[2].properties).toHaveLength(3);
|
|
392
|
-
expect(functionArgs[3].properties).toHaveLength(3);
|
|
393
|
-
expect(functionArgs[2].properties[0].key
|
|
394
|
-
.name).toEqual('f');
|
|
395
|
-
expect(functionArgs[2].properties[0].value
|
|
396
|
-
.name).toEqual('g0');
|
|
397
|
-
expect(functionArgs[2].properties[1].key
|
|
398
|
-
.name).toEqual('t');
|
|
399
|
-
expect(functionArgs[2].properties[1].value
|
|
400
|
-
.value).toEqual('GetterFunction');
|
|
401
|
-
expect(functionArgs[2].properties[2].key
|
|
402
|
-
.name).toEqual('in');
|
|
403
|
-
expect(functionArgs[2].properties[2]
|
|
404
|
-
.value.elements).toHaveLength(1);
|
|
405
|
-
expect(functionArgs[2].properties[2]
|
|
406
|
-
.value.elements[0].value).toEqual('record');
|
|
407
|
-
});
|
|
408
|
-
it('should be able to build a komaci module without colliding with standard internal function names like cg', () => {
|
|
409
|
-
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/getters-and-compositions-collisions');
|
|
410
|
-
const input = initGeneratorInput();
|
|
411
|
-
input.moduleInfo.files['test.js'] = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'script-komaci-doc.json'), {
|
|
412
|
-
encoding: 'utf-8',
|
|
413
|
-
}));
|
|
414
|
-
input.moduleInfo.files['test.html'] = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'html-komaci-doc.json'), {
|
|
415
|
-
encoding: 'utf-8',
|
|
416
|
-
}));
|
|
417
|
-
input.srcFileMap['test.js'] = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
|
|
326
|
+
describe('processTemplateStrings', () => {
|
|
327
|
+
it('can process out bad templates and successfully update metadata', () => {
|
|
328
|
+
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/template-component');
|
|
329
|
+
const src = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
|
|
418
330
|
encoding: 'utf-8',
|
|
419
331
|
});
|
|
420
|
-
|
|
421
|
-
const
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
.value).toEqual('GetterFunction');
|
|
434
|
-
expect(functionArgs[2].properties[2].key
|
|
435
|
-
.name).toEqual('in');
|
|
436
|
-
expect(functionArgs[2].properties[2]
|
|
437
|
-
.value.elements).toHaveLength(0);
|
|
438
|
-
});
|
|
439
|
-
it('can effectively process namespaced imports in functions', () => {
|
|
440
|
-
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/import-types');
|
|
441
|
-
const input = initGeneratorInput();
|
|
442
|
-
input.moduleInfo.files['test.js'] = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'script-komaci-doc.json'), {
|
|
443
|
-
encoding: 'utf-8',
|
|
444
|
-
}));
|
|
445
|
-
input.srcFileMap['test.js'] = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
|
|
446
|
-
encoding: 'utf-8',
|
|
332
|
+
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
333
|
+
const { templateStrings } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
334
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
335
|
+
moduleMetadata.adgs.set(0, (0, common_shared_1.initAdgMetadataObject)('adg0'));
|
|
336
|
+
moduleMetadata.importsByName.set('getRecord', {
|
|
337
|
+
generatorAlias: 'i0',
|
|
338
|
+
usedInPriming: false,
|
|
339
|
+
staticallyAnalyzable: false,
|
|
340
|
+
name: 'getRecord',
|
|
341
|
+
resourceName: 'lightning/uiRecordApi',
|
|
342
|
+
isFromInternalNamespace: true,
|
|
343
|
+
isFromSupportedLibrary: true,
|
|
344
|
+
komaciDocImportRef: '0/names/0',
|
|
447
345
|
});
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
{
|
|
458
|
-
expectedOutput: validationStuff_1.default.functions.mutlipleCallsFromNamespacedImport,
|
|
459
|
-
usedImports: ['Foo'],
|
|
460
|
-
compiledName: 'g1',
|
|
461
|
-
},
|
|
462
|
-
]);
|
|
463
|
-
});
|
|
464
|
-
it('can effectively process regular and default imports in functions', () => {
|
|
465
|
-
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/import-types');
|
|
466
|
-
const input = initGeneratorInput();
|
|
467
|
-
input.moduleInfo.files['test.js'] = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'script-komaci-doc.json'), {
|
|
468
|
-
encoding: 'utf-8',
|
|
469
|
-
}));
|
|
470
|
-
input.srcFileMap['test.js'] = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
|
|
471
|
-
encoding: 'utf-8',
|
|
346
|
+
moduleMetadata.importsByName.set('gql', {
|
|
347
|
+
generatorAlias: 'i0',
|
|
348
|
+
usedInPriming: false,
|
|
349
|
+
staticallyAnalyzable: false,
|
|
350
|
+
name: 'gql',
|
|
351
|
+
resourceName: 'lightning/graphql',
|
|
352
|
+
isFromInternalNamespace: true,
|
|
353
|
+
isFromSupportedLibrary: true,
|
|
354
|
+
komaciDocImportRef: '0/names/0',
|
|
472
355
|
});
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
});
|
|
484
|
-
it('can effectively process just default imports in functions', () => {
|
|
485
|
-
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/import-types');
|
|
486
|
-
const input = initGeneratorInput();
|
|
487
|
-
input.moduleInfo.files['test.js'] = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'script-komaci-doc.json'), {
|
|
488
|
-
encoding: 'utf-8',
|
|
489
|
-
}));
|
|
490
|
-
input.srcFileMap['test.js'] = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
|
|
491
|
-
encoding: 'utf-8',
|
|
356
|
+
moduleMetadata.importsByName.set('LABEL', {
|
|
357
|
+
generatorAlias: 'i0',
|
|
358
|
+
usedInPriming: false,
|
|
359
|
+
staticallyAnalyzable: false,
|
|
360
|
+
name: '*',
|
|
361
|
+
resourceName: '@salesforce/label/crazycool',
|
|
362
|
+
isFromInternalNamespace: true,
|
|
363
|
+
isFromSupportedLibrary: true,
|
|
364
|
+
komaciDocImportRef: '0/names/0',
|
|
365
|
+
importAlias: 'LABEL',
|
|
492
366
|
});
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
expectedOutput: validationStuff_1.default.functions.callFromDefault,
|
|
504
|
-
usedImports: ['baz'],
|
|
505
|
-
compiledName: 'g5',
|
|
506
|
-
},
|
|
507
|
-
]);
|
|
508
|
-
});
|
|
509
|
-
it('can effectively process aliased imports in functions', () => {
|
|
510
|
-
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/import-types');
|
|
511
|
-
const input = initGeneratorInput();
|
|
512
|
-
input.moduleInfo.files['test.js'] = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'script-komaci-doc.json'), {
|
|
513
|
-
encoding: 'utf-8',
|
|
514
|
-
}));
|
|
515
|
-
input.srcFileMap['test.js'] = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
|
|
516
|
-
encoding: 'utf-8',
|
|
367
|
+
moduleMetadata.importsByName.set('unusable', {
|
|
368
|
+
generatorAlias: 'i0',
|
|
369
|
+
usedInPriming: false,
|
|
370
|
+
staticallyAnalyzable: false,
|
|
371
|
+
name: '*',
|
|
372
|
+
resourceName: 'bad/import',
|
|
373
|
+
isFromInternalNamespace: false,
|
|
374
|
+
isFromSupportedLibrary: false,
|
|
375
|
+
komaciDocImportRef: '0/names/0',
|
|
376
|
+
importAlias: 'unusable',
|
|
517
377
|
});
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
{
|
|
523
|
-
expectedOutput: validationStuff_1.default.functions.callFromAlias,
|
|
524
|
-
usedImports: ['ulteriorMotive'],
|
|
525
|
-
compiledName: 'g4',
|
|
526
|
-
},
|
|
527
|
-
]);
|
|
528
|
-
});
|
|
529
|
-
it('can effectively process a mix of imports in functions', () => {
|
|
530
|
-
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/import-types');
|
|
531
|
-
const input = initGeneratorInput();
|
|
532
|
-
input.moduleInfo.files['test.js'] = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'script-komaci-doc.json'), {
|
|
533
|
-
encoding: 'utf-8',
|
|
534
|
-
}));
|
|
535
|
-
input.srcFileMap['test.js'] = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
|
|
536
|
-
encoding: 'utf-8',
|
|
378
|
+
moduleMetadata.adgs.get(0).properties.set('recordId', {
|
|
379
|
+
type: common_shared_1.PropertyTypes.BASE,
|
|
380
|
+
isPublic: true,
|
|
381
|
+
usedInPriming: true,
|
|
537
382
|
});
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
{
|
|
543
|
-
expectedOutput: validationStuff_1.default.functions.smorgasbord,
|
|
544
|
-
usedImports: ['Foo', 'baz', 'trouble', 'double', 'ulteriorMotive'],
|
|
545
|
-
compiledName: 'g6',
|
|
546
|
-
},
|
|
547
|
-
]);
|
|
548
|
-
});
|
|
549
|
-
it('can correctly process properties share same names with imports', () => {
|
|
550
|
-
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/import-types');
|
|
551
|
-
const input = initGeneratorInput();
|
|
552
|
-
input.moduleInfo.files['test.js'] = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'script-komaci-doc.json'), {
|
|
553
|
-
encoding: 'utf-8',
|
|
554
|
-
}));
|
|
555
|
-
input.srcFileMap['test.js'] = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
|
|
556
|
-
encoding: 'utf-8',
|
|
383
|
+
moduleMetadata.adgs.get(0).properties.set('contract', {
|
|
384
|
+
type: common_shared_1.PropertyTypes.WIRE,
|
|
385
|
+
isPublic: false,
|
|
386
|
+
usedInPriming: true,
|
|
557
387
|
});
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
{
|
|
563
|
-
expectedOutput: validationStuff_1.default.functions.samePropNames,
|
|
564
|
-
usedImports: [],
|
|
565
|
-
compiledName: 'g7',
|
|
566
|
-
},
|
|
567
|
-
]);
|
|
568
|
-
});
|
|
569
|
-
for (const type of Object.keys(validationStuff_1.default.imports)) {
|
|
570
|
-
it('can compose a ' + type + ' import as expected', () => {
|
|
571
|
-
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/import-types');
|
|
572
|
-
const input = initGeneratorInput();
|
|
573
|
-
input.moduleInfo.files['test.js'] = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'script-komaci-doc.json'), {
|
|
574
|
-
encoding: 'utf-8',
|
|
575
|
-
}));
|
|
576
|
-
input.srcFileMap['test.js'] = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
|
|
577
|
-
encoding: 'utf-8',
|
|
578
|
-
});
|
|
579
|
-
const generatorState = initGeneratorState(input);
|
|
580
|
-
const combinedModuleAST = (0, modGenScript_1.generateCombinedModule)(generatorState, input.moduleInfo.files['test.js'], input.moduleInfo.files['test.html']);
|
|
581
|
-
expect(combinedModuleAST).not.toBeUndefined();
|
|
582
|
-
validateImport(combinedModuleAST, validationStuff_1.default.imports[type].resourceName, validationStuff_1.default.imports[type].output);
|
|
388
|
+
moduleMetadata.adgs.get(0).properties.set('account', {
|
|
389
|
+
type: common_shared_1.PropertyTypes.WIRE,
|
|
390
|
+
isPublic: false,
|
|
391
|
+
usedInPriming: true,
|
|
583
392
|
});
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
}));
|
|
594
|
-
return [key, { ...val, exports: newExports }];
|
|
595
|
-
}));
|
|
596
|
-
const generatorState = initGeneratorState(input);
|
|
597
|
-
const combinedModuleAST = (0, modGenScript_1.generateCombinedModule)(generatorState, input.moduleInfo.files['test.js'], input.moduleInfo.files['test.html']);
|
|
598
|
-
expect(combinedModuleAST).not.toBeUndefined();
|
|
599
|
-
});
|
|
600
|
-
});
|
|
601
|
-
describe('processTemplateStrings', () => {
|
|
602
|
-
it('can process out bad templates and successfully update metadata', () => {
|
|
603
|
-
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/template-component');
|
|
604
|
-
const komaciDoc = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'script-komaci-doc.json'), {
|
|
605
|
-
encoding: 'utf-8',
|
|
606
|
-
}));
|
|
607
|
-
const src = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
|
|
608
|
-
encoding: 'utf-8',
|
|
393
|
+
moduleMetadata.adgs.get(0).properties.set('contractId', {
|
|
394
|
+
type: common_shared_1.PropertyTypes.TEMPLATE_STRING,
|
|
395
|
+
isPublic: false,
|
|
396
|
+
usedInPriming: true,
|
|
397
|
+
});
|
|
398
|
+
moduleMetadata.adgs.get(0).properties.set('malicious', {
|
|
399
|
+
type: common_shared_1.PropertyTypes.BASE,
|
|
400
|
+
isPublic: false,
|
|
401
|
+
usedInPriming: true,
|
|
609
402
|
});
|
|
610
|
-
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
611
|
-
const { templateStrings } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
612
|
-
const properties = (0, common_shared_1.collectPropertyMetadataFromScriptDoc)(komaciDoc);
|
|
613
|
-
const moduleLevelConsumption = {
|
|
614
|
-
consumedImports: new Map(),
|
|
615
|
-
};
|
|
616
403
|
const moduleContext = {
|
|
617
404
|
astContext: (0, common_shared_1.getAstContextObject)(ast),
|
|
618
405
|
isExternal: (0, common_shared_1.isExternalModule)('lightning'),
|
|
619
406
|
};
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
expect(
|
|
625
|
-
expect(
|
|
407
|
+
(0, componentAstProcessing_1.processTemplateStrings)(0, moduleContext, moduleMetadata, templateStrings);
|
|
408
|
+
const validTemplate = moduleMetadata.adgs
|
|
409
|
+
.get(0)
|
|
410
|
+
.properties.get('contractId');
|
|
411
|
+
expect(validTemplate).not.toBeUndefined();
|
|
412
|
+
expect(validTemplate.functionIndex).toBe(0);
|
|
413
|
+
const templateFunction = moduleMetadata.adgs.get(0).functions[validTemplate.functionIndex];
|
|
414
|
+
expect(templateFunction.generatedName).toBe('t0');
|
|
415
|
+
expect(templateFunction.componentAstNode?.node.key.name).toBe('contractId');
|
|
416
|
+
expect(templateFunction.requiredProperties).toHaveLength(1);
|
|
417
|
+
expect(templateFunction.requiredProperties).toContain('recordId');
|
|
626
418
|
});
|
|
627
419
|
});
|
|
628
420
|
//# sourceMappingURL=komaci-ast-unit.spec.js.map
|