@ngrx/signals 20.1.0 → 21.0.0-beta.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.
- package/fesm2022/ngrx-signals-entities.mjs.map +1 -1
- package/fesm2022/ngrx-signals-events.mjs +219 -57
- package/fesm2022/ngrx-signals-events.mjs.map +1 -1
- package/fesm2022/ngrx-signals-rxjs-interop.mjs +4 -4
- package/fesm2022/ngrx-signals-rxjs-interop.mjs.map +1 -1
- package/fesm2022/ngrx-signals.mjs +11 -8
- package/fesm2022/ngrx-signals.mjs.map +1 -1
- package/migrations/18_0_0-rc_3-protected-state/index.js +54 -23
- package/migrations/18_0_0-rc_3-protected-state/index.js.map +1 -1
- package/migrations/18_0_0-rc_3-writablestatesource/index.js +45 -12
- package/migrations/18_0_0-rc_3-writablestatesource/index.js.map +1 -1
- package/migrations/19_0_0-rc_0-props/index.js +72 -83
- package/migrations/19_0_0-rc_0-props/index.js.map +1 -1
- package/migrations/21_0_0-beta_0-rename-withEffects-to-withEventHandlers/index.js +103 -0
- package/migrations/21_0_0-beta_0-rename-withEffects-to-withEventHandlers/index.js.map +1 -0
- package/migrations/migration.json +5 -0
- package/package.json +8 -8
- package/schematics/ng-add/index.js +5 -5
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics-core/index.js +1 -1
- package/schematics-core/index.js.map +1 -1
- package/schematics-core/utility/ast-utils.js +198 -240
- package/schematics-core/utility/ast-utils.js.map +1 -1
- package/schematics-core/utility/change.js +68 -85
- package/schematics-core/utility/change.js.map +1 -1
- package/schematics-core/utility/config.js +7 -7
- package/schematics-core/utility/config.js.map +1 -1
- package/schematics-core/utility/find-component.js +20 -20
- package/schematics-core/utility/find-component.js.map +1 -1
- package/schematics-core/utility/find-module.js +21 -21
- package/schematics-core/utility/find-module.js.map +1 -1
- package/schematics-core/utility/json-utilts.js +4 -26
- package/schematics-core/utility/json-utilts.js.map +1 -1
- package/schematics-core/utility/libs-version.js +1 -1
- package/schematics-core/utility/libs-version.js.map +1 -1
- package/schematics-core/utility/ngrx-utils.js +110 -141
- package/schematics-core/utility/ngrx-utils.js.map +1 -1
- package/schematics-core/utility/package.js +2 -3
- package/schematics-core/utility/package.js.map +1 -1
- package/schematics-core/utility/parse-name.js +3 -3
- package/schematics-core/utility/parse-name.js.map +1 -1
- package/schematics-core/utility/project.js +13 -13
- package/schematics-core/utility/project.js.map +1 -1
- package/schematics-core/utility/strings.js +12 -12
- package/schematics-core/utility/strings.js.map +1 -1
- package/schematics-core/utility/update.js +12 -12
- package/schematics-core/utility/update.js.map +1 -1
- package/schematics-core/utility/visitors.js +78 -180
- package/schematics-core/utility/visitors.js.map +1 -1
- package/types/ngrx-signals-entities.d.ts +324 -0
- package/types/ngrx-signals-events.d.ts +360 -0
- package/types/ngrx-signals-rxjs-interop.d.ts +15 -0
- package/{testing/src/unprotected.d.ts → types/ngrx-signals-testing.d.ts} +5 -3
- package/types/ngrx-signals.d.ts +332 -0
- package/entities/index.d.ts +0 -1
- package/entities/src/entity-config.d.ts +0 -17
- package/entities/src/helpers.d.ts +0 -25
- package/entities/src/index.d.ts +0 -18
- package/entities/src/models.d.ts +0 -24
- package/entities/src/updaters/add-entities.d.ts +0 -17
- package/entities/src/updaters/add-entity.d.ts +0 -17
- package/entities/src/updaters/prepend-entities.d.ts +0 -17
- package/entities/src/updaters/prepend-entity.d.ts +0 -17
- package/entities/src/updaters/remove-all-entities.d.ts +0 -6
- package/entities/src/updaters/remove-entities.d.ts +0 -10
- package/entities/src/updaters/remove-entity.d.ts +0 -6
- package/entities/src/updaters/set-all-entities.d.ts +0 -17
- package/entities/src/updaters/set-entities.d.ts +0 -17
- package/entities/src/updaters/set-entity.d.ts +0 -17
- package/entities/src/updaters/update-all-entities.d.ts +0 -17
- package/entities/src/updaters/update-entities.d.ts +0 -56
- package/entities/src/updaters/update-entity.d.ts +0 -29
- package/entities/src/updaters/upsert-entities.d.ts +0 -17
- package/entities/src/updaters/upsert-entity.d.ts +0 -17
- package/entities/src/with-entities.d.ts +0 -22
- package/events/index.d.ts +0 -1
- package/events/src/case-reducer.d.ts +0 -20
- package/events/src/dispatcher.d.ts +0 -33
- package/events/src/event-creator-group.d.ts +0 -33
- package/events/src/event-creator.d.ts +0 -9
- package/events/src/event-instance.d.ts +0 -8
- package/events/src/events-service.d.ts +0 -47
- package/events/src/index.d.ts +0 -9
- package/events/src/inject-dispatch.d.ts +0 -46
- package/events/src/with-effects.d.ts +0 -28
- package/events/src/with-reducer.d.ts +0 -30
- package/index.d.ts +0 -1
- package/rxjs-interop/index.d.ts +0 -1
- package/rxjs-interop/src/index.d.ts +0 -1
- package/rxjs-interop/src/rx-method.d.ts +0 -12
- package/src/deep-computed.d.ts +0 -2
- package/src/deep-signal.d.ts +0 -6
- package/src/index.d.ts +0 -16
- package/src/signal-method.d.ts +0 -7
- package/src/signal-state.d.ts +0 -4
- package/src/signal-store-assertions.d.ts +0 -2
- package/src/signal-store-feature.d.ts +0 -29
- package/src/signal-store-models.d.ts +0 -30
- package/src/signal-store.d.ts +0 -115
- package/src/state-source.d.ts +0 -23
- package/src/ts-helpers.d.ts +0 -11
- package/src/with-computed.d.ts +0 -12
- package/src/with-feature.d.ts +0 -26
- package/src/with-hooks.d.ts +0 -14
- package/src/with-linked-state.d.ts +0 -52
- package/src/with-methods.d.ts +0 -8
- package/src/with-props.d.ts +0 -8
- package/src/with-state.d.ts +0 -11
- package/testing/index.d.ts +0 -1
- package/testing/src/index.d.ts +0 -1
|
@@ -1,40 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
113
|
-
|
|
97
|
+
const nodes = [sourceFile];
|
|
98
|
+
const result = [];
|
|
114
99
|
while (nodes.length > 0) {
|
|
115
|
-
|
|
100
|
+
const node = nodes.shift();
|
|
116
101
|
if (node) {
|
|
117
102
|
result.push(node);
|
|
118
103
|
if (node.getChildCount(sourceFile) >= 0) {
|
|
119
|
-
nodes.unshift
|
|
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
|
-
|
|
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(
|
|
139
|
+
throw new Error(`tried to insert ${toInsert} as first occurence with no fallback position`);
|
|
155
140
|
}
|
|
156
|
-
|
|
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
|
-
|
|
172
|
-
|
|
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
|
-
|
|
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
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
183
|
+
const namedImports = nb;
|
|
200
184
|
return namedImports.elements
|
|
201
|
-
.map(
|
|
202
|
-
|
|
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
|
-
|
|
219
|
-
.map(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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(
|
|
209
|
+
.filter((node) => {
|
|
241
210
|
return (node.kind == ts.SyntaxKind.Decorator &&
|
|
242
211
|
node.expression.kind == ts.SyntaxKind.CallExpression);
|
|
243
212
|
})
|
|
244
|
-
.map(
|
|
245
|
-
.filter(
|
|
213
|
+
.map((node) => node.expression)
|
|
214
|
+
.filter((expr) => {
|
|
246
215
|
if (expr.expression.kind == ts.SyntaxKind.Identifier) {
|
|
247
|
-
|
|
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
|
-
|
|
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
|
-
|
|
259
|
-
|
|
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(
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
272
|
-
|
|
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
|
-
|
|
279
|
-
.filter(
|
|
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(
|
|
283
|
-
|
|
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
|
-
|
|
299
|
-
|
|
300
|
-
|
|
265
|
+
const expr = node;
|
|
266
|
+
let position;
|
|
267
|
+
let toInsert;
|
|
301
268
|
if (expr.properties.length == 0) {
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
|
|
274
|
+
position = node.getEnd();
|
|
308
275
|
// Get the indentation of the last element, if any.
|
|
309
|
-
|
|
310
|
-
|
|
276
|
+
const text = node.getFullText(source);
|
|
277
|
+
const matches = text.match(/^\r?\n\s*/);
|
|
311
278
|
if (matches.length > 0) {
|
|
312
|
-
|
|
279
|
+
toInsert = `,${matches[0]}${metadataField}: [${symbolName}]`;
|
|
313
280
|
}
|
|
314
281
|
else {
|
|
315
|
-
|
|
282
|
+
toInsert = `, ${metadataField}: [${symbolName}]`;
|
|
316
283
|
}
|
|
317
284
|
}
|
|
318
|
-
|
|
319
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
341
|
-
|
|
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
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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
|
-
|
|
318
|
+
const effectsArgs = effectsModule.arguments.shift();
|
|
354
319
|
if (effectsArgs &&
|
|
355
320
|
effectsArgs.kind === ts.SyntaxKind.ArrayLiteralExpression) {
|
|
356
|
-
|
|
321
|
+
const effectsElements = effectsArgs
|
|
357
322
|
.elements;
|
|
358
|
-
|
|
359
|
-
|
|
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
|
-
|
|
330
|
+
const lastEffect = effectsElements[effectsElements.length - 1];
|
|
366
331
|
epos = lastEffect.getEnd();
|
|
367
332
|
// Get the indentation of the last element, if any.
|
|
368
|
-
|
|
369
|
-
|
|
333
|
+
const text = lastEffect.getFullText(source);
|
|
334
|
+
let effectInsert;
|
|
370
335
|
if (text.match('^\r?\r?\n')) {
|
|
371
|
-
effectInsert =
|
|
336
|
+
effectInsert = `,${text.match(/^\r?\n\s+/)[0]}${effectsSymbol}`;
|
|
372
337
|
}
|
|
373
338
|
else {
|
|
374
|
-
effectInsert =
|
|
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
|
-
|
|
385
|
-
|
|
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
|
-
|
|
354
|
+
const expr = node;
|
|
390
355
|
if (expr.properties.length == 0) {
|
|
391
356
|
position = expr.getEnd() - 1;
|
|
392
|
-
toInsert =
|
|
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
|
-
|
|
363
|
+
const text = node.getFullText(source);
|
|
399
364
|
if (text.match('^\r?\r?\n')) {
|
|
400
|
-
toInsert =
|
|
365
|
+
toInsert = `,${text.match(/^\r?\n\s+/)[0]}${metadataField}: [${symbolName}]`;
|
|
401
366
|
}
|
|
402
367
|
else {
|
|
403
|
-
toInsert =
|
|
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 =
|
|
375
|
+
toInsert = `${symbolName}`;
|
|
411
376
|
}
|
|
412
377
|
else {
|
|
413
378
|
// Get the indentation of the last element, if any.
|
|
414
|
-
|
|
379
|
+
const text = node.getFullText(source);
|
|
415
380
|
if (text.match(/^\r?\n/)) {
|
|
416
|
-
toInsert =
|
|
381
|
+
toInsert = `,${text.match(/^\r?\n(\r?)\s+/)[0]}${symbolName}`;
|
|
417
382
|
}
|
|
418
383
|
else {
|
|
419
|
-
toInsert =
|
|
384
|
+
toInsert = `, ${symbolName}`;
|
|
420
385
|
}
|
|
421
386
|
}
|
|
422
|
-
|
|
423
|
-
|
|
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
|
-
|
|
428
|
-
|
|
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
|
-
|
|
435
|
-
.filter(
|
|
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(
|
|
439
|
-
|
|
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
|
-
|
|
455
|
-
|
|
456
|
-
|
|
419
|
+
const expr = node;
|
|
420
|
+
let position;
|
|
421
|
+
let toInsert;
|
|
457
422
|
if (expr.properties.length == 0) {
|
|
458
|
-
|
|
459
|
-
|
|
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
|
-
|
|
428
|
+
position = node.getEnd();
|
|
464
429
|
// Get the indentation of the last element, if any.
|
|
465
|
-
|
|
466
|
-
|
|
430
|
+
const text = node.getFullText(source);
|
|
431
|
+
const matches = text.match(/^\r?\n\s*/);
|
|
467
432
|
if (matches.length > 0) {
|
|
468
|
-
|
|
433
|
+
toInsert = `,${matches[0]}${metadataField}: [${symbolName}]`;
|
|
469
434
|
}
|
|
470
435
|
else {
|
|
471
|
-
|
|
436
|
+
toInsert = `, ${metadataField}: [${symbolName}]`;
|
|
472
437
|
}
|
|
473
438
|
}
|
|
474
|
-
|
|
475
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
497
|
-
|
|
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
|
-
|
|
504
|
-
|
|
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
|
-
|
|
473
|
+
const expr = node;
|
|
509
474
|
if (expr.properties.length == 0) {
|
|
510
475
|
position = expr.getEnd() - 1;
|
|
511
|
-
toInsert =
|
|
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
|
-
|
|
482
|
+
const text = node.getFullText(source);
|
|
518
483
|
if (text.match('^\r?\r?\n')) {
|
|
519
|
-
toInsert =
|
|
484
|
+
toInsert = `,${text.match(/^\r?\n\s+/)[0]}${metadataField}: [${symbolName}]`;
|
|
520
485
|
}
|
|
521
486
|
else {
|
|
522
|
-
toInsert =
|
|
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 =
|
|
494
|
+
toInsert = `${symbolName}`;
|
|
530
495
|
}
|
|
531
496
|
else {
|
|
532
497
|
// Get the indentation of the last element, if any.
|
|
533
|
-
|
|
498
|
+
const text = node.getFullText(source);
|
|
534
499
|
if (text.match(/^\r?\n/)) {
|
|
535
|
-
toInsert =
|
|
500
|
+
toInsert = `,${text.match(/^\r?\n(\r?)\s+/)[0]}${symbolName}`;
|
|
536
501
|
}
|
|
537
502
|
else {
|
|
538
|
-
toInsert =
|
|
503
|
+
toInsert = `, ${symbolName}`;
|
|
539
504
|
}
|
|
540
505
|
}
|
|
541
|
-
|
|
542
|
-
|
|
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
|
-
|
|
594
|
-
|
|
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
|
-
|
|
561
|
+
const relevantImports = allImports.filter((node) => {
|
|
598
562
|
// StringLiteral of the ImportDeclaration is the import file (fileName in this case).
|
|
599
|
-
|
|
563
|
+
const importFiles = node
|
|
600
564
|
.getChildren()
|
|
601
|
-
.filter(
|
|
602
|
-
.map(
|
|
603
|
-
return importFiles.filter(
|
|
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
|
-
|
|
570
|
+
let importsAsterisk = false;
|
|
607
571
|
// imports from import file
|
|
608
|
-
|
|
609
|
-
relevantImports.forEach(
|
|
610
|
-
Array.prototype.push.apply(
|
|
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
|
-
|
|
576
|
+
importsAsterisk = true;
|
|
613
577
|
}
|
|
614
578
|
});
|
|
615
579
|
// if imports * from fileName, don't add symbolName
|
|
616
|
-
if (
|
|
580
|
+
if (importsAsterisk) {
|
|
617
581
|
return new change_1.NoopChange();
|
|
618
582
|
}
|
|
619
|
-
|
|
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
|
-
|
|
586
|
+
const fallbackPos = findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
|
623
587
|
findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
|
|
624
|
-
return insertAfterLastOccurrence(
|
|
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
|
-
|
|
630
|
-
|
|
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
|
-
|
|
635
|
-
|
|
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
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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
|
-
|
|
608
|
+
const imports = sourceFile.statements
|
|
645
609
|
.filter(ts.isImportDeclaration)
|
|
646
|
-
.filter(
|
|
647
|
-
|
|
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
|
-
|
|
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
|
-
|
|
665
|
-
|
|
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
|
-
|
|
671
|
-
|
|
630
|
+
const importSpecifiers = namedImports.elements;
|
|
631
|
+
const isAlreadyImported = importSpecifiers
|
|
672
632
|
.map(importText)
|
|
673
633
|
.includes(importToBe);
|
|
674
|
-
|
|
675
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
699
|
-
|
|
700
|
-
|
|
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
|