@komaci/esm-generator 240.1.3
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__/compile-generated-module-fixtures.spec.d.ts +2 -0
- package/build/__tests__/compile-generated-module-fixtures.spec.js +45 -0
- package/build/__tests__/fixtures-combined-files/exclude-comps-unused-import-prop/actual.d.ts +5 -0
- package/build/__tests__/fixtures-combined-files/exclude-comps-unused-import-prop/actual.js +28 -0
- package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.d.ts +28 -0
- package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.js +144 -0
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-one/actual.d.ts +8 -0
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-one/actual.js +35 -0
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-two/actual.d.ts +9 -0
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-two/actual.js +39 -0
- package/build/__tests__/fixtures-combined-files/exclude-wire-unused-import-prop/actual.d.ts +6 -0
- package/build/__tests__/fixtures-combined-files/exclude-wire-unused-import-prop/actual.js +34 -0
- package/build/__tests__/fixtures-combined-files/image-type/actual.d.ts +12 -0
- package/build/__tests__/fixtures-combined-files/image-type/actual.js +41 -0
- package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.d.ts +13 -0
- package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.js +75 -0
- package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.d.ts +17 -0
- package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.js +99 -0
- package/build/__tests__/fixtures-combined-files/include-comps-used-import-prop/actual.d.ts +5 -0
- package/build/__tests__/fixtures-combined-files/include-comps-used-import-prop/actual.js +28 -0
- package/build/__tests__/fixtures-combined-files/include-template-strings/actual.d.ts +9 -0
- package/build/__tests__/fixtures-combined-files/include-template-strings/actual.js +41 -0
- package/build/__tests__/fixtures-combined-files/include-used-import-getter/actual.d.ts +8 -0
- package/build/__tests__/fixtures-combined-files/include-used-import-getter/actual.js +38 -0
- package/build/__tests__/fixtures-combined-files/include-wire-used-import-prop/actual.d.ts +6 -0
- package/build/__tests__/fixtures-combined-files/include-wire-used-import-prop/actual.js +34 -0
- package/build/__tests__/fixtures-combined-files/unsupported-wire-from-supported-namespace/actual.d.ts +5 -0
- package/build/__tests__/fixtures-combined-files/unsupported-wire-from-supported-namespace/actual.js +19 -0
- package/build/__tests__/fixtures-script-files/class-extends-multiple-with-separate-imports/actual.d.ts +8 -0
- package/build/__tests__/fixtures-script-files/class-extends-multiple-with-separate-imports/actual.js +17 -0
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports/actual.js +13 -0
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports-alias/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports-alias/actual.js +10 -0
- package/build/__tests__/fixtures-script-files/class-props/actual.d.ts +25 -0
- package/build/__tests__/fixtures-script-files/class-props/actual.js +92 -0
- package/build/__tests__/fixtures-script-files/empty-class/actual.d.ts +3 -0
- package/build/__tests__/fixtures-script-files/empty-class/actual.js +7 -0
- package/build/__tests__/fixtures-script-files/empty-doc/actual.d.ts +1 -0
- package/build/__tests__/fixtures-script-files/empty-doc/actual.js +2 -0
- package/build/__tests__/fixtures-script-files/empty-wire/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/empty-wire/actual.js +16 -0
- package/build/__tests__/fixtures-script-files/exclude-wire-unused-import-prop/actual.d.ts +6 -0
- package/build/__tests__/fixtures-script-files/exclude-wire-unused-import-prop/actual.js +34 -0
- package/build/__tests__/fixtures-script-files/exports/actual.d.ts +21 -0
- package/build/__tests__/fixtures-script-files/exports/actual.js +63 -0
- package/build/__tests__/fixtures-script-files/imports/actual.d.ts +10 -0
- package/build/__tests__/fixtures-script-files/imports/actual.js +76 -0
- package/build/__tests__/fixtures-script-files/imports-namespaced/actual.d.ts +9 -0
- package/build/__tests__/fixtures-script-files/imports-namespaced/actual.js +59 -0
- package/build/__tests__/fixtures-script-files/include-wire-unused-import-prop/actual.d.ts +6 -0
- package/build/__tests__/fixtures-script-files/include-wire-unused-import-prop/actual.js +34 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-default/actual.d.ts +3 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-default/actual.js +10 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-local/actual.d.ts +8 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-local/actual.js +24 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-named/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-named/actual.js +17 -0
- package/build/__tests__/fixtures-script-files/inheritance-parent-unresolved/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/inheritance-parent-unresolved/actual.js +17 -0
- package/build/__tests__/fixtures-script-files/unsupported-wire-from-supported-namespace/actual.d.ts +5 -0
- package/build/__tests__/fixtures-script-files/unsupported-wire-from-supported-namespace/actual.js +19 -0
- package/build/__tests__/fixtures-script-files/wire-basic/actual.d.ts +7 -0
- package/build/__tests__/fixtures-script-files/wire-basic/actual.js +30 -0
- package/build/__tests__/fixtures-script-files/wire-functions/actual.d.ts +12 -0
- package/build/__tests__/fixtures-script-files/wire-functions/actual.js +46 -0
- package/build/__tests__/fixtures-script-files/wire-imports/actual.d.ts +10 -0
- package/build/__tests__/fixtures-script-files/wire-imports/actual.js +59 -0
- package/build/__tests__/fixtures-source-code/badImportRef.d.ts +4 -0
- package/build/__tests__/fixtures-source-code/badImportRef.js +21 -0
- package/build/__tests__/fixtures-source-code/generalMockSourceCode.d.ts +5 -0
- package/build/__tests__/fixtures-source-code/generalMockSourceCode.js +93 -0
- package/build/__tests__/general-komaci-docs/assorted-template-strings/source.d.ts +9 -0
- package/build/__tests__/general-komaci-docs/assorted-template-strings/source.js +41 -0
- package/build/__tests__/general-komaci-docs/getters-and-compositions-collisions/source.d.ts +6 -0
- package/build/__tests__/general-komaci-docs/getters-and-compositions-collisions/source.js +31 -0
- package/build/__tests__/general-komaci-docs/import-types/source.d.ts +18 -0
- package/build/__tests__/general-komaci-docs/import-types/source.js +104 -0
- package/build/__tests__/general-komaci-docs/import-types/validationStuff.d.ts +18 -0
- package/build/__tests__/general-komaci-docs/import-types/validationStuff.js +63 -0
- package/build/__tests__/general-komaci-docs/template-component/source.d.ts +8 -0
- package/build/__tests__/general-komaci-docs/template-component/source.js +34 -0
- package/build/__tests__/index.spec.d.ts +2 -0
- package/build/__tests__/index.spec.js +124 -0
- package/build/__tests__/komaci-ast-unit.spec.d.ts +2 -0
- package/build/__tests__/komaci-ast-unit.spec.js +628 -0
- package/build/__tests__/komaci-bundle-module.fixtures.spec.d.ts +2 -0
- package/build/__tests__/komaci-bundle-module.fixtures.spec.js +75 -0
- package/build/__tests__/komaci-script-module.fixtures.spec.d.ts +2 -0
- package/build/__tests__/komaci-script-module.fixtures.spec.js +66 -0
- package/build/__tests__/komaci-template-module.fixtures.spec.d.ts +2 -0
- package/build/__tests__/komaci-template-module.fixtures.spec.js +56 -0
- package/build/__tests__/modGenScript.spec.d.ts +2 -0
- package/build/__tests__/modGenScript.spec.js +110 -0
- package/build/__tests__/modGenTemplate.spec.d.ts +2 -0
- package/build/__tests__/modGenTemplate.spec.js +196 -0
- package/build/__tests__/shared.spec.d.ts +2 -0
- package/build/__tests__/shared.spec.js +62 -0
- package/build/__tests__/templateStrings.spec.d.ts +2 -0
- package/build/__tests__/templateStrings.spec.js +130 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +130 -0
- package/build/modGenScript.d.ts +38 -0
- package/build/modGenScript.js +1027 -0
- package/build/modGenTemplate.d.ts +37 -0
- package/build/modGenTemplate.js +402 -0
- package/build/shared.d.ts +170 -0
- package/build/shared.js +588 -0
- package/build/types.d.ts +132 -0
- package/build/types.js +14 -0
- package/package.json +40 -0
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const shared_1 = require("../shared");
|
|
7
|
+
const generalMockSourceCode_1 = require("./fixtures-source-code/generalMockSourceCode");
|
|
8
|
+
const modGenScript_1 = require("../modGenScript");
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
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
|
+
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
|
+
const initGeneratorState = (input) => ({
|
|
41
|
+
input,
|
|
42
|
+
adgImportSuffix: 0,
|
|
43
|
+
importAliasSuffix: 0,
|
|
44
|
+
scriptGenState: {
|
|
45
|
+
importRefsMap: {},
|
|
46
|
+
requiredFactoryFunctions: new Set([]),
|
|
47
|
+
importInfosForWireAdapter: new Set([]),
|
|
48
|
+
primingAdapterImportDeclarations: [],
|
|
49
|
+
},
|
|
50
|
+
templateGenState: {
|
|
51
|
+
importRefsMap: {},
|
|
52
|
+
requiredFactoryFunctions: new Set(),
|
|
53
|
+
refProps: new Set(),
|
|
54
|
+
},
|
|
55
|
+
iterationContext: [],
|
|
56
|
+
defaultCompImported: true,
|
|
57
|
+
adgNameMap: {},
|
|
58
|
+
isDefaultExportFound: true,
|
|
59
|
+
});
|
|
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
|
+
describe('getAstFromGenStateRawSrc', () => {
|
|
117
|
+
it('should handle LWC modules with multiple file types and multiple JS files', () => {
|
|
118
|
+
const filesMap = {};
|
|
119
|
+
filesMap['test.js'] = {
|
|
120
|
+
exports: { 'test.js': { type: 'AdgReference', value: 0 } },
|
|
121
|
+
};
|
|
122
|
+
filesMap['test.html'] = {
|
|
123
|
+
exports: { 'test.html': { type: 'CompositionReference', value: 0 } },
|
|
124
|
+
};
|
|
125
|
+
filesMap['test.css'] = {
|
|
126
|
+
exports: { 'test.css': { type: 'CompositionReference', value: 0 } },
|
|
127
|
+
};
|
|
128
|
+
filesMap['somethingElse.js'] = {
|
|
129
|
+
exports: { 'somethingElse.js': { type: 'AdgReference', value: 0 } },
|
|
130
|
+
};
|
|
131
|
+
const input = {
|
|
132
|
+
moduleInfo: {
|
|
133
|
+
name: 'test',
|
|
134
|
+
namespace: 'c',
|
|
135
|
+
type: 'bundle',
|
|
136
|
+
files: filesMap,
|
|
137
|
+
},
|
|
138
|
+
srcFileMap: {
|
|
139
|
+
'test.js': 'console.log("hi");',
|
|
140
|
+
'somethingElse.js': 'eval("bye")',
|
|
141
|
+
'test.css': 'p { text-align: center; }',
|
|
142
|
+
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
const generatorState = initGeneratorState(input);
|
|
146
|
+
const srcCode = (0, shared_1.getComponentSrcJs)(generatorState);
|
|
147
|
+
expect(srcCode).not.toBeUndefined();
|
|
148
|
+
expect(srcCode).toEqual(input.srcFileMap?.['test.js']);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
describe('proccessGetters', () => {
|
|
152
|
+
const filesMap = {};
|
|
153
|
+
filesMap['test.js'] = {
|
|
154
|
+
exports: { 'test.js': { type: 'AdgReference', value: 0 } },
|
|
155
|
+
};
|
|
156
|
+
filesMap['test.html'] = {
|
|
157
|
+
exports: { 'test.html': { type: 'CompositionReference', value: 0 } },
|
|
158
|
+
};
|
|
159
|
+
filesMap['test.css'] = {
|
|
160
|
+
exports: { 'test.css': { type: 'CompositionReference', value: 0 } },
|
|
161
|
+
};
|
|
162
|
+
filesMap['somethingElse.js'] = {
|
|
163
|
+
exports: { 'somethingElse.js': { type: 'AdgReference', value: 0 } },
|
|
164
|
+
};
|
|
165
|
+
it('should process and return only the valid getter', () => {
|
|
166
|
+
const input = {
|
|
167
|
+
moduleInfo: {
|
|
168
|
+
name: 'test',
|
|
169
|
+
namespace: 'lightning',
|
|
170
|
+
type: 'bundle',
|
|
171
|
+
files: filesMap,
|
|
172
|
+
},
|
|
173
|
+
srcFileMap: {
|
|
174
|
+
'test.js': generalMockSourceCode_1.mockOneBadGetter,
|
|
175
|
+
'somethingElse.js': 'eval("bye")',
|
|
176
|
+
'test.css': 'p { text-align: center; }',
|
|
177
|
+
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
const generatorState = initGeneratorState(input);
|
|
181
|
+
const properties = new Map();
|
|
182
|
+
properties.set('searchKey', {
|
|
183
|
+
type: common_shared_1.PropertyTypes.GETTER,
|
|
184
|
+
usedInPriming: true,
|
|
185
|
+
});
|
|
186
|
+
properties.set('perfectlyGood', {
|
|
187
|
+
type: common_shared_1.PropertyTypes.GETTER,
|
|
188
|
+
usedInPriming: true,
|
|
189
|
+
});
|
|
190
|
+
const src = (0, shared_1.getComponentSrcJs)(generatorState);
|
|
191
|
+
const moduleLevelConsumption = {
|
|
192
|
+
consumedImports: new Map(),
|
|
193
|
+
};
|
|
194
|
+
expect(src).not.toBeUndefined();
|
|
195
|
+
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
196
|
+
generatorState.scriptGenState.ast = ast;
|
|
197
|
+
const moduleContext = {
|
|
198
|
+
astContext: (0, common_shared_1.getAstContextObject)(ast),
|
|
199
|
+
isExternal: (0, common_shared_1.isExternalModule)(generatorState.input.moduleInfo.namespace),
|
|
200
|
+
};
|
|
201
|
+
generatorState.scriptGenState.importMetadata =
|
|
202
|
+
moduleContext.astContext.importDeclarations;
|
|
203
|
+
const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
204
|
+
const res = (0, shared_1.processGetters)(properties, moduleContext, moduleLevelConsumption, getters);
|
|
205
|
+
expect(res).not.toBeUndefined();
|
|
206
|
+
expect(res).toHaveLength(1);
|
|
207
|
+
expect(res[0].memberUsage).toHaveLength(1);
|
|
208
|
+
});
|
|
209
|
+
it('should process and return empty array for no valid getters', () => {
|
|
210
|
+
const input = {
|
|
211
|
+
moduleInfo: {
|
|
212
|
+
name: 'test',
|
|
213
|
+
namespace: 'lightning',
|
|
214
|
+
type: 'bundle',
|
|
215
|
+
files: filesMap,
|
|
216
|
+
},
|
|
217
|
+
srcFileMap: {
|
|
218
|
+
'test.js': generalMockSourceCode_1.mockOnlyBadGetter,
|
|
219
|
+
'somethingElse.js': 'eval("bye")',
|
|
220
|
+
'test.css': 'p { text-align: center; }',
|
|
221
|
+
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
const generatorState = initGeneratorState(input);
|
|
225
|
+
const properties = new Map();
|
|
226
|
+
properties.set('searchKey', {
|
|
227
|
+
type: common_shared_1.PropertyTypes.GETTER,
|
|
228
|
+
usedInPriming: true,
|
|
229
|
+
});
|
|
230
|
+
const src = (0, shared_1.getComponentSrcJs)(generatorState);
|
|
231
|
+
const moduleLevelConsumption = {
|
|
232
|
+
consumedImports: new Map(),
|
|
233
|
+
};
|
|
234
|
+
expect(src).not.toBeUndefined();
|
|
235
|
+
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
236
|
+
generatorState.scriptGenState.ast = ast;
|
|
237
|
+
const moduleContext = {
|
|
238
|
+
astContext: (0, common_shared_1.getAstContextObject)(ast),
|
|
239
|
+
isExternal: (0, common_shared_1.isExternalModule)(generatorState.input.moduleInfo.namespace),
|
|
240
|
+
};
|
|
241
|
+
generatorState.scriptGenState.importMetadata =
|
|
242
|
+
moduleContext.astContext.importDeclarations;
|
|
243
|
+
const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
244
|
+
const res = (0, shared_1.processGetters)(properties, moduleContext, moduleLevelConsumption, getters);
|
|
245
|
+
expect(res).not.toBeUndefined();
|
|
246
|
+
expect(res).toHaveLength(0);
|
|
247
|
+
});
|
|
248
|
+
it('should process and return only getter with just return when namespace is not lightning', () => {
|
|
249
|
+
const input = {
|
|
250
|
+
moduleInfo: {
|
|
251
|
+
name: 'test',
|
|
252
|
+
namespace: 'c',
|
|
253
|
+
type: 'bundle',
|
|
254
|
+
files: filesMap,
|
|
255
|
+
},
|
|
256
|
+
srcFileMap: {
|
|
257
|
+
'test.js': generalMockSourceCode_1.oneGoodMockWithGetterImportUse,
|
|
258
|
+
'somethingElse.js': 'eval("bye")',
|
|
259
|
+
'test.css': 'p { text-align: center; }',
|
|
260
|
+
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
const generatorState = initGeneratorState(input);
|
|
264
|
+
const properties = new Map();
|
|
265
|
+
properties.set('searchKey', {
|
|
266
|
+
type: common_shared_1.PropertyTypes.GETTER,
|
|
267
|
+
usedInPriming: true,
|
|
268
|
+
});
|
|
269
|
+
properties.set('perfectlyGood', {
|
|
270
|
+
type: common_shared_1.PropertyTypes.GETTER,
|
|
271
|
+
usedInPriming: true,
|
|
272
|
+
});
|
|
273
|
+
properties.set('perfectlyGood2', {
|
|
274
|
+
type: common_shared_1.PropertyTypes.GETTER,
|
|
275
|
+
usedInPriming: true,
|
|
276
|
+
});
|
|
277
|
+
const src = (0, shared_1.getComponentSrcJs)(generatorState);
|
|
278
|
+
const moduleLevelConsumption = {
|
|
279
|
+
consumedImports: new Map(),
|
|
280
|
+
};
|
|
281
|
+
expect(src).not.toBeUndefined();
|
|
282
|
+
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
283
|
+
generatorState.scriptGenState.ast = ast;
|
|
284
|
+
const moduleContext = {
|
|
285
|
+
astContext: (0, common_shared_1.getAstContextObject)(ast),
|
|
286
|
+
isExternal: (0, common_shared_1.isExternalModule)(generatorState.input.moduleInfo.namespace),
|
|
287
|
+
};
|
|
288
|
+
generatorState.scriptGenState.importMetadata =
|
|
289
|
+
moduleContext.astContext.importDeclarations;
|
|
290
|
+
const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
291
|
+
const res = (0, shared_1.processGetters)(properties, moduleContext, moduleLevelConsumption, getters);
|
|
292
|
+
expect(res).not.toBeUndefined();
|
|
293
|
+
expect(res).toHaveLength(1);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
describe('module generation with getter nodes', () => {
|
|
297
|
+
it('should mutate ast for any valid getters', () => {
|
|
298
|
+
const input = initGeneratorInput();
|
|
299
|
+
// Needed a different Komaci Document for this test. This Komaci Document is generated from k-tester.
|
|
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'), {
|
|
418
|
+
encoding: 'utf-8',
|
|
419
|
+
});
|
|
420
|
+
input.srcFileMap['test.html'] = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.html'), { encoding: 'utf-8' });
|
|
421
|
+
const generatorState = initGeneratorState(input);
|
|
422
|
+
const combinedModuleAST = (0, modGenScript_1.generateCombinedModule)(generatorState, input.moduleInfo.files['test.js'], input.moduleInfo.files['test.html']);
|
|
423
|
+
const resolvableModuleReturn = collectResolutionModuleReturn(combinedModuleAST);
|
|
424
|
+
const adgArgs = collectAdgFunctionArgs(resolvableModuleReturn);
|
|
425
|
+
const functionArgs = adgArgs.functions.elements;
|
|
426
|
+
expect(functionArgs[2].properties[0].key
|
|
427
|
+
.name).toEqual('f');
|
|
428
|
+
expect(functionArgs[2].properties[0].value
|
|
429
|
+
.name).toEqual('g0');
|
|
430
|
+
expect(functionArgs[2].properties[1].key
|
|
431
|
+
.name).toEqual('t');
|
|
432
|
+
expect(functionArgs[2].properties[1].value
|
|
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',
|
|
447
|
+
});
|
|
448
|
+
const generatorState = initGeneratorState(input);
|
|
449
|
+
const combinedModuleAST = (0, modGenScript_1.generateCombinedModule)(generatorState, input.moduleInfo.files['test.js'], input.moduleInfo.files['test.html']);
|
|
450
|
+
expect(combinedModuleAST).not.toBeUndefined();
|
|
451
|
+
validateFunctions(combinedModuleAST, [
|
|
452
|
+
{
|
|
453
|
+
expectedOutput: validationStuff_1.default.functions.functionCallFromNamespacedImport,
|
|
454
|
+
usedImports: ['Foo'],
|
|
455
|
+
compiledName: 'g0',
|
|
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',
|
|
472
|
+
});
|
|
473
|
+
const generatorState = initGeneratorState(input);
|
|
474
|
+
const combinedModuleAST = (0, modGenScript_1.generateCombinedModule)(generatorState, input.moduleInfo.files['test.js'], input.moduleInfo.files['test.html']);
|
|
475
|
+
expect(combinedModuleAST).not.toBeUndefined();
|
|
476
|
+
validateFunctions(combinedModuleAST, [
|
|
477
|
+
{
|
|
478
|
+
expectedOutput: validationStuff_1.default.functions.mixedCallsFromImportsWithMultipleImports,
|
|
479
|
+
usedImports: ['double', 'trouble'],
|
|
480
|
+
compiledName: 'g2',
|
|
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',
|
|
492
|
+
});
|
|
493
|
+
const generatorState = initGeneratorState(input);
|
|
494
|
+
const combinedModuleAST = (0, modGenScript_1.generateCombinedModule)(generatorState, input.moduleInfo.files['test.js'], input.moduleInfo.files['test.html']);
|
|
495
|
+
expect(combinedModuleAST).not.toBeUndefined();
|
|
496
|
+
validateFunctions(combinedModuleAST, [
|
|
497
|
+
{
|
|
498
|
+
expectedOutput: validationStuff_1.default.functions.callFromImportWithOnlySpecificImport,
|
|
499
|
+
usedImports: ['Bar'],
|
|
500
|
+
compiledName: 'g3',
|
|
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',
|
|
517
|
+
});
|
|
518
|
+
const generatorState = initGeneratorState(input);
|
|
519
|
+
const combinedModuleAST = (0, modGenScript_1.generateCombinedModule)(generatorState, input.moduleInfo.files['test.js'], input.moduleInfo.files['test.html']);
|
|
520
|
+
expect(combinedModuleAST).not.toBeUndefined();
|
|
521
|
+
validateFunctions(combinedModuleAST, [
|
|
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',
|
|
537
|
+
});
|
|
538
|
+
const generatorState = initGeneratorState(input);
|
|
539
|
+
const combinedModuleAST = (0, modGenScript_1.generateCombinedModule)(generatorState, input.moduleInfo.files['test.js'], input.moduleInfo.files['test.html']);
|
|
540
|
+
expect(combinedModuleAST).not.toBeUndefined();
|
|
541
|
+
validateFunctions(combinedModuleAST, [
|
|
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',
|
|
557
|
+
});
|
|
558
|
+
const generatorState = initGeneratorState(input);
|
|
559
|
+
const combinedModuleAST = (0, modGenScript_1.generateCombinedModule)(generatorState, input.moduleInfo.files['test.js'], input.moduleInfo.files['test.html']);
|
|
560
|
+
expect(combinedModuleAST).not.toBeUndefined();
|
|
561
|
+
validateFunctions(combinedModuleAST, [
|
|
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);
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
describe('komaciDoc variations', () => {
|
|
587
|
+
it('handles null exports', () => {
|
|
588
|
+
const input = initGeneratorInput();
|
|
589
|
+
input.moduleInfo.files = Object.fromEntries(Object.entries(input.moduleInfo.files).map(([key, val]) => {
|
|
590
|
+
const { exports = {} } = val;
|
|
591
|
+
const newExports = Object.fromEntries(Object.entries(exports).map(([key]) => {
|
|
592
|
+
return [key, null];
|
|
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',
|
|
609
|
+
});
|
|
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
|
+
const moduleContext = {
|
|
617
|
+
astContext: (0, common_shared_1.getAstContextObject)(ast),
|
|
618
|
+
isExternal: (0, common_shared_1.isExternalModule)('lightning'),
|
|
619
|
+
};
|
|
620
|
+
const validTemplates = (0, shared_1.processTemplateStrings)(properties, moduleContext, moduleLevelConsumption, templateStrings);
|
|
621
|
+
expect(validTemplates).toHaveLength(1);
|
|
622
|
+
expect(validTemplates[0].generatedName).toBe('t0');
|
|
623
|
+
expect(validTemplates[0].template.node.key.name).toBe('contractId');
|
|
624
|
+
expect(validTemplates[0].memberUsage).toHaveLength(1);
|
|
625
|
+
expect(validTemplates[0].memberUsage).toContain('recordId');
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
//# sourceMappingURL=komaci-ast-unit.spec.js.map
|