@wavemaker/react-codegen 11.14.2-rc.6311 → 12.0.0-next.28533

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 (100) hide show
  1. package/build-react-web.js +0 -19
  2. package/build-react-web.js.map +1 -1
  3. package/package-lock.json +151 -144
  4. package/package.json +2 -2
  5. package/src/app.generator.js +176 -18
  6. package/src/app.generator.js.map +1 -1
  7. package/src/gen-app-override-css.js +1 -1
  8. package/src/gen-app-override-css.js.map +1 -1
  9. package/src/handlebar-helpers.js +116 -19
  10. package/src/handlebar-helpers.js.map +1 -1
  11. package/src/project.service.js +47 -5
  12. package/src/project.service.js.map +1 -1
  13. package/src/transpile/bind.ex.transformer.js +11 -1
  14. package/src/transpile/bind.ex.transformer.js.map +1 -1
  15. package/src/transpile/components/basic/richtexteditor.transformer.js +3 -2
  16. package/src/transpile/components/basic/richtexteditor.transformer.js.map +1 -1
  17. package/src/transpile/components/basic/search.transformer.js +4 -6
  18. package/src/transpile/components/basic/search.transformer.js.map +1 -1
  19. package/src/transpile/components/container/tabpane.transformer.js +1 -1
  20. package/src/transpile/components/container/tabpane.transformer.js.map +1 -1
  21. package/src/transpile/components/container/tabs.transformer.js +4 -0
  22. package/src/transpile/components/container/tabs.transformer.js.map +1 -1
  23. package/src/transpile/components/data/card/card-content.transformer.js +5 -1
  24. package/src/transpile/components/data/card/card-content.transformer.js.map +1 -1
  25. package/src/transpile/components/data/form/form-action.transformer.js +73 -18
  26. package/src/transpile/components/data/form/form-action.transformer.js.map +1 -1
  27. package/src/transpile/components/data/form/form-field.transformer.js +46 -11
  28. package/src/transpile/components/data/form/form-field.transformer.js.map +1 -1
  29. package/src/transpile/components/data/form/form.transformer.js +53 -17
  30. package/src/transpile/components/data/form/form.transformer.js.map +1 -1
  31. package/src/transpile/components/data/list/list-transformer.js +64 -33
  32. package/src/transpile/components/data/list/list-transformer.js.map +1 -1
  33. package/src/transpile/components/data/live-filter-field.transformer.js +65 -10
  34. package/src/transpile/components/data/live-filter-field.transformer.js.map +1 -1
  35. package/src/transpile/components/data/liveform.transformer.js +11 -4
  36. package/src/transpile/components/data/liveform.transformer.js.map +1 -1
  37. package/src/transpile/components/data/table/table-action.transformer.js +6 -2
  38. package/src/transpile/components/data/table/table-action.transformer.js.map +1 -1
  39. package/src/transpile/components/data/table/table-column.transformer.js +95 -20
  40. package/src/transpile/components/data/table/table-column.transformer.js.map +1 -1
  41. package/src/transpile/components/data/table/table-group.transformer.js +16 -0
  42. package/src/transpile/components/data/table/table-group.transformer.js.map +1 -0
  43. package/src/transpile/components/data/table/table-row-action.transformer.js +6 -2
  44. package/src/transpile/components/data/table/table-row-action.transformer.js.map +1 -1
  45. package/src/transpile/components/data/table/table-row.transformer.js +7 -4
  46. package/src/transpile/components/data/table/table-row.transformer.js.map +1 -1
  47. package/src/transpile/components/data/table/table.transformer.js +29 -1
  48. package/src/transpile/components/data/table/table.transformer.js.map +1 -1
  49. package/src/transpile/components/data/table/utils.js +3 -1
  50. package/src/transpile/components/data/table/utils.js.map +1 -1
  51. package/src/transpile/components/form/button.transformer.js +12 -1
  52. package/src/transpile/components/form/button.transformer.js.map +1 -1
  53. package/src/transpile/components/input/checkbox-set.transformer.js +1 -1
  54. package/src/transpile/components/input/checkbox-set.transformer.js.map +1 -1
  55. package/src/transpile/components/input/chips.transformer.js +2 -1
  56. package/src/transpile/components/input/chips.transformer.js.map +1 -1
  57. package/src/transpile/components/input/color-picker.transformer.js +2 -1
  58. package/src/transpile/components/input/color-picker.transformer.js.map +1 -1
  59. package/src/transpile/components/input/rating.transformer.js +1 -1
  60. package/src/transpile/components/input/rating.transformer.js.map +1 -1
  61. package/src/transpile/components/input/select.transformer.js +1 -1
  62. package/src/transpile/components/input/select.transformer.js.map +1 -1
  63. package/src/transpile/components/input/text.transformer.js +3 -1
  64. package/src/transpile/components/input/text.transformer.js.map +1 -1
  65. package/src/transpile/components/input/upload.transformer.js +19 -0
  66. package/src/transpile/components/input/upload.transformer.js.map +1 -0
  67. package/src/transpile/components/nav/navbar.transformer.js +84 -0
  68. package/src/transpile/components/nav/navbar.transformer.js.map +1 -1
  69. package/src/transpile/components/navigation/popover.transformer.js +1 -1
  70. package/src/transpile/components/navigation/popover.transformer.js.map +1 -1
  71. package/src/transpile/components/page/partial-container.transformer.js +15 -6
  72. package/src/transpile/components/page/partial-container.transformer.js.map +1 -1
  73. package/src/transpile/components/prefab/prefab.transformer.js +23 -2
  74. package/src/transpile/components/prefab/prefab.transformer.js.map +1 -1
  75. package/src/transpile/components/transform-register.js +4 -0
  76. package/src/transpile/components/transform-register.js.map +1 -1
  77. package/src/transpile/components/utils.js +176 -15
  78. package/src/transpile/components/utils.js.map +1 -1
  79. package/src/transpile/property/property-parser.js +12 -0
  80. package/src/transpile/property/property-parser.js.map +1 -1
  81. package/src/transpile/style.transformer.js +7 -1
  82. package/src/transpile/style.transformer.js.map +1 -1
  83. package/src/transpile/transpile.js +370 -25
  84. package/src/transpile/transpile.js.map +1 -1
  85. package/src/utils.js +343 -36
  86. package/src/utils.js.map +1 -1
  87. package/src/utils.test.js +703 -0
  88. package/src/utils.test.js.map +1 -0
  89. package/src/variables/variable.transformer.js +302 -135
  90. package/src/variables/variable.transformer.js.map +1 -1
  91. package/templates/component/app.template.hbs +1 -0
  92. package/templates/component/component.hbs +12 -1
  93. package/templates/component/partial.hbs +8 -0
  94. package/templates/project/.env +1 -1
  95. package/templates/project/app/components.css +16 -15
  96. package/templates/project/app/globals.css +39 -0
  97. package/templates/project/app/loading.tsx +1 -1
  98. package/templates/project/package.json +8 -8
  99. package/templates/variables.template +21 -2
  100. package/templates/project/.npmrc +0 -5
