@ngx-formbar/setup 2.0.0-next.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.
@@ -0,0 +1,654 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findComponentRegistrationsNode = findComponentRegistrationsNode;
4
+ exports.findMapArrayLiteral = findMapArrayLiteral;
5
+ exports.updateMapEntries = updateMapEntries;
6
+ exports.findComponentRegistrationsObject = findComponentRegistrationsObject;
7
+ exports.addComponentRegistration = addComponentRegistration;
8
+ exports.getProvideFormbarArg = getProvideFormbarArg;
9
+ exports.matchesIdentifierName = matchesIdentifierName;
10
+ exports.registrationNodeHasKey = registrationNodeHasKey;
11
+ exports.registrationNodeUsesIdentifier = registrationNodeUsesIdentifier;
12
+ exports.registrationsObjectHasKey = registrationsObjectHasKey;
13
+ exports.registrationsObjectUsesIdentifier = registrationsObjectUsesIdentifier;
14
+ exports.componentRegistrationsObjectHasKey = componentRegistrationsObjectHasKey;
15
+ exports.componentRegistrationsObjectUsesIdentifier = componentRegistrationsObjectUsesIdentifier;
16
+ exports.provideFormbarComponentRegistrationsHasIdentifier = provideFormbarComponentRegistrationsHasIdentifier;
17
+ exports.defineFormbarConfigComponentRegistrationsHasIdentifier = defineFormbarConfigComponentRegistrationsHasIdentifier;
18
+ exports.componentRegistrationsMapProviderHasIdentifier = componentRegistrationsMapProviderHasIdentifier;
19
+ exports.directComponentRegistrationsHasIdentifier = directComponentRegistrationsHasIdentifier;
20
+ exports.appConfigProvidersComponentRegistrationsMapHasIdentifier = appConfigProvidersComponentRegistrationsMapHasIdentifier;
21
+ exports.getMapArguments = getMapArguments;
22
+ const schematics_1 = require("@angular-devkit/schematics");
23
+ const typescript_1 = require("typescript");
24
+ const change_1 = require("@schematics/angular/utility/change");
25
+ const constants_1 = require("../constants");
26
+ const decorators_1 = require("./decorators");
27
+ function findComponentRegistrationsNode(sourceFile) {
28
+ let result = null;
29
+ function visit(node) {
30
+ var _a;
31
+ if (result) {
32
+ return;
33
+ }
34
+ result =
35
+ (_a = findMapNodeInTokenRegistration(node)) !== null && _a !== void 0 ? _a : findMapNodeInProvideFormbar(node);
36
+ if (result) {
37
+ return;
38
+ }
39
+ node.forEachChild(visit);
40
+ }
41
+ sourceFile.forEachChild(visit);
42
+ return result;
43
+ }
44
+ function findMapArrayLiteral(mapExpression) {
45
+ if (!(0, typescript_1.isNewExpression)(mapExpression)) {
46
+ return null;
47
+ }
48
+ if (!mapExpression.arguments || mapExpression.arguments.length === 0) {
49
+ return null;
50
+ }
51
+ const firstArg = mapExpression.arguments[0];
52
+ if (firstArg.kind !== typescript_1.SyntaxKind.ArrayLiteralExpression) {
53
+ return null;
54
+ }
55
+ return firstArg;
56
+ }
57
+ function updateMapEntries(tree, sourceFile, filePath, mapArrayLiteral, key, componentClassName) {
58
+ const printer = (0, typescript_1.createPrinter)({});
59
+ const buffer = tree.read(filePath);
60
+ if (!buffer) {
61
+ throw new schematics_1.SchematicsException(`Missing file or unreadable: ${filePath}`);
62
+ }
63
+ const fileContent = buffer.toString('utf-8');
64
+ const newEntry = createNewMapEntry(key, componentClassName);
65
+ const updatedArray = createUpdatedArray(mapArrayLiteral, newEntry);
66
+ return createChangeForArrayUpdate(printer, sourceFile, filePath, mapArrayLiteral, updatedArray, fileContent);
67
+ }
68
+ function findComponentRegistrationsObject(sourceFile) {
69
+ let result = null;
70
+ function visit(node) {
71
+ var _a, _b;
72
+ if (result) {
73
+ return;
74
+ }
75
+ result =
76
+ (_b = (_a = findStandaloneComponentRegistrations(node)) !== null && _a !== void 0 ? _a : findFormbarConfigComponentRegistrations(node)) !== null && _b !== void 0 ? _b : findProvideFormbarComponentRegistrations(node);
77
+ if (result) {
78
+ return;
79
+ }
80
+ node.forEachChild(visit);
81
+ }
82
+ sourceFile.forEachChild(visit);
83
+ return result;
84
+ }
85
+ function addComponentRegistration(tree, sourceFile, filePath, registrationsObject, key, componentClassName) {
86
+ const printer = (0, typescript_1.createPrinter)({});
87
+ const buffer = tree.read(filePath);
88
+ if (!buffer) {
89
+ throw new schematics_1.SchematicsException(`Missing file or unreadable: ${filePath}`);
90
+ }
91
+ const fileContent = buffer.toString('utf-8');
92
+ const updatedObject = createUpdatedRegistrationsObject(registrationsObject, key, componentClassName);
93
+ return createChangeForObjectUpdate(printer, sourceFile, filePath, registrationsObject, updatedObject, fileContent);
94
+ }
95
+ function getProvideFormbarArg(sf) {
96
+ let result;
97
+ const visit = (node) => {
98
+ if (result) {
99
+ return;
100
+ }
101
+ if ((0, typescript_1.isCallExpression)(node) && (0, decorators_1.isCallee)(node.expression, 'provideFormbar')) {
102
+ if (node.arguments.length > 0 &&
103
+ (0, typescript_1.isObjectLiteralExpression)(node.arguments[0])) {
104
+ result = node.arguments[0];
105
+ return;
106
+ }
107
+ }
108
+ node.forEachChild(visit);
109
+ };
110
+ sf.forEachChild(visit);
111
+ return result;
112
+ }
113
+ function matchesIdentifierName(p, key, identifierName) {
114
+ if (!(0, typescript_1.isPropertyAssignment)(p)) {
115
+ return false;
116
+ }
117
+ const n = p.name;
118
+ const matchesKey = ((0, typescript_1.isIdentifier)(n) && n.text === key) ||
119
+ ((0, typescript_1.isStringLiteral)(n) && n.text === key);
120
+ return (matchesKey &&
121
+ (0, typescript_1.isIdentifier)(p.initializer) &&
122
+ p.initializer.text === identifierName);
123
+ }
124
+ function registrationNodeHasKey(node, key) {
125
+ if ((0, typescript_1.isNewExpression)(node)) {
126
+ const arr = findMapArrayLiteral(node);
127
+ if (!arr) {
128
+ return false;
129
+ }
130
+ return arrayLiteralHasKey(arr, key);
131
+ }
132
+ if ((0, typescript_1.isObjectLiteralExpression)(node)) {
133
+ return objectLiteralHasKey(node, key);
134
+ }
135
+ return false;
136
+ }
137
+ function registrationNodeUsesIdentifier(node, identifierName) {
138
+ if ((0, typescript_1.isNewExpression)(node)) {
139
+ const arr = findMapArrayLiteral(node);
140
+ if (!arr) {
141
+ return false;
142
+ }
143
+ return arrayLiteralUsesIdentifier(arr, identifierName);
144
+ }
145
+ if ((0, typescript_1.isObjectLiteralExpression)(node)) {
146
+ return objectLiteralUsesIdentifier(node, identifierName);
147
+ }
148
+ return false;
149
+ }
150
+ function registrationsObjectHasKey(obj, key) {
151
+ for (const p of obj.properties) {
152
+ if (!(0, typescript_1.isPropertyAssignment)(p)) {
153
+ continue;
154
+ }
155
+ const n = p.name;
156
+ const matchesKey = ((0, typescript_1.isIdentifier)(n) && n.text === key) ||
157
+ ((0, typescript_1.isStringLiteral)(n) && n.text === key);
158
+ if (matchesKey) {
159
+ return true;
160
+ }
161
+ }
162
+ return false;
163
+ }
164
+ function registrationsObjectUsesIdentifier(obj, identifierName) {
165
+ for (const p of obj.properties) {
166
+ if (!(0, typescript_1.isPropertyAssignment)(p)) {
167
+ continue;
168
+ }
169
+ if ((0, typescript_1.isIdentifier)(p.initializer) && p.initializer.text === identifierName) {
170
+ return true;
171
+ }
172
+ }
173
+ return false;
174
+ }
175
+ function componentRegistrationsObjectHasKey(node, key) {
176
+ if (!node) {
177
+ return false;
178
+ }
179
+ if (!(0, typescript_1.isObjectLiteralExpression)(node)) {
180
+ return false;
181
+ }
182
+ return registrationsObjectHasKey(node, key);
183
+ }
184
+ function componentRegistrationsObjectUsesIdentifier(node, identifierName) {
185
+ if (!node) {
186
+ return false;
187
+ }
188
+ if (!(0, typescript_1.isObjectLiteralExpression)(node)) {
189
+ return false;
190
+ }
191
+ return registrationsObjectUsesIdentifier(node, identifierName);
192
+ }
193
+ function provideFormbarComponentRegistrationsHasIdentifier(sf, key, identifierName) {
194
+ const arg = getProvideFormbarArg(sf);
195
+ if (!arg) {
196
+ return false;
197
+ }
198
+ const regProp = arg.properties.find((p) => {
199
+ if (!(0, typescript_1.isPropertyAssignment)(p)) {
200
+ return false;
201
+ }
202
+ const n = p.name;
203
+ return (((0, typescript_1.isIdentifier)(n) && n.text === 'componentRegistrations') ||
204
+ ((0, typescript_1.isStringLiteral)(n) && n.text === 'componentRegistrations'));
205
+ });
206
+ if (!regProp || !(0, typescript_1.isPropertyAssignment)(regProp)) {
207
+ return false;
208
+ }
209
+ const nested = regProp.initializer;
210
+ if (!(0, typescript_1.isObjectLiteralExpression)(nested)) {
211
+ return false;
212
+ }
213
+ const entry = nested.properties.find((p) => {
214
+ if (!(0, typescript_1.isPropertyAssignment)(p)) {
215
+ return false;
216
+ }
217
+ const n = p.name;
218
+ const matchesKey = ((0, typescript_1.isIdentifier)(n) && n.text === key) ||
219
+ ((0, typescript_1.isStringLiteral)(n) && n.text === key);
220
+ if (!matchesKey) {
221
+ return false;
222
+ }
223
+ return (0, typescript_1.isIdentifier)(p.initializer) && p.initializer.text === identifierName;
224
+ });
225
+ return !!entry;
226
+ }
227
+ function defineFormbarConfigComponentRegistrationsHasIdentifier(sf, key, identifierName) {
228
+ let found = false;
229
+ const visit = (node) => {
230
+ if (found)
231
+ return;
232
+ if ((0, typescript_1.isCallExpression)(node) &&
233
+ (0, decorators_1.isCallee)(node.expression, 'defineFormbarConfig')) {
234
+ const [firstArg] = node.arguments;
235
+ if (node.arguments.length === 0 || !(0, typescript_1.isObjectLiteralExpression)(firstArg)) {
236
+ node.forEachChild(visit);
237
+ return;
238
+ }
239
+ const regProp = firstArg.properties.find((p) => (0, typescript_1.isPropertyAssignment)(p) &&
240
+ (0, typescript_1.isIdentifier)(p.name) &&
241
+ p.name.text === 'componentRegistrations');
242
+ if (!regProp ||
243
+ !(0, typescript_1.isPropertyAssignment)(regProp) ||
244
+ !(0, typescript_1.isObjectLiteralExpression)(regProp.initializer)) {
245
+ node.forEachChild(visit);
246
+ return;
247
+ }
248
+ found = regProp.initializer.properties.some((p) => {
249
+ return matchesIdentifierName(p, key, identifierName);
250
+ });
251
+ return;
252
+ }
253
+ node.forEachChild(visit);
254
+ };
255
+ sf.forEachChild(visit);
256
+ return found;
257
+ }
258
+ function componentRegistrationsMapProviderHasIdentifier(sf, key, identifierName) {
259
+ let found = false;
260
+ const visit = (node) => {
261
+ if (found)
262
+ return;
263
+ if ((0, typescript_1.isVariableStatement)(node)) {
264
+ const decls = node.declarationList.declarations;
265
+ for (const decl of decls) {
266
+ const mapArg = getMapArguments(decl);
267
+ if (!mapArg) {
268
+ continue;
269
+ }
270
+ found = mapArg.elements.some((el) => {
271
+ return isArrayAndMatchesIdentifierName(el, key, identifierName);
272
+ });
273
+ if (found)
274
+ return;
275
+ }
276
+ }
277
+ node.forEachChild(visit);
278
+ };
279
+ sf.forEachChild(visit);
280
+ return found;
281
+ }
282
+ function directComponentRegistrationsHasIdentifier(sf, key, identifierName) {
283
+ let found = false;
284
+ const visit = (node) => {
285
+ if (found)
286
+ return;
287
+ if ((0, typescript_1.isVariableStatement)(node)) {
288
+ const decls = node.declarationList.declarations;
289
+ for (const decl of decls) {
290
+ if (!(0, typescript_1.isIdentifier)(decl.name) ||
291
+ decl.name.text !== 'componentRegistrations') {
292
+ continue;
293
+ }
294
+ const init = decl.initializer;
295
+ if (!init || !(0, typescript_1.isObjectLiteralExpression)(init)) {
296
+ continue;
297
+ }
298
+ found = init.properties.some((p) => {
299
+ return matchesIdentifierName(p, key, identifierName);
300
+ });
301
+ return;
302
+ }
303
+ }
304
+ node.forEachChild(visit);
305
+ };
306
+ sf.forEachChild(visit);
307
+ return found;
308
+ }
309
+ function appConfigProvidersComponentRegistrationsMapHasIdentifier(sf, key, identifierName) {
310
+ let found = false;
311
+ const visit = (node) => {
312
+ if (found)
313
+ return;
314
+ if (!(0, typescript_1.isVariableStatement)(node)) {
315
+ node.forEachChild(visit);
316
+ return;
317
+ }
318
+ const decls = node.declarationList.declarations;
319
+ for (const decl of decls) {
320
+ if (!(0, typescript_1.isVariableDeclaration)(decl) ||
321
+ !(0, typescript_1.isIdentifier)(decl.name) ||
322
+ decl.name.text !== 'appConfig' ||
323
+ !decl.initializer) {
324
+ continue;
325
+ }
326
+ if (!(0, typescript_1.isObjectLiteralExpression)(decl.initializer)) {
327
+ continue;
328
+ }
329
+ const providersProperty = decl.initializer.properties.find((prop) => (0, typescript_1.isPropertyAssignment)(prop) &&
330
+ (0, typescript_1.isIdentifier)(prop.name) &&
331
+ prop.name.text === 'providers');
332
+ if (!providersProperty ||
333
+ !(0, typescript_1.isPropertyAssignment)(providersProperty) ||
334
+ !(0, typescript_1.isArrayLiteralExpression)(providersProperty.initializer)) {
335
+ continue;
336
+ }
337
+ const providersArray = providersProperty.initializer;
338
+ for (const element of providersArray.elements) {
339
+ if (!(0, typescript_1.isObjectLiteralExpression)(element))
340
+ continue;
341
+ const provideProp = element.properties.find((p) => (0, typescript_1.isPropertyAssignment)(p) &&
342
+ (0, typescript_1.isIdentifier)(p.name) &&
343
+ p.name.text === 'provide' &&
344
+ (0, typescript_1.isIdentifier)(p.initializer) &&
345
+ p.initializer.text === constants_1.NGX_FW_COMPONENT_REGISTRATIONS);
346
+ if (!provideProp)
347
+ continue;
348
+ const useValueProp = element.properties.find((p) => (0, typescript_1.isPropertyAssignment)(p) &&
349
+ (0, typescript_1.isIdentifier)(p.name) &&
350
+ p.name.text === 'useValue');
351
+ if (!useValueProp ||
352
+ !(0, typescript_1.isPropertyAssignment)(useValueProp) ||
353
+ !(0, typescript_1.isNewExpression)(useValueProp.initializer)) {
354
+ continue;
355
+ }
356
+ const mapExpr = useValueProp.initializer;
357
+ if (!mapExpr.arguments ||
358
+ mapExpr.arguments.length === 0 ||
359
+ !(0, typescript_1.isArrayLiteralExpression)(mapExpr.arguments[0])) {
360
+ continue;
361
+ }
362
+ const mapArg = mapExpr.arguments[0];
363
+ found = mapArg.elements.some((el) => {
364
+ return isArrayAndMatchesIdentifierName(el, key, identifierName);
365
+ });
366
+ if (found)
367
+ return;
368
+ }
369
+ }
370
+ node.forEachChild(visit);
371
+ };
372
+ sf.forEachChild(visit);
373
+ return found;
374
+ }
375
+ function getMapArguments(decl) {
376
+ if (!(0, typescript_1.isIdentifier)(decl.name) ||
377
+ decl.name.text !== 'componentRegistrationsProvider') {
378
+ return null;
379
+ }
380
+ const init = decl.initializer;
381
+ if (!init || !(0, typescript_1.isObjectLiteralExpression)(init)) {
382
+ return null;
383
+ }
384
+ const useValueProp = init.properties.find((p) => (0, typescript_1.isPropertyAssignment)(p) &&
385
+ (0, typescript_1.isIdentifier)(p.name) &&
386
+ p.name.text === 'useValue');
387
+ if (!useValueProp || !(0, typescript_1.isPropertyAssignment)(useValueProp)) {
388
+ return null;
389
+ }
390
+ const mapExpr = useValueProp.initializer;
391
+ if (!(0, typescript_1.isNewExpression)(mapExpr) ||
392
+ !mapExpr.arguments ||
393
+ mapExpr.arguments.length === 0) {
394
+ return null;
395
+ }
396
+ const mapArg = mapExpr.arguments[0];
397
+ if (!(0, typescript_1.isArrayLiteralExpression)(mapArg)) {
398
+ return null;
399
+ }
400
+ return mapArg;
401
+ }
402
+ function findMapNodeInTokenRegistration(node) {
403
+ if (!isMapConstructorExpression(node)) {
404
+ return null;
405
+ }
406
+ const parent = node.parent;
407
+ if (!isUseValuePropertyAssignment(parent)) {
408
+ return null;
409
+ }
410
+ const grandParent = parent.parent;
411
+ if (!(0, typescript_1.isObjectLiteralExpression)(grandParent)) {
412
+ return null;
413
+ }
414
+ const hasComponentRegistrationsToken = grandParent.properties.some((prop) => isProvidePropertyWithToken(prop, constants_1.NGX_FW_COMPONENT_REGISTRATIONS));
415
+ return hasComponentRegistrationsToken ? node : null;
416
+ }
417
+ function findMapNodeInProvideFormbar(node) {
418
+ if (!isProvideFormbarCall(node)) {
419
+ return null;
420
+ }
421
+ const callExpr = node;
422
+ if (callExpr.arguments.length === 0) {
423
+ return null;
424
+ }
425
+ const arg = callExpr.arguments[0];
426
+ if (!(0, typescript_1.isObjectLiteralExpression)(arg)) {
427
+ return null;
428
+ }
429
+ const componentRegProp = arg.properties.find((prop) => isPropertyWithName(prop, 'componentRegistrations'));
430
+ if (!componentRegProp ||
431
+ !(0, typescript_1.isPropertyAssignment)(componentRegProp) ||
432
+ !(0, typescript_1.isObjectLiteralExpression)(componentRegProp.initializer)) {
433
+ return null;
434
+ }
435
+ return componentRegProp.initializer;
436
+ }
437
+ function isMapConstructorExpression(node) {
438
+ return ((0, typescript_1.isNewExpression)(node) &&
439
+ (0, typescript_1.isIdentifier)(node.expression) &&
440
+ node.expression.text === 'Map');
441
+ }
442
+ function isUseValuePropertyAssignment(node) {
443
+ return (!!node &&
444
+ (0, typescript_1.isPropertyAssignment)(node) &&
445
+ (0, typescript_1.isIdentifier)(node.name) &&
446
+ node.name.text === 'useValue');
447
+ }
448
+ function isProvidePropertyWithToken(prop, tokenName) {
449
+ return ((0, typescript_1.isPropertyAssignment)(prop) &&
450
+ (0, typescript_1.isIdentifier)(prop.name) &&
451
+ prop.name.text === 'provide' &&
452
+ (0, typescript_1.isIdentifier)(prop.initializer) &&
453
+ prop.initializer.text === tokenName);
454
+ }
455
+ function isProvideFormbarCall(node) {
456
+ return ((0, typescript_1.isCallExpression)(node) &&
457
+ (0, typescript_1.isPropertyAccessExpression)(node.expression) &&
458
+ (0, typescript_1.isIdentifier)(node.expression.name) &&
459
+ node.expression.name.text === 'provideFormbar');
460
+ }
461
+ function isPropertyWithName(prop, name) {
462
+ return ((0, typescript_1.isPropertyAssignment)(prop) &&
463
+ (0, typescript_1.isIdentifier)(prop.name) &&
464
+ prop.name.text === name);
465
+ }
466
+ function createNewMapEntry(key, componentClassName) {
467
+ return typescript_1.factory.createArrayLiteralExpression([
468
+ typescript_1.factory.createStringLiteral(key),
469
+ typescript_1.factory.createIdentifier(componentClassName),
470
+ ]);
471
+ }
472
+ function createUpdatedArray(original, newEntry) {
473
+ const elements = [...original.elements, newEntry];
474
+ return typescript_1.factory.updateArrayLiteralExpression(original, elements);
475
+ }
476
+ function createChangeForArrayUpdate(printer, sourceFile, filePath, original, updated, fileContent) {
477
+ const start = original.getStart();
478
+ const end = original.getEnd();
479
+ const newText = printer.printNode(typescript_1.EmitHint.Unspecified, updated, sourceFile);
480
+ return [
481
+ new change_1.ReplaceChange(filePath, start, fileContent.slice(start, end), newText),
482
+ ];
483
+ }
484
+ function findStandaloneComponentRegistrations(node) {
485
+ if (!(0, typescript_1.isVariableStatement)(node)) {
486
+ return null;
487
+ }
488
+ for (const declaration of node.declarationList.declarations) {
489
+ if (!(0, typescript_1.isVariableDeclaration)(declaration) ||
490
+ !(0, typescript_1.isIdentifier)(declaration.name) ||
491
+ !declaration.initializer ||
492
+ !(0, typescript_1.isObjectLiteralExpression)(declaration.initializer)) {
493
+ continue;
494
+ }
495
+ if (declaration.name.text === 'componentRegistrations' ||
496
+ declaration.name.text === 'componentsRegistrations') {
497
+ return declaration.initializer;
498
+ }
499
+ }
500
+ return null;
501
+ }
502
+ function findFormbarConfigComponentRegistrations(node) {
503
+ if (!(0, typescript_1.isVariableStatement)(node) ||
504
+ node.declarationList.declarations.length === 0) {
505
+ return null;
506
+ }
507
+ const declaration = node.declarationList.declarations[0];
508
+ if (!(0, typescript_1.isVariableDeclaration)(declaration) ||
509
+ !(0, typescript_1.isIdentifier)(declaration.name) ||
510
+ declaration.name.text !== 'formbarConfig' ||
511
+ !declaration.initializer) {
512
+ return null;
513
+ }
514
+ if (!(0, typescript_1.isCallExpression)(declaration.initializer)) {
515
+ return null;
516
+ }
517
+ const callExpr = declaration.initializer;
518
+ if (!(0, typescript_1.isIdentifier)(callExpr.expression) ||
519
+ callExpr.expression.text !== 'defineFormbarConfig' ||
520
+ callExpr.arguments.length === 0) {
521
+ return null;
522
+ }
523
+ const configArg = callExpr.arguments[0];
524
+ return getComponentRegistrationExpression(configArg);
525
+ }
526
+ function findProvideFormbarComponentRegistrations(node) {
527
+ if (!(0, typescript_1.isVariableStatement)(node)) {
528
+ return null;
529
+ }
530
+ const providersArray = findProvidersArray(node);
531
+ if (!providersArray) {
532
+ return null;
533
+ }
534
+ const provideFormbarCall = providersArray.elements.find((el) => (0, typescript_1.isCallExpression)(el) &&
535
+ (0, typescript_1.isIdentifier)(el.expression) &&
536
+ el.expression.text === 'provideFormbar');
537
+ if (!provideFormbarCall || provideFormbarCall.arguments.length === 0) {
538
+ return null;
539
+ }
540
+ const configArg = provideFormbarCall.arguments[0];
541
+ return getComponentRegistrationExpression(configArg);
542
+ }
543
+ function findProvidersArray(node) {
544
+ if (!(0, typescript_1.isVariableStatement)(node)) {
545
+ return null;
546
+ }
547
+ for (const declaration of node.declarationList.declarations) {
548
+ if (!(0, typescript_1.isVariableDeclaration)(declaration) || !declaration.initializer) {
549
+ continue;
550
+ }
551
+ if (!(0, typescript_1.isObjectLiteralExpression)(declaration.initializer)) {
552
+ continue;
553
+ }
554
+ const providersProperty = declaration.initializer.properties.find((prop) => (0, typescript_1.isPropertyAssignment)(prop) &&
555
+ (0, typescript_1.isIdentifier)(prop.name) &&
556
+ prop.name.text === 'providers');
557
+ if (!providersProperty || !(0, typescript_1.isPropertyAssignment)(providersProperty)) {
558
+ continue;
559
+ }
560
+ return providersProperty.initializer;
561
+ }
562
+ return null;
563
+ }
564
+ function createUpdatedRegistrationsObject(registrationsObject, key, componentClassName) {
565
+ const existingProperties = [...registrationsObject.properties];
566
+ const newProperty = typescript_1.factory.createPropertyAssignment(typescript_1.factory.createStringLiteral(key), typescript_1.factory.createIdentifier(componentClassName));
567
+ return typescript_1.factory.updateObjectLiteralExpression(registrationsObject, [
568
+ ...existingProperties,
569
+ newProperty,
570
+ ]);
571
+ }
572
+ function createChangeForObjectUpdate(printer, sourceFile, filePath, original, updated, fileContent) {
573
+ const start = original.getStart();
574
+ const end = original.getEnd();
575
+ const newText = printer.printNode(typescript_1.EmitHint.Unspecified, updated, sourceFile);
576
+ return [
577
+ new change_1.ReplaceChange(filePath, start, fileContent.slice(start, end), newText),
578
+ ];
579
+ }
580
+ function getComponentRegistrationExpression(configArg) {
581
+ if (!(0, typescript_1.isObjectLiteralExpression)(configArg)) {
582
+ return null;
583
+ }
584
+ const componentRegProp = configArg.properties.find((prop) => (0, typescript_1.isPropertyAssignment)(prop) &&
585
+ (0, typescript_1.isIdentifier)(prop.name) &&
586
+ prop.name.text === 'componentRegistrations');
587
+ if (!componentRegProp ||
588
+ !(0, typescript_1.isPropertyAssignment)(componentRegProp) ||
589
+ !(0, typescript_1.isObjectLiteralExpression)(componentRegProp.initializer)) {
590
+ return null;
591
+ }
592
+ return componentRegProp.initializer;
593
+ }
594
+ function isArrayAndMatchesIdentifierName(el, key, identifierName) {
595
+ if (!(0, typescript_1.isArrayLiteralExpression)(el) || el.elements.length !== 2) {
596
+ return false;
597
+ }
598
+ const [keyEl, valueEl] = el.elements;
599
+ return ((0, typescript_1.isStringLiteral)(keyEl) &&
600
+ keyEl.text === key &&
601
+ (0, typescript_1.isIdentifier)(valueEl) &&
602
+ valueEl.text === identifierName);
603
+ }
604
+ function arrayLiteralHasKey(arr, key) {
605
+ for (const el of arr.elements) {
606
+ if (!(0, typescript_1.isArrayLiteralExpression)(el) || el.elements.length !== 2) {
607
+ continue;
608
+ }
609
+ const [k] = el.elements;
610
+ if ((0, typescript_1.isStringLiteral)(k) && k.text === key) {
611
+ return true;
612
+ }
613
+ }
614
+ return false;
615
+ }
616
+ function arrayLiteralUsesIdentifier(arr, identifierName) {
617
+ for (const el of arr.elements) {
618
+ if (!(0, typescript_1.isArrayLiteralExpression)(el) || el.elements.length !== 2) {
619
+ continue;
620
+ }
621
+ const [, v] = el.elements;
622
+ if ((0, typescript_1.isIdentifier)(v) && v.text === identifierName) {
623
+ return true;
624
+ }
625
+ }
626
+ return false;
627
+ }
628
+ function objectLiteralHasKey(obj, key) {
629
+ for (const p of obj.properties) {
630
+ if (!(0, typescript_1.isPropertyAssignment)(p)) {
631
+ continue;
632
+ }
633
+ const n = p.name;
634
+ if ((0, typescript_1.isIdentifier)(n) && n.text === key) {
635
+ return true;
636
+ }
637
+ if ((0, typescript_1.isStringLiteral)(n) && n.text === key) {
638
+ return true;
639
+ }
640
+ }
641
+ return false;
642
+ }
643
+ function objectLiteralUsesIdentifier(obj, identifierName) {
644
+ for (const p of obj.properties) {
645
+ if (!(0, typescript_1.isPropertyAssignment)(p)) {
646
+ continue;
647
+ }
648
+ if ((0, typescript_1.isIdentifier)(p.initializer) && p.initializer.text === identifierName) {
649
+ return true;
650
+ }
651
+ }
652
+ return false;
653
+ }
654
+ //# sourceMappingURL=registrations.js.map