@komaci/esm-generator 264.4.0 → 266.3.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.
Files changed (130) hide show
  1. package/build/genericAstGeneration.js +80 -34
  2. package/package.json +1 -1
  3. package/build/__tests__/adgAstGeneration.spec.d.ts +0 -2
  4. package/build/__tests__/adgAstGeneration.spec.js +0 -447
  5. package/build/__tests__/compile-generated-module-fixtures.spec.d.ts +0 -2
  6. package/build/__tests__/compile-generated-module-fixtures.spec.js +0 -49
  7. package/build/__tests__/compilerConfigs.d.ts +0 -24
  8. package/build/__tests__/compilerConfigs.js +0 -126
  9. package/build/__tests__/compositionAstGeneration.spec.d.ts +0 -2
  10. package/build/__tests__/compositionAstGeneration.spec.js +0 -676
  11. package/build/__tests__/fixtures-combined-files/exclude-comps-unused-import-prop/actual.d.ts +0 -6
  12. package/build/__tests__/fixtures-combined-files/exclude-comps-unused-import-prop/actual.js +0 -28
  13. package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.d.ts +0 -29
  14. package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.js +0 -148
  15. package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-one/actual.d.ts +0 -9
  16. package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-one/actual.js +0 -35
  17. package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-two/actual.d.ts +0 -10
  18. package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-two/actual.js +0 -39
  19. package/build/__tests__/fixtures-combined-files/exclude-wire-unused-import-prop/actual.d.ts +0 -7
  20. package/build/__tests__/fixtures-combined-files/exclude-wire-unused-import-prop/actual.js +0 -34
  21. package/build/__tests__/fixtures-combined-files/image-type/actual.d.ts +0 -13
  22. package/build/__tests__/fixtures-combined-files/image-type/actual.js +0 -41
  23. package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.d.ts +0 -14
  24. package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.js +0 -79
  25. package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.d.ts +0 -18
  26. package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.js +0 -103
  27. package/build/__tests__/fixtures-combined-files/include-comps-used-import-prop/actual.d.ts +0 -6
  28. package/build/__tests__/fixtures-combined-files/include-comps-used-import-prop/actual.js +0 -28
  29. package/build/__tests__/fixtures-combined-files/include-salesforce-resourceUrl-imports/actual.d.ts +0 -6
  30. package/build/__tests__/fixtures-combined-files/include-salesforce-resourceUrl-imports/actual.js +0 -16
  31. package/build/__tests__/fixtures-combined-files/include-salesforce-resourceUrl-nonAnalyzable-imports/actual.d.ts +0 -4
  32. package/build/__tests__/fixtures-combined-files/include-salesforce-resourceUrl-nonAnalyzable-imports/actual.js +0 -18
  33. package/build/__tests__/fixtures-combined-files/include-template-strings/actual.d.ts +0 -10
  34. package/build/__tests__/fixtures-combined-files/include-template-strings/actual.js +0 -41
  35. package/build/__tests__/fixtures-combined-files/include-used-import-getter/actual.d.ts +0 -9
  36. package/build/__tests__/fixtures-combined-files/include-used-import-getter/actual.js +0 -38
  37. package/build/__tests__/fixtures-combined-files/include-wire-used-import-prop/actual.d.ts +0 -7
  38. package/build/__tests__/fixtures-combined-files/include-wire-used-import-prop/actual.js +0 -34
  39. package/build/__tests__/fixtures-combined-files/only-named-export-with-template/actual.d.ts +0 -1
  40. package/build/__tests__/fixtures-combined-files/only-named-export-with-template/actual.js +0 -2
  41. package/build/__tests__/fixtures-combined-files/unsupported-wire-from-supported-namespace/actual.d.ts +0 -6
  42. package/build/__tests__/fixtures-combined-files/unsupported-wire-from-supported-namespace/actual.js +0 -19
  43. package/build/__tests__/fixtures-combined-files-multiple-templates/invalid-renderFunc-no-valid-imports/c/component/component.d.ts +0 -5
  44. package/build/__tests__/fixtures-combined-files-multiple-templates/invalid-renderFunc-no-valid-imports/c/component/component.js +0 -14
  45. package/build/__tests__/fixtures-combined-files-multiple-templates/valid-render-function-complex/lightning/component/component.d.ts +0 -6
  46. package/build/__tests__/fixtures-combined-files-multiple-templates/valid-render-function-complex/lightning/component/component.js +0 -31
  47. package/build/__tests__/fixtures-combined-files-multiple-templates/valid-render-function-simple/lightning/component/component.d.ts +0 -6
  48. package/build/__tests__/fixtures-combined-files-multiple-templates/valid-render-function-simple/lightning/component/component.js +0 -27
  49. package/build/__tests__/fixtures-gql/multipleGqlQueries/c/component/component.d.ts +0 -15
  50. package/build/__tests__/fixtures-gql/multipleGqlQueries/c/component/component.js +0 -104
  51. package/build/__tests__/fixtures-script-files/class-extends-multiple-with-separate-imports/actual.d.ts +0 -8
  52. package/build/__tests__/fixtures-script-files/class-extends-multiple-with-separate-imports/actual.js +0 -17
  53. package/build/__tests__/fixtures-script-files/class-extends-separate-imports/actual.d.ts +0 -4
  54. package/build/__tests__/fixtures-script-files/class-extends-separate-imports/actual.js +0 -13
  55. package/build/__tests__/fixtures-script-files/class-extends-separate-imports-alias/actual.d.ts +0 -4
  56. package/build/__tests__/fixtures-script-files/class-extends-separate-imports-alias/actual.js +0 -10
  57. package/build/__tests__/fixtures-script-files/class-props/actual.d.ts +0 -30
  58. package/build/__tests__/fixtures-script-files/class-props/actual.js +0 -103
  59. package/build/__tests__/fixtures-script-files/empty-class/actual.d.ts +0 -4
  60. package/build/__tests__/fixtures-script-files/empty-class/actual.js +0 -7
  61. package/build/__tests__/fixtures-script-files/empty-doc/actual.d.ts +0 -1
  62. package/build/__tests__/fixtures-script-files/empty-doc/actual.js +0 -2
  63. package/build/__tests__/fixtures-script-files/empty-wire/actual.d.ts +0 -5
  64. package/build/__tests__/fixtures-script-files/empty-wire/actual.js +0 -16
  65. package/build/__tests__/fixtures-script-files/exclude-wire-unused-import-prop/actual.d.ts +0 -7
  66. package/build/__tests__/fixtures-script-files/exclude-wire-unused-import-prop/actual.js +0 -34
  67. package/build/__tests__/fixtures-script-files/exports/actual.d.ts +0 -22
  68. package/build/__tests__/fixtures-script-files/exports/actual.js +0 -63
  69. package/build/__tests__/fixtures-script-files/imports/actual.d.ts +0 -11
  70. package/build/__tests__/fixtures-script-files/imports/actual.js +0 -80
  71. package/build/__tests__/fixtures-script-files/imports-namespaced/actual.d.ts +0 -10
  72. package/build/__tests__/fixtures-script-files/imports-namespaced/actual.js +0 -63
  73. package/build/__tests__/fixtures-script-files/include-wire-unused-import-prop/actual.d.ts +0 -7
  74. package/build/__tests__/fixtures-script-files/include-wire-unused-import-prop/actual.js +0 -34
  75. package/build/__tests__/fixtures-script-files/inheritance-imports-default/actual.d.ts +0 -3
  76. package/build/__tests__/fixtures-script-files/inheritance-imports-default/actual.js +0 -10
  77. package/build/__tests__/fixtures-script-files/inheritance-imports-local/actual.d.ts +0 -9
  78. package/build/__tests__/fixtures-script-files/inheritance-imports-local/actual.js +0 -24
  79. package/build/__tests__/fixtures-script-files/inheritance-imports-named/actual.d.ts +0 -4
  80. package/build/__tests__/fixtures-script-files/inheritance-imports-named/actual.js +0 -17
  81. package/build/__tests__/fixtures-script-files/inheritance-parent-unresolved/actual.d.ts +0 -4
  82. package/build/__tests__/fixtures-script-files/inheritance-parent-unresolved/actual.js +0 -17
  83. package/build/__tests__/fixtures-script-files/unsupported-wire-from-supported-namespace/actual.d.ts +0 -6
  84. package/build/__tests__/fixtures-script-files/unsupported-wire-from-supported-namespace/actual.js +0 -19
  85. package/build/__tests__/fixtures-script-files/wire-basic/actual.d.ts +0 -8
  86. package/build/__tests__/fixtures-script-files/wire-basic/actual.js +0 -30
  87. package/build/__tests__/fixtures-script-files/wire-functions/actual.d.ts +0 -13
  88. package/build/__tests__/fixtures-script-files/wire-functions/actual.js +0 -46
  89. package/build/__tests__/fixtures-script-files/wire-imports/actual.d.ts +0 -11
  90. package/build/__tests__/fixtures-script-files/wire-imports/actual.js +0 -63
  91. package/build/__tests__/fixtures-source-code/badImportRef.d.ts +0 -4
  92. package/build/__tests__/fixtures-source-code/badImportRef.js +0 -31
  93. package/build/__tests__/fixtures-source-code/generalMockSourceCode.d.ts +0 -8
  94. package/build/__tests__/fixtures-source-code/generalMockSourceCode.js +0 -127
  95. package/build/__tests__/fixtures-source-code/gqlMockSource.d.ts +0 -3
  96. package/build/__tests__/fixtures-source-code/gqlMockSource.js +0 -95
  97. package/build/__tests__/functionAstGeneration.spec.d.ts +0 -2
  98. package/build/__tests__/functionAstGeneration.spec.js +0 -727
  99. package/build/__tests__/general-komaci-docs/assorted-template-strings/source.d.ts +0 -10
  100. package/build/__tests__/general-komaci-docs/assorted-template-strings/source.js +0 -41
  101. package/build/__tests__/general-komaci-docs/getters-and-compositions-collisions/source.d.ts +0 -7
  102. package/build/__tests__/general-komaci-docs/getters-and-compositions-collisions/source.js +0 -31
  103. package/build/__tests__/general-komaci-docs/import-types/source.d.ts +0 -18
  104. package/build/__tests__/general-komaci-docs/import-types/source.js +0 -108
  105. package/build/__tests__/general-komaci-docs/import-types/validationStuff.d.ts +0 -18
  106. package/build/__tests__/general-komaci-docs/import-types/validationStuff.js +0 -63
  107. package/build/__tests__/general-komaci-docs/template-component/source.d.ts +0 -8
  108. package/build/__tests__/general-komaci-docs/template-component/source.js +0 -34
  109. package/build/__tests__/generated-module/compile-graphql-with-scoped-import.spec.d.ts +0 -2
  110. package/build/__tests__/generated-module/compile-graphql-with-scoped-import.spec.js +0 -20
  111. package/build/__tests__/generated-module/lightning/component/component.d.ts +0 -18
  112. package/build/__tests__/generated-module/lightning/component/component.js +0 -168
  113. package/build/__tests__/genericAstGeneration.spec.d.ts +0 -2
  114. package/build/__tests__/genericAstGeneration.spec.js +0 -1052
  115. package/build/__tests__/index.spec.d.ts +0 -2
  116. package/build/__tests__/index.spec.js +0 -393
  117. package/build/__tests__/komaci-ast-unit.spec.d.ts +0 -2
  118. package/build/__tests__/komaci-ast-unit.spec.js +0 -422
  119. package/build/__tests__/komaci-bundle-module.fixtures.spec.d.ts +0 -2
  120. package/build/__tests__/komaci-bundle-module.fixtures.spec.js +0 -76
  121. package/build/__tests__/komaci-bundle-multiple-templates-module.fixtures.spec.d.ts +0 -2
  122. package/build/__tests__/komaci-bundle-multiple-templates-module.fixtures.spec.js +0 -117
  123. package/build/__tests__/komaci-gql.fixtures.spec.d.ts +0 -2
  124. package/build/__tests__/komaci-gql.fixtures.spec.js +0 -51
  125. package/build/__tests__/komaci-script-module.fixtures.spec.d.ts +0 -2
  126. package/build/__tests__/komaci-script-module.fixtures.spec.js +0 -70
  127. package/build/__tests__/komaci-template-module.fixtures.spec.d.ts +0 -2
  128. package/build/__tests__/komaci-template-module.fixtures.spec.js +0 -57
  129. package/build/__tests__/readAndParseBundle.d.ts +0 -22
  130. package/build/__tests__/readAndParseBundle.js +0 -80