@@ -0,0 +1,703 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("./utils");
4
+ describe("addOptionalChainingToPropertyPath", () => {
5
+ // Basic property paths
6
+ describe("Basic property paths", () => {
7
+ const basicTests = [
8
+ { input: "a", expected: "a" },
9
+ { input: "a.b", expected: "a?.b" },
10
+ { input: "a.b.c", expected: "a?.b?.c" },
11
+ { input: "a.b.c.d", expected: "a?.b?.c?.d" },
12
+ { input: "a.b.c.d.e", expected: "a?.b?.c?.d?.e" },
13
+ { input: "Variables", expected: "Variables" },
14
+ { input: "Variables.data", expected: "Variables?.data" },
15
+ { input: "Variables.data.value", expected: "Variables?.data?.value" },
16
+ { input: "Widgets", expected: "Widgets" },
17
+ { input: "Widgets.form", expected: "Widgets?.form" },
18
+ { input: "Widgets.form.value", expected: "Widgets?.form?.value" },
19
+ { input: "Props", expected: "Props" },
20
+ { input: "Props.key", expected: "Props?.key" },
21
+ { input: "fragment", expected: "fragment" },
22
+ { input: "fragment.data", expected: "fragment?.data" },
23
+ ];
24
+ test.each(basicTests)("should handle basic path: $input", ({ input, expected }) => {
25
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
26
+ });
27
+ });
28
+ // Bracket notation with numeric indices
29
+ describe("Bracket notation with numeric indices", () => {
30
+ const numericIndexTests = [
31
+ { input: "items[0]", expected: "items?.[0]" },
32
+ { input: "items[1]", expected: "items?.[1]" },
33
+ { input: "items[0].name", expected: "items?.[0]?.name" },
34
+ { input: "items[1].value", expected: "items?.[1]?.value" },
35
+ { input: "data[0][1]", expected: "data?.[0]?.[1]" },
36
+ { input: "matrix[0][1][2]", expected: "matrix?.[0]?.[1]?.[2]" },
37
+ { input: "arr[0].prop[1].nested", expected: "arr?.[0]?.prop?.[1]?.nested" },
38
+ { input: "Variables.list[0]", expected: "Variables?.list?.[0]" },
39
+ { input: "Variables.list[0].id", expected: "Variables?.list?.[0]?.id" },
40
+ { input: "Widgets.grid[0][1]", expected: "Widgets?.grid?.[0]?.[1]" },
41
+ ];
42
+ test.each(numericIndexTests)("should handle numeric index: $input", ({ input, expected }) => {
43
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
44
+ });
45
+ });
46
+ // Bracket notation with string literals
47
+ describe("Bracket notation with string literals", () => {
48
+ const stringLiteralTests = [
49
+ { input: `user['name']`, expected: `user?.['name']` },
50
+ { input: `user["name"]`, expected: `user?.["name"]` },
51
+ { input: `user['first_name']`, expected: `user?.['first_name']` },
52
+ { input: `user["last-name"]`, expected: `user?.["last-name"]` },
53
+ { input: `data['key'].value`, expected: `data?.['key']?.value` },
54
+ { input: `obj["prop"]["nested"]`, expected: `obj?.["prop"]?.["nested"]` },
55
+ { input: `Variables['key']`, expected: `Variables?.['key']` },
56
+ { input: `Variables['key'].value`, expected: `Variables?.['key']?.value` },
57
+ { input: `Widgets['form']['field']`, expected: `Widgets?.['form']?.['field']` },
58
+ { input: `data['property_dataset']`, expected: `data?.['property_dataset']` },
59
+ ];
60
+ test.each(stringLiteralTests)("should handle string literal: $input", ({ input, expected }) => {
61
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
62
+ });
63
+ });
64
+ // Bracket notation with property paths (the main fix)
65
+ describe("Bracket notation with property paths inside", () => {
66
+ const propertyPathInBracketTests = [
67
+ {
68
+ input: "data[Widgets.form.value]",
69
+ expected: "data?.[Widgets?.form?.value]",
70
+ },
71
+ {
72
+ input: "Variables.data[Widgets.form.value]",
73
+ expected: "Variables?.data?.[Widgets?.form?.value]",
74
+ },
75
+ {
76
+ input: "items[Variables.selectedIndex]",
77
+ expected: "items?.[Variables?.selectedIndex]",
78
+ },
79
+ {
80
+ input: "data[Widgets.form.value].id",
81
+ expected: "data?.[Widgets?.form?.value]?.id",
82
+ },
83
+ {
84
+ input: "Variables.stvWidgetToFieldMappings.dataSet[Widgets.editFormMetaDataForm1.formWidgets.FormMetaData_widget.datavalue]",
85
+ expected: "Variables?.stvWidgetToFieldMappings?.dataSet?.[Widgets?.editFormMetaDataForm1?.formWidgets?.FormMetaData_widget?.datavalue]",
86
+ },
87
+ {
88
+ input: "Variables.stvWidgetToFieldMappings.dataSet[Widgets.editFormMetaDataForm1.formWidgets.FormMetaData_widget.datavalue]['property_dataset']",
89
+ expected: "Variables?.stvWidgetToFieldMappings?.dataSet?.[Widgets?.editFormMetaDataForm1?.formWidgets?.FormMetaData_widget?.datavalue]?.['property_dataset']",
90
+ },
91
+ {
92
+ input: "grid[Widgets.form.selectedRow].id",
93
+ expected: "grid?.[Widgets?.form?.selectedRow]?.id",
94
+ },
95
+ {
96
+ input: "data[Props.key][Props.nested]",
97
+ expected: "data?.[Props?.key]?.[Props?.nested]",
98
+ },
99
+ {
100
+ input: "Variables.list[Widgets.dropdown.selectedValue]",
101
+ expected: "Variables?.list?.[Widgets?.dropdown?.selectedValue]",
102
+ },
103
+ {
104
+ input: "obj[Variables.key1][Variables.key2].prop",
105
+ expected: "obj?.[Variables?.key1]?.[Variables?.key2]?.prop",
106
+ },
107
+ ];
108
+ test.each(propertyPathInBracketTests)("should handle property path in bracket: $input", ({ input, expected }) => {
109
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
110
+ });
111
+ });
112
+ // Mixed scenarios
113
+ describe("Mixed scenarios", () => {
114
+ const mixedTests = [
115
+ {
116
+ input: "data[0].items[Widgets.form.value].name",
117
+ expected: "data?.[0]?.items?.[Widgets?.form?.value]?.name",
118
+ },
119
+ {
120
+ input: "Variables.list[Widgets.grid.selectedIndex]['status']",
121
+ expected: "Variables?.list?.[Widgets?.grid?.selectedIndex]?.['status']",
122
+ },
123
+ {
124
+ input: "obj['key'][Variables.index].prop[Props.id]",
125
+ expected: "obj?.['key']?.[Variables?.index]?.prop?.[Props?.id]",
126
+ },
127
+ {
128
+ input: "data[Widgets.form.value][0]['name']",
129
+ expected: "data?.[Widgets?.form?.value]?.[0]?.['name']",
130
+ },
131
+ {
132
+ input: "matrix[Variables.row][Variables.col].value",
133
+ expected: "matrix?.[Variables?.row]?.[Variables?.col]?.value",
134
+ },
135
+ ];
136
+ test.each(mixedTests)("should handle mixed scenario: $input", ({ input, expected }) => {
137
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
138
+ });
139
+ });
140
+ // Nested brackets
141
+ describe("Nested brackets", () => {
142
+ const nestedBracketTests = [
143
+ { input: "data[items[0]]", expected: "data?.[items[0]]" },
144
+ { input: "data[items[0]].value", expected: "data?.[items[0]]?.value" },
145
+ { input: "matrix[rows[0]][cols[1]]", expected: "matrix?.[rows[0]]?.[cols[1]]" },
146
+ { input: "obj[data[Widgets.form.key]]", expected: "obj?.[data[Widgets?.form?.key]]" },
147
+ { input: "data[items[Variables.index]]", expected: "data?.[items[Variables?.index]]" },
148
+ ];
149
+ test.each(nestedBracketTests)("should handle nested brackets: $input", ({ input, expected }) => {
150
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
151
+ });
152
+ });
153
+ // Edge cases
154
+ describe("Edge cases", () => {
155
+ const edgeCaseTests = [
156
+ { input: "", expected: "" },
157
+ { input: "a", expected: "a" },
158
+ { input: "_", expected: "_" },
159
+ { input: "$", expected: "$" },
160
+ { input: "_$", expected: "_$" },
161
+ { input: "a_b", expected: "a_b" },
162
+ { input: "a$b", expected: "a$b" },
163
+ { input: "a1", expected: "a1" },
164
+ { input: "a1.b2", expected: "a1?.b2" },
165
+ { input: "a_b.c_d", expected: "a_b?.c_d" },
166
+ { input: "a$b.c$d", expected: "a$b?.c$d" },
167
+ ];
168
+ test.each(edgeCaseTests)("should handle edge case: $input", ({ input, expected }) => {
169
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
170
+ });
171
+ });
172
+ // Generate hundreds of variations programmatically
173
+ describe("Generated test cases - Basic variations", () => {
174
+ const prefixes = ["Variables", "Widgets", "Props", "fragment", "data", "obj", "items"];
175
+ const properties = ["value", "data", "id", "name", "key", "selected", "form", "grid"];
176
+ const indices = [0, 1, 2, 10, 100];
177
+ const stringKeys = ["key", "name", "id", "value", "property_dataset", "first_name"];
178
+ // Generate 200+ basic property path tests
179
+ const generatedBasicTests = [];
180
+ for (const prefix of prefixes) {
181
+ for (const prop of properties) {
182
+ generatedBasicTests.push({
183
+ input: `${prefix}.${prop}`,
184
+ expected: `${prefix}?.${prop}`,
185
+ });
186
+ for (const prop2 of properties.slice(0, 3)) {
187
+ generatedBasicTests.push({
188
+ input: `${prefix}.${prop}.${prop2}`,
189
+ expected: `${prefix}?.${prop}?.${prop2}`,
190
+ });
191
+ }
192
+ }
193
+ }
194
+ test.each(generatedBasicTests)("generated basic: $input", ({ input, expected }) => {
195
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
196
+ });
197
+ });
198
+ describe("Generated test cases - Bracket with numeric indices", () => {
199
+ const prefixes = ["Variables", "Widgets", "data", "items", "arr"];
200
+ const properties = ["list", "items", "data", "array", "grid"];
201
+ const indices = [0, 1, 2, 5, 10, 99, 100];
202
+ const generatedNumericTests = [];
203
+ for (const prefix of prefixes) {
204
+ for (const prop of properties) {
205
+ for (const idx of indices) {
206
+ generatedNumericTests.push({
207
+ input: `${prefix}.${prop}[${idx}]`,
208
+ expected: `${prefix}?.${prop}?.[${idx}]`,
209
+ });
210
+ generatedNumericTests.push({
211
+ input: `${prefix}.${prop}[${idx}].id`,
212
+ expected: `${prefix}?.${prop}?.[${idx}]?.id`,
213
+ });
214
+ }
215
+ }
216
+ }
217
+ test.each(generatedNumericTests)("generated numeric: $input", ({ input, expected }) => {
218
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
219
+ });
220
+ });
221
+ describe("Generated test cases - Bracket with string literals", () => {
222
+ const prefixes = ["Variables", "Widgets", "data", "obj"];
223
+ const properties = ["data", "form", "grid", "list"];
224
+ const stringKeys = [
225
+ "key",
226
+ "name",
227
+ "id",
228
+ "value",
229
+ "property_dataset",
230
+ "first_name",
231
+ "last-name",
232
+ ];
233
+ const generatedStringTests = [];
234
+ for (const prefix of prefixes) {
235
+ for (const prop of properties) {
236
+ for (const key of stringKeys) {
237
+ generatedStringTests.push({
238
+ input: `${prefix}.${prop}['${key}']`,
239
+ expected: `${prefix}?.${prop}?.['${key}']`,
240
+ });
241
+ generatedStringTests.push({
242
+ input: `${prefix}.${prop}["${key}"]`,
243
+ expected: `${prefix}?.${prop}?.["${key}"]`,
244
+ });
245
+ }
246
+ }
247
+ }
248
+ test.each(generatedStringTests)("generated string literal: $input", ({ input, expected }) => {
249
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
250
+ });
251
+ });
252
+ describe("Generated test cases - Property paths in brackets", () => {
253
+ const outerPrefixes = ["Variables", "data", "obj", "items"];
254
+ const outerProps = ["dataSet", "list", "items", "grid", "form"];
255
+ const innerPrefixes = ["Widgets", "Variables", "Props"];
256
+ const innerProps = ["form", "grid", "dropdown", "list"];
257
+ const innerValues = ["value", "selectedValue", "selectedIndex", "datavalue"];
258
+ const generatedPropertyPathTests = [];
259
+ for (const outerPrefix of outerPrefixes) {
260
+ for (const outerProp of outerProps) {
261
+ for (const innerPrefix of innerPrefixes) {
262
+ for (const innerProp of innerProps) {
263
+ for (const innerValue of innerValues) {
264
+ generatedPropertyPathTests.push({
265
+ input: `${outerPrefix}.${outerProp}[${innerPrefix}.${innerProp}.${innerValue}]`,
266
+ expected: `${outerPrefix}?.${outerProp}?.[${innerPrefix}?.${innerProp}?.${innerValue}]`,
267
+ });
268
+ }
269
+ }
270
+ }
271
+ }
272
+ }
273
+ test.each(generatedPropertyPathTests)("generated property path in bracket: $input", ({ input, expected }) => {
274
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
275
+ });
276
+ });
277
+ describe("Generated test cases - Complex nested scenarios", () => {
278
+ const basePaths = ["Variables", "Widgets", "data"];
279
+ const middleProps = ["dataSet", "list", "items"];
280
+ const innerPaths = ["Widgets.form.value", "Variables.selectedIndex", "Props.key"];
281
+ const finalProps = ["id", "name", "value"];
282
+ const stringKeys = ["property_dataset", "key", "name"];
283
+ const generatedComplexTests = [];
284
+ for (const base of basePaths) {
285
+ for (const middle of middleProps) {
286
+ for (const inner of innerPaths) {
287
+ // Test with property path in bracket + final property
288
+ generatedComplexTests.push({
289
+ input: `${base}.${middle}[${inner}].id`,
290
+ expected: `${base}?.${middle}?.[${inner.split(".").join("?.")}]?.id`,
291
+ });
292
+ // Test with property path in bracket + string key
293
+ for (const key of stringKeys) {
294
+ generatedComplexTests.push({
295
+ input: `${base}.${middle}[${inner}]['${key}']`,
296
+ expected: `${base}?.${middle}?.[${inner.split(".").join("?.")}]?.['${key}']`,
297
+ });
298
+ }
299
+ }
300
+ }
301
+ }
302
+ test.each(generatedComplexTests)("generated complex: $input", ({ input, expected }) => {
303
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
304
+ });
305
+ });
306
+ describe("Generated test cases - Multiple bracket accesses", () => {
307
+ const prefixes = ["Variables", "data", "obj"];
308
+ const props = ["data", "list", "items"];
309
+ const bracket1 = ["Widgets.form.value", "Variables.index", "0", "'key'"];
310
+ const bracket2 = ["Props.id", "Widgets.selected", "1", "'name'"];
311
+ const generatedMultipleBracketTests = [];
312
+ for (const prefix of prefixes) {
313
+ for (const prop of props) {
314
+ for (const b1 of bracket1) {
315
+ for (const b2 of bracket2) {
316
+ const b1Processed = b1.includes(".") ? b1.split(".").join("?.") : b1;
317
+ const b2Processed = b2.includes(".") ? b2.split(".").join("?.") : b2;
318
+ generatedMultipleBracketTests.push({
319
+ input: `${prefix}.${prop}[${b1}][${b2}]`,
320
+ expected: `${prefix}?.${prop}?.[${b1Processed}]?.[${b2Processed}]`,
321
+ });
322
+ }
323
+ }
324
+ }
325
+ }
326
+ test.each(generatedMultipleBracketTests)("generated multiple brackets: $input", ({ input, expected }) => {
327
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
328
+ });
329
+ });
330
+ // Real-world scenarios from WaveMaker
331
+ describe("Real-world WaveMaker scenarios", () => {
332
+ const realWorldTests = [
333
+ {
334
+ input: "Variables.stvWidgetToFieldMappings.dataSet[Widgets.editFormMetaDataForm1.formWidgets.FormMetaData_widget.datavalue]['property_dataset']",
335
+ expected: "Variables?.stvWidgetToFieldMappings?.dataSet?.[Widgets?.editFormMetaDataForm1?.formWidgets?.FormMetaData_widget?.datavalue]?.['property_dataset']",
336
+ },
337
+ {
338
+ input: "Widgets.dataGrid1.selecteditem[Variables.selectedRowIndex].id",
339
+ expected: "Widgets?.dataGrid1?.selecteditem?.[Variables?.selectedRowIndex]?.id",
340
+ },
341
+ {
342
+ input: "Variables.userList[Widgets.userDropdown.selectedValue].email",
343
+ expected: "Variables?.userList?.[Widgets?.userDropdown?.selectedValue]?.email",
344
+ },
345
+ {
346
+ input: "Widgets.form1.formWidgets.name_widget.datavalue",
347
+ expected: "Widgets?.form1?.formWidgets?.name_widget?.datavalue",
348
+ },
349
+ {
350
+ input: "Variables.data[Widgets.grid.selectedRow][Props.columnKey]",
351
+ expected: "Variables?.data?.[Widgets?.grid?.selectedRow]?.[Props?.columnKey]",
352
+ },
353
+ {
354
+ input: "fragment.Variables.localData[Widgets.localForm.value].id",
355
+ expected: "fragment?.Variables?.localData?.[Widgets?.localForm?.value]?.id",
356
+ },
357
+ ];
358
+ test.each(realWorldTests)("real-world scenario: $input", ({ input, expected }) => {
359
+ expect((0, utils_1.addOptionalChainingToPropertyPath)(input)).toBe(expected);
360
+ });
361
+ });
362
+ });
363
+ describe("addOptionalChaining", () => {
364
+ describe("Basic functionality", () => {
365
+ const basicTests = [
366
+ { input: "Variables.data.value", expected: "Variables?.data?.value" },
367
+ { input: "Widgets.form.selected", expected: "Widgets?.form?.selected" },
368
+ { input: "data[0].name", expected: "data?.[0]?.name" },
369
+ { input: `user['name']`, expected: `user?.['name']` },
370
+ {
371
+ input: "data[Widgets.form.value]",
372
+ expected: "data?.[Widgets?.form?.value]",
373
+ },
374
+ ];
375
+ test.each(basicTests)("should add optional chaining: $input", ({ input, expected }) => {
376
+ expect((0, utils_1.addOptionalChaining)(input)).toBe(expected);
377
+ });
378
+ });
379
+ describe("With fallback", () => {
380
+ const fallbackTests = [
381
+ {
382
+ input: "Variables.data.value",
383
+ expected: '(Variables?.data?.value || "")',
384
+ options: { addFallback: true },
385
+ },
386
+ {
387
+ input: "Widgets.form.selected",
388
+ expected: '(Widgets?.form?.selected || "")',
389
+ options: { addFallback: true, fallbackValue: '""' },
390
+ },
391
+ {
392
+ input: "data[Widgets.form.value]",
393
+ expected: '(data?.[Widgets?.form?.value] || "")',
394
+ options: { addFallback: true },
395
+ },
396
+ {
397
+ input: "Variables.data.value",
398
+ expected: "(Variables?.data?.value || null)",
399
+ options: { addFallback: true, fallbackValue: "null" },
400
+ },
401
+ ];
402
+ test.each(fallbackTests)("should add fallback: $input", ({ input, expected, options }) => {
403
+ expect((0, utils_1.addOptionalChaining)(input, options)).toBe(expected);
404
+ });
405
+ });
406
+ describe("With string literals", () => {
407
+ const stringLiteralTests = [
408
+ {
409
+ input: `Variables.data["key"].value`,
410
+ expected: `Variables?.data?.["key"]?.value`,
411
+ },
412
+ {
413
+ input: `data['name'].id`,
414
+ expected: `data?.['name']?.id`,
415
+ },
416
+ {
417
+ input: `obj["prop"]['nested']`,
418
+ expected: `obj?.["prop"]?.['nested']`,
419
+ },
420
+ ];
421
+ test.each(stringLiteralTests)("should preserve string literals: $input", ({ input, expected }) => {
422
+ expect((0, utils_1.addOptionalChaining)(input)).toBe(expected);
423
+ });
424
+ });
425
+ describe("Complex expressions", () => {
426
+ const complexTests = [
427
+ {
428
+ input: "Variables.stvWidgetToFieldMappings.dataSet[Widgets.editFormMetaDataForm1.formWidgets.FormMetaData_widget.datavalue]['property_dataset']",
429
+ expected: "Variables?.stvWidgetToFieldMappings?.dataSet?.[Widgets?.editFormMetaDataForm1?.formWidgets?.FormMetaData_widget?.datavalue]?.['property_dataset']",
430
+ },
431
+ {
432
+ input: "data[Widgets.form.value][Variables.index].id",
433
+ expected: "data?.[Widgets?.form?.value]?.[Variables?.index]?.id",
434
+ },
435
+ {
436
+ input: "Variables.list[Widgets.grid.selectedRow][Props.columnKey]['status']",
437
+ expected: "Variables?.list?.[Widgets?.grid?.selectedRow]?.[Props?.columnKey]?.['status']",
438
+ },
439
+ ];
440
+ test.each(complexTests)("should handle complex expression: $input", ({ input, expected }) => {
441
+ expect((0, utils_1.addOptionalChaining)(input)).toBe(expected);
442
+ });
443
+ });
444
+ // Generate thousands of test cases for addOptionalChaining
445
+ describe("Generated test cases - Large scale", () => {
446
+ const prefixes = ["Variables", "Widgets", "Props", "data", "obj"];
447
+ const props = ["data", "list", "items", "form", "grid"];
448
+ const bracketValues = [
449
+ "Widgets.form.value",
450
+ "Variables.index",
451
+ "Props.key",
452
+ "0",
453
+ "1",
454
+ "'key'",
455
+ '"name"',
456
+ ];
457
+ const finalProps = ["id", "name", "value", "selected"];
458
+ const generatedLargeScaleTests = [];
459
+ // Generate 500+ variations
460
+ for (const prefix of prefixes) {
461
+ for (const prop of props) {
462
+ for (const bracket of bracketValues) {
463
+ const bracketProcessed = bracket.includes(".") ? bracket.split(".").join("?.") : bracket;
464
+ generatedLargeScaleTests.push({
465
+ input: `${prefix}.${prop}[${bracket}]`,
466
+ expected: `${prefix}?.${prop}?.[${bracketProcessed}]`,
467
+ });
468
+ for (const final of finalProps) {
469
+ generatedLargeScaleTests.push({
470
+ input: `${prefix}.${prop}[${bracket}].${final}`,
471
+ expected: `${prefix}?.${prop}?.[${bracketProcessed}]?.${final}`,
472
+ });
473
+ }
474
+ }
475
+ }
476
+ }
477
+ test.each(generatedLargeScaleTests)("generated large scale: $input", ({ input, expected }) => {
478
+ expect((0, utils_1.addOptionalChaining)(input)).toBe(expected);
479
+ });
480
+ });
481
+ describe("Function calls", () => {
482
+ describe("Basic function calls", () => {
483
+ const basicFunctionTests = [
484
+ { input: "obj.method()", expected: "obj?.method()" },
485
+ { input: "Variables.data.getValue()", expected: "Variables?.data?.getValue()" },
486
+ { input: "Widgets.form.getSelected()", expected: "Widgets?.form?.getSelected()" },
487
+ { input: "obj.method().prop", expected: "obj?.method()?.prop" },
488
+ { input: "obj.method().prop.value", expected: "obj?.method()?.prop?.value" },
489
+ { input: "Variables.data.getValue().id", expected: "Variables?.data?.getValue()?.id" },
490
+ ];
491
+ test.each(basicFunctionTests)("should handle basic function call: $input", ({ input, expected }) => {
492
+ expect((0, utils_1.addOptionalChaining)(input)).toBe(expected);
493
+ });
494
+ });
495
+ describe("Function calls with arguments", () => {
496
+ const functionWithArgsTests = [
497
+ { input: "obj.method(arg1)", expected: "obj?.method(arg1)" },
498
+ { input: "obj.method(arg1, arg2)", expected: "obj?.method(arg1, arg2)" },
499
+ {
500
+ input: "obj.method(Variables.data.value)",
501
+ expected: "obj?.method(Variables?.data?.value)",
502
+ },
503
+ {
504
+ input: "obj.method(Widgets.form.selected)",
505
+ expected: "obj?.method(Widgets?.form?.selected)",
506
+ },
507
+ {
508
+ input: "obj.method(Variables.data.value, Widgets.form.id)",
509
+ expected: "obj?.method(Variables?.data?.value, Widgets?.form?.id)",
510
+ },
511
+ {
512
+ input: "obj.method(Variables.data[Widgets.form.value])",
513
+ expected: "obj?.method(Variables?.data?.[Widgets?.form?.value])",
514
+ },
515
+ { input: "obj.method().prop", expected: "obj?.method()?.prop" },
516
+ { input: "obj.method(arg1).prop", expected: "obj?.method(arg1)?.prop" },
517
+ ];
518
+ test.each(functionWithArgsTests)("should handle function with args: $input", ({ input, expected }) => {
519
+ expect((0, utils_1.addOptionalChaining)(input)).toBe(expected);
520
+ });
521
+ });
522
+ describe("Chained function calls", () => {
523
+ const chainedFunctionTests = [
524
+ { input: "obj.method1().method2()", expected: "obj?.method1()?.method2()" },
525
+ {
526
+ input: "obj.method1().method2().method3()",
527
+ expected: "obj?.method1()?.method2()?.method3()",
528
+ },
529
+ { input: "Variables.data.filter().map()", expected: "Variables?.data?.filter()?.map()" },
530
+ {
531
+ input: "Variables.data.filter().map().reduce()",
532
+ expected: "Variables?.data?.filter()?.map()?.reduce()",
533
+ },
534
+ { input: "obj.method1().method2().prop", expected: "obj?.method1()?.method2()?.prop" },
535
+ {
536
+ input: "Variables.data.getValue().process().id",
537
+ expected: "Variables?.data?.getValue()?.process()?.id",
538
+ },
539
+ ];
540
+ test.each(chainedFunctionTests)("should handle chained function calls: $input", ({ input, expected }) => {
541
+ expect((0, utils_1.addOptionalChaining)(input)).toBe(expected);
542
+ });
543
+ });
544
+ describe("Function calls with array methods", () => {
545
+ const arrayMethodTests = [
546
+ {
547
+ input: "Variables.data.filter(item => item.id)",
548
+ expected: "Variables?.data?.filter(item => item?.id)",
549
+ },
550
+ {
551
+ input: "Variables.data.map(x => x.name)",
552
+ expected: "Variables?.data?.map(x => x?.name)",
553
+ },
554
+ {
555
+ input: "Variables.data.filter(item => item.id).map(x => x.name)",
556
+ expected: "Variables?.data?.filter(item => item?.id)?.map(x => x?.name)",
557
+ },
558
+ {
559
+ input: "Variables.list.filter(item => item.status === 'active')",
560
+ expected: "Variables?.list?.filter(item => item?.status === 'active')",
561
+ },
562
+ {
563
+ input: "Variables.data.reduce((acc, item) => acc + item.value, 0)",
564
+ expected: "Variables?.data?.reduce((acc, item) => acc + item?.value, 0)",
565
+ },
566
+ {
567
+ input: "Variables.data.find(item => item.id === Variables.selectedId)",
568
+ expected: "Variables?.data?.find(item => item?.id === Variables?.selectedId)",
569
+ },
570
+ ];
571
+ test.each(arrayMethodTests)("should handle array methods: $input", ({ input, expected }) => {
572
+ expect((0, utils_1.addOptionalChaining)(input)).toBe(expected);
573
+ });
574
+ });
575
+ describe("Function calls inside brackets", () => {
576
+ const functionInBracketTests = [
577
+ { input: "data[obj.method()]", expected: "data?.[obj?.method()]" },
578
+ { input: "data[obj.method().prop]", expected: "data?.[obj?.method()?.prop]" },
579
+ { input: "data[Widgets.form.getValue()]", expected: "data?.[Widgets?.form?.getValue()]" },
580
+ { input: "Variables.list[obj.method()]", expected: "Variables?.list?.[obj?.method()]" },
581
+ {
582
+ input: "data[Widgets.form.getValue()].getItem()",
583
+ expected: "data?.[Widgets?.form?.getValue()]?.getItem()",
584
+ },
585
+ {
586
+ input: "data[Widgets.form.getValue()].getItem().name",
587
+ expected: "data?.[Widgets?.form?.getValue()]?.getItem()?.name",
588
+ },
589
+ {
590
+ input: "Variables.list[obj.method()].prop",
591
+ expected: "Variables?.list?.[obj?.method()]?.prop",
592
+ },
593
+ ];
594
+ test.each(functionInBracketTests)("should handle function in bracket: $input", ({ input, expected }) => {
595
+ expect((0, utils_1.addOptionalChaining)(input)).toBe(expected);
596
+ });
597
+ });
598
+ describe("Complex function call scenarios", () => {
599
+ const complexFunctionTests = [
600
+ {
601
+ input: "data[Widgets.form.getValue()].getItem().name",
602
+ expected: "data?.[Widgets?.form?.getValue()]?.getItem()?.name",
603
+ },
604
+ {
605
+ input: "Variables.list[obj.method()].prop",
606
+ expected: "Variables?.list?.[obj?.method()]?.prop",
607
+ },
608
+ {
609
+ input: "obj.method(Variables.data[Widgets.form.value])",
610
+ expected: "obj?.method(Variables?.data?.[Widgets?.form?.value])",
611
+ },
612
+ {
613
+ input: "obj.method(Variables.data[Widgets.form.value]).prop",
614
+ expected: "obj?.method(Variables?.data?.[Widgets?.form?.value])?.prop",
615
+ },
616
+ {
617
+ input: "Variables.data.filter(item => item.id === Variables.selectedId).map(x => x.name)",
618
+ expected: "Variables?.data?.filter(item => item?.id === Variables?.selectedId)?.map(x => x?.name)",
619
+ },
620
+ {
621
+ input: "data[Widgets.form.getValue()][Variables.index].getItem()",
622
+ expected: "data?.[Widgets?.form?.getValue()]?.[Variables?.index]?.getItem()",
623
+ },
624
+ ];
625
+ test.each(complexFunctionTests)("should handle complex function scenario: $input", ({ input, expected }) => {
626
+ expect((0, utils_1.addOptionalChaining)(input)).toBe(expected);
627
+ });
628
+ });
629
+ // Generate hundreds of function call variations
630
+ describe("Generated test cases - Function calls", () => {
631
+ const prefixes = ["Variables", "Widgets", "data", "obj"];
632
+ const props = ["data", "list", "items", "form"];
633
+ const methods = ["getValue", "getSelected", "getItem", "filter", "map", "find"];
634
+ const finalProps = ["id", "name", "value"];
635
+ const generatedFunctionTests = [];
636
+ // Generate function call tests
637
+ for (const prefix of prefixes) {
638
+ for (const prop of props) {
639
+ for (const method of methods) {
640
+ generatedFunctionTests.push({
641
+ input: `${prefix}.${prop}.${method}()`,
642
+ expected: `${prefix}?.${prop}?.${method}()`,
643
+ });
644
+ for (const final of finalProps) {
645
+ generatedFunctionTests.push({
646
+ input: `${prefix}.${prop}.${method}().${final}`,
647
+ expected: `${prefix}?.${prop}?.${method}()?.${final}`,
648
+ });
649
+ }
650
+ }
651
+ }
652
+ }
653
+ // Generate chained function calls
654
+ for (const prefix of prefixes.slice(0, 2)) {
655
+ for (const prop of props.slice(0, 2)) {
656
+ for (const method1 of methods.slice(0, 3)) {
657
+ for (const method2 of methods.slice(0, 3)) {
658
+ generatedFunctionTests.push({
659
+ input: `${prefix}.${prop}.${method1}().${method2}()`,
660
+ expected: `${prefix}?.${prop}?.${method1}()?.${method2}()`,
661
+ });
662
+ }
663
+ }
664
+ }
665
+ }
666
+ test.each(generatedFunctionTests)("generated function call: $input", ({ input, expected }) => {
667
+ expect((0, utils_1.addOptionalChaining)(input)).toBe(expected);
668
+ });
669
+ });
670
+ });
671
+ describe("Pipe expressions", () => {
672
+ const pipeTests = [
673
+ {
674
+ input: '(Variables.wsGetMobileDetails.dataSet.data[0].attachment | filter: {name: "productimage"})[0].url',
675
+ expected: '(Variables?.wsGetMobileDetails?.dataSet?.data?.[0]?.attachment | filter: {name: "productimage"})?.[0]?.url',
676
+ },
677
+ {
678
+ input: "(expr | pipe).prop",
679
+ expected: "(expr | pipe)?.prop",
680
+ },
681
+ {
682
+ input: "(expr | pipe)[0].prop",
683
+ expected: "(expr | pipe)?.[0]?.prop",
684
+ },
685
+ {
686
+ input: "(Variables.data | filter: {id: 1})[0].name",
687
+ expected: "(Variables?.data | filter: {id: 1})?.[0]?.name",
688
+ },
689
+ {
690
+ input: "(Variables.list | filter: {status: 'active'})[0].id",
691
+ expected: "(Variables?.list | filter: {status: 'active'})?.[0]?.id",
692
+ },
693
+ {
694
+ input: "(Widgets.form.data | custom: 'format')?.value",
695
+ expected: "(Widgets?.form?.data | custom: 'format')?.value",
696
+ },
697
+ ];
698
+ test.each(pipeTests)("should handle pipe expression: $input", ({ input, expected }) => {
699
+ expect((0, utils_1.addOptionalChaining)(input)).toBe(expected);
700
+ });
701
+ });
702
+ });
703
+ //# sourceMappingURL=utils.test.js.map