@eslint-react/ast 1.52.9 → 1.52.10-beta.1
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/dist/index.d.mts +50 -97
- package/dist/index.d.ts +50 -97
- package/dist/index.js +520 -460
- package/dist/index.mjs +498 -459
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,519 +1,558 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from
|
|
2
|
-
import { dual, unit } from
|
|
3
|
-
import { ASTUtils } from
|
|
4
|
-
import { simpleTraverse } from
|
|
5
|
-
import {
|
|
1
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
2
|
+
import { dual, unit } from "@eslint-react/eff";
|
|
3
|
+
import { ASTUtils } from "@typescript-eslint/utils";
|
|
4
|
+
import { simpleTraverse } from "@typescript-eslint/typescript-estree";
|
|
5
|
+
import { delimiterCase, replace, toLowerCase } from "string-ts";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
//#region src/ast-array-method.ts
|
|
8
8
|
function isArrayFromCall(node, loose = true) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
10
|
+
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
11
|
+
if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
|
|
12
|
+
const name = node.callee.property.name;
|
|
13
|
+
return name === "from" || loose && name.startsWith("from");
|
|
14
14
|
}
|
|
15
15
|
function isArrayMapCall(node, loose = true) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
17
|
+
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
18
|
+
if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
|
|
19
|
+
const name = node.callee.property.name;
|
|
20
|
+
return name === "map" || loose && name.endsWith("Map");
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/ast-array-method-callback.ts
|
|
25
|
+
const indexParamPosition = new Map([
|
|
26
|
+
["every", 1],
|
|
27
|
+
["filter", 1],
|
|
28
|
+
["find", 1],
|
|
29
|
+
["findIndex", 1],
|
|
30
|
+
["findLast", 1],
|
|
31
|
+
["findLastIndex", 1],
|
|
32
|
+
["flatMap", 1],
|
|
33
|
+
["forEach", 1],
|
|
34
|
+
["map", 1],
|
|
35
|
+
["reduce", 2],
|
|
36
|
+
["reduceRight", 2],
|
|
37
|
+
["some", 1]
|
|
37
38
|
]);
|
|
38
39
|
function getArrayMethodCallbackIndexParamPosition(methodName) {
|
|
39
|
-
|
|
40
|
+
return indexParamPosition.get(methodName) ?? -1;
|
|
40
41
|
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/ast-class-id.ts
|
|
45
|
+
/**
|
|
46
|
+
* Gets class identifier from ClassDeclaration or ClassExpression
|
|
47
|
+
* @param node The AST node to check
|
|
48
|
+
* @returns class identifier or null
|
|
49
|
+
*/
|
|
41
50
|
function getClassId(node) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
return unit;
|
|
51
|
+
if (node.id != null) return node.id;
|
|
52
|
+
if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) return node.parent.id;
|
|
53
|
+
return unit;
|
|
47
54
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
AST_NODE_TYPES.FunctionDeclaration,
|
|
58
|
-
AST_NODE_TYPES.FunctionExpression,
|
|
59
|
-
AST_NODE_TYPES.TSCallSignatureDeclaration,
|
|
60
|
-
AST_NODE_TYPES.TSConstructSignatureDeclaration,
|
|
61
|
-
AST_NODE_TYPES.TSDeclareFunction,
|
|
62
|
-
AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
|
|
63
|
-
AST_NODE_TYPES.TSFunctionType,
|
|
64
|
-
AST_NODE_TYPES.TSMethodSignature
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/ast-is.ts
|
|
58
|
+
const is = ASTUtils.isNodeOfType;
|
|
59
|
+
const isOneOf = ASTUtils.isNodeOfTypes;
|
|
60
|
+
const isFunction = isOneOf([
|
|
61
|
+
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
62
|
+
AST_NODE_TYPES.FunctionDeclaration,
|
|
63
|
+
AST_NODE_TYPES.FunctionExpression
|
|
65
64
|
]);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
const isFunctionType = isOneOf([
|
|
66
|
+
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
67
|
+
AST_NODE_TYPES.FunctionDeclaration,
|
|
68
|
+
AST_NODE_TYPES.FunctionExpression,
|
|
69
|
+
AST_NODE_TYPES.TSCallSignatureDeclaration,
|
|
70
|
+
AST_NODE_TYPES.TSConstructSignatureDeclaration,
|
|
71
|
+
AST_NODE_TYPES.TSDeclareFunction,
|
|
72
|
+
AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
|
|
73
|
+
AST_NODE_TYPES.TSFunctionType,
|
|
74
|
+
AST_NODE_TYPES.TSMethodSignature
|
|
70
75
|
]);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
const isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
|
|
77
|
+
const isMethodOrProperty = isOneOf([AST_NODE_TYPES.PropertyDefinition, AST_NODE_TYPES.MethodDefinition]);
|
|
78
|
+
const isProperty = isOneOf([
|
|
79
|
+
AST_NODE_TYPES.PropertyDefinition,
|
|
80
|
+
AST_NODE_TYPES.TSIndexSignature,
|
|
81
|
+
AST_NODE_TYPES.TSParameterProperty,
|
|
82
|
+
AST_NODE_TYPES.TSPropertySignature
|
|
76
83
|
]);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
const isJSXElement = is(AST_NODE_TYPES.JSXElement);
|
|
85
|
+
const isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
|
|
86
|
+
const isJSXTagNameExpression = isOneOf([
|
|
87
|
+
AST_NODE_TYPES.JSXIdentifier,
|
|
88
|
+
AST_NODE_TYPES.JSXMemberExpression,
|
|
89
|
+
AST_NODE_TYPES.JSXNamespacedName
|
|
83
90
|
]);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
const isJSX = isOneOf([
|
|
92
|
+
AST_NODE_TYPES.JSXAttribute,
|
|
93
|
+
AST_NODE_TYPES.JSXClosingElement,
|
|
94
|
+
AST_NODE_TYPES.JSXClosingFragment,
|
|
95
|
+
AST_NODE_TYPES.JSXElement,
|
|
96
|
+
AST_NODE_TYPES.JSXEmptyExpression,
|
|
97
|
+
AST_NODE_TYPES.JSXExpressionContainer,
|
|
98
|
+
AST_NODE_TYPES.JSXFragment,
|
|
99
|
+
AST_NODE_TYPES.JSXIdentifier,
|
|
100
|
+
AST_NODE_TYPES.JSXMemberExpression,
|
|
101
|
+
AST_NODE_TYPES.JSXNamespacedName,
|
|
102
|
+
AST_NODE_TYPES.JSXOpeningElement,
|
|
103
|
+
AST_NODE_TYPES.JSXOpeningFragment,
|
|
104
|
+
AST_NODE_TYPES.JSXSpreadAttribute,
|
|
105
|
+
AST_NODE_TYPES.JSXSpreadChild,
|
|
106
|
+
AST_NODE_TYPES.JSXText
|
|
100
107
|
]);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
const isLoop = isOneOf([
|
|
109
|
+
AST_NODE_TYPES.DoWhileStatement,
|
|
110
|
+
AST_NODE_TYPES.ForInStatement,
|
|
111
|
+
AST_NODE_TYPES.ForOfStatement,
|
|
112
|
+
AST_NODE_TYPES.ForStatement,
|
|
113
|
+
AST_NODE_TYPES.WhileStatement
|
|
107
114
|
]);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
const isTypeExpression = isOneOf([
|
|
116
|
+
AST_NODE_TYPES.TSAsExpression,
|
|
117
|
+
AST_NODE_TYPES.TSTypeAssertion,
|
|
118
|
+
AST_NODE_TYPES.TSNonNullExpression,
|
|
119
|
+
AST_NODE_TYPES.TSSatisfiesExpression,
|
|
120
|
+
AST_NODE_TYPES.TSInstantiationExpression
|
|
114
121
|
]);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
122
|
+
const isTypeAssertionExpression = isOneOf([
|
|
123
|
+
AST_NODE_TYPES.TSAsExpression,
|
|
124
|
+
AST_NODE_TYPES.TSTypeAssertion,
|
|
125
|
+
AST_NODE_TYPES.TSNonNullExpression,
|
|
126
|
+
AST_NODE_TYPES.TSSatisfiesExpression
|
|
120
127
|
]);
|
|
121
128
|
|
|
122
|
-
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/ast-expression.ts
|
|
131
|
+
/**
|
|
132
|
+
* Recursively get the inner expression until it's not a TypeExpression
|
|
133
|
+
* @param node - The node to get the expression from
|
|
134
|
+
* @returns The inner expression
|
|
135
|
+
*/
|
|
123
136
|
function getJSExpression(node) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
return node;
|
|
137
|
+
if (isTypeExpression(node)) return getJSExpression(node.expression);
|
|
138
|
+
return node;
|
|
128
139
|
}
|
|
129
140
|
function isThisExpression(node) {
|
|
130
|
-
|
|
141
|
+
return getJSExpression(node).type === AST_NODE_TYPES.ThisExpression;
|
|
131
142
|
}
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/ast-function-id.ts
|
|
132
146
|
function getFunctionId(node) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
// {MaybeComponent: () => {}}
|
|
144
|
-
// {MaybeComponent() {}}
|
|
145
|
-
case (node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === AST_NODE_TYPES.Identifier):
|
|
146
|
-
return node.parent.key;
|
|
147
|
-
// class {MaybeComponent = () => {}}
|
|
148
|
-
// class {MaybeComponent() {}}
|
|
149
|
-
case (isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier):
|
|
150
|
-
return node.parent.key;
|
|
151
|
-
// Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
|
|
152
|
-
//
|
|
153
|
-
// const {MaybeComponent = () => {}} = {};
|
|
154
|
-
// ({MaybeComponent = () => {}} = {});
|
|
155
|
-
case (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier):
|
|
156
|
-
return node.parent.left;
|
|
157
|
-
// const MaybeComponent = (() => {})!;
|
|
158
|
-
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
159
|
-
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
160
|
-
case isTypeAssertionExpression(node.parent):
|
|
161
|
-
return getFunctionId(node.parent);
|
|
162
|
-
}
|
|
163
|
-
return unit;
|
|
147
|
+
switch (true) {
|
|
148
|
+
case "id" in node && node.id != null: return node.id;
|
|
149
|
+
case node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === AST_NODE_TYPES.Identifier: return node.parent.id;
|
|
150
|
+
case node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === AST_NODE_TYPES.Identifier: return node.parent.left;
|
|
151
|
+
case node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === AST_NODE_TYPES.Identifier: return node.parent.key;
|
|
152
|
+
case isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier: return node.parent.key;
|
|
153
|
+
case node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier: return node.parent.left;
|
|
154
|
+
case isTypeAssertionExpression(node.parent): return getFunctionId(node.parent);
|
|
155
|
+
}
|
|
156
|
+
return unit;
|
|
164
157
|
}
|
|
158
|
+
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/ast-function-init-path.ts
|
|
165
161
|
function getFunctionInitPath(node) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
162
|
+
if (node.type === AST_NODE_TYPES.FunctionDeclaration) return [node];
|
|
163
|
+
const { parent } = node;
|
|
164
|
+
switch (true) {
|
|
165
|
+
case parent.type === AST_NODE_TYPES.VariableDeclarator: return [
|
|
166
|
+
parent.parent,
|
|
167
|
+
parent,
|
|
168
|
+
node
|
|
169
|
+
];
|
|
170
|
+
case parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.VariableDeclarator: return [
|
|
171
|
+
parent.parent.parent,
|
|
172
|
+
parent.parent,
|
|
173
|
+
parent,
|
|
174
|
+
node
|
|
175
|
+
];
|
|
176
|
+
case parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.CallExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator: return [
|
|
177
|
+
parent.parent.parent.parent,
|
|
178
|
+
parent.parent.parent,
|
|
179
|
+
parent.parent,
|
|
180
|
+
parent,
|
|
181
|
+
node
|
|
182
|
+
];
|
|
183
|
+
case parent.type === AST_NODE_TYPES.Property && parent.parent.type === AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator: return [
|
|
184
|
+
parent.parent.parent.parent,
|
|
185
|
+
parent.parent.parent,
|
|
186
|
+
parent.parent,
|
|
187
|
+
parent,
|
|
188
|
+
node
|
|
189
|
+
];
|
|
190
|
+
case parent.type === AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration: return [
|
|
191
|
+
parent.parent.parent,
|
|
192
|
+
parent.parent,
|
|
193
|
+
parent,
|
|
194
|
+
node
|
|
195
|
+
];
|
|
196
|
+
case parent.type === AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration: return [
|
|
197
|
+
parent.parent.parent,
|
|
198
|
+
parent.parent,
|
|
199
|
+
parent,
|
|
200
|
+
node
|
|
201
|
+
];
|
|
202
|
+
}
|
|
203
|
+
return unit;
|
|
185
204
|
}
|
|
186
205
|
function hasCallInFunctionInitPath(callName, initPath) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return "name" in n.callee.property && n.callee.property.name === callName;
|
|
196
|
-
default:
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
});
|
|
206
|
+
return initPath.some((n) => {
|
|
207
|
+
if (n.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
208
|
+
switch (n.callee.type) {
|
|
209
|
+
case AST_NODE_TYPES.Identifier: return n.callee.name === callName;
|
|
210
|
+
case AST_NODE_TYPES.MemberExpression: return "name" in n.callee.property && n.callee.property.name === callName;
|
|
211
|
+
default: return false;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
200
214
|
}
|
|
215
|
+
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/ast-function-is.ts
|
|
201
218
|
function isEmptyFunction(node) {
|
|
202
|
-
|
|
219
|
+
return node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
|
|
203
220
|
}
|
|
221
|
+
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/ast-hierarchy.ts
|
|
204
224
|
function findParentNode(node, test) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
return unit;
|
|
225
|
+
if (node == null) return unit;
|
|
226
|
+
let parent = node.parent;
|
|
227
|
+
while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
|
|
228
|
+
if (test(parent)) return parent;
|
|
229
|
+
parent = parent.parent;
|
|
230
|
+
}
|
|
231
|
+
return unit;
|
|
214
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Get all nested identifiers in a expression like node
|
|
235
|
+
* @param node The node to get the nested identifiers from
|
|
236
|
+
* @returns All nested identifiers
|
|
237
|
+
*/
|
|
215
238
|
function getNestedIdentifiers(node) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
return identifiers;
|
|
239
|
+
const identifiers = [];
|
|
240
|
+
if (node.type === AST_NODE_TYPES.Identifier) identifiers.push(node);
|
|
241
|
+
if ("arguments" in node) {
|
|
242
|
+
const chunk = node.arguments.map(getNestedIdentifiers).flat(1);
|
|
243
|
+
identifiers.push(...chunk);
|
|
244
|
+
}
|
|
245
|
+
if ("elements" in node) {
|
|
246
|
+
const chunk = node.elements.filter((x) => x != null).map(getNestedIdentifiers).flat(1);
|
|
247
|
+
identifiers.push(...chunk);
|
|
248
|
+
}
|
|
249
|
+
if ("properties" in node) {
|
|
250
|
+
const chunk = node.properties.map(getNestedIdentifiers).flat(1);
|
|
251
|
+
identifiers.push(...chunk);
|
|
252
|
+
}
|
|
253
|
+
if ("expressions" in node) {
|
|
254
|
+
const chunk = node.expressions.map(getNestedIdentifiers).flat(1);
|
|
255
|
+
identifiers.push(...chunk);
|
|
256
|
+
}
|
|
257
|
+
if ("left" in node) {
|
|
258
|
+
const chunk = getNestedIdentifiers(node.left);
|
|
259
|
+
identifiers.push(...chunk);
|
|
260
|
+
}
|
|
261
|
+
if ("right" in node) {
|
|
262
|
+
const chunk = getNestedIdentifiers(node.right);
|
|
263
|
+
identifiers.push(...chunk);
|
|
264
|
+
}
|
|
265
|
+
if (node.type === AST_NODE_TYPES.Property) {
|
|
266
|
+
const chunk = getNestedIdentifiers(node.value);
|
|
267
|
+
identifiers.push(...chunk);
|
|
268
|
+
}
|
|
269
|
+
if (node.type === AST_NODE_TYPES.SpreadElement) {
|
|
270
|
+
const chunk = getNestedIdentifiers(node.argument);
|
|
271
|
+
identifiers.push(...chunk);
|
|
272
|
+
}
|
|
273
|
+
if (node.type === AST_NODE_TYPES.MemberExpression) {
|
|
274
|
+
const chunk = getNestedIdentifiers(node.object);
|
|
275
|
+
identifiers.push(...chunk);
|
|
276
|
+
}
|
|
277
|
+
if (node.type === AST_NODE_TYPES.UnaryExpression) {
|
|
278
|
+
const chunk = getNestedIdentifiers(node.argument);
|
|
279
|
+
identifiers.push(...chunk);
|
|
280
|
+
}
|
|
281
|
+
if (node.type === AST_NODE_TYPES.ChainExpression) {
|
|
282
|
+
const chunk = getNestedIdentifiers(node.expression);
|
|
283
|
+
identifiers.push(...chunk);
|
|
284
|
+
}
|
|
285
|
+
if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
|
|
286
|
+
const chunk = getNestedIdentifiers(node.expression);
|
|
287
|
+
identifiers.push(...chunk);
|
|
288
|
+
}
|
|
289
|
+
if (node.type === AST_NODE_TYPES.TSAsExpression) {
|
|
290
|
+
const chunk = getNestedIdentifiers(node.expression);
|
|
291
|
+
identifiers.push(...chunk);
|
|
292
|
+
}
|
|
293
|
+
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
294
|
+
const chunk = getNestedIdentifiers(node.expression);
|
|
295
|
+
identifiers.push(...chunk);
|
|
296
|
+
}
|
|
297
|
+
return identifiers;
|
|
277
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Gets the nested return statements in the node that are within the same function
|
|
301
|
+
* @param node The AST node
|
|
302
|
+
* @returns The nested return statements in the node
|
|
303
|
+
*/
|
|
278
304
|
function getNestedReturnStatements(node) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
statements.push(node2);
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
return statements;
|
|
305
|
+
const statements = [];
|
|
306
|
+
const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
307
|
+
simpleTraverse(node, { enter(node$1) {
|
|
308
|
+
if (node$1.type !== AST_NODE_TYPES.ReturnStatement) return;
|
|
309
|
+
const parentFunction = findParentNode(node$1, isFunction);
|
|
310
|
+
if (parentFunction !== boundaryNode) return;
|
|
311
|
+
statements.push(node$1);
|
|
312
|
+
} });
|
|
313
|
+
return statements;
|
|
294
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Get all nested expressions of type T in an expression like node
|
|
317
|
+
* @param type The type of the expression to retrieve within the node
|
|
318
|
+
* @returns A partially applied function bound to a predicate of type T. The returned function can be called passing a
|
|
319
|
+
* node, and it will return an array of all nested expressions of type T.
|
|
320
|
+
*/
|
|
295
321
|
function getNestedExpressionsOfType(type) {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
return expressions;
|
|
376
|
-
};
|
|
322
|
+
const isNodeOfType = is(type);
|
|
323
|
+
return function(node) {
|
|
324
|
+
const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
|
|
325
|
+
const expressions = [];
|
|
326
|
+
if (isNodeOfType(node)) expressions.push(node);
|
|
327
|
+
if ("arguments" in node) {
|
|
328
|
+
const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
|
|
329
|
+
expressions.push(...chunk);
|
|
330
|
+
}
|
|
331
|
+
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
332
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
333
|
+
expressions.push(...chunk);
|
|
334
|
+
}
|
|
335
|
+
if ("left" in node) {
|
|
336
|
+
const chunk = boundGetNestedExpressionsOfType(node.left);
|
|
337
|
+
expressions.push(...chunk);
|
|
338
|
+
}
|
|
339
|
+
if ("right" in node) {
|
|
340
|
+
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
341
|
+
expressions.push(...chunk);
|
|
342
|
+
}
|
|
343
|
+
if ("test" in node && node.test != null) {
|
|
344
|
+
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
345
|
+
expressions.push(...chunk);
|
|
346
|
+
}
|
|
347
|
+
if ("consequent" in node) {
|
|
348
|
+
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
349
|
+
expressions.push(...chunk);
|
|
350
|
+
}
|
|
351
|
+
if ("alternate" in node && node.alternate != null) {
|
|
352
|
+
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
353
|
+
expressions.push(...chunk);
|
|
354
|
+
}
|
|
355
|
+
if ("elements" in node) {
|
|
356
|
+
const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
|
|
357
|
+
expressions.push(...chunk);
|
|
358
|
+
}
|
|
359
|
+
if ("properties" in node) {
|
|
360
|
+
const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
|
|
361
|
+
expressions.push(...chunk);
|
|
362
|
+
}
|
|
363
|
+
if ("expressions" in node) {
|
|
364
|
+
const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
|
|
365
|
+
expressions.push(...chunk);
|
|
366
|
+
}
|
|
367
|
+
if (node.type === AST_NODE_TYPES.Property) {
|
|
368
|
+
const chunk = boundGetNestedExpressionsOfType(node.value);
|
|
369
|
+
expressions.push(...chunk);
|
|
370
|
+
}
|
|
371
|
+
if (node.type === AST_NODE_TYPES.SpreadElement) {
|
|
372
|
+
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
373
|
+
expressions.push(...chunk);
|
|
374
|
+
}
|
|
375
|
+
if (node.type === AST_NODE_TYPES.MemberExpression) {
|
|
376
|
+
const chunk = boundGetNestedExpressionsOfType(node.object);
|
|
377
|
+
expressions.push(...chunk);
|
|
378
|
+
}
|
|
379
|
+
if (node.type === AST_NODE_TYPES.UnaryExpression) {
|
|
380
|
+
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
381
|
+
expressions.push(...chunk);
|
|
382
|
+
}
|
|
383
|
+
if (node.type === AST_NODE_TYPES.ChainExpression) {
|
|
384
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
385
|
+
expressions.push(...chunk);
|
|
386
|
+
}
|
|
387
|
+
if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
|
|
388
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
389
|
+
expressions.push(...chunk);
|
|
390
|
+
}
|
|
391
|
+
if (node.type === AST_NODE_TYPES.TSAsExpression) {
|
|
392
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
393
|
+
expressions.push(...chunk);
|
|
394
|
+
}
|
|
395
|
+
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
396
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
397
|
+
expressions.push(...chunk);
|
|
398
|
+
}
|
|
399
|
+
return expressions;
|
|
400
|
+
};
|
|
377
401
|
}
|
|
378
|
-
|
|
379
|
-
|
|
402
|
+
/**
|
|
403
|
+
* Get all nested new expressions in an expression like node
|
|
404
|
+
* @param node The node to get the nested new expressions from
|
|
405
|
+
* @returns All nested new expressions
|
|
406
|
+
*/
|
|
407
|
+
const getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExpression);
|
|
408
|
+
/**
|
|
409
|
+
* Get all nested call expressions in a expression like node
|
|
410
|
+
* @param node The node to get the nested call expressions from
|
|
411
|
+
* @returns All nested call expressions
|
|
412
|
+
*/
|
|
413
|
+
const getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
|
|
414
|
+
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/ast-line.ts
|
|
417
|
+
/**
|
|
418
|
+
* Check if a node is multiline
|
|
419
|
+
* @param node The AST node to check
|
|
420
|
+
* @returns `true` if the node is multiline
|
|
421
|
+
*/
|
|
380
422
|
function isMultiLine(node) {
|
|
381
|
-
|
|
423
|
+
return node.loc.start.line !== node.loc.end.line;
|
|
382
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Check if a node is a line break
|
|
427
|
+
* @param node The AST node to check
|
|
428
|
+
* @returns boolean
|
|
429
|
+
*/
|
|
383
430
|
function isLineBreak(node) {
|
|
384
|
-
|
|
431
|
+
return isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
|
|
385
432
|
}
|
|
433
|
+
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region src/ast-literal-is.ts
|
|
386
436
|
function isLiteral(node, type) {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
case "regexp":
|
|
397
|
-
return "regex" in node;
|
|
398
|
-
case "string":
|
|
399
|
-
return typeof node.value === "string";
|
|
400
|
-
}
|
|
437
|
+
if (node.type !== AST_NODE_TYPES.Literal) return false;
|
|
438
|
+
if (type == null) return true;
|
|
439
|
+
switch (type) {
|
|
440
|
+
case "boolean": return typeof node.value === "boolean";
|
|
441
|
+
case "null": return node.value === null;
|
|
442
|
+
case "number": return typeof node.value === "number";
|
|
443
|
+
case "regexp": return "regex" in node;
|
|
444
|
+
case "string": return typeof node.value === "string";
|
|
445
|
+
}
|
|
401
446
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
return false;
|
|
441
|
-
}
|
|
442
|
-
if (a.value == null || b.value == null) {
|
|
443
|
-
return a.value === b.value;
|
|
444
|
-
}
|
|
445
|
-
return isNodeEqual(a.value, b.value);
|
|
446
|
-
}
|
|
447
|
-
case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression):
|
|
448
|
-
return true;
|
|
449
|
-
default:
|
|
450
|
-
return false;
|
|
451
|
-
}
|
|
447
|
+
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region src/ast-node-equal.ts
|
|
450
|
+
/**
|
|
451
|
+
* Determines whether node equals to another node
|
|
452
|
+
* @param a node to compare
|
|
453
|
+
* @param b node to compare
|
|
454
|
+
* @returns `true` if node equal
|
|
455
|
+
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
|
|
456
|
+
*/
|
|
457
|
+
const isNodeEqual = dual(2, (a, b) => {
|
|
458
|
+
switch (true) {
|
|
459
|
+
case a === b: return true;
|
|
460
|
+
case a.type !== b.type: return false;
|
|
461
|
+
case a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal: return a.value === b.value;
|
|
462
|
+
case a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement: return a.value.raw === b.value.raw;
|
|
463
|
+
case a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral: {
|
|
464
|
+
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
|
|
465
|
+
let i = a.quasis.length;
|
|
466
|
+
while (i--) if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) return false;
|
|
467
|
+
i = a.expressions.length;
|
|
468
|
+
while (i--) {
|
|
469
|
+
const exprA = a.expressions[i];
|
|
470
|
+
const exprB = b.expressions[i];
|
|
471
|
+
if (!isNodeEqual(exprA, exprB)) return false;
|
|
472
|
+
}
|
|
473
|
+
return true;
|
|
474
|
+
}
|
|
475
|
+
case a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier: return a.name === b.name;
|
|
476
|
+
case a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier: return a.name === b.name;
|
|
477
|
+
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
|
|
478
|
+
case a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute:
|
|
479
|
+
if (a.name.name !== b.name.name) return false;
|
|
480
|
+
if (a.value == null || b.value == null) return a.value === b.value;
|
|
481
|
+
return isNodeEqual(a.value, b.value);
|
|
482
|
+
case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression: return true;
|
|
483
|
+
default: return false;
|
|
484
|
+
}
|
|
452
485
|
});
|
|
486
|
+
|
|
487
|
+
//#endregion
|
|
488
|
+
//#region src/ast-process-env-node-env.ts
|
|
489
|
+
/**
|
|
490
|
+
* Check if the given node is a member expression that accesses `process.env.NODE_ENV`
|
|
491
|
+
* @param node The AST node
|
|
492
|
+
* @returns True if the node is a member expression that accesses `process.env.NODE_ENV`, false otherwise
|
|
493
|
+
*/
|
|
453
494
|
function isProcessEnvNodeEnv(node) {
|
|
454
|
-
|
|
495
|
+
return node != null && node.type === AST_NODE_TYPES.MemberExpression && node.object.type === AST_NODE_TYPES.MemberExpression && node.object.object.type === AST_NODE_TYPES.Identifier && node.object.object.name === "process" && node.object.property.type === AST_NODE_TYPES.Identifier && node.object.property.name === "env" && node.property.type === AST_NODE_TYPES.Identifier && node.property.name === "NODE_ENV";
|
|
455
496
|
}
|
|
497
|
+
/**
|
|
498
|
+
* Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal
|
|
499
|
+
* @param node The AST node
|
|
500
|
+
* @param operator The operator used in the comparison
|
|
501
|
+
* @param value The string literal value to compare against
|
|
502
|
+
* @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise
|
|
503
|
+
*/
|
|
456
504
|
function isProcessEnvNodeEnvCompare(node, operator, value) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
if (isLiteral(node.left, "string") && isProcessEnvNodeEnv(node.right)) {
|
|
464
|
-
return node.left.value === value;
|
|
465
|
-
}
|
|
466
|
-
return false;
|
|
505
|
+
if (node == null) return false;
|
|
506
|
+
if (node.type !== AST_NODE_TYPES.BinaryExpression) return false;
|
|
507
|
+
if (node.operator !== operator) return false;
|
|
508
|
+
if (isProcessEnvNodeEnv(node.left) && isLiteral(node.right, "string")) return node.right.value === value;
|
|
509
|
+
if (isLiteral(node.left, "string") && isProcessEnvNodeEnv(node.right)) return node.left.value === value;
|
|
510
|
+
return false;
|
|
467
511
|
}
|
|
512
|
+
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/ast-property-name.ts
|
|
468
515
|
function getPropertyName(node) {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
if (node.type === AST_NODE_TYPES.Literal) {
|
|
476
|
-
return String(node.value);
|
|
477
|
-
}
|
|
478
|
-
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
479
|
-
return node.quasis[0]?.value.raw;
|
|
480
|
-
}
|
|
481
|
-
return unit;
|
|
516
|
+
if (isTypeExpression(node)) return getPropertyName(getJSExpression(node));
|
|
517
|
+
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) return node.name;
|
|
518
|
+
if (node.type === AST_NODE_TYPES.Literal) return String(node.value);
|
|
519
|
+
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) return node.quasis[0]?.value.raw;
|
|
520
|
+
return unit;
|
|
482
521
|
}
|
|
522
|
+
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region src/ast-to-string.ts
|
|
483
525
|
function getLiteralValueType(input) {
|
|
484
|
-
|
|
485
|
-
|
|
526
|
+
if (input === null) return "null";
|
|
527
|
+
return typeof input;
|
|
486
528
|
}
|
|
487
529
|
function toDelimiterCaseType(node, delimiter = " ") {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
if (isJSX(node)) {
|
|
495
|
-
return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
|
|
496
|
-
}
|
|
497
|
-
return toLowerCase(delimiterCase(node.type, delimiter));
|
|
530
|
+
if (node.type === AST_NODE_TYPES.Literal) {
|
|
531
|
+
if ("regex" in node) return "RegExp literal";
|
|
532
|
+
return `${getLiteralValueType(node.value)} literal`;
|
|
533
|
+
}
|
|
534
|
+
if (isJSX(node)) return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
|
|
535
|
+
return toLowerCase(delimiterCase(node.type, delimiter));
|
|
498
536
|
}
|
|
537
|
+
/**
|
|
538
|
+
* Returns human readable node name for given AST node
|
|
539
|
+
* @param node AST node
|
|
540
|
+
* @param getText A function that returns the text of the node in the source code
|
|
541
|
+
* @returns Human readable node name
|
|
542
|
+
*/
|
|
499
543
|
function toString(node, getText) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
return node.value;
|
|
512
|
-
case AST_NODE_TYPES.Literal:
|
|
513
|
-
return node.raw;
|
|
514
|
-
default:
|
|
515
|
-
return getText(node);
|
|
516
|
-
}
|
|
544
|
+
switch (node.type) {
|
|
545
|
+
case AST_NODE_TYPES.Identifier:
|
|
546
|
+
case AST_NODE_TYPES.JSXIdentifier:
|
|
547
|
+
case AST_NODE_TYPES.PrivateIdentifier: return node.name;
|
|
548
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
549
|
+
case AST_NODE_TYPES.JSXMemberExpression: return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
|
|
550
|
+
case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
|
|
551
|
+
case AST_NODE_TYPES.JSXText: return node.value;
|
|
552
|
+
case AST_NODE_TYPES.Literal: return node.raw;
|
|
553
|
+
default: return getText(node);
|
|
554
|
+
}
|
|
517
555
|
}
|
|
518
556
|
|
|
519
|
-
|
|
557
|
+
//#endregion
|
|
558
|
+
export { findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getJSExpression, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isClass, isEmptyFunction, isFunction, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpression, isTypeAssertionExpression, isTypeExpression, toDelimiterCaseType, toString };
|