@@ -1,1052 +0,0 @@
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
- /**
34
- * A function to validate all adgs against to make sure we are doing the bare minimum stuff
35
- * @param adgs list of all adgs
36
- */
37
- const confirmBaselineAdgExpectations = (adgs, extraValidation) => {
38
- for (const adg of adgs) {
39
- expect(adg.requiredAdgFactoryFunctions.has(common_shared_1.IdKeys.ADG_FUNC)).toBeTruthy();
40
- if (extraValidation) {
41
- extraValidation(adg);
42
- }
43
- }
44
- };
45
- describe('valueToExpression', () => {
46
- it('composes proper statement for complex object. Includes ObjectValue, ArrayValue, PropertyReference, and Primitive Value', () => {
47
- const wireFunctionObject = {
48
- type: 'ObjectValue',
49
- value: {
50
- fields: {
51
- type: 'ArrayValue',
52
- value: [
53
- { type: 'PrimitiveValue', value: 'Account.Id' },
54
- { type: 'PrimitiveValue', value: 'Account.Name' },
55
- { type: 'PrimitiveValue', value: 'Account.CreatedById' },
56
- { type: 'PrimitiveValue', value: 'Account.CreatedDate' },
57
- { type: 'PrimitiveValue', value: 'Account.OwnerId' },
58
- { type: 'PrimitiveValue', value: 'Account.ParentId' },
59
- ],
60
- },
61
- recordId: { type: 'PropertyReference', value: 'recordId' },
62
- },
63
- };
64
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
65
- const result = (0, genericAstGeneration_1.valueToExpression)(wireFunctionObject, moduleMetadata);
66
- expect(result).not.toBeUndefined();
67
- expect(result.properties).toHaveLength(2);
68
- const objExprProperties = result.properties;
69
- expect(objExprProperties[0].key.value).toEqual('fields');
70
- expect(objExprProperties[0].value.elements).toHaveLength(6);
71
- expect(objExprProperties[0].value
72
- .elements[0].value).toEqual('Account.Id');
73
- expect(objExprProperties[0].value
74
- .elements[1].value).toEqual('Account.Name');
75
- expect(objExprProperties[0].value
76
- .elements[2].value).toEqual('Account.CreatedById');
77
- expect(objExprProperties[0].value
78
- .elements[3].value).toEqual('Account.CreatedDate');
79
- expect(objExprProperties[0].value
80
- .elements[4].value).toEqual('Account.OwnerId');
81
- expect(objExprProperties[0].value
82
- .elements[5].value).toEqual('Account.ParentId');
83
- expect(objExprProperties[1].key.value).toEqual('recordId');
84
- expect(objExprProperties[1].value
85
- .property.name).toEqual('recordId');
86
- });
87
- it('composes proper statement when komaci value is an importReference', () => {
88
- const komaciValue = {
89
- type: 'ImportReference',
90
- value: '0/names/0',
91
- namespacedMember: 'p1',
92
- };
93
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
94
- const komaciDoc = {
95
- imports: [
96
- { resourceName: 'force/shared', names: ['*'] },
97
- { resourceName: 'laf/transformWire', names: ['*'] },
98
- { resourceName: 'lightning/uiRecordApi', names: ['getRecord'] },
99
- ],
100
- };
101
- (0, common_shared_1.initializeImportMetdataFromKomaciDocument)(komaciDoc, moduleMetadata);
102
- const result = (0, genericAstGeneration_1.valueToExpression)(komaciValue, moduleMetadata);
103
- expect(result).not.toBeUndefined();
104
- expect(result.object.name).toEqual('i0');
105
- expect(result.property.name).toEqual('p1');
106
- });
107
- it('composes proper statement when komaci value is an unsupported importReference', () => {
108
- const komaciValue = {
109
- type: 'ImportReference',
110
- value: '0/names/0',
111
- namespacedMember: 'p1',
112
- };
113
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
114
- const komaciDoc = {
115
- imports: [
116
- { resourceName: 'unsuported/shared', names: ['*'] },
117
- { resourceName: 'laf/transformWire', names: ['*'] },
118
- { resourceName: 'lightning/uiRecordApi', names: ['getRecord'] },
119
- ],
120
- };
121
- (0, common_shared_1.initializeImportMetdataFromKomaciDocument)(komaciDoc, moduleMetadata);
122
- const result = (0, genericAstGeneration_1.valueToExpression)(komaciValue, moduleMetadata);
123
- expect(result).not.toBeUndefined();
124
- expect(result.type).toBe('Identifier');
125
- expect(result.name).toBe('unresolved');
126
- });
127
- it('marks invalid import reference as unresolved', () => {
128
- const komaciValue = {
129
- type: 'ImportReference',
130
- value: '7/names/0',
131
- namespacedMember: 'p1',
132
- };
133
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
134
- const komaciDoc = {
135
- imports: [
136
- { resourceName: 'unsuported/shared', names: ['*'] },
137
- { resourceName: 'laf/transformWire', names: ['*'] },
138
- { resourceName: 'lightning/uiRecordApi', names: ['getRecord'] },
139
- ],
140
- };
141
- (0, common_shared_1.initializeImportMetdataFromKomaciDocument)(komaciDoc, moduleMetadata);
142
- const result = (0, genericAstGeneration_1.valueToExpression)(komaciValue, moduleMetadata);
143
- expect(result).not.toBeUndefined();
144
- expect(result.type).toBe('Identifier');
145
- expect(result.name).toBe('unresolved');
146
- });
147
- });
148
- describe('functionToExpression', () => {
149
- it('composes proper object expression for a valid getter function', () => {
150
- //need to make a hoistedGetterFunction object
151
- // module metadata based on komaci document.
152
- const functionMeta = {
153
- type: common_shared_1.FunctionTypes.GETTER_FUNCTION,
154
- componentAstNode: undefined,
155
- requiredProperties: ['tempProp'],
156
- generatedName: `g${0}`,
157
- };
158
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
159
- const result = (0, genericAstGeneration_1.functionToExpression)(moduleMetadata, functionMeta);
160
- expect(result).not.toBeUndefined();
161
- expect(result?.type).toEqual('ObjectExpression');
162
- expect(result?.properties).toHaveLength(3);
163
- const properties = result?.properties;
164
- expect(properties[0].key.name).toEqual('f');
165
- expect(properties[0].value.name).toEqual('g0');
166
- expect(properties[1].key.name).toEqual('t');
167
- expect(properties[1].value.value).toEqual('GetterFunction');
168
- expect(properties[2].key.name).toEqual('in');
169
- expect(properties[2].value.elements).toHaveLength(1);
170
- });
171
- it('composes proper object expression for a valid template string', () => {
172
- //need to make a hoistedGetterFunction object
173
- // module metadata based on komaci document.
174
- const functionMeta = {
175
- type: common_shared_1.FunctionTypes.TEMPLATE_STRING,
176
- componentAstNode: undefined,
177
- requiredProperties: ['tempProp'],
178
- generatedName: `t${0}`,
179
- };
180
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
181
- const result = (0, genericAstGeneration_1.functionToExpression)(moduleMetadata, functionMeta);
182
- expect(result).not.toBeUndefined();
183
- expect(result?.type).toEqual('ObjectExpression');
184
- expect(result?.properties).toHaveLength(3);
185
- const properties = result?.properties;
186
- expect(properties[0].key.name).toEqual('f');
187
- expect(properties[0].value.name).toEqual('t0');
188
- expect(properties[1].key.name).toEqual('t');
189
- expect(properties[1].value.value).toEqual('TemplatedStringFunction');
190
- expect(properties[2].key.name).toEqual('in');
191
- expect(properties[2].value.elements).toHaveLength(1);
192
- });
193
- });
194
- describe('propertyToExpression', () => {
195
- it('composes proper object expression when input is property with inital value', () => {
196
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
197
- const propertyConext = {
198
- type: common_shared_1.PropertyTypes.BASE,
199
- inital: { type: 'PrimitiveValue', value: 5 },
200
- usedInPriming: false,
201
- isPublic: true,
202
- };
203
- const result = (0, genericAstGeneration_1.propertyToExpression)(moduleMetadata, propertyConext);
204
- expect(result).not.toBeUndefined();
205
- expect(result?.type).toEqual('ObjectExpression');
206
- expect(result?.properties).toHaveLength(2);
207
- const properties = result?.properties;
208
- expect(properties).toHaveLength(2);
209
- expect(properties[0].key.name).toEqual('a');
210
- expect(properties[0].value.value).toBeTruthy();
211
- expect(properties[1].key.name).toEqual('i');
212
- expect(properties[1].value.value).toEqual(5);
213
- });
214
- it('composes proper object expression when property is a getter', () => {
215
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
216
- const propertyConext = {
217
- type: common_shared_1.PropertyTypes.GETTER,
218
- usedInPriming: false,
219
- functionIndex: 0,
220
- isPublic: false,
221
- };
222
- const result = (0, genericAstGeneration_1.propertyToExpression)(moduleMetadata, propertyConext);
223
- expect(result).not.toBeUndefined();
224
- expect(result?.type).toEqual('ObjectExpression');
225
- expect(result?.properties).toHaveLength(2);
226
- const properties = result?.properties;
227
- expect(properties).toHaveLength(2);
228
- expect(properties[0].key.name).toEqual('a');
229
- expect(properties[0].value.value).toBeFalsy();
230
- expect(properties[1].key.name).toEqual('f');
231
- expect(properties[1].value.value).toEqual(0);
232
- });
233
- it('composes proper object expression when property is a Template string', () => {
234
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
235
- const propertyConext = {
236
- type: common_shared_1.PropertyTypes.TEMPLATE_STRING,
237
- usedInPriming: false,
238
- functionIndex: 0,
239
- isPublic: false,
240
- };
241
- const result = (0, genericAstGeneration_1.propertyToExpression)(moduleMetadata, propertyConext);
242
- expect(result).not.toBeUndefined();
243
- expect(result?.type).toEqual('ObjectExpression');
244
- expect(result?.properties).toHaveLength(2);
245
- const properties = result?.properties;
246
- expect(properties).toHaveLength(2);
247
- expect(properties[0].key.name).toEqual('a');
248
- expect(properties[0].value.value).toBeFalsy();
249
- expect(properties[1].key.name).toEqual('f');
250
- expect(properties[1].value.value).toEqual(0);
251
- });
252
- it('composes proper object expression when property is a wire', () => {
253
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
254
- const propertyConext = {
255
- type: common_shared_1.PropertyTypes.WIRE,
256
- usedInPriming: false,
257
- functionIndex: 1,
258
- isPublic: false,
259
- };
260
- const result = (0, genericAstGeneration_1.propertyToExpression)(moduleMetadata, propertyConext);
261
- expect(result).not.toBeUndefined();
262
- expect(result?.type).toEqual('ObjectExpression');
263
- expect(result?.properties).toHaveLength(2);
264
- const properties = result?.properties;
265
- expect(properties).toHaveLength(2);
266
- expect(properties[0].key.name).toEqual('a');
267
- expect(properties[0].value.value).toBeFalsy();
268
- expect(properties[1].key.name).toEqual('f');
269
- expect(properties[1].value.value).toEqual(1);
270
- });
271
- it('composes proper object expression when property is a wire that is unresolvabe', () => {
272
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
273
- const propertyConext = {
274
- type: common_shared_1.PropertyTypes.WIRE,
275
- usedInPriming: false,
276
- functionIndex: common_shared_1.UNSUPPORTED_FUNCTION,
277
- isPublic: false,
278
- };
279
- const result = (0, genericAstGeneration_1.propertyToExpression)(moduleMetadata, propertyConext);
280
- expect(result).not.toBeUndefined();
281
- expect(result?.type).toEqual('ObjectExpression');
282
- expect(result?.properties).toHaveLength(2);
283
- const properties = result?.properties;
284
- expect(properties).toHaveLength(2);
285
- expect(properties[0].key.name).toEqual('a');
286
- expect(properties[0].value.value).toBeFalsy();
287
- expect(properties[1].key.name).toEqual('g');
288
- expect(properties[1].value.value).toEqual(undefined);
289
- });
290
- });
291
- describe('processWireFunctionType', () => {
292
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
293
- (0, common_shared_1.composeImportMetadata)('randomWire', 'laf/transformWire', true, '0/names/0', moduleMetadata);
294
- (0, common_shared_1.composeImportMetadata)('apexWire', '@salesforce/apex/recordApi', true, '1/names/0', moduleMetadata);
295
- (0, common_shared_1.composeImportMetadata)('getRecord', 'lightning/uiRecordApi', true, '2/names/0', moduleMetadata);
296
- (0, common_shared_1.composeImportMetadata)('bacth_getRecord', 'lightning/uiRecordApi', true, '2/names/1', moduleMetadata);
297
- (0, common_shared_1.composeImportMetadata)('reducer', 'lightning/uiRecordApi', true, '2/names/2', moduleMetadata);
298
- (0, common_shared_1.composeImportMetadata)('CurrentPageReference', 'laf/transformWire', true, '3/names/0', moduleMetadata);
299
- (0, common_shared_1.composeImportMetadata)('getApexInvoker_imperative', 'force/ldsAdaptersApex', true, '4/names/0', moduleMetadata);
300
- it('throws an error when a function that isnt a wire is passed in', () => {
301
- const throwingFunc = () => (0, genericAstGeneration_1.processWireFunctionType)({
302
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
303
- type: common_shared_1.FunctionTypes.GETTER_FUNCTION,
304
- requiredProperties: [],
305
- importReference: { functionName: '' },
306
- }, moduleMetadata);
307
- expect(throwingFunc).toThrow();
308
- });
309
- it('does nothing when function refers to a non existent import', () => {
310
- const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
311
- type: common_shared_1.FunctionTypes.WIRE_FUNCTION,
312
- requiredProperties: [],
313
- importReference: { functionName: 'test' },
314
- }, moduleMetadata);
315
- expect(astStatements).toBeUndefined();
316
- });
317
- it('effectively builds metadata for a non priming adapter wire', () => {
318
- const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
319
- type: common_shared_1.FunctionTypes.WIRE_FUNCTION,
320
- requiredProperties: [],
321
- input: [
322
- {
323
- type: 'ObjectValue',
324
- value: {
325
- fields: {
326
- type: 'ArrayValue',
327
- value: [
328
- {
329
- type: 'PrimitiveValue',
330
- value: 'Account.Name',
331
- },
332
- ],
333
- },
334
- resourceId: {
335
- type: 'PropertyReference',
336
- value: 'recordId',
337
- },
338
- recordType: {
339
- type: 'PropertyReference',
340
- value: 'recordType',
341
- },
342
- },
343
- },
344
- ],
345
- importReference: { functionName: 'randomWire' },
346
- }, moduleMetadata);
347
- expect(astStatements).not.toBeUndefined();
348
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
349
- const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
350
- expect(code).toBe(`{
351
- f: i0,
352
- fN: "randomWire",
353
- t: "WireFunction",
354
- c: ctx => ({
355
- "fields": ["Account.Name"],
356
- "resourceId": ctx.props.recordId,
357
- "recordType": ctx.props.recordType
358
- }),
359
- in: ["recordId", "recordType"]
360
- }`);
361
- });
362
- it('effectively builds metadata for an apex wire', () => {
363
- const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
364
- type: common_shared_1.FunctionTypes.WIRE_FUNCTION,
365
- requiredProperties: [],
366
- importReference: { functionName: 'apexWire' },
367
- }, moduleMetadata);
368
- expect(astStatements).not.toBeUndefined();
369
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
370
- const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
371
- expect(code).toBe(`{
372
- f: i1,
373
- fN: "recordApi",
374
- t: "WireFunction",
375
- wt: "apex",
376
- c: ctx => ({})
377
- }`);
378
- });
379
- it('effectively builds metadata for an apex priming adapter wire', () => {
380
- const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
381
- type: common_shared_1.FunctionTypes.PRIMING_FUNCTION,
382
- requiredProperties: [],
383
- importReference: { functionName: 'getApexInvoker_imperative' },
384
- prevImportReference: '@salesforce/apex/foo.getBar',
385
- }, moduleMetadata);
386
- expect(astStatements).not.toBeUndefined();
387
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
388
- const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
389
- expect(code).toBe(`{
390
- f: i6,
391
- fN: "getApexInvoker_imperative",
392
- t: "PrimingFunction",
393
- wt: "apex",
394
- af: () => i6("", "foo", "getBar", false),
395
- c: ctx => ({})
396
- }`);
397
- });
398
- it('effectively builds metadata for an apexContinuation priming adapter wire', () => {
399
- const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
400
- type: common_shared_1.FunctionTypes.PRIMING_FUNCTION,
401
- requiredProperties: [],
402
- importReference: { functionName: 'getApexInvoker_imperative' },
403
- prevImportReference: '@salesforce/apexContinuation/foo.getBar',
404
- }, moduleMetadata);
405
- expect(astStatements).not.toBeUndefined();
406
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
407
- const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
408
- expect(code).toBe(`{
409
- f: i6,
410
- fN: "getApexInvoker_imperative",
411
- t: "PrimingFunction",
412
- wt: "apex",
413
- af: () => i6("", "foo", "getBar", true),
414
- c: ctx => ({})
415
- }`);
416
- });
417
- it('effectively builds metadata for a context wire', () => {
418
- const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
419
- type: common_shared_1.FunctionTypes.WIRE_FUNCTION,
420
- requiredProperties: [],
421
- importReference: { functionName: 'CurrentPageReference' },
422
- }, moduleMetadata);
423
- expect(astStatements).not.toBeUndefined();
424
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
425
- const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
426
- expect(code).toBe(`{
427
- f: i5,
428
- fN: "CurrentPageReference",
429
- t: "WireFunction",
430
- wt: "cpr",
431
- c: ctx => ({})
432
- }`);
433
- });
434
- it('effectively builds metadata for a priming adapter wire with neither a batcher or reducer', () => {
435
- const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
436
- type: common_shared_1.FunctionTypes.PRIMING_FUNCTION,
437
- requiredProperties: [],
438
- importReference: { functionName: 'getRecord' },
439
- }, moduleMetadata);
440
- expect(astStatements).not.toBeUndefined();
441
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
442
- const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
443
- expect(code).toBe(`{
444
- f: i2,
445
- fN: "getRecord",
446
- t: "PrimingFunction",
447
- c: ctx => ({})
448
- }`);
449
- });
450
- it('effectively builds metadata for a priming adapter wire without a reducer', () => {
451
- const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
452
- type: common_shared_1.FunctionTypes.PRIMING_FUNCTION,
453
- requiredProperties: [],
454
- importReference: {
455
- functionName: 'getRecord',
456
- batchingName: 'bacth_getRecord',
457
- },
458
- }, moduleMetadata);
459
- expect(astStatements).not.toBeUndefined();
460
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
461
- const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
462
- expect(code).toBe(`{
463
- f: i2,
464
- fN: "getRecord",
465
- b: i3,
466
- bN: "bacth_getRecord",
467
- t: "PrimingFunction",
468
- c: ctx => ({})
469
- }`);
470
- });
471
- it('effectively builds metadata for a priming adapter wire', () => {
472
- const astStatements = (0, genericAstGeneration_1.processWireFunctionType)({
473
- type: common_shared_1.FunctionTypes.PRIMING_FUNCTION,
474
- requiredProperties: [],
475
- importReference: {
476
- functionName: 'getRecord',
477
- batchingName: 'bacth_getRecord',
478
- reducer: 'reducer',
479
- },
480
- }, moduleMetadata);
481
- expect(astStatements).not.toBeUndefined();
482
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
483
- const { code } = (0, generator_1.default)(t.objectExpression(astStatements));
484
- expect(code).toBe(`{
485
- f: i2,
486
- fN: "getRecord",
487
- b: i3,
488
- bN: "bacth_getRecord",
489
- r: i4,
490
- t: "PrimingFunction",
491
- c: ctx => ({})
492
- }`);
493
- });
494
- });
495
- describe('processErrorFunction', () => {
496
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
497
- it('should compose ast nodes properly for error function', () => {
498
- const res = (0, genericAstGeneration_1.processErrorFunction)({
499
- type: common_shared_1.FunctionTypes.ERROR,
500
- input: [
501
- {
502
- type: 'ObjectValue',
503
- value: {
504
- error: {
505
- type: 'PrimitiveValue',
506
- value: common_shared_1.ERROR_PREFIX +
507
- 'Something that is not an error was thrown',
508
- },
509
- },
510
- },
511
- ],
512
- }, moduleMetadata);
513
- expect(res).not.toBeUndefined();
514
- const { code } = (0, generator_1.default)(t.objectExpression(res));
515
- expect(code).toBe(`{
516
- t: "ErrorFunction",
517
- c: {
518
- "error": "[komaci] Something that is not an error was thrown"
519
- }
520
- }`);
521
- });
522
- });
523
- describe('addImportStatements', () => {
524
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
525
- (0, common_shared_1.composeImportMetadata)('default', 'lightning/uiTestingApi', true, '0/names/0', moduleMetadata, 'test');
526
- (0, common_shared_1.composeImportMetadata)('regularImport', 'lightning/uiTestingApi', true, '0/names/1', moduleMetadata);
527
- (0, common_shared_1.composeImportMetadata)('tes1', 'badImport', false, '1/names/0', moduleMetadata);
528
- (0, common_shared_1.composeImportMetadata)('tes2', 'badImport', false, '1/names/1', moduleMetadata);
529
- (0, common_shared_1.composeImportMetadata)('*', '@salesforce/labels', true, '2/names/0', moduleMetadata, 'labels');
530
- (0, common_shared_1.composeImportMetadata)('tes3', 'lightning/uiRecordApi', true, '3/names/0', moduleMetadata);
531
- (0, common_shared_1.composeImportMetadata)('tes4', 'lightning/uiRecordApi', true, '3/names/1', moduleMetadata, 'changed');
532
- (0, common_shared_1.composeImportMetadata)('tes5', 'lightning/uiRecordApi', true, '3/names/2', moduleMetadata);
533
- (0, common_shared_1.composeImportMetadata)('adg', '@salesforce/komaci/c__foo__foo.js', true, '4/names/0', moduleMetadata);
534
- moduleMetadata.importsByNamespace.set('lightning/uiTestingApi', {
535
- names: new Set(['default', 'regularImport']),
536
- originalNames: new Set(['default', 'regularImport']),
537
- isDefaultSpecifier: true,
538
- isSupported: true,
539
- isNamespaceSpecifier: false,
540
- resourceName: 'lightning/uiTestingApi',
541
- });
542
- moduleMetadata.importsByNamespace.set('badImport', {
543
- names: new Set(['tes1', 'tes2']),
544
- originalNames: new Set(['tes1', 'tes2']),
545
- isDefaultSpecifier: false,
546
- isSupported: false,
547
- isNamespaceSpecifier: false,
548
- resourceName: 'badImport',
549
- });
550
- moduleMetadata.importsByNamespace.set('@salesforce/labels', {
551
- names: new Set(['*']),
552
- originalNames: new Set(['*']),
553
- isDefaultSpecifier: false,
554
- isSupported: true,
555
- isNamespaceSpecifier: true,
556
- resourceName: '@salesforce/labels',
557
- });
558
- moduleMetadata.importsByNamespace.set('lightning/uiRecordApi', {
559
- names: new Set(['tes3', 'tes4', 'tes5']),
560
- originalNames: new Set(['tes3', 'tes4', 'tes5']),
561
- isDefaultSpecifier: false,
562
- isSupported: true,
563
- isNamespaceSpecifier: false,
564
- resourceName: 'lightning/uiRecordApi',
565
- });
566
- moduleMetadata.importsByNamespace.set('@salesforce/komaci/c__foo__foo.js', {
567
- names: new Set(['adg']),
568
- originalNames: new Set(['adg']),
569
- isDefaultSpecifier: false,
570
- isSupported: true,
571
- isNamespaceSpecifier: false,
572
- resourceName: '@salesforce/komaci/c__foo__foo.js',
573
- });
574
- // lazy way to say almost all are used in priming
575
- for (const importMetadata of moduleMetadata.importsByName.values()) {
576
- importMetadata.usedInPriming =
577
- importMetadata.name !== 'tes5' && importMetadata.name !== 'tes2';
578
- }
579
- const findImportDeclaration = (statements, resourceName) => statements.find((statement) => statement.source.value === resourceName);
580
- const validateForEachList = (statements, cb) => statements.forEach(cb);
581
- const scriptModuleOnlyStatements = [];
582
- const combinedModuleStatements = [];
583
- (0, genericAstGeneration_1.addImportStatements)(moduleMetadata, scriptModuleOnlyStatements, {
584
- isComposingFromBundle: false,
585
- });
586
- (0, genericAstGeneration_1.addImportStatements)(moduleMetadata, combinedModuleStatements, {
587
- isComposingFromBundle: true,
588
- });
589
- it('can compose an import with a default and a normal import together', () => {
590
- validateForEachList([scriptModuleOnlyStatements, combinedModuleStatements], (statements) => {
591
- const importStatement = findImportDeclaration(statements, 'lightning/uiTestingApi');
592
- expect(importStatement).not.toBeUndefined();
593
- expect(importStatement.specifiers).toHaveLength(2);
594
- expect(importStatement.specifiers[0].type).toBe('ImportDefaultSpecifier');
595
- expect(importStatement
596
- .specifiers[0].local.name).toBe(moduleMetadata.importsByName.get('test')?.generatorAlias);
597
- expect(importStatement.specifiers[1].type).toBe('ImportSpecifier');
598
- expect(importStatement
599
- .specifiers[1].local.name).toBe(moduleMetadata.importsByName.get('regularImport')?.generatorAlias);
600
- expect(importStatement
601
- .specifiers[1].imported.name).toBe('regularImport');
602
- });
603
- });
604
- it('will not compose a bad import', () => {
605
- validateForEachList([scriptModuleOnlyStatements, combinedModuleStatements], (statements) => {
606
- const importStatement = findImportDeclaration(statements, 'badImport');
607
- expect(importStatement).toBeUndefined();
608
- });
609
- });
610
- it('can compose an import with a namespace import', () => {
611
- validateForEachList([scriptModuleOnlyStatements, combinedModuleStatements], (statements) => {
612
- const importStatement = findImportDeclaration(statements, '@salesforce/labels');
613
- expect(importStatement).not.toBeUndefined();
614
- expect(importStatement.specifiers).toHaveLength(1);
615
- expect(importStatement.specifiers[0].type).toBe('ImportNamespaceSpecifier');
616
- expect(importStatement
617
- .specifiers[0].local.name).toBe(moduleMetadata.importsByName.get('labels')?.generatorAlias);
618
- });
619
- });
620
- it('will leave out an import not used in priming from the composed specifiers', () => {
621
- validateForEachList([scriptModuleOnlyStatements, combinedModuleStatements], (statements) => {
622
- const importStatement = findImportDeclaration(statements, 'lightning/uiRecordApi');
623
- expect(importStatement).not.toBeUndefined();
624
- expect(importStatement.specifiers).toHaveLength(2);
625
- expect(importStatement.specifiers[0].type).toBe('ImportSpecifier');
626
- expect(importStatement
627
- .specifiers[0].imported.name).toBe('tes3');
628
- expect(importStatement.specifiers[1].type).toBe('ImportSpecifier');
629
- expect(importStatement
630
- .specifiers[1].local.name).toBe(moduleMetadata.importsByName.get('changed')?.generatorAlias);
631
- expect(importStatement
632
- .specifiers[1].imported.name).toBe('tes4');
633
- });
634
- });
635
- it('will lop the last portion of a @salesforce/komaci import off if its a combined module only', () => {
636
- const scriptImport = findImportDeclaration(scriptModuleOnlyStatements, '@salesforce/komaci/c__foo__foo.js');
637
- expect(scriptImport).not.toBeUndefined();
638
- const combinedImport = findImportDeclaration(combinedModuleStatements, '@salesforce/komaci/c__foo');
639
- expect(combinedImport).not.toBeUndefined();
640
- });
641
- });
642
- describe('collectMetadataForImportedTemplates', () => {
643
- const templateMap = {};
644
- beforeEach(() => {
645
- // fixture-template-files/component-refernece
646
- templateMap['component-reference'] = {
647
- compositions: [
648
- {
649
- type: 'Container',
650
- compositions: [
651
- {
652
- type: 'ComposedAdg',
653
- input: {
654
- type: 'ImportReference',
655
- value: '0/names/0',
656
- },
657
- properties: {},
658
- },
659
- {
660
- type: 'ComposedAdg',
661
- input: {
662
- type: 'ImportReference',
663
- value: '0/names/0',
664
- },
665
- properties: {
666
- attribute1: {
667
- type: 'PrimitiveValue',
668
- value: 'literalString1',
669
- },
670
- attribute2: {
671
- type: 'PrimitiveValue',
672
- value: 'lteralString2',
673
- },
674
- },
675
- },
676
- {
677
- type: 'ComposedAdg',
678
- input: {
679
- type: 'ImportReference',
680
- value: '0/names/0',
681
- },
682
- properties: {
683
- attribute1: {
684
- type: 'Binding',
685
- value: 'record',
686
- },
687
- attribute2: {
688
- type: 'Binding',
689
- value: 'recordId',
690
- },
691
- attribute3: {
692
- type: 'Binding',
693
- value: 'record/data/Name',
694
- },
695
- },
696
- },
697
- {
698
- type: 'ComposedAdg',
699
- input: {
700
- type: 'ImportReference',
701
- value: '0/names/0',
702
- },
703
- properties: {
704
- attribute1: {
705
- type: 'PrimitiveValue',
706
- value: 'literalString1',
707
- },
708
- attribute2: {
709
- type: 'Binding',
710
- value: 'recordId',
711
- },
712
- attribute3: {
713
- type: 'PrimitiveValue',
714
- value: true,
715
- },
716
- },
717
- },
718
- {
719
- type: 'ComposedAdg',
720
- input: {
721
- type: 'ImportReference',
722
- value: '0/names/0',
723
- },
724
- properties: {
725
- attributeUpperCase: {
726
- type: 'PrimitiveValue',
727
- value: 'convert kebab to camel',
728
- },
729
- },
730
- },
731
- {
732
- type: 'ComposedAdg',
733
- input: {
734
- type: 'ImportReference',
735
- value: '0/names/0',
736
- },
737
- properties: {
738
- StartsWithUpperCase: {
739
- type: 'PrimitiveValue',
740
- value: 'should be StartsWithUpperCase',
741
- },
742
- },
743
- },
744
- {
745
- type: 'ComposedAdg',
746
- input: {
747
- type: 'ImportReference',
748
- value: '1/names/0',
749
- },
750
- properties: {},
751
- },
752
- {
753
- type: 'ComposedAdg',
754
- input: {
755
- type: 'ImportReference',
756
- value: '2/names/0',
757
- },
758
- properties: {
759
- label: {
760
- type: 'PrimitiveValue',
761
- value: 'Base',
762
- },
763
- title: {
764
- type: 'PrimitiveValue',
765
- value: 'Looks like a link',
766
- },
767
- variant: {
768
- type: 'PrimitiveValue',
769
- value: 'base',
770
- },
771
- },
772
- },
773
- ],
774
- },
775
- ],
776
- imports: [
777
- {
778
- resourceName: '@salesforce/komaci/c__child1__child1.js',
779
- names: ['default'],
780
- },
781
- {
782
- resourceName: '@salesforce/komaci/c__upperCaseInName__upperCaseInName.js',
783
- names: ['default'],
784
- },
785
- {
786
- resourceName: '@salesforce/komaci/lightning__button__button.js',
787
- names: ['default'],
788
- },
789
- ],
790
- exports: {
791
- default: {
792
- type: 'CompositionReference',
793
- value: 0,
794
- },
795
- },
796
- };
797
- //fixture-template-files/conditional-simple
798
- templateMap['conditional-simple'] = {
799
- compositions: [
800
- {
801
- type: 'Container',
802
- compositions: [
803
- {
804
- type: 'Container',
805
- isActive: {
806
- input: {
807
- type: 'Binding',
808
- value: 'someCondition',
809
- },
810
- negate: false,
811
- },
812
- compositions: [
813
- {
814
- type: 'ComposedAdg',
815
- input: {
816
- type: 'ImportReference',
817
- value: '0/names/0',
818
- },
819
- properties: {},
820
- },
821
- {
822
- type: 'ComposedAdg',
823
- input: {
824
- type: 'ImportReference',
825
- value: '1/names/0',
826
- },
827
- properties: {},
828
- },
829
- ],
830
- },
831
- ],
832
- },
833
- ],
834
- exports: {
835
- default: {
836
- type: 'CompositionReference',
837
- value: 0,
838
- },
839
- },
840
- imports: [
841
- {
842
- resourceName: '@salesforce/komaci/c__child1__child1.js',
843
- names: ['default'],
844
- },
845
- {
846
- resourceName: '@salesforce/komaci/c__child2__child2.js',
847
- names: ['default'],
848
- },
849
- ],
850
- };
851
- });
852
- it('collects metadata info for non default templates', () => {
853
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
854
- moduleMetadata.templateKomaciDocMap = templateMap;
855
- moduleMetadata.adgGeneratorIndex = 1;
856
- const defaultAdg = (0, common_shared_1.initAdgMetadataObject)('adg0');
857
- moduleMetadata.adgs.set(0, defaultAdg);
858
- const templateImport = {
859
- name: 'default',
860
- komaciDocImportRef: '0/names/0',
861
- importAlias: 'child1',
862
- generatorAlias: 'i0',
863
- resourceName: './conditional-simple',
864
- staticallyAnalyzable: true,
865
- templateKomaciDoc: templateMap['conditional-simple'],
866
- usedInPriming: true,
867
- isFromInternalNamespace: true,
868
- isFromSupportedLibrary: true,
869
- };
870
- moduleMetadata.importsByName.set('child1', templateImport);
871
- //assuming that component-reference is the default.
872
- (0, genericAstGeneration_1.collectMetadataForImportedTemplates)(moduleMetadata);
873
- confirmBaselineAdgExpectations(Object.values(moduleMetadata.adgs));
874
- expect(moduleMetadata.adgGeneratorIndex).toBe(2);
875
- expect(moduleMetadata.importGeneratorIndex).toBe(2);
876
- expect(moduleMetadata.importIndexReference.get('t1-0/names/0')).not.toBeUndefined();
877
- expect(moduleMetadata.importIndexReference.get('t1-1/names/0')).not.toBeUndefined();
878
- });
879
- it('collects metadata info for non default templates, multiple non default templates', () => {
880
- templateMap['default-template'] = {};
881
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
882
- moduleMetadata.templateKomaciDocMap = templateMap;
883
- moduleMetadata.adgGeneratorIndex = 1;
884
- const defaultAdg = (0, common_shared_1.initAdgMetadataObject)('adg0');
885
- moduleMetadata.adgs.set(0, defaultAdg);
886
- const templateImport = {
887
- name: 'default',
888
- komaciDocImportRef: '0/names/0',
889
- importAlias: 'child1',
890
- generatorAlias: 'i0',
891
- resourceName: './component-reference',
892
- staticallyAnalyzable: true,
893
- templateKomaciDoc: templateMap['component-reference'],
894
- usedInPriming: true,
895
- isFromInternalNamespace: true,
896
- isFromSupportedLibrary: true,
897
- };
898
- moduleMetadata.importsByName.set('child1', templateImport);
899
- const templateImport2 = {
900
- name: 'default',
901
- komaciDocImportRef: '1/names/0',
902
- importAlias: 'child2',
903
- generatorAlias: 'i1',
904
- resourceName: './conditional-simple',
905
- staticallyAnalyzable: true,
906
- templateKomaciDoc: templateMap['conditional-simple'],
907
- usedInPriming: true,
908
- isFromInternalNamespace: true,
909
- isFromSupportedLibrary: true,
910
- };
911
- moduleMetadata.importsByName.set('child2', templateImport2);
912
- //assuming that component-reference is the default.
913
- (0, genericAstGeneration_1.collectMetadataForImportedTemplates)(moduleMetadata);
914
- confirmBaselineAdgExpectations(Object.values(moduleMetadata.adgs));
915
- expect(moduleMetadata.adgGeneratorIndex).toBe(3);
916
- expect(moduleMetadata.importGeneratorIndex).toBe(5);
917
- expect(moduleMetadata.importIndexReference.get('t1-0/names/0')).not.toBeUndefined();
918
- expect(moduleMetadata.importIndexReference.get('t1-1/names/0')).not.toBeUndefined();
919
- expect(moduleMetadata.importIndexReference.get('t1-2/names/0')).not.toBeUndefined();
920
- expect(moduleMetadata.importIndexReference.get('t2-0/names/0')).not.toBeUndefined();
921
- expect(moduleMetadata.importIndexReference.get('t2-1/names/0')).not.toBeUndefined();
922
- expect(moduleMetadata.adgs.get(1)?.properties.size).toBe(2);
923
- });
924
- it('no changes when only looking at the default', () => {
925
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
926
- moduleMetadata.templateKomaciDocMap = templateMap;
927
- moduleMetadata.adgGeneratorIndex = 1;
928
- const defaultAdg = (0, common_shared_1.initAdgMetadataObject)('adg0');
929
- moduleMetadata.adgs.set(0, defaultAdg);
930
- //assuming that component-reference is the default.
931
- (0, genericAstGeneration_1.collectMetadataForImportedTemplates)(moduleMetadata);
932
- confirmBaselineAdgExpectations(Object.values(moduleMetadata.adgs));
933
- expect(moduleMetadata.adgGeneratorIndex).toBe(1);
934
- expect(moduleMetadata.importGeneratorIndex).toBe(0);
935
- });
936
- it('proerly sets the adgReference when importing default template', () => {
937
- const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
938
- moduleMetadata.templateKomaciDocMap = templateMap;
939
- moduleMetadata.adgGeneratorIndex = 1;
940
- const defaultAdg = (0, common_shared_1.initAdgMetadataObject)('adg0');
941
- moduleMetadata.adgs.set(0, defaultAdg);
942
- //importing component-refernece explicitly.
943
- const templateImport = {
944
- name: 'default',
945
- komaciDocImportRef: '0/names/0',
946
- importAlias: 'defaultTemplate',
947
- generatorAlias: 'i0',
948
- resourceName: './component-reference',
949
- staticallyAnalyzable: true,
950
- templateKomaciDoc: templateMap['component-reference'],
951
- usedInPriming: true,
952
- isFromInternalNamespace: true,
953
- isFromSupportedLibrary: true,
954
- };
955
- moduleMetadata.importsByName.set('defaultTemplate', templateImport);
956
- //assuming that component-reference is the default.
957
- (0, genericAstGeneration_1.collectMetadataForImportedTemplates)(moduleMetadata);
958
- confirmBaselineAdgExpectations(Object.values(moduleMetadata.adgs));
959
- expect(moduleMetadata.adgGeneratorIndex).toBe(2);
960
- expect(templateImport.adgReference).toBe('adg1');
961
- expect(moduleMetadata.adgs.get(1)?.properties.size).toBe(2);
962
- });
963
- });
964
- describe('valueReferenceToExpression', () => {
965
- it('properly references the property that we want to refernce as a string', () => {
966
- const obj = (0, genericAstGeneration_1.valueReferenceToExpression)((0, common_shared_1.initModuleMetadataObject)(), {
967
- type: 'Binding',
968
- value: 'record/sub/path',
969
- });
970
- expect(obj.properties[0].key.name).toBe('t');
971
- expect(obj.properties[0].value.value).toBe('b');
972
- expect(obj.properties[1].key.name).toBe('v');
973
- expect(obj.properties[1].value.value).toBe('record.sub.path');
974
- });
975
- it('properly references a binding in an iteration context by value', () => {
976
- const obj = (0, genericAstGeneration_1.valueReferenceToExpression)((0, common_shared_1.initModuleMetadataObject)(), {
977
- type: 'Binding',
978
- value: 'item/val',
979
- }, ['item']);
980
- expect(obj.properties[0].key.name).toBe('t');
981
- expect(obj.properties[0].value.value).toBe('s');
982
- expect(obj.properties[1].key.name).toBe('v');
983
- expect(obj.properties[1]
984
- .value.object.name).toBe('user_var_item');
985
- expect(obj.properties[1]
986
- .value.property.name).toBe('val');
987
- });
988
- it('handles whatever this weird typing edge case is where value is undefined', () => {
989
- const obj = (0, genericAstGeneration_1.valueReferenceToExpression)((0, common_shared_1.initModuleMetadataObject)(), {
990
- type: 'PrimitiveValue',
991
- });
992
- expect(obj.properties[0].key.name).toBe('t');
993
- expect(obj.properties[0].value.value).toBe('s');
994
- expect(obj.properties[1].key.name).toBe('v');
995
- expect(obj.properties[1].value.name).toBe('undefined');
996
- });
997
- it('properly references a static value', () => {
998
- const obj = (0, genericAstGeneration_1.valueReferenceToExpression)((0, common_shared_1.initModuleMetadataObject)(), {
999
- type: 'PrimitiveValue',
1000
- value: 'reference',
1001
- });
1002
- expect(obj.properties[0].key.name).toBe('t');
1003
- expect(obj.properties[0].value.value).toBe('s');
1004
- expect(obj.properties[1].key.name).toBe('v');
1005
- expect(obj.properties[1].value.value).toBe('reference');
1006
- });
1007
- });
1008
- describe('generateGqlImportStatement', () => {
1009
- it('generates the import statement properly', () => {
1010
- const gqlMetadataMap = new Map();
1011
- const gqlMetadata = {
1012
- hash: '123456',
1013
- hasExpressions: false,
1014
- location: {
1015
- startLine: 0,
1016
- endLine: 0,
1017
- startColumn: 0,
1018
- endColumn: 0,
1019
- start: 242,
1020
- end: 801,
1021
- },
1022
- isHoisted: false,
1023
- valid: true,
1024
- generatedImportAlias: '_123456',
1025
- importPath: '@salesforce/lds/c__component',
1026
- };
1027
- gqlMetadataMap.set('loc_242_801', gqlMetadata);
1028
- const gqlMetadata2 = {
1029
- hash: '123456789',
1030
- hasExpressions: true,
1031
- location: {
1032
- startLine: 0,
1033
- endLine: 0,
1034
- startColumn: 0,
1035
- endColumn: 0,
1036
- start: 826,
1037
- end: 1316,
1038
- },
1039
- isHoisted: false,
1040
- valid: false,
1041
- generatedImportAlias: '_123456789',
1042
- importPath: 'temp/path',
1043
- };
1044
- gqlMetadataMap.set('loc_826_1316', gqlMetadata2);
1045
- const statements = [];
1046
- (0, genericAstGeneration_1.generateGqlImportStatements)(gqlMetadataMap, statements);
1047
- expect(statements).toHaveLength(1);
1048
- const code = (0, generator_1.default)(statements[0]).code;
1049
- expect(code).toBe('import { _123456 } from "@salesforce/lds/c__component";');
1050
- });
1051
- });
1052
- //# sourceMappingURL=genericAstGeneration.spec.js.map