@eslint-react/ast 2.0.0-next.0 → 2.0.0-next.10
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.ts +6 -1
- package/dist/index.js +207 -241
- package/package.json +8 -16
- package/dist/index.d.mts +0 -284
- package/dist/index.mjs +0 -589
package/dist/index.js
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var typescriptEstree = require('@typescript-eslint/typescript-estree');
|
|
7
|
-
var stringTs = require('string-ts');
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
2
|
+
import { or, dual, _ } from '@eslint-react/eff';
|
|
3
|
+
import { ASTUtils } from '@typescript-eslint/utils';
|
|
4
|
+
import { simpleTraverse } from '@typescript-eslint/typescript-estree';
|
|
5
|
+
import { toLowerCase, delimiterCase, replace } from 'string-ts';
|
|
8
6
|
|
|
9
7
|
// src/ast-array-method.ts
|
|
10
8
|
function isArrayFromCall(node, loose = true) {
|
|
11
|
-
if (node.type !==
|
|
12
|
-
if (node.callee.type !==
|
|
13
|
-
if (node.callee.property.type !==
|
|
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;
|
|
14
12
|
const name = node.callee.property.name;
|
|
15
13
|
return name === "from" || loose && name.startsWith("from");
|
|
16
14
|
}
|
|
17
15
|
function isArrayMapCall(node, loose = true) {
|
|
18
|
-
if (node.type !==
|
|
19
|
-
if (node.callee.type !==
|
|
20
|
-
if (node.callee.property.type !==
|
|
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;
|
|
21
19
|
const name = node.callee.property.name;
|
|
22
20
|
return name === "map" || loose && name.endsWith("Map");
|
|
23
21
|
}
|
|
@@ -40,155 +38,162 @@ var indexParamPosition = /* @__PURE__ */ new Map([
|
|
|
40
38
|
function getArrayMethodCallbackIndexParamPosition(methodName) {
|
|
41
39
|
return indexParamPosition.get(methodName) ?? -1;
|
|
42
40
|
}
|
|
41
|
+
function getArrayPatternElementNameAt(node, at) {
|
|
42
|
+
const { parent } = node;
|
|
43
|
+
if (!("id" in parent) || parent.id?.type !== AST_NODE_TYPES.ArrayPattern) return true;
|
|
44
|
+
const element = parent.id.elements[at];
|
|
45
|
+
if (element?.type !== AST_NODE_TYPES.Identifier) return _;
|
|
46
|
+
return element.name;
|
|
47
|
+
}
|
|
43
48
|
function getClassId(node) {
|
|
44
49
|
if (node.id != null) return node.id;
|
|
45
|
-
if (node.parent.type ===
|
|
50
|
+
if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) {
|
|
46
51
|
return node.parent.id;
|
|
47
52
|
}
|
|
48
|
-
return
|
|
53
|
+
return _;
|
|
49
54
|
}
|
|
50
|
-
var is =
|
|
51
|
-
var isOneOf =
|
|
55
|
+
var is = ASTUtils.isNodeOfType;
|
|
56
|
+
var isOneOf = ASTUtils.isNodeOfTypes;
|
|
52
57
|
var isFunction = isOneOf([
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
59
|
+
AST_NODE_TYPES.FunctionDeclaration,
|
|
60
|
+
AST_NODE_TYPES.FunctionExpression
|
|
56
61
|
]);
|
|
57
62
|
var isFunctionType = isOneOf([
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
64
|
+
AST_NODE_TYPES.FunctionDeclaration,
|
|
65
|
+
AST_NODE_TYPES.FunctionExpression,
|
|
66
|
+
AST_NODE_TYPES.TSCallSignatureDeclaration,
|
|
67
|
+
AST_NODE_TYPES.TSConstructSignatureDeclaration,
|
|
68
|
+
AST_NODE_TYPES.TSDeclareFunction,
|
|
69
|
+
AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
|
|
70
|
+
AST_NODE_TYPES.TSFunctionType,
|
|
71
|
+
AST_NODE_TYPES.TSMethodSignature
|
|
67
72
|
]);
|
|
68
|
-
var isClass = isOneOf([
|
|
73
|
+
var isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
|
|
69
74
|
var isMethodOrProperty = isOneOf([
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
AST_NODE_TYPES.PropertyDefinition,
|
|
76
|
+
AST_NODE_TYPES.MethodDefinition
|
|
72
77
|
]);
|
|
73
78
|
var isLoop = isOneOf([
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
AST_NODE_TYPES.DoWhileStatement,
|
|
80
|
+
AST_NODE_TYPES.ForInStatement,
|
|
81
|
+
AST_NODE_TYPES.ForOfStatement,
|
|
82
|
+
AST_NODE_TYPES.ForStatement,
|
|
83
|
+
AST_NODE_TYPES.WhileStatement
|
|
79
84
|
]);
|
|
80
|
-
var isControlFlow =
|
|
85
|
+
var isControlFlow = or(
|
|
81
86
|
isLoop,
|
|
82
87
|
isOneOf([
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
AST_NODE_TYPES.IfStatement,
|
|
89
|
+
AST_NODE_TYPES.SwitchStatement
|
|
85
90
|
])
|
|
86
91
|
);
|
|
87
|
-
var isConditional =
|
|
92
|
+
var isConditional = or(
|
|
88
93
|
isControlFlow,
|
|
89
94
|
isOneOf([
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
AST_NODE_TYPES.LogicalExpression,
|
|
96
|
+
AST_NODE_TYPES.ConditionalExpression
|
|
92
97
|
])
|
|
93
98
|
);
|
|
94
|
-
var isArrayTupleType = isOneOf([
|
|
99
|
+
var isArrayTupleType = isOneOf([AST_NODE_TYPES.TSArrayType, AST_NODE_TYPES.TSTupleType]);
|
|
95
100
|
var isProperty = isOneOf([
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
AST_NODE_TYPES.PropertyDefinition,
|
|
102
|
+
AST_NODE_TYPES.TSIndexSignature,
|
|
103
|
+
AST_NODE_TYPES.TSParameterProperty,
|
|
104
|
+
AST_NODE_TYPES.TSPropertySignature
|
|
100
105
|
]);
|
|
101
|
-
var isJSXElement = is(
|
|
102
|
-
var isJSXFragment = is(
|
|
106
|
+
var isJSXElement = is(AST_NODE_TYPES.JSXElement);
|
|
107
|
+
var isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
|
|
103
108
|
var isJSXTagNameExpression = isOneOf([
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
AST_NODE_TYPES.JSXIdentifier,
|
|
110
|
+
AST_NODE_TYPES.JSXMemberExpression,
|
|
111
|
+
AST_NODE_TYPES.JSXNamespacedName
|
|
107
112
|
]);
|
|
108
113
|
var isJSX = isOneOf([
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
AST_NODE_TYPES.JSXAttribute,
|
|
115
|
+
AST_NODE_TYPES.JSXClosingElement,
|
|
116
|
+
AST_NODE_TYPES.JSXClosingFragment,
|
|
117
|
+
AST_NODE_TYPES.JSXElement,
|
|
118
|
+
AST_NODE_TYPES.JSXEmptyExpression,
|
|
119
|
+
AST_NODE_TYPES.JSXExpressionContainer,
|
|
120
|
+
AST_NODE_TYPES.JSXFragment,
|
|
121
|
+
AST_NODE_TYPES.JSXIdentifier,
|
|
122
|
+
AST_NODE_TYPES.JSXMemberExpression,
|
|
123
|
+
AST_NODE_TYPES.JSXNamespacedName,
|
|
124
|
+
AST_NODE_TYPES.JSXOpeningElement,
|
|
125
|
+
AST_NODE_TYPES.JSXOpeningFragment,
|
|
126
|
+
AST_NODE_TYPES.JSXSpreadAttribute,
|
|
127
|
+
AST_NODE_TYPES.JSXSpreadChild,
|
|
128
|
+
AST_NODE_TYPES.JSXText
|
|
124
129
|
]);
|
|
125
130
|
var isDestructuringPattern = isOneOf([
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
AST_NODE_TYPES.ArrayPattern,
|
|
132
|
+
AST_NODE_TYPES.AssignmentPattern,
|
|
133
|
+
AST_NODE_TYPES.ObjectPattern,
|
|
134
|
+
AST_NODE_TYPES.RestElement
|
|
130
135
|
]);
|
|
131
136
|
var isTypeDeclaration = isOneOf([
|
|
132
|
-
|
|
133
|
-
|
|
137
|
+
AST_NODE_TYPES.TSInterfaceDeclaration,
|
|
138
|
+
AST_NODE_TYPES.TSTypeAliasDeclaration
|
|
134
139
|
]);
|
|
135
140
|
var isLeftHandSideExpression = isOneOf([
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
141
|
+
AST_NODE_TYPES.ArrayExpression,
|
|
142
|
+
AST_NODE_TYPES.ArrayPattern,
|
|
143
|
+
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
144
|
+
AST_NODE_TYPES.CallExpression,
|
|
145
|
+
AST_NODE_TYPES.ClassExpression,
|
|
146
|
+
AST_NODE_TYPES.FunctionExpression,
|
|
147
|
+
AST_NODE_TYPES.Identifier,
|
|
148
|
+
AST_NODE_TYPES.JSXElement,
|
|
149
|
+
AST_NODE_TYPES.JSXFragment,
|
|
150
|
+
AST_NODE_TYPES.Literal,
|
|
151
|
+
AST_NODE_TYPES.TemplateLiteral,
|
|
152
|
+
AST_NODE_TYPES.MemberExpression,
|
|
153
|
+
AST_NODE_TYPES.MetaProperty,
|
|
154
|
+
AST_NODE_TYPES.ObjectExpression,
|
|
155
|
+
AST_NODE_TYPES.ObjectPattern,
|
|
156
|
+
AST_NODE_TYPES.SequenceExpression,
|
|
157
|
+
AST_NODE_TYPES.Super,
|
|
158
|
+
AST_NODE_TYPES.TaggedTemplateExpression,
|
|
159
|
+
AST_NODE_TYPES.ThisExpression
|
|
155
160
|
]);
|
|
156
161
|
var isLeftHandSideExpressionType = isOneOf([
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
162
|
+
AST_NODE_TYPES.ArrayExpression,
|
|
163
|
+
AST_NODE_TYPES.ArrayPattern,
|
|
164
|
+
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
165
|
+
AST_NODE_TYPES.CallExpression,
|
|
166
|
+
AST_NODE_TYPES.ClassExpression,
|
|
167
|
+
AST_NODE_TYPES.FunctionExpression,
|
|
168
|
+
AST_NODE_TYPES.Identifier,
|
|
169
|
+
AST_NODE_TYPES.JSXElement,
|
|
170
|
+
AST_NODE_TYPES.JSXFragment,
|
|
171
|
+
AST_NODE_TYPES.Literal,
|
|
172
|
+
AST_NODE_TYPES.TemplateLiteral,
|
|
173
|
+
AST_NODE_TYPES.MemberExpression,
|
|
174
|
+
AST_NODE_TYPES.MetaProperty,
|
|
175
|
+
AST_NODE_TYPES.ObjectExpression,
|
|
176
|
+
AST_NODE_TYPES.ObjectPattern,
|
|
177
|
+
AST_NODE_TYPES.SequenceExpression,
|
|
178
|
+
AST_NODE_TYPES.Super,
|
|
179
|
+
AST_NODE_TYPES.TaggedTemplateExpression,
|
|
180
|
+
AST_NODE_TYPES.ThisExpression,
|
|
181
|
+
AST_NODE_TYPES.TSAsExpression,
|
|
182
|
+
AST_NODE_TYPES.TSNonNullExpression,
|
|
183
|
+
AST_NODE_TYPES.TSTypeAssertion
|
|
179
184
|
]);
|
|
180
185
|
var isTypeExpression = isOneOf([
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
+
AST_NODE_TYPES.TSAsExpression,
|
|
187
|
+
AST_NODE_TYPES.TSTypeAssertion,
|
|
188
|
+
AST_NODE_TYPES.TSNonNullExpression,
|
|
189
|
+
AST_NODE_TYPES.TSSatisfiesExpression,
|
|
190
|
+
AST_NODE_TYPES.TSInstantiationExpression
|
|
186
191
|
]);
|
|
187
192
|
var isTypeAssertionExpression = isOneOf([
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
AST_NODE_TYPES.TSAsExpression,
|
|
194
|
+
AST_NODE_TYPES.TSTypeAssertion,
|
|
195
|
+
AST_NODE_TYPES.TSNonNullExpression,
|
|
196
|
+
AST_NODE_TYPES.TSSatisfiesExpression
|
|
192
197
|
]);
|
|
193
198
|
|
|
194
199
|
// src/ast-expression.ts
|
|
@@ -199,7 +204,7 @@ function getJSExpression(node) {
|
|
|
199
204
|
return node;
|
|
200
205
|
}
|
|
201
206
|
function isThisExpression(node) {
|
|
202
|
-
return getJSExpression(node).type ===
|
|
207
|
+
return getJSExpression(node).type === AST_NODE_TYPES.ThisExpression;
|
|
203
208
|
}
|
|
204
209
|
function getFunctionId(node) {
|
|
205
210
|
switch (true) {
|
|
@@ -207,24 +212,24 @@ function getFunctionId(node) {
|
|
|
207
212
|
case ("id" in node && node.id != null):
|
|
208
213
|
return node.id;
|
|
209
214
|
// const whatever = function MaybeComponent() {};
|
|
210
|
-
case (node.parent.type ===
|
|
215
|
+
case (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === AST_NODE_TYPES.Identifier):
|
|
211
216
|
return node.parent.id;
|
|
212
217
|
// MaybeComponent = () => {};
|
|
213
|
-
case (node.parent.type ===
|
|
218
|
+
case (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === AST_NODE_TYPES.Identifier):
|
|
214
219
|
return node.parent.left;
|
|
215
220
|
// {MaybeComponent: () => {}}
|
|
216
221
|
// {MaybeComponent() {}}
|
|
217
|
-
case (node.parent.type ===
|
|
222
|
+
case (node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === AST_NODE_TYPES.Identifier):
|
|
218
223
|
return node.parent.key;
|
|
219
224
|
// class {MaybeComponent = () => {}}
|
|
220
225
|
// class {MaybeComponent() {}}
|
|
221
|
-
case (isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type ===
|
|
226
|
+
case (isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier):
|
|
222
227
|
return node.parent.key;
|
|
223
228
|
// Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
|
|
224
229
|
//
|
|
225
230
|
// const {MaybeComponent = () => {}} = {};
|
|
226
231
|
// ({MaybeComponent = () => {}} = {});
|
|
227
|
-
case (node.parent.type ===
|
|
232
|
+
case (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier):
|
|
228
233
|
return node.parent.left;
|
|
229
234
|
// const MaybeComponent = (() => {})!;
|
|
230
235
|
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
@@ -232,38 +237,38 @@ function getFunctionId(node) {
|
|
|
232
237
|
case isTypeAssertionExpression(node.parent):
|
|
233
238
|
return getFunctionId(node.parent);
|
|
234
239
|
}
|
|
235
|
-
return
|
|
240
|
+
return _;
|
|
236
241
|
}
|
|
237
242
|
function getFunctionInitPath(node) {
|
|
238
|
-
if (node.type ===
|
|
243
|
+
if (node.type === AST_NODE_TYPES.FunctionDeclaration) {
|
|
239
244
|
return [node];
|
|
240
245
|
}
|
|
241
246
|
const { parent } = node;
|
|
242
247
|
switch (true) {
|
|
243
|
-
case parent.type ===
|
|
248
|
+
case parent.type === AST_NODE_TYPES.VariableDeclarator:
|
|
244
249
|
return [parent.parent, parent, node];
|
|
245
|
-
case (parent.type ===
|
|
250
|
+
case (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
|
|
246
251
|
return [parent.parent.parent, parent.parent, parent, node];
|
|
247
|
-
case (parent.type ===
|
|
252
|
+
case (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.CallExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
|
|
248
253
|
return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
|
|
249
|
-
case (parent.type ===
|
|
254
|
+
case (parent.type === AST_NODE_TYPES.Property && parent.parent.type === AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
|
|
250
255
|
return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
|
|
251
|
-
case (parent.type ===
|
|
256
|
+
case (parent.type === AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
|
|
252
257
|
return [parent.parent.parent, parent.parent, parent, node];
|
|
253
|
-
case (parent.type ===
|
|
258
|
+
case (parent.type === AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
|
|
254
259
|
return [parent.parent.parent, parent.parent, parent, node];
|
|
255
260
|
}
|
|
256
|
-
return
|
|
261
|
+
return _;
|
|
257
262
|
}
|
|
258
263
|
function hasCallInFunctionInitPath(callName, initPath) {
|
|
259
264
|
return initPath.some((n) => {
|
|
260
|
-
if (n.type !==
|
|
265
|
+
if (n.type !== AST_NODE_TYPES.CallExpression) {
|
|
261
266
|
return false;
|
|
262
267
|
}
|
|
263
268
|
switch (n.callee.type) {
|
|
264
|
-
case
|
|
269
|
+
case AST_NODE_TYPES.Identifier:
|
|
265
270
|
return n.callee.name === callName;
|
|
266
|
-
case
|
|
271
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
267
272
|
return "name" in n.callee.property && n.callee.property.name === callName;
|
|
268
273
|
default:
|
|
269
274
|
return false;
|
|
@@ -271,22 +276,25 @@ function hasCallInFunctionInitPath(callName, initPath) {
|
|
|
271
276
|
});
|
|
272
277
|
}
|
|
273
278
|
function isEmptyFunction(node) {
|
|
274
|
-
return node.body.type ===
|
|
279
|
+
return node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
|
|
280
|
+
}
|
|
281
|
+
function isImmediatelyInvokedFunction(node) {
|
|
282
|
+
return node.type !== AST_NODE_TYPES.FunctionDeclaration && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node;
|
|
275
283
|
}
|
|
276
284
|
function findParentNode(node, test) {
|
|
277
|
-
if (node == null) return
|
|
285
|
+
if (node == null) return _;
|
|
278
286
|
let parent = node.parent;
|
|
279
|
-
while (parent != null && parent.type !==
|
|
287
|
+
while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
|
|
280
288
|
if (test(parent)) {
|
|
281
289
|
return parent;
|
|
282
290
|
}
|
|
283
291
|
parent = parent.parent;
|
|
284
292
|
}
|
|
285
|
-
return
|
|
293
|
+
return _;
|
|
286
294
|
}
|
|
287
295
|
function getNestedIdentifiers(node) {
|
|
288
296
|
const identifiers = [];
|
|
289
|
-
if (node.type ===
|
|
297
|
+
if (node.type === AST_NODE_TYPES.Identifier) {
|
|
290
298
|
identifiers.push(node);
|
|
291
299
|
}
|
|
292
300
|
if ("arguments" in node) {
|
|
@@ -313,35 +321,35 @@ function getNestedIdentifiers(node) {
|
|
|
313
321
|
const chunk = getNestedIdentifiers(node.right);
|
|
314
322
|
identifiers.push(...chunk);
|
|
315
323
|
}
|
|
316
|
-
if (node.type ===
|
|
324
|
+
if (node.type === AST_NODE_TYPES.Property) {
|
|
317
325
|
const chunk = getNestedIdentifiers(node.value);
|
|
318
326
|
identifiers.push(...chunk);
|
|
319
327
|
}
|
|
320
|
-
if (node.type ===
|
|
328
|
+
if (node.type === AST_NODE_TYPES.SpreadElement) {
|
|
321
329
|
const chunk = getNestedIdentifiers(node.argument);
|
|
322
330
|
identifiers.push(...chunk);
|
|
323
331
|
}
|
|
324
|
-
if (node.type ===
|
|
332
|
+
if (node.type === AST_NODE_TYPES.MemberExpression) {
|
|
325
333
|
const chunk = getNestedIdentifiers(node.object);
|
|
326
334
|
identifiers.push(...chunk);
|
|
327
335
|
}
|
|
328
|
-
if (node.type ===
|
|
336
|
+
if (node.type === AST_NODE_TYPES.UnaryExpression) {
|
|
329
337
|
const chunk = getNestedIdentifiers(node.argument);
|
|
330
338
|
identifiers.push(...chunk);
|
|
331
339
|
}
|
|
332
|
-
if (node.type ===
|
|
340
|
+
if (node.type === AST_NODE_TYPES.ChainExpression) {
|
|
333
341
|
const chunk = getNestedIdentifiers(node.expression);
|
|
334
342
|
identifiers.push(...chunk);
|
|
335
343
|
}
|
|
336
|
-
if (node.type ===
|
|
344
|
+
if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
|
|
337
345
|
const chunk = getNestedIdentifiers(node.expression);
|
|
338
346
|
identifiers.push(...chunk);
|
|
339
347
|
}
|
|
340
|
-
if (node.type ===
|
|
348
|
+
if (node.type === AST_NODE_TYPES.TSAsExpression) {
|
|
341
349
|
const chunk = getNestedIdentifiers(node.expression);
|
|
342
350
|
identifiers.push(...chunk);
|
|
343
351
|
}
|
|
344
|
-
if (node.type ===
|
|
352
|
+
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
345
353
|
const chunk = getNestedIdentifiers(node.expression);
|
|
346
354
|
identifiers.push(...chunk);
|
|
347
355
|
}
|
|
@@ -350,9 +358,9 @@ function getNestedIdentifiers(node) {
|
|
|
350
358
|
function getNestedReturnStatements(node) {
|
|
351
359
|
const statements = [];
|
|
352
360
|
const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
353
|
-
|
|
361
|
+
simpleTraverse(node, {
|
|
354
362
|
enter(node2) {
|
|
355
|
-
if (node2.type !==
|
|
363
|
+
if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
|
|
356
364
|
return;
|
|
357
365
|
}
|
|
358
366
|
const parentFunction = findParentNode(node2, isFunction);
|
|
@@ -412,51 +420,51 @@ function getNestedExpressionsOfType(type) {
|
|
|
412
420
|
const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
|
|
413
421
|
expressions.push(...chunk);
|
|
414
422
|
}
|
|
415
|
-
if (node.type ===
|
|
423
|
+
if (node.type === AST_NODE_TYPES.Property) {
|
|
416
424
|
const chunk = boundGetNestedExpressionsOfType(node.value);
|
|
417
425
|
expressions.push(...chunk);
|
|
418
426
|
}
|
|
419
|
-
if (node.type ===
|
|
427
|
+
if (node.type === AST_NODE_TYPES.SpreadElement) {
|
|
420
428
|
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
421
429
|
expressions.push(...chunk);
|
|
422
430
|
}
|
|
423
|
-
if (node.type ===
|
|
431
|
+
if (node.type === AST_NODE_TYPES.MemberExpression) {
|
|
424
432
|
const chunk = boundGetNestedExpressionsOfType(node.object);
|
|
425
433
|
expressions.push(...chunk);
|
|
426
434
|
}
|
|
427
|
-
if (node.type ===
|
|
435
|
+
if (node.type === AST_NODE_TYPES.UnaryExpression) {
|
|
428
436
|
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
429
437
|
expressions.push(...chunk);
|
|
430
438
|
}
|
|
431
|
-
if (node.type ===
|
|
439
|
+
if (node.type === AST_NODE_TYPES.ChainExpression) {
|
|
432
440
|
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
433
441
|
expressions.push(...chunk);
|
|
434
442
|
}
|
|
435
|
-
if (node.type ===
|
|
443
|
+
if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
|
|
436
444
|
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
437
445
|
expressions.push(...chunk);
|
|
438
446
|
}
|
|
439
|
-
if (node.type ===
|
|
447
|
+
if (node.type === AST_NODE_TYPES.TSAsExpression) {
|
|
440
448
|
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
441
449
|
expressions.push(...chunk);
|
|
442
450
|
}
|
|
443
|
-
if (node.type ===
|
|
451
|
+
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
444
452
|
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
445
453
|
expressions.push(...chunk);
|
|
446
454
|
}
|
|
447
455
|
return expressions;
|
|
448
456
|
};
|
|
449
457
|
}
|
|
450
|
-
var getNestedNewExpressions = getNestedExpressionsOfType(
|
|
451
|
-
var getNestedCallExpressions = getNestedExpressionsOfType(
|
|
458
|
+
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExpression);
|
|
459
|
+
var getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
|
|
452
460
|
function isMultiLine(node) {
|
|
453
461
|
return node.loc.start.line !== node.loc.end.line;
|
|
454
462
|
}
|
|
455
463
|
function isLineBreak(node) {
|
|
456
|
-
return isOneOf([
|
|
464
|
+
return isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
|
|
457
465
|
}
|
|
458
466
|
function isLiteral(node, type) {
|
|
459
|
-
if (node.type !==
|
|
467
|
+
if (node.type !== AST_NODE_TYPES.Literal) return false;
|
|
460
468
|
if (type == null) return true;
|
|
461
469
|
switch (type) {
|
|
462
470
|
case "boolean":
|
|
@@ -471,17 +479,17 @@ function isLiteral(node, type) {
|
|
|
471
479
|
return typeof node.value === "string";
|
|
472
480
|
}
|
|
473
481
|
}
|
|
474
|
-
var isNodeEqual =
|
|
482
|
+
var isNodeEqual = dual(2, (a, b) => {
|
|
475
483
|
switch (true) {
|
|
476
484
|
case a === b:
|
|
477
485
|
return true;
|
|
478
486
|
case a.type !== b.type:
|
|
479
487
|
return false;
|
|
480
|
-
case (a.type ===
|
|
488
|
+
case (a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal):
|
|
481
489
|
return a.value === b.value;
|
|
482
|
-
case (a.type ===
|
|
490
|
+
case (a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement):
|
|
483
491
|
return a.value.raw === b.value.raw;
|
|
484
|
-
case (a.type ===
|
|
492
|
+
case (a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral): {
|
|
485
493
|
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) {
|
|
486
494
|
return false;
|
|
487
495
|
}
|
|
@@ -501,13 +509,13 @@ var isNodeEqual = eff.dual(2, (a, b) => {
|
|
|
501
509
|
}
|
|
502
510
|
return true;
|
|
503
511
|
}
|
|
504
|
-
case (a.type ===
|
|
512
|
+
case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier):
|
|
505
513
|
return a.name === b.name;
|
|
506
|
-
case (a.type ===
|
|
514
|
+
case (a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier):
|
|
507
515
|
return a.name === b.name;
|
|
508
|
-
case (a.type ===
|
|
516
|
+
case (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression):
|
|
509
517
|
return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
|
|
510
|
-
case (a.type ===
|
|
518
|
+
case (a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute): {
|
|
511
519
|
if (a.name.name !== b.name.name) {
|
|
512
520
|
return false;
|
|
513
521
|
}
|
|
@@ -516,18 +524,18 @@ var isNodeEqual = eff.dual(2, (a, b) => {
|
|
|
516
524
|
}
|
|
517
525
|
return isNodeEqual(a.value, b.value);
|
|
518
526
|
}
|
|
519
|
-
case (a.type ===
|
|
527
|
+
case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression):
|
|
520
528
|
return true;
|
|
521
529
|
default:
|
|
522
530
|
return false;
|
|
523
531
|
}
|
|
524
532
|
});
|
|
525
533
|
function isProcessEnvNodeEnv(node) {
|
|
526
|
-
return node != null && node.type ===
|
|
534
|
+
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";
|
|
527
535
|
}
|
|
528
536
|
function isProcessEnvNodeEnvCompare(node, operator, value) {
|
|
529
537
|
if (node == null) return false;
|
|
530
|
-
if (node.type !==
|
|
538
|
+
if (node.type !== AST_NODE_TYPES.BinaryExpression) return false;
|
|
531
539
|
if (node.operator !== operator) return false;
|
|
532
540
|
if (isProcessEnvNodeEnv(node.left) && isLiteral(node.right, "string")) {
|
|
533
541
|
return node.right.value === value;
|
|
@@ -541,96 +549,54 @@ function getPropertyName(node) {
|
|
|
541
549
|
if (isTypeExpression(node)) {
|
|
542
550
|
return getPropertyName(getJSExpression(node));
|
|
543
551
|
}
|
|
544
|
-
if (node.type ===
|
|
552
|
+
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
545
553
|
return node.name;
|
|
546
554
|
}
|
|
547
|
-
if (node.type ===
|
|
555
|
+
if (node.type === AST_NODE_TYPES.Literal) {
|
|
548
556
|
return String(node.value);
|
|
549
557
|
}
|
|
550
|
-
if (node.type ===
|
|
558
|
+
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
551
559
|
return node.quasis[0]?.value.raw;
|
|
552
560
|
}
|
|
553
|
-
return
|
|
561
|
+
return _;
|
|
562
|
+
}
|
|
563
|
+
function isThenCall(node) {
|
|
564
|
+
return node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "then";
|
|
554
565
|
}
|
|
555
566
|
function getLiteralValueType(input) {
|
|
556
567
|
if (input === null) return "null";
|
|
557
568
|
return typeof input;
|
|
558
569
|
}
|
|
559
570
|
function toDelimiterCaseType(node, delimiter = " ") {
|
|
560
|
-
if (node.type ===
|
|
571
|
+
if (node.type === AST_NODE_TYPES.Literal) {
|
|
561
572
|
if ("regex" in node) {
|
|
562
573
|
return "RegExp literal";
|
|
563
574
|
}
|
|
564
575
|
return `${getLiteralValueType(node.value)} literal`;
|
|
565
576
|
}
|
|
566
577
|
if (isJSX(node)) {
|
|
567
|
-
return `JSX ${
|
|
578
|
+
return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
|
|
568
579
|
}
|
|
569
|
-
return
|
|
580
|
+
return toLowerCase(delimiterCase(node.type, delimiter));
|
|
570
581
|
}
|
|
571
582
|
function toString(node, getText) {
|
|
572
583
|
switch (node.type) {
|
|
573
|
-
case
|
|
574
|
-
case
|
|
575
|
-
case
|
|
584
|
+
case AST_NODE_TYPES.Identifier:
|
|
585
|
+
case AST_NODE_TYPES.JSXIdentifier:
|
|
586
|
+
case AST_NODE_TYPES.PrivateIdentifier:
|
|
576
587
|
return node.name;
|
|
577
|
-
case
|
|
578
|
-
case
|
|
588
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
589
|
+
case AST_NODE_TYPES.JSXMemberExpression:
|
|
579
590
|
return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
|
|
580
|
-
case
|
|
591
|
+
case AST_NODE_TYPES.JSXNamespacedName:
|
|
581
592
|
return `${node.namespace.name}:${node.name.name}`;
|
|
582
|
-
case
|
|
593
|
+
case AST_NODE_TYPES.JSXText:
|
|
583
594
|
return node.value;
|
|
584
|
-
case
|
|
595
|
+
case AST_NODE_TYPES.Literal:
|
|
585
596
|
return node.raw;
|
|
586
597
|
default:
|
|
587
598
|
return getText(node);
|
|
588
599
|
}
|
|
589
600
|
}
|
|
590
601
|
|
|
591
|
-
|
|
592
|
-
exports.getArrayMethodCallbackIndexParamPosition = getArrayMethodCallbackIndexParamPosition;
|
|
593
|
-
exports.getClassId = getClassId;
|
|
594
|
-
exports.getFunctionId = getFunctionId;
|
|
595
|
-
exports.getFunctionInitPath = getFunctionInitPath;
|
|
596
|
-
exports.getJSExpression = getJSExpression;
|
|
597
|
-
exports.getNestedCallExpressions = getNestedCallExpressions;
|
|
598
|
-
exports.getNestedExpressionsOfType = getNestedExpressionsOfType;
|
|
599
|
-
exports.getNestedIdentifiers = getNestedIdentifiers;
|
|
600
|
-
exports.getNestedNewExpressions = getNestedNewExpressions;
|
|
601
|
-
exports.getNestedReturnStatements = getNestedReturnStatements;
|
|
602
|
-
exports.getPropertyName = getPropertyName;
|
|
603
|
-
exports.hasCallInFunctionInitPath = hasCallInFunctionInitPath;
|
|
604
|
-
exports.is = is;
|
|
605
|
-
exports.isArrayFromCall = isArrayFromCall;
|
|
606
|
-
exports.isArrayMapCall = isArrayMapCall;
|
|
607
|
-
exports.isArrayTupleType = isArrayTupleType;
|
|
608
|
-
exports.isClass = isClass;
|
|
609
|
-
exports.isConditional = isConditional;
|
|
610
|
-
exports.isControlFlow = isControlFlow;
|
|
611
|
-
exports.isDestructuringPattern = isDestructuringPattern;
|
|
612
|
-
exports.isEmptyFunction = isEmptyFunction;
|
|
613
|
-
exports.isFunction = isFunction;
|
|
614
|
-
exports.isFunctionType = isFunctionType;
|
|
615
|
-
exports.isJSX = isJSX;
|
|
616
|
-
exports.isJSXElement = isJSXElement;
|
|
617
|
-
exports.isJSXFragment = isJSXFragment;
|
|
618
|
-
exports.isJSXTagNameExpression = isJSXTagNameExpression;
|
|
619
|
-
exports.isLeftHandSideExpression = isLeftHandSideExpression;
|
|
620
|
-
exports.isLeftHandSideExpressionType = isLeftHandSideExpressionType;
|
|
621
|
-
exports.isLineBreak = isLineBreak;
|
|
622
|
-
exports.isLiteral = isLiteral;
|
|
623
|
-
exports.isLoop = isLoop;
|
|
624
|
-
exports.isMethodOrProperty = isMethodOrProperty;
|
|
625
|
-
exports.isMultiLine = isMultiLine;
|
|
626
|
-
exports.isNodeEqual = isNodeEqual;
|
|
627
|
-
exports.isOneOf = isOneOf;
|
|
628
|
-
exports.isProcessEnvNodeEnv = isProcessEnvNodeEnv;
|
|
629
|
-
exports.isProcessEnvNodeEnvCompare = isProcessEnvNodeEnvCompare;
|
|
630
|
-
exports.isProperty = isProperty;
|
|
631
|
-
exports.isThisExpression = isThisExpression;
|
|
632
|
-
exports.isTypeAssertionExpression = isTypeAssertionExpression;
|
|
633
|
-
exports.isTypeDeclaration = isTypeDeclaration;
|
|
634
|
-
exports.isTypeExpression = isTypeExpression;
|
|
635
|
-
exports.toDelimiterCaseType = toDelimiterCaseType;
|
|
636
|
-
exports.toString = toString;
|
|
602
|
+
export { findParentNode, getArrayMethodCallbackIndexParamPosition, getArrayPatternElementNameAt, getClassId, getFunctionId, getFunctionInitPath, getJSExpression, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isImmediatelyInvokedFunction, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeDeclaration, isTypeExpression, toDelimiterCaseType, toString };
|