@ngrx/store-devtools 20.1.0 → 21.0.0-rc.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 (54) hide show
  1. package/fesm2022/ngrx-store-devtools.mjs +13 -13
  2. package/migrations/17_0_0-beta/index.js +58 -63
  3. package/migrations/17_0_0-beta/index.js.map +1 -1
  4. package/migrations/6_0_0/index.js +1 -1
  5. package/migrations/6_0_0/index.js.map +1 -1
  6. package/package.json +5 -5
  7. package/schematics/ng-add/index.js +71 -87
  8. package/schematics/ng-add/index.js.map +1 -1
  9. package/schematics-core/index.js +1 -1
  10. package/schematics-core/index.js.map +1 -1
  11. package/schematics-core/utility/ast-utils.js +198 -240
  12. package/schematics-core/utility/ast-utils.js.map +1 -1
  13. package/schematics-core/utility/change.js +68 -85
  14. package/schematics-core/utility/change.js.map +1 -1
  15. package/schematics-core/utility/config.js +7 -7
  16. package/schematics-core/utility/config.js.map +1 -1
  17. package/schematics-core/utility/find-component.js +20 -20
  18. package/schematics-core/utility/find-component.js.map +1 -1
  19. package/schematics-core/utility/find-module.js +21 -21
  20. package/schematics-core/utility/find-module.js.map +1 -1
  21. package/schematics-core/utility/json-utilts.js +4 -26
  22. package/schematics-core/utility/json-utilts.js.map +1 -1
  23. package/schematics-core/utility/libs-version.js +1 -1
  24. package/schematics-core/utility/libs-version.js.map +1 -1
  25. package/schematics-core/utility/ngrx-utils.js +110 -141
  26. package/schematics-core/utility/ngrx-utils.js.map +1 -1
  27. package/schematics-core/utility/package.js +2 -3
  28. package/schematics-core/utility/package.js.map +1 -1
  29. package/schematics-core/utility/parse-name.js +3 -3
  30. package/schematics-core/utility/parse-name.js.map +1 -1
  31. package/schematics-core/utility/project.js +13 -13
  32. package/schematics-core/utility/project.js.map +1 -1
  33. package/schematics-core/utility/standalone.js +133 -211
  34. package/schematics-core/utility/standalone.js.map +1 -1
  35. package/schematics-core/utility/strings.js +12 -12
  36. package/schematics-core/utility/strings.js.map +1 -1
  37. package/schematics-core/utility/update.js +12 -12
  38. package/schematics-core/utility/update.js.map +1 -1
  39. package/schematics-core/utility/visitors.js +78 -180
  40. package/schematics-core/utility/visitors.js.map +1 -1
  41. package/types/ngrx-store-devtools.d.ts +252 -0
  42. package/index.d.ts +0 -6
  43. package/public_api.d.ts +0 -1
  44. package/src/actions.d.ts +0 -79
  45. package/src/config.d.ts +0 -126
  46. package/src/devtools-dispatcher.d.ts +0 -6
  47. package/src/devtools.d.ts +0 -35
  48. package/src/extension.d.ts +0 -52
  49. package/src/index.d.ts +0 -6
  50. package/src/instrument.d.ts +0 -9
  51. package/src/provide-store-devtools.d.ts +0 -26
  52. package/src/reducer.d.ts +0 -47
  53. package/src/utils.d.ts +0 -42
  54. package/src/zone-config.d.ts +0 -9
@@ -1,40 +1,37 @@
1
1
  "use strict";
2
- var __values = (this && this.__values) || function(o) {
3
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
- if (m) return m.call(o);
5
- if (o && typeof o.length === "number") return {
6
- next: function () {
7
- if (o && i >= o.length) o = void 0;
8
- return { value: o && o[i++], done: !o };
9
- }
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
10
26
  };
11
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
- };
13
- var __read = (this && this.__read) || function (o, n) {
14
- var m = typeof Symbol === "function" && o[Symbol.iterator];
15
- if (!m) return o;
16
- var i = m.call(o), r, ar = [], e;
17
- try {
18
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
- }
20
- catch (error) { e = { error: error }; }
21
- finally {
22
- try {
23
- if (r && !r.done && (m = i["return"])) m.call(i);
24
- }
25
- finally { if (e) throw e.error; }
26
- }
27
- return ar;
28
- };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
- if (ar || !(i in from)) {
32
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
- ar[i] = from[i];
34
- }
35
- }
36
- return to.concat(ar || Array.prototype.slice.call(from));
37
- };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
38
35
  Object.defineProperty(exports, "__esModule", { value: true });
39
36
  exports.findNodes = findNodes;
40
37
  exports.getSourceNodes = getSourceNodes;
@@ -58,8 +55,8 @@ exports.containsProperty = containsProperty;
58
55
  * Use of this source code is governed by an MIT-style license that can be
