Skip to content

Commit 5f15e99

Browse files
committed
refactor(utilities/ast): consolidate nested expression retrieval into a single file
1 parent 93de1fa commit 5f15e99

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

packages/utilities/ast/src/get-nested-call-expressions.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/utilities/ast/src/get-nested-expressions-of-type.ts renamed to packages/utilities/ast/src/get-nested-expressions.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import { ASTUtils } from "@typescript-eslint/utils";
88
* @returns A partially applied function bound to a predicate of type T. The returned function can be called passing a
99
* node, and it will return an array of all nested expressions of type T.
1010
*/
11-
export function getNestedExpressionsOfType<TNodeType extends T>(
12-
type: TNodeType,
13-
): (node: TSESTree.Node) => Extract<TSESTree.Node, { type: TNodeType }>[] {
11+
// dprint-ignore
12+
export function getNestedExpressionsOfType<TNodeType extends T>(type: TNodeType): (node: TSESTree.Node) => Extract<TSESTree.Node, { type: TNodeType }>[] {
1413
const isNodeOfType = ASTUtils.isNodeOfType(type);
1514
return function(node) {
1615
const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
@@ -110,3 +109,17 @@ export function getNestedExpressionsOfType<TNodeType extends T>(
110109
return expressions;
111110
};
112111
}
112+
113+
/**
114+
* Get all nested new expressions in an expression like node
115+
* @param node The node to get the nested new expressions from
116+
* @returns All nested new expressions
117+
*/
118+
export const getNestedNewExpressions = getNestedExpressionsOfType(T.NewExpression);
119+
120+
/**
121+
* Get all nested call expressions in a expression like node
122+
* @param node The node to get the nested call expressions from
123+
* @returns All nested call expressions
124+
*/
125+
export const getNestedCallExpressions = getNestedExpressionsOfType(T.CallExpression);

packages/utilities/ast/src/get-nested-new-expressions.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/utilities/ast/src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ export * from "./get-class-identifier";
44
export * from "./get-ecma-expression";
55
export * from "./get-function-identifier";
66
export * from "./get-literal-value-type";
7-
export * from "./get-nested-call-expressions";
8-
export * from "./get-nested-expressions-of-type";
7+
export * from "./get-nested-expressions";
98
export * from "./get-nested-identifiers";
10-
export * from "./get-nested-new-expressions";
119
export * from "./get-nested-return-statements";
1210
export * from "./get-top-level-identifier";
1311
export * from "./is";

0 commit comments

Comments
 (0)