UNPKG

1.25 kBJavaScriptView Raw
1"use strict";
2var change_1 = require('./change');
3/**
4 * Find all nodes from the AST in the subtree of node of SyntaxKind kind.
5 * @param node
6 * @param kind
7 * @param max The maximum number of items to return.
8 * @return all nodes of kind, or [] if none is found
9 */
10function findNodes(node, kind, max) {
11 if (max === void 0) { max = Infinity; }
12 if (!node || max == 0) {
13 return [];
14 }
15 var arr = [];
16 if (node.kind === kind) {
17 arr.push(node);
18 max--;
19 }
20 if (max > 0) {
21 for (var _i = 0, _a = node.getChildren(); _i < _a.length; _i++) {
22 var child = _a[_i];
23 findNodes(child, kind, max).forEach(function (node) {
24 if (max > 0) {
25 arr.push(node);
26 }
27 max--;
28 });
29 if (max <= 0) {
30 break;
31 }
32 }
33 }
34 return arr;
35}
36exports.findNodes = findNodes;
37function removeAstNode(node) {
38 var source = node.getSourceFile();
39 return new change_1.RemoveChange(source.path, node.getStart(source), node.getFullText(source));
40}
41exports.removeAstNode = removeAstNode;
42//# sourceMappingURL=/Users/hans/Sources/angular-cli/packages/@angular-cli/ast-tools/src/node.js.map
\No newline at end of file