-
-
Notifications
You must be signed in to change notification settings - Fork 601
/
NodePath.ts
100 lines (95 loc) · 2.83 KB
/
NodePath.ts
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
export interface INode extends Object {
id?: {
name: string;
};
arguments?: INode[];
body?: INode[];
elements?: INode[];
expression?: {
left: {
computed: boolean,
object: INode,
property: INode,
type: string,
},
operator: string,
right: INode,
type: string,
};
filter?: (p: (p: INode) => boolean) => INode;
find?: (objectExpression: object, filterExpression?: object) => INode;
forEach?: (p: (p: INode) => void) => INode;
get?: (property: string) => INode;
remove?: (_?: void) => void;
nodes?: (_?: void) => INode[];
pop?: (_?: void) => INode;
key?: {
name: string;
value: INode | string;
};
node?: INode;
name?: string;
object?: object;
parent?: INode;
properties?: INode[];
property?: INode;
prune?: Function;
replaceWith?: (objectExpression: object) => INode;
size?: (_?: void) => number;
type?: string;
value?: INode | string | any;
toSource?: (object: {
quote?: string,
}) => string;
source?: string;
ast?: INode;
rules?: IModuleRule[];
__paths?: INode[];
}
interface IModuleRule {
loader?: string;
}
interface IExpressionObject {
name?: string;
}
export interface IJSCodeshift extends Object {
(source?: INode | string): INode;
withParser?: (parser: string) => IJSCodeshift;
identifier?: (key: string) => INode;
literal?: (key: valueType) => INode;
memberExpression?: (node1: INode, node2: INode, bool?: boolean) => INode;
objectProperty?: (key: INode, property: valueType) => INode;
objectExpression?: (properties: INode[]) => INode;
newExpression?: (expression: INode, args: INode[]) => INode;
callExpression?: (expression: INode, args: INode[]) => INode;
variableDeclarator?: (key: INode, args: INode) => INode;
variableDeclaration?: (key: string, args: INode[]) => INode;
arrayExpression?: (args?: INode[]) => INode;
property?: (type: string, key: INode, value: INode) => INode;
program?: (nodes: INode[]) => INode;
booleanLiteral?: (bool: boolean) => INode;
arrowFunctionExpression?: (params: INode[], body: INode, exp: INode) => INode;
blockStatement?: (body: INode[]) => INode;
ifStatement?: (test: INode, consequent: INode, alternate?: INode) => INode;
returnStatement?: (arg: INode) => INode;
binaryExpression?: (operator: string, left: INode, right: INode) => INode;
Property?: IExpressionObject;
NewExpression?: IExpressionObject;
CallExpression?: IExpressionObject;
VariableDeclarator?: IExpressionObject;
Identifier?: IExpressionObject;
Literal?: IExpressionObject;
ArrayExpression?: IExpressionObject;
MemberExpression?: IExpressionObject;
FunctionExpression?: IExpressionObject;
ObjectExpression?: IExpressionObject;
BlockStatement?: IExpressionObject;
Program?: IExpressionObject;
ArrowFunctionExpression?: IExpressionObject;
filters?: {
VariableDeclarator: {
requiresModule: Function,
},
};
}
export type valueType = string | number | boolean | any[] | INode | null;