59
56
  * found in the LICENSE file at https://angular.io/license
60
57
  */
61
- var ts = require("typescript");
62
- var change_1 = require("./change");
58
+ const ts = __importStar(require("typescript"));
59
+ const change_1 = require("./change");
63
60
  /**
64
61
  * Find all nodes from the AST in the subtree of node of SyntaxKind kind.
65
62
  * @param node
@@ -67,39 +64,27 @@ var change_1 = require("./change");
67
64
  * @param max The maximum number of items to return.
68
65
  * @return all nodes of kind, or [] if none is found
69
66
  */
70
- function findNodes(node, kind, max) {
71
- var e_1, _a;
72
- if (max === void 0) { max = Infinity; }
67
+ function findNodes(node, kind, max = Infinity) {
73
68
  if (!node || max == 0) {
74
69
  return [];
75
70
  }
76
- var arr = [];
71
+ const arr = [];
77
72
  if (node.kind === kind) {
78
73
  arr.push(node);
79
74
  max--;
80
75
  }
81
76
  if (max > 0) {
82
- try {
83
- for (var _b = __values(node.getChildren()), _c = _b.next(); !_c.done; _c = _b.next()) {
84
- var child = _c.value;
85
- findNodes(child, kind, max).forEach(function (node) {
86
- if (max > 0) {
87
- arr.push(node);
88
- }
89
- max--;
90
- });
91
- if (max <= 0) {
92
- break;
77
+ for (const child of node.getChildren()) {
78
+ findNodes(child, kind, max).forEach((node) => {
79
+ if (max > 0) {
80
+ arr.push(node);
93
81
  }
82
+ max--;
83
+ });
84
+ if (max <= 0) {
85
+ break;
94
86
  }
95
87
  }
96
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
97
- finally {
98
- try {
99
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
100
- }
101
- finally { if (e_1) throw e_1.error; }
102
- }
103
88
  }
104
89
  return arr;
105
90
  }
@@ -109,14 +94,14 @@ function findNodes(node, kind, max) {
109
94
  * @returns {Observable<ts.Node>} An observable of all the nodes in the source.
110
95
  */
111
96
  function getSourceNodes(sourceFile) {
112
- var nodes = [sourceFile];
113
- var result = [];
97
+ const nodes = [sourceFile];
98
+ const result = [];
114
99
  while (nodes.length > 0) {
115
- var node = nodes.shift();
100
+ const node = nodes.shift();
116
101
  if (node) {
117
102
  result.push(node);
118
103
  if (node.getChildCount(sourceFile) >= 0) {
119
- nodes.unshift.apply(nodes, __spreadArray([], __read(node.getChildren()), false));
104
+ nodes.unshift(...node.getChildren());
120
105
  }
121
106
  }
122
107
  }
@@ -143,7 +128,7 @@ function nodesByPosition(first, second) {
143
128
  * @throw Error if toInsert is first occurence but fall back is not set
144
129
  */
145
130
  function insertAfterLastOccurrence(nodes, toInsert, file, fallbackPos, syntaxKind) {
146
- var lastItem = nodes.sort(nodesByPosition).pop();
131
+ let lastItem = nodes.sort(nodesByPosition).pop();
147
132
  if (!lastItem) {
148
133
  throw new Error();
149
134
  }
@@ -151,9 +136,9 @@ function insertAfterLastOccurrence(nodes, toInsert, file, fallbackPos, syntaxKin
151
136
  lastItem = findNodes(lastItem, syntaxKind).sort(nodesByPosition).pop();
152
137
  }
153
138
  if (!lastItem && fallbackPos == undefined) {
154
- throw new Error("tried to insert ".concat(toInsert, " as first occurence with no fallback position"));
139
+ throw new Error(`tried to insert ${toInsert} as first occurence with no fallback position`);
155
140
  }
156
- var lastItemPosition = lastItem ? lastItem.end : fallbackPos;
141
+ const lastItemPosition = lastItem ? lastItem.end : fallbackPos;
157
142
  return new change_1.InsertChange(file, lastItemPosition, toInsert);
158
143
  }
159
144
  function getContentOfKeyLiteral(_source, node) {
@@ -168,9 +153,8 @@ function getContentOfKeyLiteral(_source, node) {
168
153
  }
169
154
  }
170
155
  function _angularImportsFromNode(node, _sourceFile) {
171
- var _a;
172
- var ms = node.moduleSpecifier;
173
- var modulePath;
156
+ const ms = node.moduleSpecifier;
157
+ let modulePath;
174
158
  switch (ms.kind) {
175
159
  case ts.SyntaxKind.StringLiteral:
176
160
  modulePath = ms.text;
@@ -187,21 +171,19 @@ function _angularImportsFromNode(node, _sourceFile) {
187
171
  return {};
188
172
  }
189
173
  else if (node.importClause.namedBindings) {
190
- var nb = node.importClause.namedBindings;
174
+ const nb = node.importClause.namedBindings;
191
175
  if (nb.kind == ts.SyntaxKind.NamespaceImport) {
192
176
  // This is of the form `import * as name from 'path'`. Return `name.`.
193
- return _a = {},
194
- _a[nb.name.text + '.'] = modulePath,
195
- _a;
177
+ return {
178
+ [nb.name.text + '.']: modulePath,
179
+ };
196
180
  }
197
181
  else {
198
182
  // This is of the form `import {a,b,c} from 'path'`
199
- var namedImports = nb;
183
+ const namedImports = nb;
200
184
  return namedImports.elements
201
- .map(function (is) {
202
- return is.propertyName ? is.propertyName.text : is.name.text;
203
- })
204
- .reduce(function (acc, curr) {
185
+ .map((is) => is.propertyName ? is.propertyName.text : is.name.text)
186
+ .reduce((acc, curr) => {
205
187
  acc[curr] = modulePath;
206
188
  return acc;
207
189
  }, {});
@@ -215,72 +197,57 @@ function _angularImportsFromNode(node, _sourceFile) {
215
197
  }
216
198
  }
217
199
  function getDecoratorMetadata(source, identifier, module) {
218
- var angularImports = findNodes(source, ts.SyntaxKind.ImportDeclaration)
219
- .map(function (node) {
220
- return _angularImportsFromNode(node, source);
221
- })
222
- .reduce(function (acc, current) {
223
- var e_2, _a;
224
- try {
225
- for (var _b = __values(Object.keys(current)), _c = _b.next(); !_c.done; _c = _b.next()) {
226
- var key = _c.value;
227
- acc[key] = current[key];
228
- }
229
- }
230
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
231
- finally {
232
- try {
233
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
234
- }
235
- finally { if (e_2) throw e_2.error; }
200
+ const angularImports = findNodes(source, ts.SyntaxKind.ImportDeclaration)
201
+ .map((node) => _angularImportsFromNode(node, source))
202
+ .reduce((acc, current) => {
203
+ for (const key of Object.keys(current)) {
204
+ acc[key] = current[key];
236
205
  }
237
206
  return acc;
238
207
  }, {});
239
208
  return getSourceNodes(source)
240
- .filter(function (node) {
209
+ .filter((node) => {
241
210
  return (node.kind == ts.SyntaxKind.Decorator &&
242
211
  node.expression.kind == ts.SyntaxKind.CallExpression);
243
212
  })
244
- .map(function (node) { return node.expression; })
245
- .filter(function (expr) {
213
+ .map((node) => node.expression)
214
+ .filter((expr) => {
246
215
  if (expr.expression.kind == ts.SyntaxKind.Identifier) {
247
- var id = expr.expression;
216
+ const id = expr.expression;
248
217
  return (id.getFullText(source) == identifier &&
249
218
  angularImports[id.getFullText(source)] === module);
250
219
  }
251
220
  else if (expr.expression.kind == ts.SyntaxKind.PropertyAccessExpression) {
252
221
  // This covers foo.NgModule when importing * as foo.
253
- var paExpr = expr.expression;
222
+ const paExpr = expr.expression;
254
223
  // If the left expression is not an identifier, just give up at that point.
255
224
  if (paExpr.expression.kind !== ts.SyntaxKind.Identifier) {
256
225
  return false;
257
226
  }
258
- var id = paExpr.name.text;
259
- var moduleId = paExpr.expression.getText(source);
227
+ const id = paExpr.name.text;
228
+ const moduleId = paExpr.expression.getText(source);
260
229
  return id === identifier && angularImports[moduleId + '.'] === module;
261
230
  }
262
231
  return false;
263
232
  })
264
- .filter(function (expr) {
265
- return expr.arguments[0] &&
266
- expr.arguments[0].kind == ts.SyntaxKind.ObjectLiteralExpression;
267
- })
268
- .map(function (expr) { return expr.arguments[0]; });
233
+ .filter((expr) => expr.arguments[0] &&
234
+ expr.arguments[0].kind == ts.SyntaxKind.ObjectLiteralExpression)
235
+ .map((expr) => expr.arguments[0]);
269
236
  }
270
237
  function _addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbolName, importPath) {
271
- var nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core');
272
- var node = nodes[0]; // eslint-disable-line @typescript-eslint/no-explicit-any
238
+ const nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core');
239
+ let node = nodes[0]; // eslint-disable-line @typescript-eslint/no-explicit-any
273
240
  // Find the decorator declaration.
274
241
  if (!node) {
275
242
  return [];
276
243
  }
277
244
  // Get all the children property assignment of object literals.
278
- var matchingProperties = node.properties
279
- .filter(function (prop) { return prop.kind == ts.SyntaxKind.PropertyAssignment; })
245
+ const matchingProperties = node.properties
246
+ .filter((prop) => prop.kind == ts.SyntaxKind.PropertyAssignment)
280
247
  // Filter out every fields that's not "metadataField". Also handles string literals
281
248
  // (but not expressions).
282
- .filter(function (prop) {
283
- var name = prop.name;
249
+ .filter((prop) => {
250
+ const name = prop.name;
284
251
  switch (name.kind) {
285
252
  case ts.SyntaxKind.Identifier:
286
253
  return name.getText(source) == metadataField;
@@ -295,36 +262,36 @@ function _addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbo
295
262
  }
296
263
  if (matchingProperties.length == 0) {
297
264
  // We haven't found the field in the metadata declaration. Insert a new field.
298
- var expr = node;
299
- var position_1;
300
- var toInsert_1;
265
+ const expr = node;
266
+ let position;
267
+ let toInsert;
301
268
  if (expr.properties.length == 0) {
302
- position_1 = expr.getEnd() - 1;
303
- toInsert_1 = " ".concat(metadataField, ": [").concat(symbolName, "]\n");
269
+ position = expr.getEnd() - 1;
270
+ toInsert = ` ${metadataField}: [${symbolName}]\n`;
304
271
  }
305
272
  else {
306
273
  node = expr.properties[expr.properties.length - 1];
307
- position_1 = node.getEnd();
274
+ position = node.getEnd();
308
275
  // Get the indentation of the last element, if any.
309
- var text = node.getFullText(source);
310
- var matches = text.match(/^\r?\n\s*/);
276
+ const text = node.getFullText(source);
277
+ const matches = text.match(/^\r?\n\s*/);
311
278
  if (matches.length > 0) {
312
- toInsert_1 = ",".concat(matches[0]).concat(metadataField, ": [").concat(symbolName, "]");
279
+ toInsert = `,${matches[0]}${metadataField}: [${symbolName}]`;
313
280
  }
314
281
  else {
315
- toInsert_1 = ", ".concat(metadataField, ": [").concat(symbolName, "]");
282
+ toInsert = `, ${metadataField}: [${symbolName}]`;
316
283
  }
317
284
  }
318
- var newMetadataProperty = new change_1.InsertChange(ngModulePath, position_1, toInsert_1);
319
- var newMetadataImport = insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath);
285
+ const newMetadataProperty = new change_1.InsertChange(ngModulePath, position, toInsert);
286
+ const newMetadataImport = insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath);
320
287
  return [newMetadataProperty, newMetadataImport];
321
288
  }
322
- var assignment = matchingProperties[0];
289
+ const assignment = matchingProperties[0];
323
290
  // If it's not an array, nothing we can do really.
324
291
  if (assignment.initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {
325
292
  return [];
326
293
  }
327
- var arrLiteral = assignment.initializer;
294
+ const arrLiteral = assignment.initializer;
328
295
  if (arrLiteral.elements.length == 0) {
329
296
  // Forward the property.
330
297
  node = arrLiteral;
@@ -337,41 +304,39 @@ function _addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbo
337
304
  return [];
338
305
  }
339
306
  if (Array.isArray(node)) {
340
- var nodeArray = node;
341
- var symbolsArray = nodeArray.map(function (node) { return node.getText(); });
307
+ const nodeArray = node;
308
+ const symbolsArray = nodeArray.map((node) => node.getText());
342
309
  if (symbolsArray.includes(symbolName)) {
343
310
  return [];
344
311
  }
345
312
  node = node[node.length - 1];
346
- var effectsModule = nodeArray.find(function (node) {
347
- return (node.getText().includes('EffectsModule.forRoot') &&
348
- symbolName.includes('EffectsModule.forRoot')) ||
349
- (node.getText().includes('EffectsModule.forFeature') &&
350
- symbolName.includes('EffectsModule.forFeature'));
351
- });
313
+ const effectsModule = nodeArray.find((node) => (node.getText().includes('EffectsModule.forRoot') &&
314
+ symbolName.includes('EffectsModule.forRoot')) ||
315
+ (node.getText().includes('EffectsModule.forFeature') &&
316
+ symbolName.includes('EffectsModule.forFeature')));
352
317
  if (effectsModule && symbolName.includes('EffectsModule')) {
353
- var effectsArgs = effectsModule.arguments.shift();
318
+ const effectsArgs = effectsModule.arguments.shift();
354
319
  if (effectsArgs &&
355
320
  effectsArgs.kind === ts.SyntaxKind.ArrayLiteralExpression) {
356
- var effectsElements = effectsArgs
321
+ const effectsElements = effectsArgs
357
322
  .elements;
358
- var _a = __read(symbolName.match(/\[(.*)\]/), 2), effectsSymbol = _a[1];
359
- var epos = void 0;
323
+ const [, effectsSymbol] = symbolName.match(/\[(.*)\]/);
324
+ let epos;
360
325
  if (effectsElements.length === 0) {
361
326
  epos = effectsArgs.getStart() + 1;
362
327
  return [new change_1.InsertChange(ngModulePath, epos, effectsSymbol)];
363
328
  }
364
329
  else {
365
- var lastEffect = effectsElements[effectsElements.length - 1];
330
+ const lastEffect = effectsElements[effectsElements.length - 1];
366
331
  epos = lastEffect.getEnd();
367
332
  // Get the indentation of the last element, if any.
368
- var text = lastEffect.getFullText(source);
369
- var effectInsert = void 0;
333
+ const text = lastEffect.getFullText(source);
334
+ let effectInsert;
370
335
  if (text.match('^\r?\r?\n')) {
371
- effectInsert = ",".concat(text.match(/^\r?\n\s+/)[0]).concat(effectsSymbol);
336
+ effectInsert = `,${text.match(/^\r?\n\s+/)[0]}${effectsSymbol}`;
372
337
  }
373
338
  else {
374
- effectInsert = ", ".concat(effectsSymbol);
339
+ effectInsert = `, ${effectsSymbol}`;
375
340
  }
376
341
  return [new change_1.InsertChange(ngModulePath, epos, effectInsert)];
377
342
  }
@@ -381,62 +346,62 @@ function _addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbo
381
346
  }
382
347
  }
383
348
  }
384
- var toInsert;
385
- var position = node.getEnd();
349
+ let toInsert;
350
+ let position = node.getEnd();
386
351
  if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {
387
352
  // We haven't found the field in the metadata declaration. Insert a new
388
353
  // field.
389
- var expr = node;
354
+ const expr = node;
390
355
  if (expr.properties.length == 0) {
391
356
  position = expr.getEnd() - 1;
392
- toInsert = " ".concat(metadataField, ": [").concat(symbolName, "]\n");
357
+ toInsert = ` ${metadataField}: [${symbolName}]\n`;
393
358
  }
394
359
  else {
395
360
  node = expr.properties[expr.properties.length - 1];
396
361
  position = node.getEnd();
397
362
  // Get the indentation of the last element, if any.
398
- var text = node.getFullText(source);
363
+ const text = node.getFullText(source);
399
364
  if (text.match('^\r?\r?\n')) {
400
- toInsert = ",".concat(text.match(/^\r?\n\s+/)[0]).concat(metadataField, ": [").concat(symbolName, "]");
365
+ toInsert = `,${text.match(/^\r?\n\s+/)[0]}${metadataField}: [${symbolName}]`;
401
366
  }
402
367
  else {
403
- toInsert = ", ".concat(metadataField, ": [").concat(symbolName, "]");
368
+ toInsert = `, ${metadataField}: [${symbolName}]`;
404
369
  }
405
370
  }
406
371
  }
407
372
  else if (node.kind == ts.SyntaxKind.ArrayLiteralExpression) {
408
373
  // We found the field but it's empty. Insert it just before the `]`.
409
374
  position--;
410
- toInsert = "".concat(symbolName);
375
+ toInsert = `${symbolName}`;
411
376
  }
412
377
  else {
413
378
  // Get the indentation of the last element, if any.
414
- var text = node.getFullText(source);
379
+ const text = node.getFullText(source);
415
380
  if (text.match(/^\r?\n/)) {
416
- toInsert = ",".concat(text.match(/^\r?\n(\r?)\s+/)[0]).concat(symbolName);
381
+ toInsert = `,${text.match(/^\r?\n(\r?)\s+/)[0]}${symbolName}`;
417
382
  }
418
383
  else {
419
- toInsert = ", ".concat(symbolName);
384
+ toInsert = `, ${symbolName}`;
420
385
  }
421
386
  }
422
- var insert = new change_1.InsertChange(ngModulePath, position, toInsert);
423
- var importInsert = insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath);
387
+ const insert = new change_1.InsertChange(ngModulePath, position, toInsert);
388
+ const importInsert = insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath);
424
389
  return [insert, importInsert];
425
390
  }
426
391
  function _addSymbolToComponentMetadata(source, componentPath, metadataField, symbolName, importPath) {
427
- var nodes = getDecoratorMetadata(source, 'Component', '@angular/core');
428
- var node = nodes[0]; // eslint-disable-line @typescript-eslint/no-explicit-any
392
+ const nodes = getDecoratorMetadata(source, 'Component', '@angular/core');
393
+ let node = nodes[0]; // eslint-disable-line @typescript-eslint/no-explicit-any
429
394
  // Find the decorator declaration.
430
395
  if (!node) {
431
396
  return [];
432
397
  }
433
398
  // Get all the children property assignment of object literals.
434
- var matchingProperties = node.properties
435
- .filter(function (prop) { return prop.kind == ts.SyntaxKind.PropertyAssignment; })
399
+ const matchingProperties = node.properties
400
+ .filter((prop) => prop.kind == ts.SyntaxKind.PropertyAssignment)
436
401
  // Filter out every fields that's not "metadataField". Also handles string literals
437
402
  // (but not expressions).
438
- .filter(function (prop) {
439
- var name = prop.name;
403
+ .filter((prop) => {
404
+ const name = prop.name;
440
405
  switch (name.kind) {
441
406
  case ts.SyntaxKind.Identifier:
442
407
  return name.getText(source) == metadataField;
@@ -451,36 +416,36 @@ function _addSymbolToComponentMetadata(source, componentPath, metadataField, sym
451
416
  }
452
417
  if (matchingProperties.length == 0) {
453
418
  // We haven't found the field in the metadata declaration. Insert a new field.
454
- var expr = node;
455
- var position_2;
456
- var toInsert_2;
419
+ const expr = node;
420
+ let position;
421
+ let toInsert;
457
422
  if (expr.properties.length == 0) {
458
- position_2 = expr.getEnd() - 1;
459
- toInsert_2 = " ".concat(metadataField, ": [").concat(symbolName, "]\n");
423
+ position = expr.getEnd() - 1;
424
+ toInsert = ` ${metadataField}: [${symbolName}]\n`;
460
425
  }
461
426
  else {
462
427
  node = expr.properties[expr.properties.length - 1];
463
- position_2 = node.getEnd();
428
+ position = node.getEnd();
464
429
  // Get the indentation of the last element, if any.
465
- var text = node.getFullText(source);
466
- var matches = text.match(/^\r?\n\s*/);
430
+ const text = node.getFullText(source);
431
+ const matches = text.match(/^\r?\n\s*/);
467
432
  if (matches.length > 0) {
468
- toInsert_2 = ",".concat(matches[0]).concat(metadataField, ": [").concat(symbolName, "]");
433
+ toInsert = `,${matches[0]}${metadataField}: [${symbolName}]`;
469
434
  }
470
435
  else {
471
- toInsert_2 = ", ".concat(metadataField, ": [").concat(symbolName, "]");
436
+ toInsert = `, ${metadataField}: [${symbolName}]`;
472
437
  }
473
438
  }
474
- var newMetadataProperty = new change_1.InsertChange(componentPath, position_2, toInsert_2);
475
- var newMetadataImport = insertImport(source, componentPath, symbolName.replace(/\..*$/, ''), importPath);
439
+ const newMetadataProperty = new change_1.InsertChange(componentPath, position, toInsert);
440
+ const newMetadataImport = insertImport(source, componentPath, symbolName.replace(/\..*$/, ''), importPath);
476
441
  return [newMetadataProperty, newMetadataImport];
477
442
  }
478
- var assignment = matchingProperties[0];
443
+ const assignment = matchingProperties[0];
479
444
  // If it's not an array, nothing we can do really.
480
445
  if (assignment.initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {
481
446
  return [];
482
447
  }
483
- var arrLiteral = assignment.initializer;
448
+ const arrLiteral = assignment.initializer;
484
449
  if (arrLiteral.elements.length == 0) {
485
450
  // Forward the property.
486
451
  node = arrLiteral;
@@ -493,53 +458,53 @@ function _addSymbolToComponentMetadata(source, componentPath, metadataField, sym
493
458
  return [];
494
459
  }
495
460
  if (Array.isArray(node)) {
496
- var nodeArray = node;
497
- var symbolsArray = nodeArray.map(function (node) { return node.getText(); });
461
+ const nodeArray = node;
462
+ const symbolsArray = nodeArray.map((node) => node.getText());
498
463
  if (symbolsArray.includes(symbolName)) {
499
464
  return [];
500
465
  }
501
466
  node = node[node.length - 1];
502
467
  }
503
- var toInsert;
504
- var position = node.getEnd();
468
+ let toInsert;
469
+ let position = node.getEnd();
505
470
  if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {
506
471
  // We haven't found the field in the metadata declaration. Insert a new
507
472
  // field.
508
- var expr = node;
473
+ const expr = node;
509
474
  if (expr.properties.length == 0) {
510
475
  position = expr.getEnd() - 1;
511
- toInsert = " ".concat(metadataField, ": [").concat(symbolName, "]\n");
476
+ toInsert = ` ${metadataField}: [${symbolName}]\n`;
512
477
  }
513
478
  else {
514
479
  node = expr.properties[expr.properties.length - 1];
515
480
  position = node.getEnd();
516
481
  // Get the indentation of the last element, if any.
517
- var text = node.getFullText(source);
482
+ const text = node.getFullText(source);
518
483
  if (text.match('^\r?\r?\n')) {
519
- toInsert = ",".concat(text.match(/^\r?\n\s+/)[0]).concat(metadataField, ": [").concat(symbolName, "]");
484
+ toInsert = `,${text.match(/^\r?\n\s+/)[0]}${metadataField}: [${symbolName}]`;
520
485
  }
521
486
  else {
522
- toInsert = ", ".concat(metadataField, ": [").concat(symbolName, "]");
487
+ toInsert = `, ${metadataField}: [${symbolName}]`;
523
488
  }
524
489
  }
525
490
  }
526
491
  else if (node.kind == ts.SyntaxKind.ArrayLiteralExpression) {
527
492
  // We found the field but it's empty. Insert it just before the `]`.
528
493
  position--;
529
- toInsert = "".concat(symbolName);
494
+ toInsert = `${symbolName}`;
530
495
  }
531
496
  else {
532
497
  // Get the indentation of the last element, if any.
533
- var text = node.getFullText(source);
498
+ const text = node.getFullText(source);
534
499
  if (text.match(/^\r?\n/)) {
535
- toInsert = ",".concat(text.match(/^\r?\n(\r?)\s+/)[0]).concat(symbolName);
500
+ toInsert = `,${text.match(/^\r?\n(\r?)\s+/)[0]}${symbolName}`;
536
501
  }
537
502
  else {
538
- toInsert = ", ".concat(symbolName);
503
+ toInsert = `, ${symbolName}`;
539
504
  }
540
505
  }
541
- var insert = new change_1.InsertChange(componentPath, position, toInsert);
542
- var importInsert = insertImport(source, componentPath, symbolName.replace(/\..*$/, ''), importPath);
506
+ const insert = new change_1.InsertChange(componentPath, position, toInsert);
507
+ const importInsert = insertImport(source, componentPath, symbolName.replace(/\..*$/, ''), importPath);
543
508
  return [insert, importInsert];
544
509
  }
545
510
  /**
@@ -589,69 +554,65 @@ function addBootstrapToModule(source, modulePath, classifiedName, importPath) {
589
554
  * @param isDefault (if true, import follows style for importing default exports)
590
555
  * @return Change
591
556
  */
592
- function insertImport(source, fileToEdit, symbolName, fileName, isDefault) {
593
- if (isDefault === void 0) { isDefault = false; }
594
- var rootNode = source;
595
- var allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
557
+ function insertImport(source, fileToEdit, symbolName, fileName, isDefault = false) {
558
+ const rootNode = source;
559
+ const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
596
560
  // get nodes that map to import statements from the file fileName
597
- var relevantImports = allImports.filter(function (node) {
561
+ const relevantImports = allImports.filter((node) => {
598
562
  // StringLiteral of the ImportDeclaration is the import file (fileName in this case).
599
- var importFiles = node
563
+ const importFiles = node
600
564
  .getChildren()
601
- .filter(function (child) { return child.kind === ts.SyntaxKind.StringLiteral; })
602
- .map(function (n) { return n.text; });
603
- return importFiles.filter(function (file) { return file === fileName; }).length === 1;
565
+ .filter((child) => child.kind === ts.SyntaxKind.StringLiteral)
566
+ .map((n) => n.text);
567
+ return importFiles.filter((file) => file === fileName).length === 1;
604
568
  });
605
569
  if (relevantImports.length > 0) {
606
- var importsAsterisk_1 = false;
570
+ let importsAsterisk = false;
607
571
  // imports from import file
608
- var imports_1 = [];
609
- relevantImports.forEach(function (n) {
610
- Array.prototype.push.apply(imports_1, findNodes(n, ts.SyntaxKind.Identifier));
572
+ const imports = [];
573
+ relevantImports.forEach((n) => {
574
+ Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));
611
575
  if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
612
- importsAsterisk_1 = true;
576
+ importsAsterisk = true;
613
577
  }
614
578
  });
615
579
  // if imports * from fileName, don't add symbolName
616
- if (importsAsterisk_1) {
580
+ if (importsAsterisk) {
617
581
  return new change_1.NoopChange();
618
582
  }
619
- var importTextNodes = imports_1.filter(function (n) { return n.text === symbolName; });
583
+ const importTextNodes = imports.filter((n) => n.text === symbolName);
620
584
  // insert import if it's not there
621
585
  if (importTextNodes.length === 0) {
622
- var fallbackPos_1 = findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
586
+ const fallbackPos = findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
623
587
  findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
624
- return insertAfterLastOccurrence(imports_1, ", ".concat(symbolName), fileToEdit, fallbackPos_1);
588
+ return insertAfterLastOccurrence(imports, `, ${symbolName}`, fileToEdit, fallbackPos);
625
589
  }
626
590
  return new change_1.NoopChange();
627
591
  }
628
592
  // no such import declaration exists
629
- var useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral).filter(function (n) { return n.getText() === 'use strict'; });
630
- var fallbackPos = 0;
593
+ const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral).filter((n) => n.getText() === 'use strict');
594
+ let fallbackPos = 0;
631
595
  if (useStrict.length > 0) {
632
596
  fallbackPos = useStrict[0].end;
633
597
  }
634
- var open = isDefault ? '' : '{ ';
635
- var close = isDefault ? '' : ' }';
598
+ const open = isDefault ? '' : '{ ';
599
+ const close = isDefault ? '' : ' }';
636
600
  // if there are no imports or 'use strict' statement, insert import at beginning of file
637
- var insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
638
- var separator = insertAtBeginning ? '' : ';\n';
639
- var toInsert = "".concat(separator, "import ").concat(open).concat(symbolName).concat(close) +
640
- " from '".concat(fileName, "'").concat(insertAtBeginning ? ';\n' : '');
601
+ const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
602
+ const separator = insertAtBeginning ? '' : ';\n';
603
+ const toInsert = `${separator}import ${open}${symbolName}${close}` +
604
+ ` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
641
605
  return insertAfterLastOccurrence(allImports, toInsert, fileToEdit, fallbackPos, ts.SyntaxKind.StringLiteral);
642
606
  }
643
607
  function replaceImport(sourceFile, path, importFrom, importAsIs, importToBe) {
644
- var imports = sourceFile.statements
608
+ const imports = sourceFile.statements
645
609
  .filter(ts.isImportDeclaration)
646
- .filter(function (_a) {
647
- var moduleSpecifier = _a.moduleSpecifier;
648
- return moduleSpecifier.getText(sourceFile) === "'".concat(importFrom, "'") ||
649
- moduleSpecifier.getText(sourceFile) === "\"".concat(importFrom, "\"");
650
- });
610
+ .filter(({ moduleSpecifier }) => moduleSpecifier.getText(sourceFile) === `'${importFrom}'` ||
611
+ moduleSpecifier.getText(sourceFile) === `"${importFrom}"`);
651
612
  if (imports.length === 0) {
652
613
  return [];
653
614
  }
654
- var importText = function (specifier) {
615
+ const importText = (specifier) => {
655
616
  if (specifier.name.text) {
656
617
  return specifier.name.text;
657
618
  }
@@ -661,18 +622,17 @@ function replaceImport(sourceFile, path, importFrom, importAsIs, importToBe) {
661
622
  }
662
623
  return '';
663
624
  };
664
- var changes = imports.map(function (p) {
665
- var _a;
666
- var namedImports = (_a = p === null || p === void 0 ? void 0 : p.importClause) === null || _a === void 0 ? void 0 : _a.namedBindings;
625
+ const changes = imports.map((p) => {
626
+ const namedImports = p?.importClause?.namedBindings;
667
627
  if (!namedImports) {
668
628
  return [];
669
629
  }
670
- var importSpecifiers = namedImports.elements;
671
- var isAlreadyImported = importSpecifiers
630
+ const importSpecifiers = namedImports.elements;
631
+ const isAlreadyImported = importSpecifiers
672
632
  .map(importText)
673
633
  .includes(importToBe);
674
- var importChanges = importSpecifiers.map(function (specifier, index) {
675
- var text = importText(specifier);
634
+ const importChanges = importSpecifiers.map((specifier, index) => {
635
+ const text = importText(specifier);
676
636
  // import is not the one we're looking for, can be skipped
677
637
  if (text !== importAsIs) {
678
638
  return undefined;
@@ -681,7 +641,7 @@ function replaceImport(sourceFile, path, importFrom, importAsIs, importToBe) {
681
641
  if (!isAlreadyImported) {
682
642
  return (0, change_1.createReplaceChange)(sourceFile, specifier, importAsIs, importToBe);
683
643
  }
684
- var nextIdentifier = importSpecifiers[index + 1];
644
+ const nextIdentifier = importSpecifiers[index + 1];
685
645
  // identifer is not the last, also clean up the comma
686
646
  if (nextIdentifier) {
687
647
  return (0, change_1.createRemoveChange)(sourceFile, specifier, specifier.getStart(sourceFile), nextIdentifier.getStart(sourceFile));
@@ -691,14 +651,12 @@ function replaceImport(sourceFile, path, importFrom, importAsIs, importToBe) {
691
651
  });
692
652
  return importChanges.filter(Boolean);
693
653
  });
694
- return changes.reduce(function (imports, curr) { return imports.concat(curr); }, []);
654
+ return changes.reduce((imports, curr) => imports.concat(curr), []);
695
655
  }
696
656
  function containsProperty(objectLiteral, propertyName) {
697
657
  return (objectLiteral &&
698
- objectLiteral.properties.some(function (prop) {
699
- return ts.isPropertyAssignment(prop) &&
700
- ts.isIdentifier(prop.name) &&
701
- prop.name.text === propertyName;
702
- }));
658
+ objectLiteral.properties.some((prop) => ts.isPropertyAssignment(prop) &&
659
+ ts.isIdentifier(prop.name) &&
660
+ prop.name.text === propertyName));
703
661
  }
704
662
  //# sourceMappingURL=ast-utils.js.map