-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
index.js
27 lines (23 loc) 路 856 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// @flow
import * as t from "@babel/types";
import type { NodePath } from "@babel/traverse";
// A transparent expression wrapper is an AST node that most plugins will wish
// to skip, as its presence does not affect the behaviour of the code. This
// includes expressions used for types, and extra parenthesis. For example, in
// (a as any)(), this helper can be used to skip the TSAsExpression when
// determining the callee.
export function isTransparentExprWrapper(node: Node) {
return (
t.isTSAsExpression(node) ||
t.isTSTypeAssertion(node) ||
t.isTSNonNullExpression(node) ||
t.isTypeCastExpression(node) ||
t.isParenthesizedExpression(node)
);
}
export function skipTransparentExprWrappers(path: NodePath): NodePath {
while (isTransparentExprWrapper(path.node)) {
path = path.get("expression");
}
return path;
}